react-mention-input 1.0.7 → 1.0.9

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,61 +1,61 @@
1
- .mention-container {
2
- position: relative;
3
- display: flex;
4
- align-items: center;
5
- }
6
-
7
- .mention-input {
8
- width: 100%;
9
- padding: 12px 16px;
10
- border: 1px solid #ccc;
11
- border-radius: 8px;
12
- outline: none;
13
- font-size: 16px;
14
- box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
15
- transition: border 0.2s, box-shadow 0.2s;
16
- }
17
- .mention-input:focus {
18
- border: 1px solid #007BFF;
19
- }
20
-
21
- .send-button {
22
- padding: 8px 12px;
23
- border: none;
24
- background-color: #007BFF;
25
- color: #fff;
26
- border-radius: 50%;
27
- cursor: pointer;
28
- font-size: 18px;
29
- display: flex;
30
- align-items: center;
31
- justify-content: center;
32
- }
33
-
34
- .suggestion-list {
35
- position: absolute;
36
- top: 100%;
37
- left: 0;
38
- right: 0;
39
- background-color: #fff;
40
- border: 1px solid #ddd;
41
- border-radius: 4px;
42
- list-style: none;
43
- margin: 4px 0;
44
- padding: 0;
45
- max-height: 150px;
46
- overflow-y: auto;
47
- box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
48
- z-index: 1;
49
- }
50
-
51
- .suggestion-item {
52
- padding: 8px 12px;
53
- cursor: pointer;
54
- border-bottom: 1px solid #ddd;
55
- transition: background-color 0.2s;
56
- }
57
- .suggestion-item:hover {
58
- background-color: #f5f5f5;
59
- }
60
-
61
- /*# sourceMappingURL=MentionInput.css.map */
1
+ .mention-container {
2
+ position: relative;
3
+ display: flex;
4
+ align-items: center;
5
+ }
6
+
7
+ .mention-input {
8
+ width: 100%;
9
+ padding: 12px 16px;
10
+ border: 1px solid #ccc;
11
+ border-radius: 8px;
12
+ outline: none;
13
+ font-size: 16px;
14
+ box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
15
+ transition: border 0.2s, box-shadow 0.2s;
16
+ }
17
+ .mention-input:focus {
18
+ border: 1px solid #007BFF;
19
+ }
20
+
21
+ .send-button {
22
+ padding: 8px 12px;
23
+ border: none;
24
+ background-color: #007BFF;
25
+ color: #fff;
26
+ border-radius: 50%;
27
+ cursor: pointer;
28
+ font-size: 18px;
29
+ display: flex;
30
+ align-items: center;
31
+ justify-content: center;
32
+ }
33
+
34
+ .suggestion-list {
35
+ position: absolute;
36
+ top: 100%;
37
+ left: 0;
38
+ right: 0;
39
+ background-color: #fff;
40
+ border: 1px solid #ddd;
41
+ border-radius: 4px;
42
+ list-style: none;
43
+ margin: 4px 0;
44
+ padding: 0;
45
+ max-height: 150px;
46
+ overflow-y: auto;
47
+ box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
48
+ z-index: 1;
49
+ }
50
+
51
+ .suggestion-item {
52
+ padding: 8px 12px;
53
+ cursor: pointer;
54
+ border-bottom: 1px solid #ddd;
55
+ transition: background-color 0.2s;
56
+ }
57
+ .suggestion-item:hover {
58
+ background-color: #f5f5f5;
59
+ }
60
+
61
+
@@ -1,5 +1,5 @@
1
- import React from 'react';
2
- import './MentionInput.scss';
1
+ import React, { ReactNode } from 'react';
2
+ import './MentionInput.css';
3
3
  interface User {
4
4
  id: number;
5
5
  name: string;
@@ -9,8 +9,7 @@ interface MentionInputProps {
9
9
  placeholder?: string;
10
10
  containerClassName?: string;
11
11
  inputClassName?: string;
12
- suggestionListClassName?: string;
13
- suggestionItemClassName?: string;
12
+ sendButtonIcon?: ReactNode;
14
13
  onSendMessage?: (message: string) => void;
15
14
  }
16
15
  declare const MentionInput: React.FC<MentionInputProps>;
@@ -1,31 +1,10 @@
1
1
  import React, { useState } from 'react';
2
- import './MentionInput.scss'; // Import the SCSS file
2
+ import './MentionInput.css'; // Import the CSS file
3
3
  var MentionInput = function (_a) {
4
- var users = _a.users, placeholder = _a.placeholder, containerClassName = _a.containerClassName, inputClassName = _a.inputClassName, suggestionListClassName = _a.suggestionListClassName, suggestionItemClassName = _a.suggestionItemClassName, onSendMessage = _a.onSendMessage;
4
+ var users = _a.users, placeholder = _a.placeholder, containerClassName = _a.containerClassName, inputClassName = _a.inputClassName, sendButtonIcon = _a.sendButtonIcon, onSendMessage = _a.onSendMessage;
5
5
  var _b = useState(''), inputValue = _b[0], setInputValue = _b[1];
6
- var _c = useState([]), suggestions = _c[0], setSuggestions = _c[1];
7
- var _d = useState(false), showSuggestions = _d[0], setShowSuggestions = _d[1];
8
6
  var handleInputChange = function (e) {
9
- var value = e.target.value;
10
- setInputValue(value);
11
- var mentionMatch = value.match(/@(\w*)$/);
12
- if (mentionMatch) {
13
- var query_1 = mentionMatch[1].toLowerCase();
14
- var filteredUsers = users.filter(function (user) {
15
- return user.name.toLowerCase().startsWith(query_1);
16
- });
17
- setSuggestions(filteredUsers);
18
- setShowSuggestions(true);
19
- }
20
- else {
21
- setShowSuggestions(false);
22
- }
23
- };
24
- var handleSuggestionClick = function (user) {
25
- var mentionIndex = inputValue.lastIndexOf('@');
26
- var newValue = "".concat(inputValue.substring(0, mentionIndex + 1)).concat(user.name, " ");
27
- setInputValue(newValue);
28
- setShowSuggestions(false);
7
+ setInputValue(e.target.value);
29
8
  };
30
9
  var handleSendMessage = function () {
31
10
  if (inputValue.trim() && onSendMessage) {
@@ -40,8 +19,8 @@ var MentionInput = function (_a) {
40
19
  }
41
20
  };
42
21
  return (React.createElement("div", { className: "mention-container ".concat(containerClassName || '') },
43
- React.createElement("input", { type: "text", value: inputValue, onChange: handleInputChange, onKeyPress: handleKeyPress, placeholder: placeholder || 'Type a message...', className: "mention-input ".concat(inputClassName || '') }),
44
- React.createElement("button", { onClick: handleSendMessage, className: "send-button" }, "\u27A4"),
45
- showSuggestions && (React.createElement("ul", { className: "suggestion-list ".concat(suggestionListClassName || '') }, suggestions.map(function (user) { return (React.createElement("li", { key: user.id, onClick: function () { return handleSuggestionClick(user); }, className: "suggestion-item ".concat(suggestionItemClassName || '') }, user.name)); })))));
22
+ React.createElement("div", { className: "input-wrapper" },
23
+ React.createElement("input", { type: "text", value: inputValue, onChange: handleInputChange, onKeyPress: handleKeyPress, placeholder: placeholder || 'Type @ to mention someone...', className: "mention-input ".concat(inputClassName || '') }),
24
+ React.createElement("button", { onClick: handleSendMessage, className: "send-button" }, sendButtonIcon ? sendButtonIcon : ''))));
46
25
  };
47
26
  export default MentionInput;
package/package.json CHANGED
@@ -1,13 +1,12 @@
1
1
  {
2
2
  "name": "react-mention-input",
3
- "version": "1.0.7",
3
+ "version": "1.0.9",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "scripts": {
7
7
  "test": "echo \"Error: no test specified\" && exit 1",
8
- "build": "tsc && npm run build-css",
9
- "build-css": "sass src/MentionInput.scss dist/MentionInput.css",
10
- "watch-css": "sass --watch src/MentionInput.scss:dist/MentionInput.css"
8
+ "build": "tsc && npm run copy-css",
9
+ "copy-css": "copyfiles -u 1 src/**/*.css dist"
11
10
  },
12
11
  "keywords": [
13
12
  "mention",
@@ -28,6 +27,7 @@
28
27
  "@types/node": "^22.9.0",
29
28
  "@types/react": "^18.3.12",
30
29
  "@types/react-dom": "^18.3.1",
30
+ "copyfiles": "^2.4.1",
31
31
  "csstype": "^3.1.3",
32
32
  "sass": "^1.81.0",
33
33
  "typescript": "^5.6.3"
@@ -13,10 +13,9 @@
13
13
  font-size: 16px;
14
14
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
15
15
  transition: border 0.2s, box-shadow 0.2s;
16
-
17
- &:focus {
18
- border: 1px solid #007BFF;
19
- }
16
+ }
17
+ .mention-input:focus {
18
+ border: 1px solid #007BFF;
20
19
  }
21
20
 
22
21
  .send-button {
@@ -54,8 +53,9 @@
54
53
  cursor: pointer;
55
54
  border-bottom: 1px solid #ddd;
56
55
  transition: background-color 0.2s;
57
-
58
- &:hover {
59
- background-color: #f5f5f5;
60
- }
61
56
  }
57
+ .suggestion-item:hover {
58
+ background-color: #f5f5f5;
59
+ }
60
+
61
+
@@ -1,5 +1,5 @@
1
- import React, { useState, ChangeEvent, KeyboardEvent } from 'react';
2
- import './MentionInput.scss'; // Import the SCSS file
1
+ import React, { useState, ChangeEvent, KeyboardEvent, ReactNode } from 'react';
2
+ import './MentionInput.css'; // Import the CSS file
3
3
 
4
4
  interface User {
5
5
  id: number;
@@ -9,10 +9,9 @@ interface User {
9
9
  interface MentionInputProps {
10
10
  users: User[];
11
11
  placeholder?: string;
12
- containerClassName?: string; // New prop for container class
13
- inputClassName?: string; // New prop for input class
14
- suggestionListClassName?: string; // New prop for suggestion list class
15
- suggestionItemClassName?: string; // New prop for suggestion item class
12
+ containerClassName?: string;
13
+ inputClassName?: string;
14
+ sendButtonIcon?: ReactNode;
16
15
  onSendMessage?: (message: string) => void;
17
16
  }
18
17
 
@@ -21,36 +20,13 @@ const MentionInput: React.FC<MentionInputProps> = ({
21
20
  placeholder,
22
21
  containerClassName,
23
22
  inputClassName,
24
- suggestionListClassName,
25
- suggestionItemClassName,
23
+ sendButtonIcon,
26
24
  onSendMessage,
27
25
  }) => {
28
26
  const [inputValue, setInputValue] = useState<string>('');
29
- const [suggestions, setSuggestions] = useState<User[]>([]);
30
- const [showSuggestions, setShowSuggestions] = useState<boolean>(false);
31
27
 
32
28
  const handleInputChange = (e: ChangeEvent<HTMLInputElement>) => {
33
- const value = e.target.value;
34
- setInputValue(value);
35
-
36
- const mentionMatch = value.match(/@(\w*)$/);
37
- if (mentionMatch) {
38
- const query = mentionMatch[1].toLowerCase();
39
- const filteredUsers = users.filter((user) =>
40
- user.name.toLowerCase().startsWith(query)
41
- );
42
- setSuggestions(filteredUsers);
43
- setShowSuggestions(true);
44
- } else {
45
- setShowSuggestions(false);
46
- }
47
- };
48
-
49
- const handleSuggestionClick = (user: User) => {
50
- const mentionIndex = inputValue.lastIndexOf('@');
51
- const newValue = `${inputValue.substring(0, mentionIndex + 1)}${user.name} `;
52
- setInputValue(newValue);
53
- setShowSuggestions(false);
29
+ setInputValue(e.target.value);
54
30
  };
55
31
 
56
32
  const handleSendMessage = () => {
@@ -69,33 +45,19 @@ const MentionInput: React.FC<MentionInputProps> = ({
69
45
 
70
46
  return (
71
47
  <div className={`mention-container ${containerClassName || ''}`}>
72
- <input
73
- type="text"
74
- value={inputValue}
75
- onChange={handleInputChange}
76
- onKeyPress={handleKeyPress}
77
- placeholder={placeholder || 'Type a message...'}
78
- className={`mention-input ${inputClassName || ''}`}
79
- />
80
- <button
81
- onClick={handleSendMessage}
82
- className="send-button"
83
- >
84
-
85
- </button>
86
- {showSuggestions && (
87
- <ul className={`suggestion-list ${suggestionListClassName || ''}`}>
88
- {suggestions.map((user) => (
89
- <li
90
- key={user.id}
91
- onClick={() => handleSuggestionClick(user)}
92
- className={`suggestion-item ${suggestionItemClassName || ''}`}
93
- >
94
- {user.name}
95
- </li>
96
- ))}
97
- </ul>
98
- )}
48
+ <div className="input-wrapper">
49
+ <input
50
+ type="text"
51
+ value={inputValue}
52
+ onChange={handleInputChange}
53
+ onKeyPress={handleKeyPress}
54
+ placeholder={placeholder || 'Type @ to mention someone...'}
55
+ className={`mention-input ${inputClassName || ''}`}
56
+ />
57
+ <button onClick={handleSendMessage} className="send-button">
58
+ {sendButtonIcon ? sendButtonIcon : '➤'}
59
+ </button>
60
+ </div>
99
61
  </div>
100
62
  );
101
63
  };
package/tsconfig.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "compilerOptions": {
3
3
  "target": "ES5",
4
+ "sourceMap": false,
4
5
  "module": "ESNext",
5
6
  "moduleResolution": "node",
6
7
  "jsx": "react",
@@ -1 +0,0 @@
1
- {"version":3,"sourceRoot":"","sources":["../src/MentionInput.scss"],"names":[],"mappings":"AAAA;EACE;EACA;EACA;;;AAGF;EACE;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;AAEA;EACE;;;AAIJ;EACE;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;;AAGF;EACE;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;;AAGF;EACE;EACA;EACA;EACA;;AAEA;EACE","file":"MentionInput.css"}