Skip to content

Commit e7127e8

Browse files
committed
docs
1 parent 241999c commit e7127e8

File tree

1 file changed

+139
-9
lines changed

1 file changed

+139
-9
lines changed

apps/www/content/docs/multi-select.mdx

+139-9
Original file line numberDiff line numberDiff line change
@@ -77,20 +77,150 @@ export default function MySelectEditor() {
7777

7878
## Plugins
7979

80+
### TagPlugin
81+
82+
Inline void element plugin.
83+
8084
### MultiSelectPlugin
8185

82-
Handling multi-select elements in the editor. Built on top of TagPlugin.
86+
Extension of the TagPlugin that constrains the editor to tag elements.
8387

84-
<APIOptions>
85-
<APIItem name="type" type="string" optional>
86-
The type identifier for multi-select elements.
88+
## API
89+
90+
### editor.tf.insert.tag
8791

88-
- **Default:** `'multi-select'`
92+
Inserts a new multi-select element at the current selection.
93+
94+
<APIParameters>
95+
<APIItem name="props" type="TagLike">
96+
Properties for the multi-select element:
97+
<APISubList>
98+
<APISubListItem parent="props" name="value" type="string">
99+
The unique value of the multi-select element.
100+
</APISubListItem>
101+
</APISubList>
89102
</APIItem>
90-
</APIOptions>
103+
</APIParameters>
91104

92-
### TagPlugin
105+
## Hooks
93106

94-
Inline void element plugin.
107+
### useSelectedItems
95108

96-
## API
109+
Hook to get the currently selected tag items in the editor.
110+
111+
<APIReturns>
112+
<APIItem type="TagLike[]">
113+
Array of selected tag items, each containing a value and any additional properties.
114+
</APIItem>
115+
</APIReturns>
116+
117+
### getSelectedItems
118+
119+
Gets all tag items in the editor.
120+
121+
<APIParameters>
122+
<APIItem name="editor" type="SlateEditor">
123+
The Slate editor instance.
124+
</APIItem>
125+
</APIParameters>
126+
127+
<APIReturns>
128+
<APIItem type="TagLike[]">
129+
Array of tag items in the editor.
130+
</APIItem>
131+
</APIReturns>
132+
133+
### isEqualTags
134+
135+
Utility function to compare two sets of tags for equality, ignoring order.
136+
137+
<APIParameters>
138+
<APIItem name="editor" type="SlateEditor">
139+
The Slate editor instance.
140+
</APIItem>
141+
<APIItem name="newTags" type="TagLike[]" optional>
142+
New set of tags to compare against the current editor tags.
143+
</APIItem>
144+
</APIParameters>
145+
146+
<APIReturns>
147+
<APIItem type="boolean">
148+
`true` if both sets contain the same values, `false` otherwise.
149+
</APIItem>
150+
</APIReturns>
151+
152+
### useSelectableItems
153+
154+
Hook to get the available items that can be selected, filtered by search and excluding already selected items.
155+
156+
<APIParameters>
157+
<APIItem name="options" type="object">
158+
<APISubList>
159+
<APISubListItem parent="options" name="allowNew" type="boolean" optional>
160+
Whether to allow creating new items.
161+
162+
- **Default:** `true`
163+
</APISubListItem>
164+
<APISubListItem parent="options" name="filter" type="(value: string, search: string) => boolean" optional>
165+
Custom filter function for items.
166+
</APISubListItem>
167+
<APISubListItem parent="options" name="items" type="T[]" optional>
168+
Array of available items.
169+
</APISubListItem>
170+
<APISubListItem parent="options" name="newItemFilter" type="(search: string) => boolean" optional>
171+
Filter function for new items.
172+
</APISubListItem>
173+
<APISubListItem parent="options" name="newItemPosition" type="'end' | 'start'" optional>
174+
Position of new items in the list.
175+
176+
- **Default:** `'end'`
177+
</APISubListItem>
178+
</APISubList>
179+
</APIItem>
180+
</APIParameters>
181+
182+
<APIReturns>
183+
<APIItem type="T[]">
184+
Filtered array of selectable items.
185+
</APIItem>
186+
</APIReturns>
187+
188+
### useSelectEditorCombobox
189+
190+
Hook to handle combobox behavior in the editor, including text cleanup and item selection.
191+
192+
<APIParameters>
193+
<APIItem name="options" type="object">
194+
<APISubList>
195+
<APISubListItem parent="options" name="open" type="boolean">
196+
Whether the combobox is open.
197+
</APISubListItem>
198+
<APISubListItem parent="options" name="selectFirstItem" type="() => void">
199+
Function to select the first item in the combobox.
200+
</APISubListItem>
201+
<APISubListItem parent="options" name="onValueChange" type="(items: TagLike[]) => void" optional>
202+
Callback when selected items change.
203+
</APISubListItem>
204+
</APISubList>
205+
</APIItem>
206+
</APIParameters>
207+
208+
## Types
209+
210+
### TTagElement
211+
212+
```ts
213+
type TTagElement = TElement & {
214+
value: string;
215+
[key: string]: unknown;
216+
};
217+
```
218+
219+
### TagLike
220+
221+
```ts
222+
type TagLike = {
223+
value: string;
224+
[key: string]: unknown;
225+
};
226+
```

0 commit comments

Comments
 (0)