This repository was archived by the owner on Mar 18, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1k
Expand file tree
/
Copy pathindex.tsx
More file actions
417 lines (416 loc) · 19.2 KB
/
index.tsx
File metadata and controls
417 lines (416 loc) · 19.2 KB
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
// eslint-disable-next-line import/no-unresolved
// eslint-disable-next-line import/no-duplicates
import customComponentExampleCode from '!!raw-loader!../../../components/Examples/mention/CustomComponentMentionEditor/CustomComponentMentionEditor';
// eslint-disable-next-line import/no-unresolved
import customComponentExampleStylesCode from '!!raw-loader!../../../components/Examples/mention/CustomComponentMentionEditor/CustomComponentMentionEditor.module.css';
// eslint-disable-next-line import/no-unresolved
// eslint-disable-next-line import/no-duplicates
import customExampleCode from '!!raw-loader!../../../components/Examples/mention/CustomMentionEditor/CustomMentionEditor';
// eslint-disable-next-line import/no-unresolved
import customExampleEditorStylesCode from '!!raw-loader!../../../components/Examples/mention/CustomMentionEditor/CustomMentionEditor.module.css';
// eslint-disable-next-line import/no-unresolved
import customExampleMentionsCode from '!!raw-loader!../../../components/Examples/mention/CustomMentionEditor/Mentions';
// eslint-disable-next-line import/no-unresolved
import customExampleMentionsStylesCode from '!!raw-loader!../../../components/Examples/mention/CustomMentionEditor/MentionsStyles.module.css';
// eslint-disable-next-line import/no-unresolved
// eslint-disable-next-line import/no-duplicates
import multiComponentExampleCode from '!!raw-loader!../../../components/Examples/mention/MultiMentionTriggers/MultiMentionTriggers';
// eslint-disable-next-line import/no-unresolved
import multiComponentExampleStylesCode from '!!raw-loader!../../../components/Examples/mention/MultiMentionTriggers/MultiMentionTriggers.module.css';
// eslint-disable-next-line import/no-unresolved
// eslint-disable-next-line import/no-duplicates
import remoteExampleCode from '!!raw-loader!../../../components/Examples/mention/RemoteMentionEditor/RemoteMentionEditor';
// eslint-disable-next-line import/no-unresolved
import remoteExampleEditorStylesCode from '!!raw-loader!../../../components/Examples/mention/RemoteMentionEditor/RemoteMentionEditor.module.css';
// eslint-disable-next-line import/no-unresolved
import simpleExampleMentionsCode from '!!raw-loader!../../../components/Examples/mention/SimpleMentionEditor/Mentions';
// eslint-disable-next-line import/no-unresolved
// eslint-disable-next-line import/no-duplicates
import simpleExampleCode from '!!raw-loader!../../../components/Examples/mention/SimpleMentionEditor/SimpleMentionEditor';
// eslint-disable-next-line import/no-unresolved
import simpleExampleEditorStylesCode from '!!raw-loader!../../../components/Examples/mention/SimpleMentionEditor/SimpleMentionEditor.module.css';
// eslint-disable-next-line import/no-unresolved
import webpackConfig from '!!raw-loader!../../../components/Examples/mention/webpackConfig';
import React, { ReactElement } from 'react';
import AlternateContainer from '../../../components/AlternateContainer/AlternateContainer';
import Code from '../../../components/Code/Code';
import Container from '../../../components/Container/Container';
// eslint-disable-next-line import/no-duplicates
import CustomComponentMentionEditor from '../../../components/Examples/mention/CustomComponentMentionEditor/CustomComponentMentionEditor';
// eslint-disable-next-line import/no-duplicates
import CustomMentionEditor from '../../../components/Examples/mention/CustomMentionEditor/CustomMentionEditor';
// eslint-disable-next-line import/no-duplicates
import MultiMentionTriggers from '../../../components/Examples/mention/MultiMentionTriggers/MultiMentionTriggers';
// eslint-disable-next-line import/no-duplicates
import RemoteMentionEditor from '../../../components/Examples/mention/RemoteMentionEditor/RemoteMentionEditor';
// eslint-disable-next-line import/no-duplicates
import SimpleMentionEditor from '../../../components/Examples/mention/SimpleMentionEditor/SimpleMentionEditor';
import Heading from '../../../components/Heading/Heading';
import InlineCode from '../../../components/InlineCode/InlineCode';
import ExternalLink from '../../../components/Link/Link';
import PluginPageFrame from '../../../components/PluginPageFrame/PluginPageFrame';
import styles from './Mention.module.css';
export default function Mention(): ReactElement {
return (
<PluginPageFrame filePath={'packages/docs/pages/plugin/mention/index.tsx'}>
<Container>
<Heading level={2}>Mention</Heading>
<p>
Mentions for everyone! This plugin allows the user to choose an entry
from a list. After selection an entry the search text will be replace
with the selected entity. The list of suggestions mentions needs to
contain at least a name to display. If desired a link and/or an avatar
image can be provided.
</p>
<Heading level={3}>Escape Behaviour</Heading>
<p>
While the suggestion popover is open, the user can close it by
pressing ESC. This will be stored for as long as the the selection
stays inside the word that triggered the search. After the selection
left this word once the escape behaviour will be reset. The
suggestions will appear again once the user selects the word that that
triggered the selection.
</p>
<Heading level={3}>Supported Environment</Heading>
<ul className={styles.list}>
<li className={styles.listEntry}>Desktop: Yes</li>
<li className={styles.listEntry}>Mobile: Yes</li>
<li className={styles.listEntry}>Screen-reader: Yes</li>
</ul>
</Container>
<AlternateContainer>
<Heading level={2}>Getting Started</Heading>
<Code code="npm install @draft-js-plugins/editor" />
<Code code="npm install @draft-js-plugins/mention" />
<Code code="Please checkout the 'Simple Example' further down the page." />
<Heading level={3}>Importing the default styles</Heading>
<p>
The plugin ships with a default styling available at this location in
the installed package:
<InlineCode
code={'node_modules/@draft-js-plugins/mention/lib/plugin.css'}
/>
</p>
<Heading level={4}>Webpack Usage</Heading>
<ul className={styles.list}>
<li className={styles.listEntry}>
1. Install Webpack loaders:
<InlineCode code={'npm i style-loader css-loader --save-dev'} />
</li>
<li className={styles.listEntry}>
2. Add the below section to Webpack config (if your config already
has a loaders array, simply add the below loader object to your
existing list.
<Code code={webpackConfig} className={styles.guideCodeBlock} />
</li>
<li className={styles.listEntry}>
3. Add the below import line to your component to tell Webpack to
inject the style to your component.
<Code
code={"import '@draft-js-plugins/mention/lib/plugin.css';"}
className={styles.guideCodeBlock}
/>
</li>
<li className={styles.listEntry}>4. Restart Webpack.</li>
</ul>
</AlternateContainer>
<Container>
<Heading level={2}>Configuration Parameters</Heading>
<div className={styles.param}>
<span className={styles.paramName}>theme</span>
<span>Object of CSS classes with the following keys.</span>
<div className={styles.subParams}>
<div className={styles.subParam}>
<span className={styles.subParamName}>mention:</span>
CSS class for mention text.
</div>
<div className={styles.subParam}>
<span className={styles.subParamName}>mentionSuggestions:</span>
CSS class for suggestions component.
</div>
<div className={styles.subParam}>
<span className={styles.subParamName}>
mentionSuggestionsPopup:
</span>
CSS class for popup.js suggestions component.
</div>
<div className={styles.subParam}>
<span className={styles.subParamName}>
mentionSuggestionsPopupVisible:
</span>
CSS class for popup.js suggestions component when it is visible.
Can be used for animations.
</div>
<div className={styles.subParam}>
<span className={styles.subParamName}>
mentionSuggestionsEntry:
</span>
CSS class for an entry in the suggestions component.
</div>
<div className={styles.subParam}>
<span className={styles.subParamName}>
mentionSuggestionsEntryFocused:
</span>
CSS class for the focused entry in the suggestions component.
</div>
<div className={styles.subParam}>
<span className={styles.subParamName}>
mentionSuggestionsEntryText:
</span>
CSS class for an entry’s text in the suggestions component.
</div>
<div className={styles.subParam}>
<span className={styles.subParamName}>
mentionSuggestionsEntryAvatar:
</span>
CSS class for an entry’s avatar image in the suggestions
component.
</div>
</div>
</div>
<div className={styles.param}>
<span className={styles.paramName}>positionSuggestions</span>
<span>
<b>Deprecated, use popperOptions instead</b> The function can be
used to manipulate the position of the popover containing the
suggestions. It receives one object as arguments containing the
visible rectangle surrounding the decorated search string including
the @. In addition the object contains prevProps and props. An
object should be returned which can contain all sorts of styles. The
defined properties will be applied as inline-styles.
</span>
</div>
<div className={styles.param}>
<span className={styles.paramName}>popperOptions</span>
<span>
This options will be used to initialize popper.js. Read in detail
about it{' '}
<ExternalLink href="https://popper.js.org/docs/v2/">
here.
</ExternalLink>
</span>
</div>
<div className={styles.param}>
<span className={styles.paramName}>entityMutability</span>
<span>
Can be one of: "IMMUTABLE", "SEGMENTED" or
"MUTABLE". Read in detail about it
<ExternalLink href="https://draftjs.org/docs/advanced-topics-entities/#mutability">
here
</ExternalLink>
</span>
</div>
<div className={styles.param}>
<span className={styles.paramName}>mentionPrefix</span>
<span>
Allows you to define a custom prefix to add to the selected
mention's name. Can either be a string or a function that takes
the `mentionTrigger` as an argument and returns a string. Defaults
to an empty string.
</span>
</div>
<div className={styles.param}>
<span className={styles.paramName}>mentionTrigger</span>
<span>
Allows you to provide a array custom character to change when the
search is triggered. By default it is set to `@`. By default typing
`@` will trigger the search for mentions. It also does support a
multi-charater mentionTrigger. You can use it like `mentionTrigger:
['@', '(']`.
</span>
</div>
<div className={styles.param}>
<span className={styles.paramName}>mentionRegExp</span>
<span>
Allows you to overwrite the regular expression for initiating the
dropdown. By default this supports any alphanumeric character as
well as Chinese, Japanese & Korean characters. We are happy to
accept pull requests to extend the default mentionRegExp as well.
</span>
</div>
<div className={styles.param}>
<span className={styles.paramName}>supportWhitespace</span>
<span>
Allows you to support a whitespace while typing a search option,
useful for searching first and last names. By default this is set to
`false`
</span>
</div>
<div className={styles.param}>
<span className={styles.paramName}>mentionComponent</span>
<span>
If provided the passed component is used to render a Mention. It
receives the following props: entityKey, mention, className &
decoratedText
</span>
</div>
<Heading level={3}>MentionSuggestions</Heading>
<div>
The MentionSuggestions component is part of the plugin and should
placed somewhere in the JSX after the Editor. It takes the following
props:
<div className={styles.param}>
<span className={styles.paramName}>open</span>
<span>Controlled state of mention popup.</span>
</div>
<div className={styles.param}>
<span className={styles.paramName}>onOpenChange</span>
<span>
A callback which is triggered whenever the suggestions popover
should be opened or closed.
</span>
</div>
<div className={styles.param}>
<span className={styles.paramName}>suggestions</span>
<span>The list of suggestions to be shown.</span>
</div>
<div className={styles.param}>
<span className={styles.paramName}>onSearchChange</span>
<span>
A callback which is triggered whenever the search term changes.
The first argument is an object which contains the search term in
the property value.
</span>
</div>
<div className={styles.param}>
<span className={styles.paramName}>entryComponent</span>
<span>
Component to be used as the template for each of the suggestions
entry.
</span>
</div>
<div className={styles.param}>
<span className={styles.paramName}>onAddMention</span>
<span>
A callback which is triggered whenever the mention is about to be
added. The first argument of this callback will contain the
mention entry.
</span>
</div>
<div className={styles.param}>
<span className={styles.paramName}>popoverComponent</span>
<span>
<b>Deprecated, use popperOptions/popoverContainer instead</b>{' '}
Component to be used as the template for the popover (the parent
of entryComponent). Defaults to a div.
</span>
</div>
<div className={styles.param}>
<span className={styles.paramName}>popoverContainer</span>
<span>
Defaults to a div which is bound to popper.js. If don't want
to have a popover you can overwrite the component with you own.
</span>
</div>
<div className={styles.param}>
<span className={styles.paramName}>renderEmptyPopup</span>
<span>
If set to true if will render the popup even if there are no
mentions to show. This can for example be used to show a message
that there are no matching mentions.
</span>
</div>
<div className={styles.param}>
<span className={styles.paramName}>
mentionSuggestionsComponent
</span>
<span>
Component to be used to render the suggestions dropdown. It must
implement the same interface like{' '}
<InlineCode code="MentionSuggestions" />. Defaults to{' '}
<InlineCode code="MentionSuggestions" />.
</span>
</div>
<div className={styles.param}>
<span>
Additional properties are passed to the{' '}
<InlineCode code="popoverComponent" />
</span>
</div>
</div>
<Heading level={3}>Additional Exports</Heading>
<div>
In addition to the plugin the module exports{' '}
<InlineCode code={'defaultSuggestionsFilter'} />. As first argument it
takes the search term as a String. The second argument is an array of
mentions. The third argument is a trigger that is used to filter multi
mentions. The function returns the filter list based on substring
matches.
<Code code="import { defaultSuggestionsFilter } from '@draft-js-plugins/mention';" />
</div>
</Container>
<Container>
<Heading level={2}>Simple Example</Heading>
<SimpleMentionEditor />
<Code
code={simpleExampleCode as unknown as string}
name="SimpleMentionEditor.tsx"
/>
<Code
code={simpleExampleMentionsCode as unknown as string}
name="Mentions.ts"
/>
<Code
code={simpleExampleEditorStylesCode}
name="SimpleMentionEditor.module.css"
/>
</Container>
<Container>
<Heading level={2}>Custom Themed Mention Example</Heading>
<CustomMentionEditor />
<Code
code={customExampleCode as unknown as string}
name="CustomMentionEditor.ts"
/>
<Code
code={customExampleMentionsStylesCode}
name="MentionsStyles.module.css"
/>
<Code
code={customExampleMentionsCode as unknown as string}
name="Mentions.ts"
/>
<Code
code={customExampleEditorStylesCode}
name="CustomMentionEditor.module.css"
/>
</Container>
<Container>
<Heading level={2}>Remote Data Mention Example</Heading>
<RemoteMentionEditor />
<Code
code={remoteExampleCode as unknown as string}
name="RemoteMentionEditor.tsx"
/>
<Code
code={remoteExampleEditorStylesCode}
name="RemoteMentionEditor.module.css"
/>
</Container>
<Container>
<Heading level={2}>Custom Mention Component Example</Heading>
<CustomComponentMentionEditor />
<Code
code={customComponentExampleCode as unknown as string}
name="CustomComponentMentionEditor.tsx"
/>
<Code
code={customComponentExampleStylesCode}
name="CustomComponentMentionEditor.module.css"
/>
</Container>
<Container>
<Heading level={2}>Multi Mention Triggers</Heading>
<MultiMentionTriggers />
<Code
code={multiComponentExampleCode as unknown as string}
name="MultiMentionTriggers.tsx"
/>
<Code
code={multiComponentExampleStylesCode}
name="MultiMentionTriggers.module.css"
/>
</Container>
</PluginPageFrame>
);
}