react-mention-input 1.1.6 → 1.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,75 +1,75 @@
1
- .message-card-container {
2
- display: flex;
3
- flex-direction: column;
4
- gap: 16px; /* Space between cards */
5
- }
6
-
7
- .message-card {
8
- display: flex;
9
- flex-direction: column;
10
- border: 1px solid #ccc;
11
- border-radius: 8px;
12
- padding: 16px;
13
- background-color: #fff;
14
- transition: box-shadow 0.2s;
15
- }
16
-
17
- .message-card:hover {
18
- box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
19
- }
20
-
21
- .message-card-header {
22
- display: flex;
23
- align-items: center;
24
- margin-bottom: 8px; /* Space between header and body */
25
- }
26
-
27
- .message-card-img,
28
- .message-card-initials {
29
- width: 48px;
30
- height: 48px;
31
- border-radius: 50%;
32
- display: flex;
33
- align-items: center;
34
- justify-content: center;
35
- font-size: 16px;
36
- font-weight: bold;
37
- color: #fff;
38
- background-color: #007bff;
39
- text-transform: uppercase;
40
- margin-right: 16px;
41
- }
42
- .message-card-info {
43
- display: flex;
44
- flex-direction: column;
45
- }
46
-
47
- .message-card-name {
48
- margin: 0;
49
- font-size: 18px;
50
- font-weight: bold;
51
- line-height: 1.2; /* Adjust line height for better spacing */
52
- }
53
-
54
- .message-card-date {
55
- margin: 0;
56
- font-size: 14px;
57
- color: #888;
58
- line-height: 1.2; /* Adjust line height for better spacing */
59
- }
60
-
61
- .message-card-body {
62
- margin-top: 8px; /* Space between header and comment */
63
- }
64
-
65
- .message-card-comment {
66
- margin: 0;
67
- font-size: 16px;
68
- line-height: 1.5; /* Optimal line height for readability */
69
- }
70
- .mention-highlight {
71
- background-color: #e0f7fa;
72
- color: #007bff;
73
- padding: 2px 4px;
74
- border-radius: 4px;
1
+ .message-card-container {
2
+ display: flex;
3
+ flex-direction: column;
4
+ gap: 16px; /* Space between cards */
5
+ }
6
+
7
+ .message-card {
8
+ display: flex;
9
+ flex-direction: column;
10
+ border: 1px solid #ccc;
11
+ border-radius: 8px;
12
+ padding: 16px;
13
+ background-color: #fff;
14
+ transition: box-shadow 0.2s;
15
+ }
16
+
17
+ .message-card:hover {
18
+ box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
19
+ }
20
+
21
+ .message-card-header {
22
+ display: flex;
23
+ align-items: center;
24
+ margin-bottom: 8px; /* Space between header and body */
25
+ }
26
+
27
+ .message-card-img,
28
+ .message-card-initials {
29
+ width: 48px;
30
+ height: 48px;
31
+ border-radius: 50%;
32
+ display: flex;
33
+ align-items: center;
34
+ justify-content: center;
35
+ font-size: 16px;
36
+ font-weight: bold;
37
+ color: #fff;
38
+ background-color: #007bff;
39
+ text-transform: uppercase;
40
+ margin-right: 16px;
41
+ }
42
+ .message-card-info {
43
+ display: flex;
44
+ flex-direction: column;
45
+ }
46
+
47
+ .message-card-name {
48
+ margin: 0;
49
+ font-size: 18px;
50
+ font-weight: bold;
51
+ line-height: 1.2; /* Adjust line height for better spacing */
52
+ }
53
+
54
+ .message-card-date {
55
+ margin: 0;
56
+ font-size: 14px;
57
+ color: #888;
58
+ line-height: 1.2; /* Adjust line height for better spacing */
59
+ }
60
+
61
+ .message-card-body {
62
+ margin-top: 8px; /* Space between header and comment */
63
+ }
64
+
65
+ .message-card-comment {
66
+ margin: 0;
67
+ font-size: 16px;
68
+ line-height: 1.5; /* Optimal line height for readability */
69
+ }
70
+ .mention-highlight {
71
+ background-color: #e0f7fa;
72
+ color: #007bff;
73
+ padding: 2px 4px;
74
+ border-radius: 4px;
75
75
  }
@@ -1,167 +1,167 @@
1
- import React, { CSSProperties, useState, ReactNode } from "react";
2
- import "./ShowMessageCard.css";
3
-
4
- interface MessageCardProps {
5
- [key: string]: any; // Support dynamic keys
6
- }
7
-
8
- interface ShowMessageCardProps {
9
- data: MessageCardProps[];
10
- nameKey?: string; // Custom key for name
11
- dateKey?: string; // Custom key for date
12
- commentKey?: string; // Custom key for comment
13
- imgSrcKey?: string; // Custom key for image source
14
- containerClassName?: string; // Class for the outermost container
15
- containerStyle?: CSSProperties; // Style for the outermost container
16
- cardClassName?: string; // Class for the card
17
- cardStyle?: CSSProperties; // Style for the card
18
- headerClassName?: string; // Class for the card header
19
- headerStyle?: CSSProperties; // Style for the card header
20
- imgClassName?: string; // Class for the image
21
- imgStyle?: CSSProperties; // Style for the image
22
- infoClassName?: string; // Class for the user info container
23
- infoStyle?: CSSProperties; // Style for the user info container
24
- nameClassName?: string; // Class for the user name
25
- nameStyle?: CSSProperties; // Style for the user name
26
- dateClassName?: string; // Class for the date
27
- dateStyle?: CSSProperties; // Style for the date
28
- bodyClassName?: string; // Class for the card body
29
- bodyStyle?: CSSProperties; // Style for the card body
30
- commentClassName?: string; // Class for the comment text
31
- commentStyle?: CSSProperties; // Style for the comment text
32
- renderItem?: (element: MessageCardProps) => ReactNode; // Custom render function
33
- }
34
-
35
- export const ShowMessageCard: React.FC<ShowMessageCardProps> = ({
36
- data,
37
- nameKey = "name",
38
- dateKey = "date",
39
- commentKey = "comment",
40
- imgSrcKey = "imgSrc",
41
- containerClassName,
42
- containerStyle,
43
- cardClassName,
44
- cardStyle,
45
- headerClassName,
46
- headerStyle,
47
- imgClassName,
48
- imgStyle,
49
- infoClassName,
50
- infoStyle,
51
- nameClassName,
52
- nameStyle,
53
- dateClassName,
54
- dateStyle,
55
- bodyClassName,
56
- bodyStyle,
57
- commentClassName,
58
- commentStyle,
59
- renderItem, // Custom render function
60
- }) => {
61
- // State to manage initials for images that fail to load
62
- const [initialsState, setInitialsState] = useState<{ [key: string]: boolean }>(
63
- {}
64
- );
65
-
66
- // Handle image load failure
67
- const handleImageError = (id: string | number) => {
68
- setInitialsState((prevState) => ({
69
- ...prevState,
70
- [id]: true, // Show initials for the specific card
71
- }));
72
- };
73
-
74
- // Helper function to generate initials from the name
75
- const getInitials = (name: string) => {
76
- const nameParts = name.split(" ");
77
- const initials = nameParts
78
- .map((part) => part[0]?.toUpperCase() || "") // Take the first letter of each part
79
- .slice(0, 2) // Limit to 2 letters
80
- .join("");
81
- return initials;
82
- };
83
-
84
- return (
85
- <div
86
- className={`message-card-container ${containerClassName || ""}`}
87
- style={containerStyle}
88
- >
89
- {data.map((item, index) => {
90
- if (renderItem !== undefined) {
91
- // Use custom render function if provided
92
- return (
93
- <React.Fragment key={item.id || index}>
94
- {renderItem(item)}
95
- </React.Fragment>
96
- );
97
- }
98
-
99
- const showInitials = initialsState[item.id || index] || !item[imgSrcKey]; // Decide whether to show initials
100
-
101
- return (
102
- <div
103
- key={item.id || index}
104
- className={`message-card ${cardClassName || ""}`}
105
- style={cardStyle}
106
- >
107
- <div
108
- className={`message-card-header ${headerClassName || ""}`}
109
- style={headerStyle}
110
- >
111
- {showInitials ? (
112
- <div
113
- className={`message-card-initials ${imgClassName || ""}`}
114
- style={imgStyle}
115
- >
116
- {getInitials(item[nameKey])}
117
- </div>
118
- ) : (
119
- <img
120
- src={item[imgSrcKey]}
121
- alt={item[nameKey]}
122
- className={`message-card-img ${imgClassName || ""}`}
123
- style={imgStyle}
124
- onError={() => handleImageError(item.id || index)} // Pass card id or index
125
- />
126
- )}
127
- <div
128
- className={`message-card-info ${infoClassName || ""}`}
129
- style={infoStyle}
130
- >
131
- <h3
132
- className={`message-card-name ${nameClassName || ""}`}
133
- style={nameStyle}
134
- >
135
- {item[nameKey]}
136
- </h3>
137
- <p
138
- className={`message-card-date ${dateClassName || ""}`}
139
- style={dateStyle}
140
- >
141
- {item[dateKey]}
142
- </p>
143
- </div>
144
- </div>
145
- <div
146
- className={`message-card-body ${bodyClassName || ""}`}
147
- style={bodyStyle}
148
- >
149
- {/* <p
150
- className={`message-card-comment ${commentClassName || ""}`}
151
- style={commentStyle}
152
- >
153
- {item[commentKey]}
154
- </p> */}
155
- <p
156
- className={`message-card-comment ${commentClassName || ""}`}
157
- style={commentStyle}
158
- dangerouslySetInnerHTML={{ __html: item[commentKey] }}
159
- ></p>
160
- </div>
161
- </div>
162
- );
163
- })}
164
- </div>
165
- );
166
- };
167
-
1
+ import React, { CSSProperties, useState, ReactNode } from "react";
2
+ import "./ShowMessageCard.css";
3
+
4
+ interface MessageCardProps {
5
+ [key: string]: any; // Support dynamic keys
6
+ }
7
+
8
+ interface ShowMessageCardProps {
9
+ data: MessageCardProps[];
10
+ nameKey?: string; // Custom key for name
11
+ dateKey?: string; // Custom key for date
12
+ commentKey?: string; // Custom key for comment
13
+ imgSrcKey?: string; // Custom key for image source
14
+ containerClassName?: string; // Class for the outermost container
15
+ containerStyle?: CSSProperties; // Style for the outermost container
16
+ cardClassName?: string; // Class for the card
17
+ cardStyle?: CSSProperties; // Style for the card
18
+ headerClassName?: string; // Class for the card header
19
+ headerStyle?: CSSProperties; // Style for the card header
20
+ imgClassName?: string; // Class for the image
21
+ imgStyle?: CSSProperties; // Style for the image
22
+ infoClassName?: string; // Class for the user info container
23
+ infoStyle?: CSSProperties; // Style for the user info container
24
+ nameClassName?: string; // Class for the user name
25
+ nameStyle?: CSSProperties; // Style for the user name
26
+ dateClassName?: string; // Class for the date
27
+ dateStyle?: CSSProperties; // Style for the date
28
+ bodyClassName?: string; // Class for the card body
29
+ bodyStyle?: CSSProperties; // Style for the card body
30
+ commentClassName?: string; // Class for the comment text
31
+ commentStyle?: CSSProperties; // Style for the comment text
32
+ renderItem?: (element: MessageCardProps) => ReactNode; // Custom render function
33
+ }
34
+
35
+ export const ShowMessageCard: React.FC<ShowMessageCardProps> = ({
36
+ data,
37
+ nameKey = "name",
38
+ dateKey = "date",
39
+ commentKey = "comment",
40
+ imgSrcKey = "imgSrc",
41
+ containerClassName,
42
+ containerStyle,
43
+ cardClassName,
44
+ cardStyle,
45
+ headerClassName,
46
+ headerStyle,
47
+ imgClassName,
48
+ imgStyle,
49
+ infoClassName,
50
+ infoStyle,
51
+ nameClassName,
52
+ nameStyle,
53
+ dateClassName,
54
+ dateStyle,
55
+ bodyClassName,
56
+ bodyStyle,
57
+ commentClassName,
58
+ commentStyle,
59
+ renderItem, // Custom render function
60
+ }) => {
61
+ // State to manage initials for images that fail to load
62
+ const [initialsState, setInitialsState] = useState<{ [key: string]: boolean }>(
63
+ {}
64
+ );
65
+
66
+ // Handle image load failure
67
+ const handleImageError = (id: string | number) => {
68
+ setInitialsState((prevState) => ({
69
+ ...prevState,
70
+ [id]: true, // Show initials for the specific card
71
+ }));
72
+ };
73
+
74
+ // Helper function to generate initials from the name
75
+ const getInitials = (name: string) => {
76
+ const nameParts = name.split(" ");
77
+ const initials = nameParts
78
+ .map((part) => part[0]?.toUpperCase() || "") // Take the first letter of each part
79
+ .slice(0, 2) // Limit to 2 letters
80
+ .join("");
81
+ return initials;
82
+ };
83
+
84
+ return (
85
+ <div
86
+ className={`message-card-container ${containerClassName || ""}`}
87
+ style={containerStyle}
88
+ >
89
+ {data.map((item, index) => {
90
+ if (renderItem !== undefined) {
91
+ // Use custom render function if provided
92
+ return (
93
+ <React.Fragment key={item.id || index}>
94
+ {renderItem(item)}
95
+ </React.Fragment>
96
+ );
97
+ }
98
+
99
+ const showInitials = initialsState[item.id || index] || !item[imgSrcKey]; // Decide whether to show initials
100
+
101
+ return (
102
+ <div
103
+ key={item.id || index}
104
+ className={`message-card ${cardClassName || ""}`}
105
+ style={cardStyle}
106
+ >
107
+ <div
108
+ className={`message-card-header ${headerClassName || ""}`}
109
+ style={headerStyle}
110
+ >
111
+ {showInitials ? (
112
+ <div
113
+ className={`message-card-initials ${imgClassName || ""}`}
114
+ style={imgStyle}
115
+ >
116
+ {getInitials(item[nameKey])}
117
+ </div>
118
+ ) : (
119
+ <img
120
+ src={item[imgSrcKey]}
121
+ alt={item[nameKey]}
122
+ className={`message-card-img ${imgClassName || ""}`}
123
+ style={imgStyle}
124
+ onError={() => handleImageError(item.id || index)} // Pass card id or index
125
+ />
126
+ )}
127
+ <div
128
+ className={`message-card-info ${infoClassName || ""}`}
129
+ style={infoStyle}
130
+ >
131
+ <h3
132
+ className={`message-card-name ${nameClassName || ""}`}
133
+ style={nameStyle}
134
+ >
135
+ {item[nameKey]}
136
+ </h3>
137
+ <p
138
+ className={`message-card-date ${dateClassName || ""}`}
139
+ style={dateStyle}
140
+ >
141
+ {item[dateKey]}
142
+ </p>
143
+ </div>
144
+ </div>
145
+ <div
146
+ className={`message-card-body ${bodyClassName || ""}`}
147
+ style={bodyStyle}
148
+ >
149
+ {/* <p
150
+ className={`message-card-comment ${commentClassName || ""}`}
151
+ style={commentStyle}
152
+ >
153
+ {item[commentKey]}
154
+ </p> */}
155
+ <p
156
+ className={`message-card-comment ${commentClassName || ""}`}
157
+ style={commentStyle}
158
+ dangerouslySetInnerHTML={{ __html: item[commentKey] }}
159
+ ></p>
160
+ </div>
161
+ </div>
162
+ );
163
+ })}
164
+ </div>
165
+ );
166
+ };
167
+
package/src/index.ts CHANGED
@@ -1,2 +1,2 @@
1
- export {default as MentionInput} from './MentionInput';
2
- export { ShowMessageCard } from './ShowMessageCard';
1
+ export {default as MentionInput} from './MentionInput';
2
+ export { ShowMessageCard } from './ShowMessageCard';
package/tsconfig.json CHANGED
@@ -1,15 +1,15 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES5",
4
- "sourceMap": false,
5
- "module": "ESNext",
6
- "moduleResolution": "node",
7
- "jsx": "react",
8
- "lib": ["dom", "es6"], // Ensure karein ki 'es6' included ho
9
- "declaration": true,
10
- "outDir": "./dist",
11
- "strict": true,
12
- "esModuleInterop": true
13
- }
14
-
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES5",
4
+ "sourceMap": false,
5
+ "module": "ESNext",
6
+ "moduleResolution": "node",
7
+ "jsx": "react",
8
+ "lib": ["dom", "es6"], // Ensure karein ki 'es6' included ho
9
+ "declaration": true,
10
+ "outDir": "./dist",
11
+ "strict": true,
12
+ "esModuleInterop": true
13
+ }
14
+
15
15
  }