@@ -277,6 +277,52 @@ previous category, have the suffix `Attributes`.
277277 </TabItem >
278278</Tabs >
279279
280+ ## Working with enumerations
281+
282+ To implement widgets that use enumerations (` options: EnumOption<SchemaValue>[] ` ),
283+ use the functions from the ` @sjsf/form/options.svelte ` module.
284+
285+ ``` ts
286+ import { idMapper , singleOption } from " @sjsf/form/options.svelte" ;
287+
288+ const mapped = singleOption ({
289+ mapper : () => idMapper (options ),
290+ value : () => value ,
291+ update : (v ) => (value = v ),
292+ });
293+ ```
294+
295+ Now, ` mapped.value ` will correspond to the ` option.id ` of the current option,
296+ and when it changes, value will be assigned the corresponding ` option.value ` :
297+
298+ ``` svelte
299+ <select bind:value={mapped.value} {...attributes}>
300+ <option value={UNDEFINED_ID}>{placeholder}</option>
301+ {#each options as option (option.id)}
302+ <option value={option.id} disabled={option.disabled}>
303+ {option.label}
304+ </option>
305+ {/each}
306+ </select>
307+ ```
308+
309+ You can also use the ` multipleOptions ` function to implement multi-select behavior.
310+ In this case, ` mapped.value ` will be an array of ` option.id ` :
311+
312+ ``` svelte
313+ <script lang="ts">
314+ import { idMapper, singleOption } from "@sjsf/form/options.svelte";
315+
316+ const mapped = multipleOptions({
317+ mapper: () => idMapper(options),
318+ value: () => value,
319+ update: (v) => (value = v),
320+ })
321+ </script>
322+
323+ <select multiple bind:value={mapped.value} {...attributes}>
324+ ...
325+ ```
280326
281327## Retrieving theme components
282328
0 commit comments