@vev/silke 1.1.10 → 1.2.0
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 +163 -78
- package/CHANGELOG.md +31 -0
- package/dist/index.js +44 -41
- package/dist/index.js.LEGAL.txt +1 -1
- package/dist/index.js.map +7 -0
- package/dist/styles.css +1597 -1014
- package/dist/types/components/index.d.ts +2 -0
- package/dist/types/components/silke-autocomplete-field/autocomplete-item.d.ts +1 -1
- package/dist/types/components/silke-autocomplete-field/silke-autocomplete-field-native.d.ts +5 -0
- package/dist/types/components/silke-box/silke-box.d.ts +2 -0
- package/dist/types/components/silke-button/silke-dropdown-button.d.ts +3 -1
- package/dist/types/components/silke-card/silke-card-grid.d.ts +1 -0
- package/dist/types/components/silke-card/silke-card.d.ts +1 -0
- package/dist/types/components/silke-command-text-field/index.d.ts +1 -1
- package/dist/types/components/silke-command-text-field/silke-command-text-field.d.ts +16 -0
- package/dist/types/components/silke-command-text-field/utils.d.ts +25 -0
- package/dist/types/components/silke-css-number-field/silke-css-number-field.spec.d.ts +1 -0
- package/dist/types/components/silke-expression-input/index.d.ts +3 -0
- package/dist/types/components/silke-expression-input/silke-expression-input-tag.d.ts +6 -0
- package/dist/types/components/silke-expression-input/silke-expression-input.d.ts +29 -0
- package/dist/types/components/silke-expression-input/utils.d.ts +18 -0
- package/dist/types/components/silke-form-schema/fields/array-field-inline.d.ts +2 -1
- package/dist/types/components/silke-form-schema/fields/array-field-modal.d.ts +2 -1
- package/dist/types/components/silke-form-schema/fields/array-field.d.ts +1 -1
- package/dist/types/components/silke-form-schema/fields/group-field.d.ts +1 -1
- package/dist/types/components/silke-form-schema/fields/layout-field.d.ts +1 -1
- 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 +1 -1
- package/dist/types/components/silke-form-schema/fields/string-field.d.ts +1 -1
- package/dist/types/components/silke-form-schema/index.d.ts +1 -0
- package/dist/types/components/silke-form-schema/silke-form-schema.d.ts +4 -1
- package/dist/types/components/silke-form-schema/silke-schema-decorator.d.ts +17 -0
- package/dist/types/components/silke-form-schema/silke-schema-field.d.ts +2 -1
- package/dist/types/components/silke-form-schema/silke-schema-fields.d.ts +2 -0
- package/dist/types/components/silke-form-schema/silke-schema-path.spec.d.ts +1 -0
- package/dist/types/components/silke-gradient-picker/silke-gradient-utils.d.ts +2 -0
- package/dist/types/components/silke-icon-picker/color-swatch-section.d.ts +6 -0
- package/dist/types/components/silke-icon-picker/emoji-tab.d.ts +1 -1
- package/dist/types/components/silke-icon-picker/icons-tab.d.ts +1 -1
- package/dist/types/components/silke-icon-picker/silke-icon-picker.d.ts +2 -0
- package/dist/types/components/silke-icon-picker/utils.d.ts +2 -0
- package/dist/types/components/silke-list/silke-list-item.d.ts +5 -1
- package/dist/types/components/silke-list/types.d.ts +1 -0
- package/dist/types/components/silke-navigation-link/silke-navigation-link.d.ts +15 -0
- package/dist/types/components/silke-popover/popover-context.spec.d.ts +1 -0
- package/dist/types/components/silke-rich-text-field/blockquote.d.ts +21 -0
- package/dist/types/components/silke-rich-text-field/blockquote.spec.d.ts +1 -0
- package/dist/types/components/silke-rich-text-field/dropcap.d.ts +27 -0
- package/dist/types/components/silke-rich-text-field/dropcap.spec.d.ts +1 -0
- package/dist/types/components/silke-rich-text-field/floating-layer.d.ts +12 -0
- package/dist/types/components/silke-rich-text-field/font-size.d.ts +2 -0
- package/dist/types/components/silke-rich-text-field/formatting-toolbar.d.ts +9 -0
- package/dist/types/components/silke-rich-text-field/index.d.ts +1 -0
- package/dist/types/components/silke-rich-text-field/jsdom-rects.d.ts +10 -0
- package/dist/types/components/silke-rich-text-field/link-menu.d.ts +26 -0
- package/dist/types/components/silke-rich-text-field/link-menu.spec.d.ts +1 -0
- package/dist/types/components/silke-rich-text-field/link-suggestions.d.ts +48 -0
- package/dist/types/components/silke-rich-text-field/link-suggestions.spec.d.ts +1 -0
- package/dist/types/components/silke-rich-text-field/link-tooltip.d.ts +15 -0
- package/dist/types/components/silke-rich-text-field/list-item.d.ts +15 -0
- package/dist/types/components/silke-rich-text-field/list-link-fontsize.spec.d.ts +1 -0
- package/dist/types/components/silke-rich-text-field/lorem-ipsum.d.ts +10 -0
- package/dist/types/components/silke-rich-text-field/lorem-ipsum.spec.d.ts +1 -0
- package/dist/types/components/silke-rich-text-field/paste.d.ts +1 -0
- package/dist/types/components/silke-rich-text-field/paste.spec.d.ts +1 -0
- package/dist/types/components/silke-rich-text-field/plugins.d.ts +18 -0
- package/dist/types/components/silke-rich-text-field/plugins.spec.d.ts +1 -0
- package/dist/types/components/silke-rich-text-field/silke-rich-text-field.d.ts +60 -0
- package/dist/types/components/silke-rich-text-field/slash-menu-items.d.ts +10 -0
- package/dist/types/components/silke-rich-text-field/slash-menu.d.ts +11 -0
- package/dist/types/components/silke-rich-text-field/table-content-sync.spec.d.ts +1 -0
- package/dist/types/components/silke-rich-text-field/table-toolbar.d.ts +17 -0
- package/dist/types/components/silke-rich-text-field/table-toolbar.spec.d.ts +1 -0
- package/dist/types/components/silke-rich-text-field/table.spec.d.ts +1 -0
- package/dist/types/components/silke-rich-text-field/use-link-hover.d.ts +15 -0
- package/dist/types/components/silke-rich-text-field/use-slash-menu.d.ts +13 -0
- package/dist/types/components/silke-rich-text-field/utils.d.ts +13 -0
- package/dist/types/components/silke-sortable-list/index.d.ts +1 -1
- package/dist/types/components/silke-sortable-list/silke-nested-sortable-list.d.ts +8 -1
- package/dist/types/components/silke-theme-card/silke-theme-card.d.ts +13 -6
- package/dist/types/components/silke-theme-swatch/silke-theme-swatch.d.ts +6 -1
- package/dist/types/icons.d.ts +16 -0
- package/esbuild.config.mjs +9 -4
- package/package.json +22 -9
- package/src/components/index.ts +2 -0
- package/src/components/silke-alert-banner/silke-alert-banner.tsx +1 -1
- package/src/components/silke-autocomplete-field/autocomplete-item.tsx +47 -61
- package/src/components/silke-autocomplete-field/silke-autocomplete-field-native.tsx +13 -2
- package/src/components/silke-autocomplete-field/silke-autocomplete-field.tsx +8 -5
- package/src/components/silke-autocomplete-field/silke-autocomplete-popup-native.tsx +2 -1
- package/src/components/silke-box/silke-box.scss +4 -0
- package/src/components/silke-box/silke-box.tsx +4 -0
- package/src/components/silke-button/silke-dropdown-button.tsx +4 -1
- package/src/components/silke-card/silke-card.scss +4 -0
- package/src/components/silke-card/silke-card.tsx +3 -0
- package/src/components/silke-command-text-field/index.ts +1 -0
- package/src/components/silke-command-text-field/silke-command-parser.spec.ts +55 -0
- package/src/components/silke-command-text-field/silke-command-parser.ts +33 -2
- package/src/components/silke-command-text-field/silke-command-text-field.module.scss +3 -0
- package/src/components/silke-command-text-field/silke-command-text-field.tsx +53 -48
- package/src/components/silke-command-text-field/utils.spec.ts +192 -0
- package/src/components/silke-command-text-field/utils.ts +99 -16
- package/src/components/silke-css-number-field/silke-css-number-field.spec.tsx +115 -0
- package/src/components/silke-css-number-field/silke-css-number-field.tsx +33 -0
- package/src/components/silke-expression-input/index.ts +3 -0
- package/src/components/silke-expression-input/silke-expression-input-tag.tsx +37 -0
- package/src/components/silke-expression-input/silke-expression-input.mdx +40 -0
- package/src/components/silke-expression-input/silke-expression-input.scss +24 -0
- package/src/components/silke-expression-input/silke-expression-input.tsx +343 -0
- package/src/components/silke-expression-input/utils.ts +144 -0
- package/src/components/silke-form-schema/fields/array-field-inline.tsx +4 -0
- package/src/components/silke-form-schema/fields/array-field-modal.tsx +4 -0
- package/src/components/silke-form-schema/fields/array-field.tsx +6 -11
- package/src/components/silke-form-schema/fields/group-field.tsx +2 -0
- package/src/components/silke-form-schema/fields/layout-field.tsx +2 -0
- package/src/components/silke-form-schema/fields/object-field.tsx +2 -0
- package/src/components/silke-form-schema/fields/popover-field.tsx +2 -0
- package/src/components/silke-form-schema/fields/string-field.tsx +27 -1
- package/src/components/silke-form-schema/index.ts +1 -0
- package/src/components/silke-form-schema/silke-form-schema.mdx +30 -1
- package/src/components/silke-form-schema/silke-form-schema.tsx +12 -6
- package/src/components/silke-form-schema/silke-schema-decorator.tsx +32 -0
- package/src/components/silke-form-schema/silke-schema-field.tsx +19 -2
- package/src/components/silke-form-schema/silke-schema-fields.tsx +30 -4
- package/src/components/silke-form-schema/silke-schema-path.spec.tsx +160 -0
- package/src/components/silke-gradient-picker/silke-gradient-picker.tsx +3 -1
- package/src/components/silke-gradient-picker/silke-gradient-utils.ts +23 -3
- package/src/components/silke-icon/silke-shape.tsx +1 -1
- package/src/components/silke-icon-picker/color-swatch-section.tsx +61 -0
- package/src/components/silke-icon-picker/emoji-tab.tsx +8 -6
- package/src/components/silke-icon-picker/icons-tab.tsx +8 -7
- package/src/components/silke-icon-picker/silke-icon-picker.tsx +52 -25
- package/src/components/silke-icon-picker/styles.scss +66 -1
- package/src/components/silke-icon-picker/utils.ts +2 -0
- package/src/components/silke-list/silke-list-item.scss +10 -0
- package/src/components/silke-list/silke-list-item.tsx +16 -3
- package/src/components/silke-list/silke-list.mdx +18 -0
- package/src/components/silke-list/types.ts +1 -0
- package/src/components/silke-navigation-link/silke-navigation-link.scss +162 -42
- package/src/components/silke-navigation-link/silke-navigation-link.tsx +99 -21
- package/src/components/silke-popover/popover-context.spec.tsx +44 -0
- package/src/components/silke-popover-native/silke-popover-native.scss +5 -3
- package/src/components/silke-rich-text-field/blockquote.spec.ts +151 -0
- package/src/components/silke-rich-text-field/blockquote.ts +90 -0
- package/src/components/silke-rich-text-field/dropcap.spec.ts +67 -0
- package/src/components/silke-rich-text-field/dropcap.ts +59 -0
- package/src/components/silke-rich-text-field/floating-layer.tsx +15 -0
- package/src/components/silke-rich-text-field/font-size.ts +62 -0
- package/src/components/silke-rich-text-field/formatting-toolbar.tsx +145 -0
- package/src/components/silke-rich-text-field/index.ts +1 -0
- package/src/components/silke-rich-text-field/jsdom-rects.ts +15 -0
- package/src/components/silke-rich-text-field/link-menu.spec.tsx +502 -0
- package/src/components/silke-rich-text-field/link-menu.tsx +553 -0
- package/src/components/silke-rich-text-field/link-suggestions.spec.ts +203 -0
- package/src/components/silke-rich-text-field/link-suggestions.ts +188 -0
- package/src/components/silke-rich-text-field/link-tooltip.tsx +60 -0
- package/src/components/silke-rich-text-field/list-item.ts +64 -0
- package/src/components/silke-rich-text-field/list-link-fontsize.spec.ts +135 -0
- package/src/components/silke-rich-text-field/lorem-ipsum.spec.ts +131 -0
- package/src/components/silke-rich-text-field/lorem-ipsum.ts +51 -0
- package/src/components/silke-rich-text-field/paste.spec.ts +93 -0
- package/src/components/silke-rich-text-field/paste.ts +39 -0
- package/src/components/silke-rich-text-field/plugins.spec.ts +143 -0
- package/src/components/silke-rich-text-field/plugins.ts +230 -0
- package/src/components/silke-rich-text-field/silke-rich-text-field.mdx +180 -0
- package/src/components/silke-rich-text-field/silke-rich-text-field.scss +343 -0
- package/src/components/silke-rich-text-field/silke-rich-text-field.tsx +505 -0
- package/src/components/silke-rich-text-field/slash-menu-items.ts +112 -0
- package/src/components/silke-rich-text-field/slash-menu.tsx +50 -0
- package/src/components/silke-rich-text-field/table-content-sync.spec.tsx +61 -0
- package/src/components/silke-rich-text-field/table-toolbar.spec.tsx +168 -0
- package/src/components/silke-rich-text-field/table-toolbar.tsx +121 -0
- package/src/components/silke-rich-text-field/table.spec.ts +87 -0
- package/src/components/silke-rich-text-field/use-link-hover.ts +63 -0
- package/src/components/silke-rich-text-field/use-slash-menu.ts +130 -0
- package/src/components/silke-rich-text-field/utils.ts +55 -0
- package/src/components/silke-sortable-list/index.ts +1 -1
- package/src/components/silke-sortable-list/silke-nested-sortable-list.scss +11 -1
- package/src/components/silke-sortable-list/silke-nested-sortable-list.tsx +9 -0
- package/src/components/silke-sortable-list/silke-sortable-list.mdx +13 -0
- package/src/components/silke-tag/silke-tag.scss +12 -3
- package/src/components/silke-theme-card/silke-theme-card.module.scss +141 -45
- package/src/components/silke-theme-card/silke-theme-card.tsx +76 -47
- package/src/components/silke-theme-swatch/silke-theme-swatch.mdx +56 -0
- package/src/components/silke-theme-swatch/silke-theme-swatch.module.scss +53 -63
- package/src/components/silke-theme-swatch/silke-theme-swatch.tsx +99 -14
- package/src/icons.tsx +51 -5
- package/tsconfig.build.tsbuildinfo +0 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { SchemaFieldProps, StringField as StringFieldType } from '@vev/utils';
|
|
2
|
-
import React, { useRef, useState } from 'react';
|
|
2
|
+
import React, { useEffect, useRef, useState } from 'react';
|
|
3
3
|
import { SilkeTextField } from '../../silke-text-field';
|
|
4
|
+
import { SilkeRichTextField } from '../../silke-rich-text-field';
|
|
4
5
|
import { getTitle } from './utils/schema-util';
|
|
5
6
|
import { SilkeBox } from '../../silke-box';
|
|
6
7
|
import { SilkeText, SilkeTextSmall } from '../../silke-text';
|
|
@@ -15,9 +16,17 @@ const StringField = ({
|
|
|
15
16
|
disabled,
|
|
16
17
|
readonly,
|
|
17
18
|
onChange,
|
|
19
|
+
context,
|
|
18
20
|
}: SchemaFieldProps<StringFieldType>) => {
|
|
19
21
|
const { options } = schema;
|
|
20
22
|
|
|
23
|
+
const [linkItems, setLinkItems] = useState<{ label: string; value: string; icon?: any; subLabel?: string }[]>([]);
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
if (options?.html && context?.actions?.availableLinks) {
|
|
26
|
+
Promise.resolve(context.actions.availableLinks()).then(setLinkItems);
|
|
27
|
+
}
|
|
28
|
+
}, [options?.html, context?.actions?.availableLinks]);
|
|
29
|
+
|
|
21
30
|
const textFieldRef = useRef(null);
|
|
22
31
|
const dropdownRef = useRef<HTMLDivElement>(null);
|
|
23
32
|
|
|
@@ -52,6 +61,23 @@ const StringField = ({
|
|
|
52
61
|
}
|
|
53
62
|
}
|
|
54
63
|
|
|
64
|
+
if (options?.html) {
|
|
65
|
+
return (
|
|
66
|
+
<SilkeRichTextField
|
|
67
|
+
disabled={disabled}
|
|
68
|
+
readOnly={readonly}
|
|
69
|
+
value={value || ''}
|
|
70
|
+
label={getTitle(schema)}
|
|
71
|
+
placeholder={options?.placeholder}
|
|
72
|
+
onChange={onChange}
|
|
73
|
+
linkItems={linkItems.length > 0 ? linkItems : undefined}
|
|
74
|
+
kind="zombie"
|
|
75
|
+
size="s"
|
|
76
|
+
flex
|
|
77
|
+
/>
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
|
|
55
81
|
return (
|
|
56
82
|
<SilkeBox>
|
|
57
83
|
<SilkeTextField
|
|
@@ -91,6 +91,35 @@ const [value, setValue] = React.useState({});
|
|
|
91
91
|
</div>;
|
|
92
92
|
```
|
|
93
93
|
|
|
94
|
+
## Rich text field
|
|
95
|
+
|
|
96
|
+
Use `options.html: true` on a string field to render a rich text editor with formatting support (bold, italic, headings, lists, blockquotes, code blocks, links, and dividers). The value is stored as an HTML string.
|
|
97
|
+
|
|
98
|
+
```js
|
|
99
|
+
const schema = [
|
|
100
|
+
{
|
|
101
|
+
type: 'string',
|
|
102
|
+
name: 'bio',
|
|
103
|
+
title: 'Bio',
|
|
104
|
+
options: { html: true, placeholder: 'Tell us about yourself...' },
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
type: 'string',
|
|
108
|
+
name: 'notes',
|
|
109
|
+
title: 'Notes',
|
|
110
|
+
options: { html: true, placeholder: 'Meeting notes...' },
|
|
111
|
+
initialValue: '<h2>Agenda</h2><ul><li>Review design tokens</li><li>Ship rich text field</li></ul>',
|
|
112
|
+
},
|
|
113
|
+
];
|
|
114
|
+
|
|
115
|
+
const [value, setValue] = React.useState({});
|
|
116
|
+
|
|
117
|
+
<div style={{ width: '300px' }}>
|
|
118
|
+
<SilkeFormSchema schema={schema} value={value} onChange={setValue} context={{}} />
|
|
119
|
+
<pre>{JSON.stringify(value, null, 2)}</pre>
|
|
120
|
+
</div>;
|
|
121
|
+
```
|
|
122
|
+
|
|
94
123
|
## Select fields
|
|
95
124
|
|
|
96
125
|
Dropdown, radio, checkbox, and autocomplete selection.
|
|
@@ -410,7 +439,7 @@ const schema = [
|
|
|
410
439
|
type: 'string',
|
|
411
440
|
name: 'body',
|
|
412
441
|
title: 'Body Text',
|
|
413
|
-
options: {
|
|
442
|
+
options: { html: true, placeholder: 'Enter body text...' },
|
|
414
443
|
},
|
|
415
444
|
{ type: 'link', name: 'ctaLink', title: 'CTA Link' },
|
|
416
445
|
{
|
|
@@ -3,6 +3,7 @@ import React from 'react';
|
|
|
3
3
|
import { SilkeForm, SilkeFormProps } from '../silke-form';
|
|
4
4
|
import TextFieldContext from '../silke-text-field/text-field-context';
|
|
5
5
|
import { SilkeSchemaContext } from './silke-schema-context';
|
|
6
|
+
import { SilkeSchemaDecoratorProvider, SilkeSchemaFieldDecorator } from './silke-schema-decorator';
|
|
6
7
|
import { SilkeSchemaFields } from './silke-schema-fields';
|
|
7
8
|
import { SilkeTextFieldOutlineProps } from '../silke-text-field/silke-text-field-outline';
|
|
8
9
|
|
|
@@ -15,6 +16,8 @@ type SilkeFormSchemaProps<T extends { [key: string]: any }> = {
|
|
|
15
16
|
readonly?: boolean;
|
|
16
17
|
disabled?: boolean;
|
|
17
18
|
variables?: LocalVariable[];
|
|
19
|
+
/** Renders extra UI beside every field, eg a per-breakpoint status dot. */
|
|
20
|
+
fieldDecorator?: SilkeSchemaFieldDecorator;
|
|
18
21
|
} & SilkeFormProps<T>;
|
|
19
22
|
|
|
20
23
|
// pages?: { title: string; key: string; path?: string }[];
|
|
@@ -25,15 +28,18 @@ export function SilkeFormSchema<T extends { [key: string]: any }>({
|
|
|
25
28
|
value,
|
|
26
29
|
context,
|
|
27
30
|
inline = false,
|
|
31
|
+
fieldDecorator,
|
|
28
32
|
...rest
|
|
29
33
|
}: SilkeFormSchemaProps<T>) {
|
|
30
34
|
return (
|
|
31
|
-
<SilkeSchemaContext context={context}>
|
|
32
|
-
<
|
|
33
|
-
<
|
|
34
|
-
<
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
<SilkeSchemaContext context={{ ...context, value: context.value ?? value }}>
|
|
36
|
+
<SilkeSchemaDecoratorProvider decorator={fieldDecorator}>
|
|
37
|
+
<SilkeForm {...rest} value={value}>
|
|
38
|
+
<TextFieldContext size="s" kind="default" inline={inline}>
|
|
39
|
+
<SilkeSchemaFields schema={schema} value={value} {...rest} />
|
|
40
|
+
</TextFieldContext>
|
|
41
|
+
</SilkeForm>
|
|
42
|
+
</SilkeSchemaDecoratorProvider>
|
|
37
43
|
</SilkeSchemaContext>
|
|
38
44
|
);
|
|
39
45
|
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { VevProps } from '@vev/utils';
|
|
2
|
+
import React, { createContext, ReactNode, useContext } from 'react';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Renders extra UI beside a schema field — a status dot, a badge, a menu.
|
|
6
|
+
*
|
|
7
|
+
* `path` is the field's address inside the form value, eg `slides.1.label`, so
|
|
8
|
+
* the decorator can look the field's stored value up. It is undefined when the
|
|
9
|
+
* form was rendered without a path.
|
|
10
|
+
*/
|
|
11
|
+
export type SilkeSchemaFieldDecorator = (field: VevProps, path?: string) => ReactNode;
|
|
12
|
+
|
|
13
|
+
const DecoratorContext = createContext<SilkeSchemaFieldDecorator | undefined>(undefined);
|
|
14
|
+
|
|
15
|
+
export function SilkeSchemaDecoratorProvider({
|
|
16
|
+
decorator,
|
|
17
|
+
children,
|
|
18
|
+
}: {
|
|
19
|
+
decorator?: SilkeSchemaFieldDecorator;
|
|
20
|
+
children: ReactNode;
|
|
21
|
+
}) {
|
|
22
|
+
return <DecoratorContext.Provider value={decorator}>{children}</DecoratorContext.Provider>;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function useSchemaFieldDecorator(): SilkeSchemaFieldDecorator | undefined {
|
|
26
|
+
return useContext(DecoratorContext);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Joins a parent path with a field name or an array index. */
|
|
30
|
+
export function joinSchemaPath(path: string | undefined, segment: string | number): string {
|
|
31
|
+
return path === undefined ? String(segment) : `${path}.${segment}`;
|
|
32
|
+
}
|
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
import { safeEvalFunction } from './safe-eval';
|
|
12
12
|
import { isEvalCallback } from './schema-utils';
|
|
13
13
|
import { useSchemaContext } from './silke-schema-context';
|
|
14
|
+
import { useSchemaFieldDecorator } from './silke-schema-decorator';
|
|
14
15
|
import { SilkeDivider } from '../silke-divider';
|
|
15
16
|
|
|
16
17
|
import ArrayField from './fields/array-field';
|
|
@@ -39,6 +40,7 @@ type SilkeSchemaFieldProps = {
|
|
|
39
40
|
disabled?: boolean;
|
|
40
41
|
readonly?: boolean;
|
|
41
42
|
itemIndex?: number;
|
|
43
|
+
path?: string;
|
|
42
44
|
};
|
|
43
45
|
|
|
44
46
|
const SCHEMA_FIELD_COMPONENTS: Partial<SchemaFieldComponents> = {
|
|
@@ -69,8 +71,10 @@ export function SilkeSchemaField({
|
|
|
69
71
|
disabled,
|
|
70
72
|
readonly,
|
|
71
73
|
itemIndex,
|
|
74
|
+
path,
|
|
72
75
|
}: SilkeSchemaFieldProps) {
|
|
73
76
|
const extendedFields = useExtendedFields();
|
|
77
|
+
const decorator = useSchemaFieldDecorator();
|
|
74
78
|
|
|
75
79
|
const { value, onChange } = useFormField({ name: field?.name, value: fieldValue });
|
|
76
80
|
|
|
@@ -99,11 +103,17 @@ export function SilkeSchemaField({
|
|
|
99
103
|
|
|
100
104
|
const getVariableType = (field: VevProps) => {
|
|
101
105
|
if (field.component) return 'none';
|
|
102
|
-
if (
|
|
106
|
+
if (
|
|
107
|
+
field.type === 'number' &&
|
|
108
|
+
(field.options?.display === 'slider' || field.options?.display === 'range-slider')
|
|
109
|
+
)
|
|
110
|
+
return 'none';
|
|
103
111
|
if (field.type === 'string') return 'text';
|
|
104
112
|
return field.type;
|
|
105
113
|
};
|
|
106
114
|
|
|
115
|
+
const decoration = decorator?.(field, path);
|
|
116
|
+
|
|
107
117
|
return (
|
|
108
118
|
<>
|
|
109
119
|
{['object', 'divider'].includes(field?.type) && !isFirst && (
|
|
@@ -111,7 +121,12 @@ export function SilkeSchemaField({
|
|
|
111
121
|
<SilkeDivider dark />
|
|
112
122
|
</SilkeBox>
|
|
113
123
|
)}
|
|
114
|
-
<SilkeBox
|
|
124
|
+
<SilkeBox
|
|
125
|
+
hPad={!noPad ? 'm' : undefined}
|
|
126
|
+
flex
|
|
127
|
+
vAlign={decoration ? 'end' : undefined}
|
|
128
|
+
gap={decoration ? 'xs' : undefined}
|
|
129
|
+
>
|
|
115
130
|
<SilkeVariablesWrapper
|
|
116
131
|
component={Field}
|
|
117
132
|
disabled={disabled}
|
|
@@ -125,6 +140,7 @@ export function SilkeSchemaField({
|
|
|
125
140
|
context={context}
|
|
126
141
|
help={field.description}
|
|
127
142
|
itemIndex={itemIndex}
|
|
143
|
+
path={path}
|
|
128
144
|
onChange={async (value: any) => {
|
|
129
145
|
if (isEvalCallback(field.onChange)) {
|
|
130
146
|
value = await safeEvalFunction(field.onChange.value, value, context);
|
|
@@ -135,6 +151,7 @@ export function SilkeSchemaField({
|
|
|
135
151
|
onChange(value);
|
|
136
152
|
}}
|
|
137
153
|
/>
|
|
154
|
+
{decoration}
|
|
138
155
|
</SilkeBox>
|
|
139
156
|
</>
|
|
140
157
|
);
|
|
@@ -5,6 +5,18 @@ import { SilkeSchemaField } from './silke-schema-field';
|
|
|
5
5
|
import { SilkeBox } from '../silke-box';
|
|
6
6
|
import { isFunction } from 'lodash';
|
|
7
7
|
import { useSchemaContext } from './silke-schema-context';
|
|
8
|
+
import { joinSchemaPath } from './silke-schema-decorator';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* layout, group, popover and divider render their children into the parent
|
|
12
|
+
* value, so they do not add a segment of their own.
|
|
13
|
+
*/
|
|
14
|
+
const TRANSPARENT_TYPES = ['layout', 'group', 'popover', 'divider'];
|
|
15
|
+
|
|
16
|
+
function getFieldPath(path: string | undefined, field: VevProps): string | undefined {
|
|
17
|
+
if (!field?.name || TRANSPARENT_TYPES.includes(field.type)) return path;
|
|
18
|
+
return joinSchemaPath(path, field.name);
|
|
19
|
+
}
|
|
8
20
|
|
|
9
21
|
type SilkeSchemaFieldsProps<T extends { [key: string]: any }> = {
|
|
10
22
|
schema: VevProps[];
|
|
@@ -13,18 +25,20 @@ type SilkeSchemaFieldsProps<T extends { [key: string]: any }> = {
|
|
|
13
25
|
disabled?: boolean;
|
|
14
26
|
readonly?: boolean;
|
|
15
27
|
itemIndex?: number;
|
|
28
|
+
/** Address of the object these fields write into, eg `slides.1`. */
|
|
29
|
+
path?: string;
|
|
16
30
|
} & SilkeFormProps<T>;
|
|
17
31
|
|
|
18
32
|
export function SilkeSchemaFields<T extends { [key: string]: any }>(
|
|
19
33
|
props: SilkeSchemaFieldsProps<T>,
|
|
20
34
|
) {
|
|
21
|
-
const { schema = [], row, ...rest } = props;
|
|
35
|
+
const { schema = [], row, path, ...rest } = props;
|
|
22
36
|
const context = useSchemaContext();
|
|
23
37
|
const [filteredSchema, setFilteredSchema] = useState(schema);
|
|
24
38
|
|
|
25
39
|
// Filter hidden fields here, so they don't use any space in the sidebar
|
|
26
40
|
useEffect(() => {
|
|
27
|
-
const ctxWithValue = { ...context, value:
|
|
41
|
+
const ctxWithValue = { ...context, value: context.value ?? rest?.value };
|
|
28
42
|
const isHidden = async (field: VevProps) => {
|
|
29
43
|
if (isFunction(field?.hidden)) {
|
|
30
44
|
return await field?.hidden(ctxWithValue, rest?.itemIndex);
|
|
@@ -49,14 +63,26 @@ export function SilkeSchemaFields<T extends { [key: string]: any }>(
|
|
|
49
63
|
}, [context, schema, rest?.itemIndex, rest?.value]);
|
|
50
64
|
|
|
51
65
|
return (
|
|
52
|
-
<SilkeBox
|
|
66
|
+
<SilkeBox
|
|
67
|
+
flex
|
|
68
|
+
column={!row}
|
|
69
|
+
gap="s"
|
|
70
|
+
vPad={row ? undefined : 's'}
|
|
71
|
+
vAlign={row ? 'end' : undefined}
|
|
72
|
+
style={{ width: '100%' }}
|
|
73
|
+
>
|
|
53
74
|
{filteredSchema.map((field, index) => {
|
|
54
75
|
return (
|
|
55
76
|
<span
|
|
56
77
|
key={(field?.name || 'field') + index}
|
|
57
78
|
style={field?.flex ? { flex: 1, minWidth: 0 } : undefined}
|
|
58
79
|
>
|
|
59
|
-
<SilkeSchemaField
|
|
80
|
+
<SilkeSchemaField
|
|
81
|
+
field={field}
|
|
82
|
+
{...rest}
|
|
83
|
+
path={getFieldPath(path, field)}
|
|
84
|
+
isFirst={index === 0}
|
|
85
|
+
/>
|
|
60
86
|
</span>
|
|
61
87
|
);
|
|
62
88
|
})}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { act, fireEvent, render, screen } from '@testing-library/react';
|
|
2
|
+
import { SchemaContextModel, VevProps } from '@vev/utils';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { SilkeFormSchema } from './silke-form-schema';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The decorator is the only consumer of a field's path, so recording what it is
|
|
8
|
+
* handed is the way to check the path survives every level of nesting.
|
|
9
|
+
*/
|
|
10
|
+
/** SilkeSchemaFields filters hidden fields in an async effect, so let it settle. */
|
|
11
|
+
const settle = () => act(async () => undefined);
|
|
12
|
+
|
|
13
|
+
async function renderSchema(schema: VevProps[], value: Record<string, any>) {
|
|
14
|
+
const paths: { name?: string; path?: string }[] = [];
|
|
15
|
+
|
|
16
|
+
render(
|
|
17
|
+
<SilkeFormSchema
|
|
18
|
+
schema={schema}
|
|
19
|
+
value={value}
|
|
20
|
+
context={{ value } as SchemaContextModel}
|
|
21
|
+
fieldDecorator={(field, path) => {
|
|
22
|
+
paths.push({ name: field.name, path });
|
|
23
|
+
return null;
|
|
24
|
+
}}
|
|
25
|
+
/>,
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
await settle();
|
|
29
|
+
return paths;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
describe('schema field paths', () => {
|
|
33
|
+
it('uses the field name at the top level', async () => {
|
|
34
|
+
const paths = await renderSchema([{ type: 'number', name: 'columns' }] as VevProps[], {
|
|
35
|
+
columns: 3,
|
|
36
|
+
});
|
|
37
|
+
expect(paths).toContainEqual({ name: 'columns', path: 'columns' });
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('nests under an object field', async () => {
|
|
41
|
+
const schema = [
|
|
42
|
+
{
|
|
43
|
+
type: 'object',
|
|
44
|
+
name: 'padding',
|
|
45
|
+
fields: [{ type: 'number', name: 'top' }],
|
|
46
|
+
},
|
|
47
|
+
] as VevProps[];
|
|
48
|
+
|
|
49
|
+
const paths = await renderSchema(schema, { padding: { top: 24 } });
|
|
50
|
+
expect(paths).toContainEqual({ name: 'top', path: 'padding.top' });
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it('does not nest under a group, which writes into the parent value', async () => {
|
|
54
|
+
const schema = [
|
|
55
|
+
{
|
|
56
|
+
type: 'group',
|
|
57
|
+
title: 'Advanced',
|
|
58
|
+
fields: [{ type: 'number', name: 'gap' }],
|
|
59
|
+
},
|
|
60
|
+
] as VevProps[];
|
|
61
|
+
|
|
62
|
+
const paths = await renderSchema(schema, { gap: 8 });
|
|
63
|
+
expect(paths).toContainEqual({ name: 'gap', path: 'gap' });
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('does not nest under a layout, which writes into the parent value', async () => {
|
|
67
|
+
const schema = [
|
|
68
|
+
{
|
|
69
|
+
type: 'layout',
|
|
70
|
+
options: { display: 'row' },
|
|
71
|
+
fields: [{ type: 'number', name: 'width' }],
|
|
72
|
+
},
|
|
73
|
+
] as VevProps[];
|
|
74
|
+
|
|
75
|
+
const paths = await renderSchema(schema, { width: 100 });
|
|
76
|
+
expect(paths).toContainEqual({ name: 'width', path: 'width' });
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it('does not nest under a named group either, because its children still write flat', async () => {
|
|
80
|
+
const schema = [
|
|
81
|
+
{
|
|
82
|
+
type: 'group',
|
|
83
|
+
name: 'advanced',
|
|
84
|
+
title: 'Advanced',
|
|
85
|
+
fields: [{ type: 'number', name: 'gap' }],
|
|
86
|
+
},
|
|
87
|
+
] as VevProps[];
|
|
88
|
+
|
|
89
|
+
const paths = await renderSchema(schema, { gap: 8 });
|
|
90
|
+
expect(paths).toContainEqual({ name: 'gap', path: 'gap' });
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it('does not nest under a named layout either', async () => {
|
|
94
|
+
const schema = [
|
|
95
|
+
{
|
|
96
|
+
type: 'layout',
|
|
97
|
+
name: 'row',
|
|
98
|
+
options: { display: 'row' },
|
|
99
|
+
fields: [{ type: 'number', name: 'width' }],
|
|
100
|
+
},
|
|
101
|
+
] as VevProps[];
|
|
102
|
+
|
|
103
|
+
const paths = await renderSchema(schema, { width: 100 });
|
|
104
|
+
expect(paths).toContainEqual({ name: 'width', path: 'width' });
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it('nests a group inside an object under the object only', async () => {
|
|
108
|
+
const schema = [
|
|
109
|
+
{
|
|
110
|
+
type: 'object',
|
|
111
|
+
name: 'padding',
|
|
112
|
+
fields: [
|
|
113
|
+
{
|
|
114
|
+
type: 'group',
|
|
115
|
+
title: 'Advanced',
|
|
116
|
+
fields: [{ type: 'number', name: 'top' }],
|
|
117
|
+
},
|
|
118
|
+
],
|
|
119
|
+
},
|
|
120
|
+
] as VevProps[];
|
|
121
|
+
|
|
122
|
+
const paths = await renderSchema(schema, { padding: { top: 24 } });
|
|
123
|
+
expect(paths).toContainEqual({ name: 'top', path: 'padding.top' });
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
describe('array item paths', () => {
|
|
128
|
+
const schema = [
|
|
129
|
+
{
|
|
130
|
+
type: 'array',
|
|
131
|
+
name: 'slides',
|
|
132
|
+
of: 'object',
|
|
133
|
+
fields: [{ type: 'string', name: 'label' }],
|
|
134
|
+
},
|
|
135
|
+
] as VevProps[];
|
|
136
|
+
|
|
137
|
+
it('includes the index of the item being edited', async () => {
|
|
138
|
+
const value = { slides: [{ label: 'One' }, { label: 'Two' }] };
|
|
139
|
+
const paths: (string | undefined)[] = [];
|
|
140
|
+
|
|
141
|
+
render(
|
|
142
|
+
<SilkeFormSchema
|
|
143
|
+
schema={schema}
|
|
144
|
+
value={value}
|
|
145
|
+
context={{ value } as SchemaContextModel}
|
|
146
|
+
fieldDecorator={(field, path) => {
|
|
147
|
+
if (field.name === 'label') paths.push(path);
|
|
148
|
+
return null;
|
|
149
|
+
}}
|
|
150
|
+
/>,
|
|
151
|
+
);
|
|
152
|
+
|
|
153
|
+
// The item editor only mounts once an item is opened.
|
|
154
|
+
await settle();
|
|
155
|
+
fireEvent.click(screen.getByText('Two'));
|
|
156
|
+
await settle();
|
|
157
|
+
|
|
158
|
+
expect(paths).toContain('slides.1.label');
|
|
159
|
+
});
|
|
160
|
+
});
|
|
@@ -41,7 +41,9 @@ export function SilkeGradientPicker({ ...props }: SilkeGradientPickerProps) {
|
|
|
41
41
|
|
|
42
42
|
const newGradient = { ...gradient };
|
|
43
43
|
newGradient.stops = newGradient.stops.slice();
|
|
44
|
-
|
|
44
|
+
const next = { ...newGradient.stops[selectedIndex], color };
|
|
45
|
+
if (!color.startsWith('var(')) delete next.opacity;
|
|
46
|
+
newGradient.stops[selectedIndex] = next;
|
|
45
47
|
handleChange(newGradient);
|
|
46
48
|
};
|
|
47
49
|
|
|
@@ -12,8 +12,25 @@ export type SilkeGradient = {
|
|
|
12
12
|
type SilkeGradientStop = {
|
|
13
13
|
color: string;
|
|
14
14
|
position: number;
|
|
15
|
+
/** Optional alpha (0–1) applied via color-mix when `color` is a CSS var() reference. */
|
|
16
|
+
opacity?: number;
|
|
15
17
|
};
|
|
16
18
|
|
|
19
|
+
const COLOR_MIX_VAR_REG =
|
|
20
|
+
/^color-mix\(\s*in\s+srgb\s*,\s*(var\([^)]+\))\s+(\d+(?:\.\d+)?)%\s*,\s*transparent\s*\)$/i;
|
|
21
|
+
|
|
22
|
+
function parseColorMix(value: string): { color: string; opacity: number } | null {
|
|
23
|
+
const match = value.match(COLOR_MIX_VAR_REG);
|
|
24
|
+
if (!match) return null;
|
|
25
|
+
return { color: match[1], opacity: parseFloat(match[2]) / 100 };
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function formatStopColor(color: string, opacity: number | undefined): string {
|
|
29
|
+
if (opacity === undefined || opacity >= 1 || !color.startsWith('var(')) return color;
|
|
30
|
+
const pct = Math.max(0, Math.min(100, Math.round(opacity * 100)));
|
|
31
|
+
return `color-mix(in srgb, ${color} ${pct}%, transparent)`;
|
|
32
|
+
}
|
|
33
|
+
|
|
17
34
|
function getGradientParts(gradient: string): string[] {
|
|
18
35
|
if (!gradient) return [];
|
|
19
36
|
gradient = gradient
|
|
@@ -37,10 +54,12 @@ export function getGradientModelFromCSS(cssGradient: string): SilkeGradient {
|
|
|
37
54
|
const stops: Partial<SilkeGradientStop>[] = [];
|
|
38
55
|
for (const part of parts) {
|
|
39
56
|
const [color, offsetString] = getCSSAttrParts(part, ' ');
|
|
40
|
-
|
|
57
|
+
const mix = parseColorMix(color);
|
|
58
|
+
if (mix || tinycolor(color).isValid() || color.startsWith('var(')) {
|
|
41
59
|
let position: number | undefined;
|
|
42
60
|
if (offsetString) position = (parseFloat(offsetString) || 0) / 100;
|
|
43
|
-
stops.push({ color, position });
|
|
61
|
+
if (mix) stops.push({ color: mix.color, opacity: mix.opacity, position });
|
|
62
|
+
else stops.push({ color, position });
|
|
44
63
|
} else {
|
|
45
64
|
gradient.pos = part;
|
|
46
65
|
}
|
|
@@ -53,7 +72,8 @@ export function getGradientModelFromCSS(cssGradient: string): SilkeGradient {
|
|
|
53
72
|
|
|
54
73
|
export function getCSSFromGradientModel({ stops, pos, type }: SilkeGradient): string {
|
|
55
74
|
const values = sortBy(stops, 'position').map(
|
|
56
|
-
(stop) =>
|
|
75
|
+
(stop) =>
|
|
76
|
+
`${formatStopColor(stop.color, stop.opacity)} ${Math.round(stop.position * 100)}%`,
|
|
57
77
|
);
|
|
58
78
|
|
|
59
79
|
if (pos) values.unshift(pos);
|
|
@@ -16,7 +16,7 @@ export function SilkeShape({ shape, className = 'fill' }: ShapePreviewProps) {
|
|
|
16
16
|
return (
|
|
17
17
|
<svg className={className} style={{ background: undefined }} viewBox={`0 0 ${width} ${height}`}>
|
|
18
18
|
{path.map((d, index) => (
|
|
19
|
-
<path key={index} d={d} fill="
|
|
19
|
+
<path key={index} d={d} fill="currentColor" />
|
|
20
20
|
))}
|
|
21
21
|
</svg>
|
|
22
22
|
);
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import React, { useRef, useState } from 'react';
|
|
2
|
+
import classnames from 'classnames/bind';
|
|
3
|
+
import { useFormField } from '../../hooks/form';
|
|
4
|
+
import { isInside, useMouseDown } from '../../hooks/use-mouse';
|
|
5
|
+
import { SilkeBox } from '../silke-box';
|
|
6
|
+
import { SilkeColorSwatchButton } from '../silke-color-swatches/silke-color-swatch-button';
|
|
7
|
+
import { FormFieldProps } from '../silke-form';
|
|
8
|
+
import styles from './styles.scss';
|
|
9
|
+
|
|
10
|
+
const cl = classnames.bind(styles);
|
|
11
|
+
|
|
12
|
+
interface ColorSwatchSectionProps {
|
|
13
|
+
colorName: string;
|
|
14
|
+
presetColors: string[];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function ColorSwatchSection({ colorName, presetColors }: ColorSwatchSectionProps) {
|
|
18
|
+
const { value, onChange } = useFormField<FormFieldProps<string>>({ name: colorName });
|
|
19
|
+
const [open, setOpen] = useState(false);
|
|
20
|
+
const dropdownRef = useRef<HTMLDivElement>(null);
|
|
21
|
+
|
|
22
|
+
useMouseDown((e) => {
|
|
23
|
+
const el = dropdownRef.current;
|
|
24
|
+
if (el && document.contains(e.target as HTMLElement) && !isInside(e, el)) {
|
|
25
|
+
setOpen(false);
|
|
26
|
+
}
|
|
27
|
+
}, !open);
|
|
28
|
+
|
|
29
|
+
return (
|
|
30
|
+
<SilkeBox className={cl('colorSwatchTrigger', { colorSwatchTriggerActive: open })}>
|
|
31
|
+
<SilkeColorSwatchButton
|
|
32
|
+
value={value || '#c2c2c2'}
|
|
33
|
+
size="s"
|
|
34
|
+
title="Background color"
|
|
35
|
+
onClick={() => setOpen(!open)}
|
|
36
|
+
aria-label="Background color"
|
|
37
|
+
aria-expanded={open}
|
|
38
|
+
/>
|
|
39
|
+
{open && (
|
|
40
|
+
<div ref={dropdownRef} className={cl('colorSwatchDropdown')}>
|
|
41
|
+
<SilkeBox column gap="s" pad="s" bg="neutral-10" rounded="small" shadow="level3">
|
|
42
|
+
<div className={cl('colorSwatchGrid')}>
|
|
43
|
+
{presetColors.map((color) => (
|
|
44
|
+
<SilkeColorSwatchButton
|
|
45
|
+
key={color}
|
|
46
|
+
value={color}
|
|
47
|
+
size="s"
|
|
48
|
+
selected={value === color}
|
|
49
|
+
onClick={() => {
|
|
50
|
+
onChange(value === color ? undefined : color);
|
|
51
|
+
setOpen(false);
|
|
52
|
+
}}
|
|
53
|
+
/>
|
|
54
|
+
))}
|
|
55
|
+
</div>
|
|
56
|
+
</SilkeBox>
|
|
57
|
+
</div>
|
|
58
|
+
)}
|
|
59
|
+
</SilkeBox>
|
|
60
|
+
);
|
|
61
|
+
}
|
|
@@ -4,7 +4,6 @@ import { SilkeButton } from '../silke-button';
|
|
|
4
4
|
import ButtonContext from '../silke-button/context';
|
|
5
5
|
import { SilkeSearchField } from '../silke-search-field';
|
|
6
6
|
import { SilkeText } from '../silke-text';
|
|
7
|
-
import { SilkeToolbar } from '../silke-toolbar';
|
|
8
7
|
import { SilkeVirtualGrid } from '../silke-virtual';
|
|
9
8
|
import { TabProps } from './utils';
|
|
10
9
|
import styles from './styles.scss';
|
|
@@ -47,7 +46,7 @@ async function fetchEmojis(): Promise<EmojiData> {
|
|
|
47
46
|
return emojiPromise;
|
|
48
47
|
}
|
|
49
48
|
|
|
50
|
-
export default function EmojiTab({ onSelect }: TabProps) {
|
|
49
|
+
export default function EmojiTab({ onSelect, extra }: TabProps) {
|
|
51
50
|
const [emojis, setEmojis] = useState<EmojiData | null>(null);
|
|
52
51
|
const [query, setQuery] = useState('');
|
|
53
52
|
useEffect(() => {
|
|
@@ -96,18 +95,20 @@ export default function EmojiTab({ onSelect }: TabProps) {
|
|
|
96
95
|
|
|
97
96
|
return (
|
|
98
97
|
<ButtonContext size="base" kind="ghost">
|
|
99
|
-
<
|
|
98
|
+
<SilkeBox gap="s" vAlign="center" hPad="m" vPad="xs">
|
|
100
99
|
<SilkeSearchField
|
|
101
|
-
placeholder="Search emoji
|
|
100
|
+
placeholder="Search emoji"
|
|
102
101
|
autoFocus
|
|
103
102
|
flex
|
|
104
103
|
size="base"
|
|
104
|
+
kind="default"
|
|
105
105
|
search={query}
|
|
106
106
|
onChange={setQuery}
|
|
107
107
|
onReset={() => setQuery('')}
|
|
108
108
|
/>
|
|
109
|
+
{extra}
|
|
109
110
|
<SilkeButton icon="random" onClick={handleRandom} />
|
|
110
|
-
</
|
|
111
|
+
</SilkeBox>
|
|
111
112
|
<SilkeBox column gap="s" pad="m" flex scroll>
|
|
112
113
|
{!emojis && (
|
|
113
114
|
<SilkeBox gap="xxs">
|
|
@@ -118,13 +119,14 @@ export default function EmojiTab({ onSelect }: TabProps) {
|
|
|
118
119
|
)}
|
|
119
120
|
{filtered.map((category) => (
|
|
120
121
|
<Fragment key={category.id}>
|
|
121
|
-
<SilkeText
|
|
122
|
+
<SilkeText size="small" weight="strong" color="neutral-100">
|
|
122
123
|
{category.name}
|
|
123
124
|
</SilkeText>
|
|
124
125
|
|
|
125
126
|
<SilkeVirtualGrid
|
|
126
127
|
items={category.emojis}
|
|
127
128
|
cell={[32, 32]}
|
|
129
|
+
className={styles.iconGrid}
|
|
128
130
|
style={{
|
|
129
131
|
fontFamily:
|
|
130
132
|
'"Segoe UI Emoji", "Segoe UI Symbol", "Segoe UI", "Apple Color Emoji", "Twemoji Mozilla", "Noto Color Emoji", "Android Emoji"',
|