forked from transcrobes/mui-rte
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.tsx
133 lines (125 loc) Β· 2.98 KB
/
index.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import React, { FunctionComponent } from 'react'
import ListItemText from '@mui/material/ListItemText'
import ListItemAvatar from '@mui/material/ListItemAvatar'
import Avatar from '@mui/material/Avatar'
import MUIRichTextEditor, { TAutocompleteItem } from '../../'
const save = (data: string) => {
console.log(data)
}
type TStaff = {
job: string
name: string
color: string
}
const Staff: FunctionComponent<TStaff> = (props) => {
return (
<>
<ListItemAvatar>
<Avatar style={{
backgroundColor: props.color
}}>{props.name.substr(0, 1)}</Avatar>
</ListItemAvatar>
<ListItemText
primary={props.name}
secondary={props.job}
/>
</>
)
}
const emojis: TAutocompleteItem[] = [
{
keys: ["face", "grin"],
value: "π",
content: "π",
},
{
keys: ["face", "beaming"],
value: "π",
content: "π",
},
{
keys: ["face", "joy"],
value: "π",
content: "π",
},
{
keys: ["face", "grin", "big"],
value: "π",
content: "π",
},
{
keys: ["face", "grin", "smile"],
value: "π",
content: "π",
},
{
keys: ["face", "sweat"],
value: "π
",
content: "π
",
}
]
const cities: TAutocompleteItem[] = [
{
keys: ["mexico"],
value: "Mexico City",
content: "Mexico City",
},
{
keys: ["mexico", "beach"],
value: "Cancun",
content: "Cancun",
},
{
keys: ["japan", "olympics"],
value: "Tokyo",
content: "Tokyo",
},
{
keys: ["japan"],
value: "Osaka",
content: "Osaka",
}
]
const staff = [
{
keys: ["all", "foo", "manager"],
value: "Foo Bar",
content: <Staff name="Foo Bar" job="Manager" color="tomato" />,
},
{
keys: ["all", "bar", "support"],
value: "Bar Foo",
content: <Staff name="Bar Foo" job="Technical Support" color="orange" />,
},
{
keys: ["all", "mui", "manager"],
value: "Mui Rte",
content: <Staff name="Mui Rte" job="Manager" color="dodgerblue" />,
}
]
const Autocomplete = () => {
return (
<MUIRichTextEditor
label="Try typing ':grin' or '/mexico'..."
onSave={save}
autocomplete={{
strategies: [
{
items: emojis,
triggerChar: ":"
},
{
items: cities,
triggerChar: "/"
},
{
items: staff,
triggerChar: "@",
insertSpaceAfter: false
}
]
}}
/>
)
}
export default Autocomplete