@vev/silke 1.1.8 → 1.1.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +800 -0
- package/CHANGELOG.md +17 -0
- package/CLAUDE.md +102 -0
- package/dist/index.js +44 -40
- package/dist/index.js.LEGAL.txt +1 -1
- package/dist/styles.css +470 -254
- package/dist/types/components/index.d.ts +2 -0
- package/dist/types/components/silke-command-text-field/attachment-chip.d.ts +8 -0
- package/dist/types/components/silke-command-text-field/attachment-list.d.ts +15 -0
- package/dist/types/components/silke-command-text-field/file-utils.d.ts +33 -0
- package/dist/types/components/silke-command-text-field/file-utils.spec.d.ts +1 -0
- package/dist/types/components/silke-command-text-field/index.d.ts +6 -1
- package/dist/types/components/silke-command-text-field/silke-command-text-field.d.ts +23 -6
- package/dist/types/components/silke-command-text-field/utils.d.ts +14 -1
- package/dist/types/components/silke-conditions-input/utils.d.ts +1 -1
- package/dist/types/components/silke-css-number-field/silke-css-context.d.ts +2 -0
- package/dist/types/components/silke-css-number-field/silke-css-number-field.d.ts +2 -0
- package/dist/types/components/silke-css-number-field/utils.d.ts +1 -1
- package/dist/types/components/silke-form-schema/fields/group-field.d.ts +3 -0
- package/dist/types/components/silke-form-schema/fields/object-field.d.ts +1 -1
- package/dist/types/components/silke-form-schema/fields/popover-field.d.ts +3 -0
- package/dist/types/components/silke-form-schema/fields/utils/generate-image.d.ts +5 -0
- package/dist/types/components/silke-form-schema/fields/utils/index.d.ts +1 -1
- package/dist/types/components/silke-form-schema/silke-schema-field.d.ts +2 -1
- package/dist/types/components/silke-gradient-picker/index.d.ts +3 -0
- package/dist/types/components/silke-icon/silke-icon.d.ts +1 -1
- package/dist/types/components/silke-list/silke-list.d.ts +6 -1
- package/dist/types/components/silke-list/types.d.ts +2 -0
- package/dist/types/components/silke-shortcut-button/silke-shortcut-button.d.ts +4 -1
- package/dist/types/components/silke-theme-card/index.d.ts +1 -0
- package/dist/types/components/silke-theme-card/silke-theme-card.d.ts +18 -0
- package/dist/types/components/silke-theme-swatch/index.d.ts +1 -0
- package/dist/types/components/silke-theme-swatch/silke-theme-swatch.d.ts +11 -0
- package/dist/types/icons.d.ts +7 -2
- package/package.json +32 -20
- package/src/components/index.ts +2 -0
- package/src/components/silke-autocomplete-field/silke-autocomplete-popup-native.tsx +25 -18
- package/src/components/silke-button/silke-dropdown-button.mdx +1 -1
- package/src/components/silke-color-picker/color.ts +5 -3
- package/src/components/silke-color-swatches/silke-swatches.tsx +3 -3
- package/src/components/silke-command-text-field/attachment-chip.tsx +71 -0
- package/src/components/silke-command-text-field/attachment-list.tsx +72 -0
- package/src/components/silke-command-text-field/file-utils.spec.ts +148 -0
- package/src/components/silke-command-text-field/file-utils.ts +159 -0
- package/src/components/silke-command-text-field/index.ts +14 -0
- package/src/components/silke-command-text-field/silke-command-text-field.mdx +109 -13
- package/src/components/silke-command-text-field/silke-command-text-field.module.scss +65 -40
- package/src/components/silke-command-text-field/silke-command-text-field.tsx +113 -135
- package/src/components/silke-command-text-field/utils.spec.ts +109 -1
- package/src/components/silke-command-text-field/utils.ts +44 -7
- package/src/components/silke-css-number-field/silke-css-context.tsx +2 -0
- package/src/components/silke-css-number-field/silke-css-number-field.tsx +7 -4
- package/src/components/silke-css-number-field/utils.ts +8 -2
- package/src/components/silke-form-schema/fields/array-field-modal.tsx +69 -48
- package/src/components/silke-form-schema/fields/array-field.tsx +144 -130
- package/src/components/silke-form-schema/fields/color-field.tsx +118 -18
- package/src/components/silke-form-schema/fields/group-field.tsx +49 -0
- package/src/components/silke-form-schema/fields/icon-field.tsx +59 -39
- package/src/components/silke-form-schema/fields/image-field.tsx +50 -39
- package/src/components/silke-form-schema/fields/number-field.tsx +190 -116
- package/src/components/silke-form-schema/fields/object-field.tsx +2 -0
- package/src/components/silke-form-schema/fields/popover-field.tsx +65 -0
- package/src/components/silke-form-schema/fields/select-field.tsx +43 -30
- package/src/components/silke-form-schema/fields/string-field.tsx +1 -1
- package/src/components/silke-form-schema/fields/styles.scss +2 -39
- package/src/components/silke-form-schema/fields/toggle-field.tsx +48 -15
- package/src/components/silke-form-schema/fields/utils/generate-image.ts +20 -0
- package/src/components/silke-form-schema/fields/utils/generate-title.ts +1 -1
- package/src/components/silke-form-schema/fields/utils/index.ts +1 -1
- package/src/components/silke-form-schema/silke-form-schema.mdx +498 -311
- package/src/components/silke-form-schema/silke-schema-field.tsx +10 -3
- package/src/components/silke-form-schema/silke-schema-fields.tsx +9 -5
- package/src/components/silke-gradient-picker/index.ts +3 -0
- package/src/components/silke-icon/silke-icon.mdx +13 -1
- package/src/components/silke-icon/silke-icon.tsx +6 -2
- package/src/components/silke-list/silke-list.tsx +59 -26
- package/src/components/silke-list/types.ts +2 -0
- package/src/components/silke-navigation-link/silke-navigation-link.scss +1 -0
- package/src/components/silke-shortcut-button/silke-shortcut-button.scss +16 -0
- package/src/components/silke-shortcut-button/silke-shortcut-button.tsx +9 -0
- package/src/components/silke-slider/silke-slider.module.scss +1 -1
- package/src/components/silke-text-field/silke-text-field-outline.tsx +9 -6
- package/src/components/silke-text-field/silke-text-field.scss +3 -0
- package/src/components/silke-text-field/silke-text-field.tsx +1 -1
- package/src/components/silke-theme-card/index.ts +1 -0
- package/src/components/silke-theme-card/silke-theme-card.mdx +50 -0
- package/src/components/silke-theme-card/silke-theme-card.module.scss +82 -0
- package/src/components/silke-theme-card/silke-theme-card.tsx +82 -0
- package/src/components/silke-theme-swatch/index.ts +1 -0
- package/src/components/silke-theme-swatch/silke-theme-swatch.mdx +59 -0
- package/src/components/silke-theme-swatch/silke-theme-swatch.module.scss +108 -0
- package/src/components/silke-theme-swatch/silke-theme-swatch.tsx +49 -0
- package/src/components/silke-variables-wrapper/silke-variables-wrapper.tsx +9 -8
- package/src/icons.tsx +41 -7
- package/tsconfig.build.tsbuildinfo +1 -1
- package/project.json +0 -12
|
@@ -1,428 +1,615 @@
|
|
|
1
1
|
# Schema Form
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Build dynamic settings panels from a declarative schema. Each field type maps to a UI component automatically.
|
|
4
|
+
|
|
5
|
+
## Basic fields
|
|
6
|
+
|
|
7
|
+
The most common field types: text, numbers, toggles, colors, and images.
|
|
4
8
|
|
|
5
9
|
```js
|
|
6
10
|
const schema = [
|
|
11
|
+
{ type: 'string', name: 'title', title: 'Title', initialValue: 'Hello world' },
|
|
7
12
|
{
|
|
8
13
|
type: 'string',
|
|
9
|
-
name: '
|
|
10
|
-
title: '
|
|
11
|
-
|
|
14
|
+
name: 'description',
|
|
15
|
+
title: 'Description',
|
|
16
|
+
options: { multiline: 3, placeholder: 'Write something...' },
|
|
12
17
|
},
|
|
18
|
+
{ type: 'number', name: 'count', title: 'Count', initialValue: 5 },
|
|
13
19
|
{
|
|
14
|
-
type: '
|
|
15
|
-
name: '
|
|
16
|
-
title: '
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
type: 'number',
|
|
21
|
+
name: 'opacity',
|
|
22
|
+
title: 'Opacity',
|
|
23
|
+
initialValue: 0.8,
|
|
24
|
+
options: { min: 0, max: 100, scale: 100, display: 'slider' },
|
|
25
|
+
},
|
|
26
|
+
{ type: 'boolean', name: 'visible', title: 'Visible', initialValue: true },
|
|
27
|
+
{ type: 'color', name: 'color', title: 'Color' },
|
|
28
|
+
{ type: 'image', name: 'image', title: 'Image' },
|
|
29
|
+
{ type: 'link', name: 'link', title: 'Link' },
|
|
30
|
+
];
|
|
31
|
+
|
|
32
|
+
const [value, setValue] = React.useState({});
|
|
33
|
+
|
|
34
|
+
const context = {
|
|
35
|
+
actions: {
|
|
36
|
+
imageLibraryOpen: (cb) => cb({ key: 'demo', url: ipsum.image() }),
|
|
37
|
+
imageLibraryClose: () => {},
|
|
22
38
|
},
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
<div style={{ width: '300px' }}>
|
|
42
|
+
<SilkeFormSchema schema={schema} value={value} onChange={setValue} context={context} />
|
|
43
|
+
<pre>{JSON.stringify(value, null, 2)}</pre>
|
|
44
|
+
</div>;
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Range slider
|
|
48
|
+
|
|
49
|
+
A dual-handle slider for selecting a numeric range. Set `display: 'range-slider'` with `min` and `max` bounds (in display space). The value is a `[min, max]` tuple.
|
|
50
|
+
|
|
51
|
+
```js
|
|
52
|
+
const schema = [
|
|
23
53
|
{
|
|
24
54
|
type: 'number',
|
|
25
|
-
name: '
|
|
26
|
-
title: '
|
|
27
|
-
|
|
55
|
+
name: 'priceRange',
|
|
56
|
+
title: 'Price Range',
|
|
57
|
+
initialValue: [200, 800],
|
|
58
|
+
options: { display: 'range-slider', min: 0, max: 1000 },
|
|
28
59
|
},
|
|
29
60
|
{
|
|
30
61
|
type: 'number',
|
|
31
|
-
name: '
|
|
32
|
-
title: '
|
|
33
|
-
|
|
62
|
+
name: 'opacity',
|
|
63
|
+
title: 'Opacity Range',
|
|
64
|
+
initialValue: [0.2, 0.8],
|
|
65
|
+
options: { display: 'range-slider', min: 0, max: 100, scale: 100 },
|
|
66
|
+
},
|
|
67
|
+
];
|
|
68
|
+
|
|
69
|
+
const [value, setValue] = React.useState({});
|
|
70
|
+
|
|
71
|
+
<div style={{ width: '300px' }}>
|
|
72
|
+
<SilkeFormSchema schema={schema} value={value} onChange={setValue} context={{}} />
|
|
73
|
+
<pre>{JSON.stringify(value, null, 2)}</pre>
|
|
74
|
+
</div>;
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## Icon field
|
|
78
|
+
|
|
79
|
+
Pick shapes from the shape library. Stores the full shape object `{ key, name, path }` where `path` is `[width, height, pathData]`.
|
|
80
|
+
|
|
81
|
+
```js
|
|
82
|
+
const schema = [
|
|
83
|
+
{ type: 'icon', name: 'icon', title: 'Icon' },
|
|
84
|
+
];
|
|
85
|
+
|
|
86
|
+
const [value, setValue] = React.useState({});
|
|
87
|
+
|
|
88
|
+
<div style={{ width: '300px' }}>
|
|
89
|
+
<SilkeFormSchema schema={schema} value={value} onChange={setValue} context={{}} />
|
|
90
|
+
<pre>{JSON.stringify(value, null, 2)}</pre>
|
|
91
|
+
</div>;
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## Select fields
|
|
95
|
+
|
|
96
|
+
Dropdown, radio, checkbox, and autocomplete selection.
|
|
97
|
+
|
|
98
|
+
```js
|
|
99
|
+
const schema = [
|
|
100
|
+
{
|
|
101
|
+
type: 'select',
|
|
102
|
+
name: 'size',
|
|
103
|
+
title: 'Size',
|
|
34
104
|
options: {
|
|
35
|
-
|
|
105
|
+
display: 'dropdown',
|
|
106
|
+
items: [
|
|
107
|
+
{ label: 'Small', value: 's' },
|
|
108
|
+
{ label: 'Medium', value: 'm' },
|
|
109
|
+
{ label: 'Large', value: 'l' },
|
|
110
|
+
],
|
|
36
111
|
},
|
|
37
112
|
},
|
|
38
113
|
{
|
|
39
|
-
type: '
|
|
40
|
-
name: '
|
|
41
|
-
title: '
|
|
42
|
-
description: 'Slider for component',
|
|
114
|
+
type: 'select',
|
|
115
|
+
name: 'alignment',
|
|
116
|
+
title: 'Alignment',
|
|
43
117
|
options: {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
118
|
+
display: 'radio',
|
|
119
|
+
items: [
|
|
120
|
+
{ label: 'Left', value: 'left' },
|
|
121
|
+
{ label: 'Center', value: 'center' },
|
|
122
|
+
{ label: 'Right', value: 'right' },
|
|
123
|
+
],
|
|
48
124
|
},
|
|
49
125
|
},
|
|
50
126
|
{
|
|
51
|
-
type: '
|
|
52
|
-
name: '
|
|
53
|
-
title: '
|
|
54
|
-
|
|
127
|
+
type: 'select',
|
|
128
|
+
name: 'features',
|
|
129
|
+
title: 'Features',
|
|
130
|
+
options: {
|
|
131
|
+
multiselect: true,
|
|
132
|
+
display: 'checkbox',
|
|
133
|
+
items: [
|
|
134
|
+
{ label: 'Animations', value: 'animations' },
|
|
135
|
+
{ label: 'Shadows', value: 'shadows' },
|
|
136
|
+
{ label: 'Rounded corners', value: 'rounded' },
|
|
137
|
+
],
|
|
138
|
+
},
|
|
55
139
|
},
|
|
140
|
+
];
|
|
141
|
+
|
|
142
|
+
const [value, setValue] = React.useState({});
|
|
143
|
+
|
|
144
|
+
<div style={{ width: '300px' }}>
|
|
145
|
+
<SilkeFormSchema schema={schema} value={value} onChange={setValue} context={{}} />
|
|
146
|
+
<pre>{JSON.stringify(value, null, 2)}</pre>
|
|
147
|
+
</div>;
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
## Row layout
|
|
151
|
+
|
|
152
|
+
Place fields side-by-side using `layout` with `display: 'row'`. Use `flex: true` on fields that should stretch to fill available space.
|
|
153
|
+
|
|
154
|
+
```js
|
|
155
|
+
const schema = [
|
|
56
156
|
{
|
|
57
|
-
type: '
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
157
|
+
type: 'layout',
|
|
158
|
+
options: { display: 'row' },
|
|
159
|
+
fields: [
|
|
160
|
+
{ type: 'number', name: 'width', title: 'W', flex: true },
|
|
161
|
+
{ type: 'number', name: 'height', title: 'H', flex: true },
|
|
162
|
+
],
|
|
61
163
|
},
|
|
62
164
|
{
|
|
63
|
-
|
|
64
|
-
|
|
165
|
+
type: 'layout',
|
|
166
|
+
options: { display: 'row' },
|
|
167
|
+
fields: [
|
|
168
|
+
{ type: 'number', name: 'x', title: 'X', flex: true },
|
|
169
|
+
{ type: 'number', name: 'y', title: 'Y', flex: true },
|
|
170
|
+
],
|
|
65
171
|
},
|
|
66
172
|
{
|
|
67
|
-
type: '
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
173
|
+
type: 'layout',
|
|
174
|
+
options: { display: 'row' },
|
|
175
|
+
fields: [
|
|
176
|
+
{ type: 'number', name: 'top', title: 'Top', flex: true },
|
|
177
|
+
{ type: 'number', name: 'right', title: 'Right', flex: true },
|
|
178
|
+
{ type: 'number', name: 'bottom', title: 'Bottom', flex: true },
|
|
179
|
+
{ type: 'number', name: 'left', title: 'Left', flex: true },
|
|
180
|
+
],
|
|
181
|
+
},
|
|
182
|
+
];
|
|
183
|
+
|
|
184
|
+
const [value, setValue] = React.useState({});
|
|
185
|
+
|
|
186
|
+
<div style={{ width: '300px' }}>
|
|
187
|
+
<SilkeFormSchema schema={schema} value={value} onChange={setValue} context={{}} />
|
|
188
|
+
</div>;
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
## Groups
|
|
192
|
+
|
|
193
|
+
Use `group` to organize fields into collapsible card sections with a bold title header and chevron toggle. Set `collapsed: true` to start closed.
|
|
194
|
+
|
|
195
|
+
```js
|
|
196
|
+
const schema = [
|
|
197
|
+
{ type: 'string', name: 'title', title: 'Title', initialValue: 'My Component' },
|
|
198
|
+
{
|
|
199
|
+
type: 'group',
|
|
200
|
+
title: 'Background',
|
|
201
|
+
fields: [
|
|
202
|
+
{ type: 'image', name: 'bgImage', title: 'Image' },
|
|
203
|
+
{ type: 'color', name: 'bgColor', title: 'Color' },
|
|
204
|
+
],
|
|
205
|
+
},
|
|
206
|
+
{
|
|
207
|
+
type: 'group',
|
|
208
|
+
title: 'Typography',
|
|
209
|
+
fields: [
|
|
72
210
|
{
|
|
73
|
-
type: '
|
|
74
|
-
name: '
|
|
211
|
+
type: 'select',
|
|
212
|
+
name: 'fontWeight',
|
|
213
|
+
title: 'Weight',
|
|
214
|
+
options: {
|
|
215
|
+
display: 'dropdown',
|
|
216
|
+
items: [
|
|
217
|
+
{ label: 'Regular', value: '400' },
|
|
218
|
+
{ label: 'Medium', value: '500' },
|
|
219
|
+
{ label: 'Bold', value: '700' },
|
|
220
|
+
],
|
|
221
|
+
},
|
|
222
|
+
},
|
|
223
|
+
{ type: 'number', name: 'fontSize', title: 'Font Size' },
|
|
224
|
+
{ type: 'color', name: 'textColor', title: 'Text Color' },
|
|
225
|
+
],
|
|
226
|
+
},
|
|
227
|
+
{
|
|
228
|
+
type: 'group',
|
|
229
|
+
title: 'Advanced Settings',
|
|
230
|
+
options: { collapsed: true },
|
|
231
|
+
fields: [
|
|
232
|
+
{ type: 'number', name: 'zIndex', title: 'Z-Index' },
|
|
233
|
+
{ type: 'boolean', name: 'lazyLoad', title: 'Lazy Load' },
|
|
234
|
+
{ type: 'string', name: 'cssClass', title: 'CSS Class' },
|
|
235
|
+
],
|
|
236
|
+
},
|
|
237
|
+
];
|
|
238
|
+
|
|
239
|
+
const [value, setValue] = React.useState({});
|
|
240
|
+
|
|
241
|
+
<div style={{ width: '300px' }}>
|
|
242
|
+
<SilkeFormSchema schema={schema} value={value} onChange={setValue} context={{}} />
|
|
243
|
+
</div>;
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
## Popover settings
|
|
247
|
+
|
|
248
|
+
Use `popover` to tuck away extra settings behind a button. Works great inside a `layout` row next to a field.
|
|
249
|
+
|
|
250
|
+
```js
|
|
251
|
+
const schema = [
|
|
252
|
+
{
|
|
253
|
+
type: 'layout', options: { display: 'row' },
|
|
254
|
+
fields: [
|
|
255
|
+
{ type: 'string', name: 'url', title: 'API URL', flex: true },
|
|
256
|
+
{
|
|
257
|
+
type: 'popover',
|
|
258
|
+
title: 'Request Options',
|
|
259
|
+
options: { icon: 'settings' },
|
|
75
260
|
fields: [
|
|
76
261
|
{
|
|
77
|
-
type: '
|
|
78
|
-
name: '
|
|
262
|
+
type: 'select',
|
|
263
|
+
name: 'method',
|
|
264
|
+
title: 'Method',
|
|
265
|
+
options: {
|
|
266
|
+
display: 'dropdown',
|
|
267
|
+
items: [
|
|
268
|
+
{ label: 'GET', value: 'GET' },
|
|
269
|
+
{ label: 'POST', value: 'POST' },
|
|
270
|
+
{ label: 'PUT', value: 'PUT' },
|
|
271
|
+
],
|
|
272
|
+
},
|
|
79
273
|
},
|
|
274
|
+
{ type: 'number', name: 'timeout', title: 'Timeout (ms)' },
|
|
275
|
+
{ type: 'boolean', name: 'cache', title: 'Enable Cache' },
|
|
276
|
+
],
|
|
277
|
+
},
|
|
278
|
+
],
|
|
279
|
+
},
|
|
280
|
+
{
|
|
281
|
+
type: 'layout', options: { display: 'row' },
|
|
282
|
+
fields: [
|
|
283
|
+
{ type: 'color', name: 'color', title: 'Color', flex: true },
|
|
284
|
+
{
|
|
285
|
+
type: 'popover',
|
|
286
|
+
title: 'Color Options',
|
|
287
|
+
options: { icon: 'settings' },
|
|
288
|
+
fields: [
|
|
80
289
|
{
|
|
81
|
-
type: '
|
|
82
|
-
name: '
|
|
290
|
+
type: 'number',
|
|
291
|
+
name: 'opacity',
|
|
292
|
+
title: 'Opacity',
|
|
293
|
+
options: { min: 0, max: 100, scale: 100, display: 'slider' },
|
|
83
294
|
},
|
|
84
295
|
{
|
|
85
|
-
type: '
|
|
86
|
-
name: '
|
|
87
|
-
title: '
|
|
296
|
+
type: 'select',
|
|
297
|
+
name: 'blendMode',
|
|
298
|
+
title: 'Blend Mode',
|
|
299
|
+
options: {
|
|
300
|
+
display: 'dropdown',
|
|
301
|
+
items: [
|
|
302
|
+
{ label: 'Normal', value: 'normal' },
|
|
303
|
+
{ label: 'Multiply', value: 'multiply' },
|
|
304
|
+
{ label: 'Screen', value: 'screen' },
|
|
305
|
+
{ label: 'Overlay', value: 'overlay' },
|
|
306
|
+
],
|
|
307
|
+
},
|
|
88
308
|
},
|
|
89
309
|
],
|
|
90
310
|
},
|
|
91
311
|
],
|
|
92
312
|
},
|
|
313
|
+
];
|
|
314
|
+
|
|
315
|
+
const [value, setValue] = React.useState({});
|
|
316
|
+
|
|
317
|
+
<div style={{ width: '300px' }}>
|
|
318
|
+
<SilkeFormSchema schema={schema} value={value} onChange={setValue} context={{}} />
|
|
319
|
+
</div>;
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
## Array fields
|
|
323
|
+
|
|
324
|
+
Repeatable lists with drag-and-drop sorting.
|
|
325
|
+
|
|
326
|
+
- `of: 'string'` — simple string list
|
|
327
|
+
- `of: 'object'` with `fields` — structured items with a fixed schema
|
|
328
|
+
- `of: [...]` — multiple item types the user can pick from when adding
|
|
329
|
+
|
|
330
|
+
```js
|
|
331
|
+
const schema = [
|
|
93
332
|
{
|
|
94
333
|
type: 'array',
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
description: 'Array for string',
|
|
334
|
+
name: 'tags',
|
|
335
|
+
title: 'Tags',
|
|
98
336
|
of: 'string',
|
|
99
337
|
},
|
|
100
338
|
{
|
|
101
339
|
type: 'array',
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
340
|
+
name: 'links',
|
|
341
|
+
title: 'Links',
|
|
342
|
+
of: 'object',
|
|
343
|
+
fields: [
|
|
344
|
+
{ type: 'string', name: 'label', title: 'Label' },
|
|
345
|
+
{ type: 'string', name: 'url', title: 'URL', options: { type: 'url' } },
|
|
346
|
+
{ type: 'boolean', name: 'external', title: 'Open in new tab' },
|
|
347
|
+
],
|
|
348
|
+
},
|
|
349
|
+
{
|
|
350
|
+
type: 'array',
|
|
351
|
+
name: 'blocks',
|
|
352
|
+
title: 'Content Blocks',
|
|
105
353
|
of: [
|
|
106
|
-
{
|
|
107
|
-
type: 'string',
|
|
108
|
-
name: 'field-string',
|
|
109
|
-
},
|
|
110
|
-
{
|
|
111
|
-
type: 'number',
|
|
112
|
-
name: 'field-number',
|
|
113
|
-
title: 'Number field',
|
|
114
|
-
},
|
|
115
354
|
{
|
|
116
355
|
type: 'object',
|
|
117
|
-
name: '
|
|
356
|
+
name: 'text',
|
|
357
|
+
title: 'Text Block',
|
|
118
358
|
fields: [
|
|
119
|
-
{
|
|
120
|
-
|
|
121
|
-
type: 'string',
|
|
122
|
-
},
|
|
123
|
-
{
|
|
124
|
-
name: 'obj-2',
|
|
125
|
-
type: 'string',
|
|
126
|
-
},
|
|
359
|
+
{ type: 'string', name: 'heading', title: 'Heading' },
|
|
360
|
+
{ type: 'string', name: 'body', title: 'Body', options: { multiline: 3 } },
|
|
127
361
|
],
|
|
128
362
|
},
|
|
129
|
-
],
|
|
130
|
-
},
|
|
131
|
-
{
|
|
132
|
-
type: 'object',
|
|
133
|
-
title: 'Object field',
|
|
134
|
-
name: 'objectKey',
|
|
135
|
-
description: 'Object for component',
|
|
136
|
-
fields: [
|
|
137
363
|
{
|
|
138
|
-
type: '
|
|
139
|
-
name: '
|
|
140
|
-
title: '
|
|
364
|
+
type: 'object',
|
|
365
|
+
name: 'image',
|
|
366
|
+
title: 'Image Block',
|
|
367
|
+
fields: [
|
|
368
|
+
{ type: 'image', name: 'src', title: 'Image' },
|
|
369
|
+
{ type: 'string', name: 'alt', title: 'Alt Text' },
|
|
370
|
+
],
|
|
141
371
|
},
|
|
142
372
|
{
|
|
143
|
-
type: '
|
|
144
|
-
name: '
|
|
145
|
-
title: '
|
|
373
|
+
type: 'object',
|
|
374
|
+
name: 'cta',
|
|
375
|
+
title: 'CTA Block',
|
|
376
|
+
fields: [
|
|
377
|
+
{ type: 'string', name: 'label', title: 'Button Label' },
|
|
378
|
+
{ type: 'link', name: 'link', title: 'Link' },
|
|
379
|
+
],
|
|
146
380
|
},
|
|
147
381
|
],
|
|
148
382
|
},
|
|
383
|
+
];
|
|
384
|
+
|
|
385
|
+
const [value, setValue] = React.useState({
|
|
386
|
+
tags: ['Design', 'Code'],
|
|
387
|
+
links: [
|
|
388
|
+
{ label: 'Docs', url: 'https://docs.example.com', external: true },
|
|
389
|
+
],
|
|
390
|
+
blocks: [
|
|
391
|
+
{ text: { heading: 'Welcome', body: 'Hello world' } },
|
|
392
|
+
{ image: { alt: 'Hero image' } },
|
|
393
|
+
],
|
|
394
|
+
});
|
|
395
|
+
|
|
396
|
+
<div style={{ width: '300px' }}>
|
|
397
|
+
<SilkeFormSchema schema={schema} value={value} onChange={setValue} context={{}} />
|
|
398
|
+
<pre>{JSON.stringify(value, null, 2)}</pre>
|
|
399
|
+
</div>;
|
|
400
|
+
```
|
|
401
|
+
|
|
402
|
+
## Combining everything
|
|
403
|
+
|
|
404
|
+
A realistic component settings panel using groups, layouts, and popovers together.
|
|
405
|
+
|
|
406
|
+
```js
|
|
407
|
+
const schema = [
|
|
408
|
+
{ type: 'string', name: 'heading', title: 'Heading', initialValue: 'Welcome' },
|
|
149
409
|
{
|
|
150
|
-
type: '
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
options: {
|
|
155
|
-
items: [
|
|
156
|
-
{
|
|
157
|
-
label: 'Option 1',
|
|
158
|
-
value: 'one',
|
|
159
|
-
},
|
|
160
|
-
{
|
|
161
|
-
label: 'Option 2',
|
|
162
|
-
value: 'two',
|
|
163
|
-
},
|
|
164
|
-
{
|
|
165
|
-
label: 'Option 3',
|
|
166
|
-
value: 'three',
|
|
167
|
-
},
|
|
168
|
-
],
|
|
169
|
-
},
|
|
170
|
-
},
|
|
171
|
-
{
|
|
172
|
-
type: 'select',
|
|
173
|
-
title: 'Multi select field',
|
|
174
|
-
name: 'multiSelectField',
|
|
175
|
-
description: 'Select field for component',
|
|
176
|
-
options: {
|
|
177
|
-
multiselect: true,
|
|
178
|
-
items: [
|
|
179
|
-
{
|
|
180
|
-
label: 'Option 1',
|
|
181
|
-
value: 'one',
|
|
182
|
-
},
|
|
183
|
-
{
|
|
184
|
-
label: 'Option 2',
|
|
185
|
-
value: 'two',
|
|
186
|
-
},
|
|
187
|
-
{
|
|
188
|
-
label: 'Option 3',
|
|
189
|
-
value: 'three',
|
|
190
|
-
},
|
|
191
|
-
],
|
|
192
|
-
},
|
|
193
|
-
},
|
|
194
|
-
{
|
|
195
|
-
type: 'select',
|
|
196
|
-
title: 'Multi select dropdown field',
|
|
197
|
-
name: 'multipleSelectDropdownField',
|
|
198
|
-
description: 'Select field for component',
|
|
199
|
-
options: {
|
|
200
|
-
display: 'dropdown',
|
|
201
|
-
items: [
|
|
202
|
-
{
|
|
203
|
-
label: 'Option 1',
|
|
204
|
-
value: 'one',
|
|
205
|
-
},
|
|
206
|
-
{
|
|
207
|
-
label: 'Option 2',
|
|
208
|
-
value: 'two',
|
|
209
|
-
},
|
|
210
|
-
{
|
|
211
|
-
label: 'Option 3',
|
|
212
|
-
value: 'three',
|
|
213
|
-
},
|
|
214
|
-
],
|
|
215
|
-
},
|
|
410
|
+
type: 'string',
|
|
411
|
+
name: 'body',
|
|
412
|
+
title: 'Body Text',
|
|
413
|
+
options: { multiline: 3, placeholder: 'Enter body text...' },
|
|
216
414
|
},
|
|
415
|
+
{ type: 'link', name: 'ctaLink', title: 'CTA Link' },
|
|
217
416
|
{
|
|
218
|
-
type: '
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
{
|
|
227
|
-
label: 'Option 1',
|
|
228
|
-
value: 'one',
|
|
229
|
-
},
|
|
230
|
-
{
|
|
231
|
-
label: 'Option 2',
|
|
232
|
-
value: 'two',
|
|
233
|
-
},
|
|
234
|
-
{
|
|
235
|
-
label: 'Option 3',
|
|
236
|
-
value: 'three',
|
|
237
|
-
},
|
|
238
|
-
],
|
|
239
|
-
},
|
|
417
|
+
type: 'array',
|
|
418
|
+
name: 'buttons',
|
|
419
|
+
title: 'Buttons',
|
|
420
|
+
of: 'object',
|
|
421
|
+
fields: [
|
|
422
|
+
{ type: 'string', name: 'label', title: 'Label' },
|
|
423
|
+
{ type: 'link', name: 'link', title: 'Link' },
|
|
424
|
+
],
|
|
240
425
|
},
|
|
426
|
+
{ type: 'divider' },
|
|
241
427
|
{
|
|
242
|
-
type: '
|
|
243
|
-
|
|
244
|
-
display: 'row',
|
|
245
|
-
},
|
|
428
|
+
type: 'group',
|
|
429
|
+
title: 'Layout',
|
|
246
430
|
fields: [
|
|
247
431
|
{
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
type: 'string',
|
|
432
|
+
type: 'layout', options: { display: 'row' },
|
|
433
|
+
fields: [
|
|
434
|
+
{ type: 'number', name: 'columns', title: 'Cols', flex: true },
|
|
435
|
+
{ type: 'number', name: 'gap', title: 'Gap', flex: true },
|
|
436
|
+
],
|
|
254
437
|
},
|
|
255
438
|
{
|
|
256
|
-
|
|
257
|
-
|
|
439
|
+
type: 'layout', options: { display: 'row' },
|
|
440
|
+
fields: [
|
|
441
|
+
{
|
|
442
|
+
type: 'select',
|
|
443
|
+
name: 'align',
|
|
444
|
+
title: 'Align',
|
|
445
|
+
flex: true,
|
|
446
|
+
options: {
|
|
447
|
+
display: 'dropdown',
|
|
448
|
+
items: [
|
|
449
|
+
{ label: 'Left', value: 'left' },
|
|
450
|
+
{ label: 'Center', value: 'center' },
|
|
451
|
+
{ label: 'Right', value: 'right' },
|
|
452
|
+
],
|
|
453
|
+
},
|
|
454
|
+
},
|
|
455
|
+
{
|
|
456
|
+
type: 'popover',
|
|
457
|
+
title: 'Spacing',
|
|
458
|
+
options: { icon: 'settings' },
|
|
459
|
+
fields: [
|
|
460
|
+
{
|
|
461
|
+
type: 'layout', options: { display: 'row' },
|
|
462
|
+
fields: [
|
|
463
|
+
{ type: 'number', name: 'padTop', title: 'Top', flex: true },
|
|
464
|
+
{ type: 'number', name: 'padRight', title: 'Right', flex: true },
|
|
465
|
+
],
|
|
466
|
+
},
|
|
467
|
+
{
|
|
468
|
+
type: 'layout', options: { display: 'row' },
|
|
469
|
+
fields: [
|
|
470
|
+
{ type: 'number', name: 'padBottom', title: 'Bottom', flex: true },
|
|
471
|
+
{ type: 'number', name: 'padLeft', title: 'Left', flex: true },
|
|
472
|
+
],
|
|
473
|
+
},
|
|
474
|
+
],
|
|
475
|
+
},
|
|
476
|
+
],
|
|
258
477
|
},
|
|
478
|
+
],
|
|
479
|
+
},
|
|
480
|
+
{
|
|
481
|
+
type: 'group',
|
|
482
|
+
title: 'Background',
|
|
483
|
+
fields: [
|
|
484
|
+
{ type: 'image', name: 'bgImage', title: 'Image' },
|
|
485
|
+
{ type: 'color', name: 'bgColor', title: 'Color' },
|
|
259
486
|
{
|
|
260
|
-
|
|
261
|
-
|
|
487
|
+
type: 'number',
|
|
488
|
+
name: 'bgOpacity',
|
|
489
|
+
title: 'Opacity',
|
|
490
|
+
options: { min: 0, max: 100, scale: 100, display: 'slider' },
|
|
262
491
|
},
|
|
263
492
|
{
|
|
264
|
-
|
|
265
|
-
|
|
493
|
+
type: 'array',
|
|
494
|
+
name: 'overlays',
|
|
495
|
+
title: 'Overlays',
|
|
496
|
+
of: 'object',
|
|
497
|
+
fields: [
|
|
498
|
+
{ type: 'color', name: 'color', title: 'Color' },
|
|
499
|
+
{ type: 'number', name: 'opacity', title: 'Opacity', options: { min: 0, max: 100, scale: 100, display: 'slider' } },
|
|
500
|
+
],
|
|
266
501
|
},
|
|
267
502
|
],
|
|
268
503
|
},
|
|
504
|
+
{
|
|
505
|
+
type: 'group',
|
|
506
|
+
title: 'Advanced',
|
|
507
|
+
options: { collapsed: true },
|
|
508
|
+
fields: [
|
|
509
|
+
{ type: 'boolean', name: 'lazyLoad', title: 'Lazy Load' },
|
|
510
|
+
{ type: 'string', name: 'anchor', title: 'Anchor ID' },
|
|
511
|
+
{ type: 'string', name: 'ariaLabel', title: 'Aria Label' },
|
|
512
|
+
],
|
|
513
|
+
},
|
|
269
514
|
];
|
|
270
515
|
|
|
271
|
-
const [
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
setFormState((state) => {
|
|
276
|
-
console.log('state', state);
|
|
277
|
-
return { ...state, [name]: val };
|
|
278
|
-
});
|
|
279
|
-
}, []);
|
|
516
|
+
const [value, setValue] = React.useState({
|
|
517
|
+
buttons: [{ label: 'Get Started' }, { label: 'Learn More' }],
|
|
518
|
+
overlays: [{ color: '#00000080', opacity: 0.5 }],
|
|
519
|
+
});
|
|
280
520
|
|
|
281
521
|
<div style={{ width: '300px' }}>
|
|
282
|
-
<SilkeFormSchema
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
}}
|
|
294
|
-
/>
|
|
295
|
-
<pre>{JSON.stringify(formState, null, 2)}</pre>
|
|
522
|
+
<SilkeFormSchema schema={schema} value={value} onChange={setValue} context={{
|
|
523
|
+
actions: {
|
|
524
|
+
imageLibraryOpen: (cb) => cb({ key: 'demo', url: ipsum.image() }),
|
|
525
|
+
imageLibraryClose: () => {},
|
|
526
|
+
},
|
|
527
|
+
currentPage: { title: 'Home', key: 'home', path: '/' },
|
|
528
|
+
pages: [
|
|
529
|
+
{ title: 'Home', key: 'home', path: '/' },
|
|
530
|
+
{ title: 'About', key: 'about', path: '/about' },
|
|
531
|
+
],
|
|
532
|
+
}} />
|
|
296
533
|
</div>;
|
|
297
534
|
```
|
|
298
535
|
|
|
299
|
-
##
|
|
536
|
+
## Conditional visibility
|
|
537
|
+
|
|
538
|
+
Use the `hidden` property to show or hide fields based on other field values.
|
|
300
539
|
|
|
301
540
|
```js
|
|
302
541
|
const schema = [
|
|
303
542
|
{
|
|
304
|
-
type: '
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
initialValue: '
|
|
543
|
+
type: 'select',
|
|
544
|
+
name: 'mode',
|
|
545
|
+
title: 'Mode',
|
|
546
|
+
initialValue: 'simple',
|
|
547
|
+
options: {
|
|
548
|
+
display: 'radio',
|
|
549
|
+
items: [
|
|
550
|
+
{ label: 'Simple', value: 'simple' },
|
|
551
|
+
{ label: 'Advanced', value: 'advanced' },
|
|
552
|
+
],
|
|
553
|
+
},
|
|
308
554
|
},
|
|
555
|
+
{ type: 'string', name: 'title', title: 'Title' },
|
|
309
556
|
{
|
|
310
557
|
type: 'string',
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
558
|
+
name: 'subtitle',
|
|
559
|
+
title: 'Subtitle',
|
|
560
|
+
hidden: (ctx) => ctx.value.mode !== 'advanced',
|
|
314
561
|
},
|
|
315
562
|
{
|
|
316
|
-
type: '
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
type: '__eval__',
|
|
321
|
-
value: `async (context) => (await context.storage.getItem('field3')) || 'Eval value'`,
|
|
322
|
-
},
|
|
323
|
-
onChange: {
|
|
324
|
-
type: '__eval__',
|
|
325
|
-
value: `async (value, context) => {
|
|
326
|
-
await context.storage.setItem('field3', value)
|
|
327
|
-
return value;
|
|
328
|
-
}`,
|
|
329
|
-
},
|
|
563
|
+
type: 'number',
|
|
564
|
+
name: 'maxItems',
|
|
565
|
+
title: 'Max Items',
|
|
566
|
+
hidden: (ctx) => ctx.value.mode !== 'advanced',
|
|
330
567
|
},
|
|
331
568
|
{
|
|
332
|
-
type: '
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
type: '__eval__',
|
|
337
|
-
value: `(value, context) => value+context.value.field3`,
|
|
338
|
-
},
|
|
339
|
-
initialValue: { type: '__eval__', value: `"Hello"` },
|
|
569
|
+
type: 'boolean',
|
|
570
|
+
name: 'debug',
|
|
571
|
+
title: 'Debug Mode',
|
|
572
|
+
hidden: (ctx) => ctx.value.mode !== 'advanced',
|
|
340
573
|
},
|
|
341
574
|
];
|
|
342
575
|
|
|
343
|
-
const storage = {
|
|
344
|
-
getItem: (key) => localStorage.getItem(key) || '',
|
|
345
|
-
setItem: (key, value) => localStorage.setItem(key, value),
|
|
346
|
-
};
|
|
347
|
-
|
|
348
576
|
const [value, setValue] = React.useState({});
|
|
349
577
|
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
<div>
|
|
353
|
-
<SilkeFormSchema schema={schema} value={value} context={context} onChange={setValue} />
|
|
354
|
-
<pre>{JSON.stringify(value, null, 2)}</pre>
|
|
578
|
+
<div style={{ width: '300px' }}>
|
|
579
|
+
<SilkeFormSchema schema={schema} value={value} onChange={setValue} context={{}} />
|
|
355
580
|
</div>;
|
|
356
581
|
```
|
|
357
582
|
|
|
358
|
-
##
|
|
583
|
+
## Async and initial values
|
|
584
|
+
|
|
585
|
+
Fields support static defaults, functions, and eval callbacks for dynamic initialization.
|
|
359
586
|
|
|
360
587
|
```js
|
|
361
588
|
const schema = [
|
|
362
589
|
{
|
|
363
590
|
type: 'string',
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
},
|
|
368
|
-
{
|
|
369
|
-
type: 'number',
|
|
370
|
-
name: 'numberKey',
|
|
371
|
-
title: 'Number field',
|
|
372
|
-
description: 'Field for entering numbers',
|
|
373
|
-
},
|
|
374
|
-
{
|
|
375
|
-
type: 'number',
|
|
376
|
-
name: 'numberMs',
|
|
377
|
-
title: 'Number Seconds',
|
|
378
|
-
description: 'Field with format',
|
|
379
|
-
options: {
|
|
380
|
-
format: 'ms',
|
|
381
|
-
},
|
|
591
|
+
title: 'Static default',
|
|
592
|
+
name: 'field1',
|
|
593
|
+
initialValue: 'Hello',
|
|
382
594
|
},
|
|
383
595
|
{
|
|
384
|
-
type: '
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
596
|
+
type: 'string',
|
|
597
|
+
title: 'Function default',
|
|
598
|
+
name: 'field2',
|
|
599
|
+
initialValue: () => 'Computed at render',
|
|
388
600
|
},
|
|
389
601
|
{
|
|
390
|
-
type: '
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
602
|
+
type: 'string',
|
|
603
|
+
title: 'Eval callback',
|
|
604
|
+
name: 'field3',
|
|
605
|
+
initialValue: { type: '__eval__', value: `"Evaluated"` },
|
|
394
606
|
},
|
|
395
607
|
];
|
|
396
608
|
|
|
397
|
-
const [
|
|
398
|
-
|
|
399
|
-
const handleChange = React.useCallback((name, val) => {
|
|
400
|
-
console.log(name, val);
|
|
401
|
-
setFormState((state) => {
|
|
402
|
-
console.log('state', state);
|
|
403
|
-
return { ...state, [name]: val };
|
|
404
|
-
});
|
|
405
|
-
}, []);
|
|
609
|
+
const [value, setValue] = React.useState({});
|
|
406
610
|
|
|
407
611
|
<div style={{ width: '300px' }}>
|
|
408
|
-
<
|
|
409
|
-
|
|
410
|
-
{
|
|
411
|
-
key: 'variable-1',
|
|
412
|
-
type: 'text',
|
|
413
|
-
name: 'Variable 1',
|
|
414
|
-
value: 'Variable 1',
|
|
415
|
-
},
|
|
416
|
-
{
|
|
417
|
-
key: 'variable-1',
|
|
418
|
-
type: 'number',
|
|
419
|
-
name: 'Variable 2',
|
|
420
|
-
value: 1,
|
|
421
|
-
},
|
|
422
|
-
]}
|
|
423
|
-
>
|
|
424
|
-
<SilkeFormSchema schema={schema} value={formState} onChange={setFormState} context={{}} />
|
|
425
|
-
</SilkeCSSContext>
|
|
426
|
-
<pre>{JSON.stringify(formState, null, 2)}</pre>
|
|
612
|
+
<SilkeFormSchema schema={schema} value={value} context={{}} onChange={setValue} />
|
|
613
|
+
<pre>{JSON.stringify(value, null, 2)}</pre>
|
|
427
614
|
</div>;
|
|
428
615
|
```
|