|
1 | | -import { Meta, Canvas } from '@storybook/addon-docs'; |
2 | | -import { JsonForm } from '@sagold/react-json-editor'; |
3 | 1 | import * as ArrayItems from './ArrayItems.stories'; |
| 2 | +import { JsonForm } from '@sagold/react-json-editor'; |
| 3 | +import { Markdown } from '@storybook/blocks'; |
| 4 | +import { Meta, Canvas } from '@storybook/addon-docs'; |
| 5 | +import { Tabs } from './components/Tabs'; |
4 | 6 |
|
5 | 7 | <Meta title="ArrayItems" /> |
6 | 8 |
|
7 | 9 | # Array Items |
8 | 10 |
|
9 | | -> _json-schema_ has a set of definitions for array items. This section details how those definitions transfer to a user interface build with _@sagold/react-json-editor_ and its default widgets. |
10 | | -
|
11 | | -Validation of data is fully supported, the following list tracks support of the user interface: |
12 | | - |
13 | | -| Status | Feature | Comments | |
14 | | -| :----: | :------------------------------------ | :------------------------------------------------- | |
15 | | -| ✅ | [items array-schema](#array-schema) | defined set of array items | |
16 | | -| ❎ | [additionalItems](#additional-items) | ui does not support adding arbitrary data | |
17 | | -| ✅ | [items object-schema](#object-schema) | object schema for child-items | |
18 | | -| ✅ | [items oneOf](#one-of) | |
19 | | -| ✅ | [length](#length) | support for **minItems** and **maxItems** | |
20 | | -| ✅ | [if-then-else](#if-then-else) | |
21 | | -| ❌ | enum | only supported by validation not by user interface | |
22 | | -| ✅ | [not](#not) | validation only, exlude specific item types | |
23 | | -| ✅ | [uniqueItems](#uniqueitems) | validation only, exclude redundant items | |
24 | | -| ✅ | [contains](#contains) | validation only, ensure a specific item is present | |
| 11 | +> _json-schema_ has a set of definitions for array items. This section details how those definitions transfer to a user |
| 12 | +> interface build with _@sagold/react-json-editor_ and _@sagold/rje-mantine-widgets_. |
| 13 | +
|
| 14 | +Validation of data is fully supported, the following list tracks support by the user interface: |
| 15 | + |
| 16 | +<Markdown> |
| 17 | + {` |
| 18 | + | Status | Feature | draft | Comments | |
| 19 | + | :----: | :------------------------------------ | :--: | :---------------------------------------------------- | |
| 20 | + | ❎ | [additionalItems](#additional-items) | <= 2019-09 | ui does not support adding arbitrary data | |
| 21 | + | ✅ | [contains](#contains) | * | validation only, ensure a specific item is present | |
| 22 | + | ❌ | enum | * | only supported by validation not by user interface | |
| 23 | + | ✅ | [items object-schema](#object-schema) | * | object schema for child-items | |
| 24 | + | ✅ | [items oneOf](#one-of) | * | |
| 25 | + | ✅ | [items array-schema](#array-schema) | <= 2019-09 | defined set of array items | |
| 26 | + | ✅ | [prefixItems](#array-schema) | >= 2020-12 | defined set of array items | |
| 27 | + | ✅ | [if-then-else](#if-then-else) | * | |
| 28 | + | ✅ | [length](#length) | * | support for **minItems** and **maxItems** | |
| 29 | + | ✅ | [not](#not) | * | validation only, exlude specific item types | |
| 30 | + | ✅ | [uniqueItems](#unique-items) | * | validation only, exclude redundant items | |
| 31 | + `} |
| 32 | +</Markdown> |
25 | 33 |
|
26 | 34 | ## Array Schema |
27 | 35 |
|
28 | | -Fixed number and schema of array items |
| 36 | +Using array-items schema you define a JSON Schema for a fixed numer of array items. With no additional items defined, |
| 37 | +item edit options are disabled. |
29 | 38 |
|
30 | | -<Canvas className="inline" of={ArrayItems.ItemsArray} /> |
| 39 | +<Tabs> |
| 40 | + <Canvas tabTitle="draft-2020-12" className="inline" of={ArrayItems.ItemsArray} /> |
| 41 | + <Canvas tabTitle="draft-2019-09" className="inline" of={ArrayItems.ItemsArrayDraft2019} /> |
| 42 | +</Tabs> |
31 | 43 |
|
32 | | -## additional items |
| 44 | +## Additional items |
33 | 45 |
|
34 | 46 | With items defined by an items-array, `additionalItems=undefined` or `additionalItems=true` will allow any additional child. |
35 | 47 |
|
36 | | -- **Note**, for a missing `additionalItems` setting, add-options are disabled |
| 48 | +- **Note** Keyword `additionalItems` has been removed with draft-2020-12 |
| 49 | +- **Note** for a missing `additionalItems` setting, add-options are disabled |
37 | 50 |
|
38 | | -<Canvas className="inline" of={ArrayItems.AdditionalItemsUndefined} /> |
| 51 | +<Tabs> |
| 52 | + <Canvas tabTitle="draft-2019-09" className="inline" of={ArrayItems.AdditionalItemsUndefined} /> |
| 53 | +</Tabs> |
39 | 54 |
|
40 | 55 | With items defined by an items-array, `additionalItems=true`, the add option is available. Here, item is initialized with `null` as no schema can be derived. Thus, no input element is renderer (null-widget) for adding items. Any input items are accepted. |
41 | 56 |
|
42 | 57 | - **Note** This feature will need support to define custom data, initially offering an json-editor |
43 | 58 |
|
44 | | -<Canvas className="inline" of={ArrayItems.AdditionalItemsTrue} /> |
| 59 | +<Tabs> |
| 60 | + <Canvas tabTitle="draft-2019-09" className="inline" of={ArrayItems.AdditionalItemsTrue} /> |
| 61 | +</Tabs> |
45 | 62 |
|
46 | 63 | Preventing additional items will disable add-options and remove any undefined item from user form and exported data. In the following example, the array is initialized with three values: |
47 | 64 |
|
48 | | -<Canvas className="inline" of={ArrayItems.AdditionalItemsFalse} /> |
| 65 | +<Tabs> |
| 66 | + <Canvas tabTitle="draft-2019-09" className="inline" of={ArrayItems.AdditionalItemsFalse} /> |
| 67 | +</Tabs> |
49 | 68 |
|
50 | 69 | With items defined by an items-array and `additionalItems` set to a valid json-schema, items may be added in the given format. |
51 | 70 |
|
52 | | -<Canvas className="inline" of={ArrayItems.AdditionalItemsSchema} /> |
| 71 | +<Tabs> |
| 72 | + <Canvas tabTitle="draft-2019-09" className="inline" of={ArrayItems.AdditionalItemsSchema} /> |
| 73 | +</Tabs> |
53 | 74 |
|
54 | 75 | ## Object Schema |
55 | 76 |
|
56 | | -Array items can contain any supported json-schema: |
| 77 | +An array object-schema defines the structure for all array-items which are not defined by an array-schema (items, |
| 78 | +prefixItems). Without length restrictions array edit-options are always enabled. |
57 | 79 |
|
58 | | -<Canvas className="inline" of={ArrayItems.ItemsObject} /> |
| 80 | +<Tabs> |
| 81 | + <Canvas tabTitle="draft-2020-12" className="inline" of={ArrayItems.ItemsObject} /> |
| 82 | + <Canvas tabTitle="draft-2019-09" className="inline" of={ArrayItems.ItemsObjectDraft2019} /> |
| 83 | +</Tabs> |
59 | 84 |
|
60 | 85 | ## One Of |
61 | 86 |
|
|
0 commit comments