Skip to content

Commit 485f3a1

Browse files
committed
docs: update readme
1 parent eda77c5 commit 485f3a1

File tree

1 file changed

+95
-3
lines changed

1 file changed

+95
-3
lines changed

README.MD

Lines changed: 95 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,97 @@
1-
# react-mix-tag-input
1+
# React Mix Tag Input
22

3-
Allow text input with tag
3+
A react input component that pairs text with tags, supports multiline entry, and provides customizable tag rendering.
44

5-
example coming soon
5+
### [Full Documentation](https://arif-un.github.io/react-mix-tag-input/#custom-tag-view)
6+
7+
#### Installation
8+
9+
```
10+
npm install @arif-un/react-mix-tag-input
11+
```
12+
13+
```
14+
import MixTagInput from "mix-tag-input";
15+
16+
const [value, setValue] = useState<MixInputValues>([
17+
[ "Text ", {type: "tag", attrs: {id: "1", label: "Tag"}} ]
18+
]);
19+
20+
<MixTagInput value={value} onChange={handleChange} />
21+
```
22+
23+
24+
### Props
25+
26+
#### `<MixTagInput />`
27+
28+
| Prop | Description | Default | Type |
29+
|------|-------------|---------|------|
30+
| `ref` | React forwardRef with options of component | | [MixInputRef](#mixinputref-react.forwardref) |
31+
| `value` | Values of Mix Input | [] | [MixInputValues](MixInputValues) |
32+
| `onChange` | Function to handle the change event | | (value: [MixInputValues](MixInputValues)) => void |
33+
| `disabled` | Boolean value to set the input as disabled | false | Boolean |
34+
| `placeholder` | Placeholder text | | string |
35+
| `immediatelyRender` | Boolean value to render the component immediately on mount. Useful for server side rendering | false | Boolean |
36+
| `tagClassName` | Class name for tags | mi-tag | string |
37+
| `editorOptions` | Options for the editor | {} | [Editor](Editor) |
38+
| `tagAttrs` | Allowed attributes for tags, that returns with tag value on change and also render as data-* attribute | | { [key: string]: string } |
39+
| `tagView` | Custom tag view component | | React.FC<[TagViewProps](TagViewProps)> |
40+
41+
42+
### MixInputRef: React.forwardRef
43+
44+
```typescript
45+
import { type MixInputRef } from '@arif-un/react-mix-tag-input';
46+
47+
const ref = useRef<MixInputRef>(null);
48+
49+
// ...
50+
ref.current?.insertContent({ type: 'tag', attrs: { id: '1', label: 'Tag' } });
51+
// ...
52+
53+
return <MixTagInput ref={ref} />;
54+
```
55+
56+
| Prop | Description | Type |
57+
|------|-------------|------|
58+
| insertContent | Function to insert content in the editor current caret position, accepts Tag or Text alone or in array | (content: [Tag](Tag) \| string \| ([Tag](Tag) \| string)[]) => void |
59+
| element | Returns the editor element | HTMLDivElement |
60+
| editor | Returns the editor instance | [Editor](Editor) |
61+
62+
63+
### MixInputValues: (string | Tag)[][]
64+
65+
```typescript
66+
const text = 'Any text string'
67+
68+
const tag: Tag = {
69+
type: 'tag',
70+
attrs: {
71+
id: '1',
72+
label: 'Tag',
73+
className: 'tag-class',
74+
style: {color: 'cyan'}
75+
[key: string]: string // key and default value need to specify in 'tagAttrs' prop
76+
},
77+
}
78+
79+
const firstLineValues: MixInputValues = [[ text, tag ]]
80+
81+
return <MixTagInput value={firstLineValues} />;
82+
```
83+
84+
#### Tag
85+
| Prop | Description | Type |
86+
|------|-------------|------|
87+
| type | Type of the tag | `'tag'` |
88+
| attrs | Attributes of the tag | `object` |
89+
| attrs.id | Unique identifier of the tag | `string` |
90+
| attrs.label | Label of the tag | `string` |
91+
| attrs.className | Class name of the tag | `string` |
92+
| attrs.style | Style of the tag | `React.CSSProperties` |
93+
| attrs.[key: string] | Any other attribute. Key and default value need to specify in tagAttrs prop in order to get back with tag value on change and also render as data-* attribute | `string` |
94+
95+
96+
97+

0 commit comments

Comments
 (0)