react-rich-textarea-chips 1.0.0
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.
- package/README.md +91 -0
- package/dist/index.cjs +54 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.js +16456 -0
- package/dist/style.css +3 -0
- package/package.json +58 -0
package/README.md
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# react-rich-textarea-chips
|
|
2
|
+
|
|
3
|
+
A modern React rich-text editor component built on top of **Lexical**, allowing users to insert custom placeholder chips (tokens like `{{username}}`, `{{token}}`, etc.) into a styled rich textarea.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Token Chips**: Add non-editable placeholders/chips easily using standard template syntax (e.g., `{{first_name}}`).
|
|
8
|
+
- **Lexical Engine**: Robust, standard-compliant rich-text input behavior.
|
|
9
|
+
- **Customizable**: Built-in menu for inserting chips from a list.
|
|
10
|
+
- **Tailwind-compatible**: Styled gracefully out of the box with optional custom styling.
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npm install react-rich-textarea-chips
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Make sure you also have the peer dependencies installed:
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npm install react react-dom
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Usage
|
|
25
|
+
|
|
26
|
+
### Import Styles
|
|
27
|
+
|
|
28
|
+
Before using the component, import the library styles in your application entry file (e.g. `main.js`, `index.js`, or `App.js`):
|
|
29
|
+
|
|
30
|
+
```javascript
|
|
31
|
+
import 'react-rich-textarea-chips/style.css';
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### Component Integration
|
|
35
|
+
|
|
36
|
+
```jsx
|
|
37
|
+
import React, { useState } from 'react';
|
|
38
|
+
import { RichInputWithPlaceholderChips } from 'react-rich-textarea-chips';
|
|
39
|
+
|
|
40
|
+
function App() {
|
|
41
|
+
const [value, setValue] = useState('Hello {{first_name}}! Welcome to our platform.');
|
|
42
|
+
|
|
43
|
+
const chips = [
|
|
44
|
+
{ label: 'First Name', value: 'first_name' },
|
|
45
|
+
{ label: 'Last Name', value: 'last_name' },
|
|
46
|
+
{ label: 'Email Address', value: 'email' },
|
|
47
|
+
'company_name' // Can also pass plain strings
|
|
48
|
+
];
|
|
49
|
+
|
|
50
|
+
const handleChange = (e) => {
|
|
51
|
+
console.log('Serialized content:', e.target.value);
|
|
52
|
+
setValue(e.target.value);
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
return (
|
|
56
|
+
<div style={{ padding: '20px', maxWidth: '600px' }}>
|
|
57
|
+
<h3>Email Template Editor</h3>
|
|
58
|
+
<RichInputWithPlaceholderChips
|
|
59
|
+
value={value}
|
|
60
|
+
onChange={handleChange}
|
|
61
|
+
placeholderChips={chips}
|
|
62
|
+
placeholder="Type something..."
|
|
63
|
+
rows={4}
|
|
64
|
+
/>
|
|
65
|
+
</div>
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export default App;
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Props
|
|
73
|
+
|
|
74
|
+
The `RichInputWithPlaceholderChips` component accepts the following props:
|
|
75
|
+
|
|
76
|
+
| Prop | Type | Default | Description |
|
|
77
|
+
|---|---|---|---|
|
|
78
|
+
| `value` | `string` | `""` | Controlled value of the editor containing standard text and `{{token}}` formatting. |
|
|
79
|
+
| `onChange` | `(event: { target: { value: string, name?: string, id?: string } }) => void` | `undefined` | Callback invoked when content changes. `e.target.value` provides the serialized string. |
|
|
80
|
+
| `placeholder` | `string` | `""` | Placeholder text shown when the editor is empty. |
|
|
81
|
+
| `placeholderChips` | `Array<string \| { label: string, value: string }>` | `[]` | List of chips that can be inserted via the dropdown/plus menu. |
|
|
82
|
+
| `disabled` | `boolean` | `false` | Disables the editor. |
|
|
83
|
+
| `rows` | `number` | `undefined` | Minimum height based on number of text rows (each row adds ~24px). |
|
|
84
|
+
| `minHeight` | `string` | `undefined` | Minimum height CSS value (e.g. `"120px"`). |
|
|
85
|
+
| `maxHeight` | `string` | `undefined` | Maximum height CSS value (e.g. `"400px"`). |
|
|
86
|
+
| `className` | `string` | `""` | Custom class names for the container wrapper. |
|
|
87
|
+
| `contentClassName` | `string` | `""` | Custom class names for the editor content area. |
|
|
88
|
+
|
|
89
|
+
## License
|
|
90
|
+
|
|
91
|
+
MIT
|