@vev/silke 1.0.10 → 1.0.12
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/CHANGELOG.md +9 -0
- package/dist/chunk-4MB64AQL.js +22 -0
- package/dist/chunk-4MB64AQL.js.LEGAL.txt +8 -0
- package/dist/chunk-4MB64AQL.js.map +7 -0
- package/dist/index.js +9 -25
- package/dist/index.js.LEGAL.txt +6 -9
- package/dist/index.js.map +4 -4
- package/dist/silke-code-editor-HZRG3D6C.js +23 -0
- package/dist/silke-code-editor-HZRG3D6C.js.map +7 -0
- package/dist/styles.css +4338 -2599
- package/esbuild.config.mjs +2 -1
- package/jest.config.js +2 -1
- package/package.json +12 -8
- package/src/_variables.scss +121 -1
- package/src/components/index.ts +6 -0
- package/src/components/silke-autocomplete-field/autocomplete-item.tsx +15 -13
- package/src/components/silke-autocomplete-field/autocomplete-tags.tsx +14 -7
- package/src/components/silke-autocomplete-field/silke-autocomplete-field.mdx +31 -4
- package/src/components/silke-autocomplete-field/silke-autocomplete-field.scss +8 -6
- package/src/components/silke-autocomplete-field/silke-autocomplete-field.tsx +64 -23
- package/src/components/silke-box/silke-box.scss +21 -47
- package/src/components/silke-box/silke-box.tsx +23 -31
- package/src/components/silke-breadcrumbs/silke-breadcrumb.scss +3 -3
- package/src/components/silke-button/index.ts +3 -1
- package/src/components/silke-button/silke-big-button.scss +38 -0
- package/src/components/silke-button/silke-big-button.tsx +49 -0
- package/src/components/silke-button/silke-button-set.tsx +15 -3
- package/src/components/silke-button/silke-button.mdx +41 -19
- package/src/components/silke-button/silke-button.scss +97 -90
- package/src/components/silke-button/silke-button.tsx +20 -5
- package/src/components/silke-button/silke-file-select-button.tsx +86 -0
- package/src/components/silke-card/silke-card-grid.tsx +9 -9
- package/src/components/silke-card/silke-card.mdx +23 -9
- package/src/components/silke-card/silke-card.scss +92 -39
- package/src/components/silke-card/silke-card.tsx +50 -27
- package/src/components/silke-checkbox/silke-checkbox.scss +39 -17
- package/src/components/silke-checkbox/silke-checkbox.tsx +4 -1
- package/src/components/silke-code-editor/index.tsx +12 -0
- package/src/components/silke-code-editor/silke-code-editor.mdx +97 -0
- package/src/components/silke-code-editor/silke-code-editor.tsx +52 -0
- package/src/components/silke-code-snippet/silke-code-snippet.scss +2 -10
- package/src/components/silke-code-snippet/silke-code-snippet.tsx +10 -3
- package/src/components/silke-color-palettes/silke-color-palette.tsx +11 -2
- package/src/components/silke-color-picker/color-picker.scss +10 -6
- package/src/components/silke-color-picker/silke-color-info.tsx +14 -4
- package/src/components/silke-color-picker/silke-color-picker-button.tsx +4 -3
- package/src/components/silke-color-picker/silke-color-picker.tsx +4 -2
- package/src/components/silke-color-picker/silke-opacity-slider.tsx +11 -12
- package/src/components/silke-color-swatches/silke-color-swatch-button.tsx +10 -4
- package/src/components/silke-color-swatches/silke-swatches.tsx +2 -2
- package/src/components/silke-content-column/index.ts +1 -0
- package/src/components/silke-content-column/silke-content-column.mdx +7 -0
- package/src/components/silke-content-column/silke-content-column.scss +39 -0
- package/src/components/silke-content-column/silke-content-column.tsx +14 -0
- package/src/components/silke-context-menu/silke-context-menu-item.tsx +9 -4
- package/src/components/silke-context-menu/silke-context-menu.mdx +16 -12
- package/src/components/silke-context-menu/silke-context-menu.scss +16 -0
- package/src/components/silke-context-menu/silke-context-menu.tsx +62 -39
- package/src/components/silke-css-number-field/silke-css-context.tsx +1 -0
- package/src/components/silke-css-number-field/silke-css-number-field.scss +18 -3
- package/src/components/silke-css-number-field/silke-css-number-field.tsx +32 -13
- package/src/components/silke-css-number-field/utils.ts +2 -0
- package/src/components/silke-divider/silke-divider.scss +4 -2
- package/src/components/silke-drawer/silke-drawer.scss +3 -3
- package/src/components/silke-drawer/silke-drawer.tsx +3 -3
- package/src/components/silke-form/silke-form.tsx +1 -9
- package/src/components/silke-form-schema/fields/array-field-inline.tsx +2 -3
- package/src/components/silke-form-schema/fields/array-field-modal.tsx +1 -1
- package/src/components/silke-form-schema/fields/array-field.tsx +2 -2
- package/src/components/silke-form-schema/fields/event-field.tsx +120 -0
- package/src/components/silke-form-schema/fields/icon-field.tsx +1 -1
- package/src/components/silke-form-schema/fields/image-field.tsx +1 -1
- package/src/components/silke-form-schema/fields/link-field.tsx +8 -1
- package/src/components/silke-form-schema/fields/number-field.tsx +24 -8
- package/src/components/silke-form-schema/fields/object-field.tsx +1 -1
- package/src/components/silke-form-schema/fields/select-field.tsx +9 -2
- package/src/components/silke-form-schema/fields/styles.scss +2 -2
- package/src/components/silke-form-schema/fields/toggle-field.tsx +14 -13
- package/src/components/silke-form-schema/fields/upload-field.tsx +37 -0
- package/src/components/silke-form-schema/fields/utils/generate-image.ts +3 -4
- package/src/components/silke-form-schema/fields/utils/generate-title.ts +1 -3
- package/src/components/silke-form-schema/index.ts +1 -0
- package/src/components/silke-form-schema/silke-extended-fields-context.tsx +22 -0
- package/src/components/silke-form-schema/silke-schema-field.tsx +19 -6
- package/src/components/silke-icon/silke-icon.scss +3 -2
- package/src/components/silke-icon/silke-icon.tsx +7 -3
- package/src/components/silke-icon/silke-shape.tsx +3 -2
- package/src/components/silke-icon-picker/emoji-tab.tsx +2 -2
- package/src/components/silke-icon-picker/icons-tab.tsx +1 -1
- package/src/components/silke-icon-picker/silke-icon-picker.tsx +1 -1
- package/src/components/silke-iframe-portal/index.ts +4 -0
- package/src/components/silke-iframe-portal/silke-iframe-context.ts +6 -0
- package/src/components/silke-iframe-portal/silke-iframe-css-link.tsx +20 -0
- package/src/components/silke-iframe-portal/silke-iframe-portal.mdx +34 -0
- package/src/components/silke-iframe-portal/silke-iframe-portal.tsx +77 -0
- package/src/components/silke-iframe-portal/silke-iframe-script.tsx +20 -0
- package/src/components/silke-link/silke-link.scss +2 -2
- package/src/components/silke-link/silke-link.tsx +8 -9
- package/src/components/silke-list/silke-list.scss +1 -1
- package/src/components/silke-list-card/index.ts +1 -0
- package/src/components/silke-list-card/silke-list-card.mdx +50 -0
- package/src/components/silke-list-card/silke-list-card.scss +57 -0
- package/src/components/silke-list-card/silke-list-card.tsx +65 -0
- package/src/components/silke-loader/index.ts +1 -0
- package/src/components/silke-loader/silke-loader-overlay.tsx +63 -0
- package/src/components/silke-loader/silke-loader.scss +112 -0
- package/src/components/silke-loader/silke-loader.tsx +1 -0
- package/src/components/silke-modal/silke-confirmation-modal.tsx +1 -1
- package/src/components/silke-modal/silke-modal.mdx +1 -1
- package/src/components/silke-modal/silke-modal.scss +16 -10
- package/src/components/silke-modal/silke-modal.tsx +65 -47
- package/src/components/silke-navigation-link/silke-navigation-link.scss +69 -41
- package/src/components/silke-navigation-link/silke-navigation-link.tsx +26 -14
- package/src/components/silke-notification/confetti.tsx +164 -0
- package/src/components/silke-notification/silke-notification.mdx +137 -20
- package/src/components/silke-notification/silke-notification.scss +116 -89
- package/src/components/silke-notification/silke-notification.tsx +44 -113
- package/src/components/silke-object-field/silke-object-field.tsx +1 -1
- package/src/components/silke-overflow-menu/silke-overflow-menu.mdx +2 -2
- package/src/components/silke-overflow-menu/silke-overflow-menu.scss +12 -4
- package/src/components/silke-overflow-menu/silke-overflow-menu.tsx +53 -30
- package/src/components/silke-popover/silke-popover.mdx +2 -2
- package/src/components/silke-popover/silke-popover.tsx +23 -5
- package/src/components/silke-progress-indicator/silke-progress-indicator.scss +5 -5
- package/src/components/silke-radio-button/silke-radio-button-group.tsx +1 -1
- package/src/components/silke-radio-button/silke-radio-button.scss +24 -9
- package/src/components/silke-search-field/silke-search-field.tsx +10 -5
- package/src/components/silke-select-field/silke-select-field.mdx +11 -5
- package/src/components/silke-skeleton/silke-skeleton.scss +2 -2
- package/src/components/silke-slider/range-slider.scss +13 -10
- package/src/components/silke-slider/silke-slider.tsx +5 -0
- package/src/components/silke-sortable-list/silke-nested-sortable-item.tsx +105 -0
- package/src/components/silke-sortable-list/silke-nested-sortable-list.scss +37 -25
- package/src/components/silke-sortable-list/silke-nested-sortable-list.tsx +180 -127
- package/src/components/silke-sortable-list/silke-nested-sortable-utils.ts +53 -23
- package/src/components/silke-sortable-list/silke-sortable-item-wrapper.tsx +1 -1
- package/src/components/silke-sortable-list/silke-sortable-list.mdx +12 -16
- package/src/components/silke-sortable-list/silke-sortable-list.scss +39 -29
- package/src/components/silke-sortable-list/silke-sortable-list.tsx +27 -15
- package/src/components/silke-steps/index.ts +1 -0
- package/src/components/silke-steps/silke-steps.mdx +60 -0
- package/src/components/silke-steps/silke-steps.scss +14 -0
- package/src/components/silke-steps/silke-steps.tsx +53 -0
- package/src/components/silke-table/silke-table.mdx +44 -13
- package/src/components/silke-table/silke-table.scss +19 -9
- package/src/components/silke-table/silke-table.tsx +80 -71
- package/src/components/silke-table/table-row.tsx +11 -6
- package/src/components/silke-tabs/silke-tab.tsx +4 -0
- package/src/components/silke-tabs/silke-tabs.scss +18 -15
- package/src/components/silke-tabs/silke-tabs.tsx +4 -7
- package/src/components/silke-tag/silke-tag.mdx +36 -2
- package/src/components/silke-tag/silke-tag.scss +49 -30
- package/src/components/silke-tag/silke-tag.tsx +21 -6
- package/src/components/silke-text/silke-text-types.ts +2 -1
- package/src/components/silke-text/silke-text.mdx +28 -20
- package/src/components/silke-text/silke-text.scss +8 -7
- package/src/components/silke-text/silke-title.scss +1 -1
- package/src/components/silke-text-field/silke-text-field-outline.tsx +4 -4
- package/src/components/silke-text-field/silke-text-field.mdx +32 -14
- package/src/components/silke-text-field/silke-text-field.scss +41 -23
- package/src/components/silke-text-field/silke-text-field.tsx +13 -5
- package/src/components/silke-text-field/text-field-context.tsx +1 -1
- package/src/components/silke-theme-editor/index.ts +1 -0
- package/src/components/silke-theme-editor/silke-theme-editor.tsx +165 -0
- package/src/components/silke-tile/silke-tile.scss +13 -18
- package/src/components/silke-tile/silke-tile.tsx +11 -17
- package/src/components/silke-toggle/silke-toggle.scss +17 -9
- package/src/components/silke-toggle/silke-toggle.tsx +1 -1
- package/src/components/silke-toolbar/silke-toolbar.scss +1 -1
- package/src/components/silke-tooltip/silke-definition-tooltip.tsx +14 -6
- package/src/components/silke-tooltip/silke-icon-tooltip.tsx +48 -34
- package/src/components/silke-tooltip/silke-interactive-tooltip.tsx +5 -3
- package/src/components/silke-tooltip/silke-tooltip.mdx +69 -2
- package/src/components/silke-tooltip/silke-tooltip.scss +71 -46
- package/src/components/silke-tooltip/silke-tooltip.tsx +142 -52
- package/src/components/silke-tooltip/utils.ts +93 -0
- package/src/components/silke-upload-field/silke-upload-field.mdx +14 -0
- package/src/components/silke-upload-field/silke-upload-field.scss +26 -17
- package/src/components/silke-upload-field/silke-upload-field.tsx +37 -14
- package/src/docs/app.tsx +118 -25
- package/src/docs/components/code-block/code-block.scss +0 -2
- package/src/docs/components/code-block/code-block.tsx +17 -9
- package/src/hooks/drag-and-drop/use-drag.tsx +5 -1
- package/src/hooks/drag-and-drop/use-drop.tsx +5 -4
- package/src/icons.tsx +194 -10
- package/src/index.mdx +66 -1
- package/src/main.tsx +5 -2
- package/src/silke-theme-provider.tsx +51 -3
- package/src/styles/core.scss +56 -91
- package/webpack.docs.ts +1 -3
- package/webpack.config.ts +0 -131
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { SchemaFieldProps, UploadField as UploadFieldType } from '@vev/react';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { SilkeBox } from '../../silke-box';
|
|
4
|
+
import { SilkeTextSmall } from '../../silke-text';
|
|
5
|
+
import { SilkeUploadField } from '../../silke-upload-field';
|
|
6
|
+
import { startCase } from 'lodash';
|
|
7
|
+
|
|
8
|
+
const UploadField = (props: SchemaFieldProps<UploadFieldType>) => {
|
|
9
|
+
const { schema, onChange } = props;
|
|
10
|
+
|
|
11
|
+
return (
|
|
12
|
+
<SilkeBox column flex vPad="s">
|
|
13
|
+
<SilkeTextSmall>{schema.title || startCase(schema.name)}</SilkeTextSmall>
|
|
14
|
+
{schema.description && (
|
|
15
|
+
<SilkeTextSmall color="neutral-80">{schema.description}</SilkeTextSmall>
|
|
16
|
+
)}
|
|
17
|
+
|
|
18
|
+
<SilkeBox column>
|
|
19
|
+
<SilkeUploadField
|
|
20
|
+
accept={schema.accept}
|
|
21
|
+
multiple={false}
|
|
22
|
+
dropzoneStyle={{ width: '100%' }}
|
|
23
|
+
fileItemStyle={{ width: '100%' }}
|
|
24
|
+
maxSize={4096}
|
|
25
|
+
name={props.schema.name}
|
|
26
|
+
value={props.value}
|
|
27
|
+
useFileModel
|
|
28
|
+
onChange={(res) => {
|
|
29
|
+
onChange(res);
|
|
30
|
+
}}
|
|
31
|
+
/>
|
|
32
|
+
</SilkeBox>
|
|
33
|
+
</SilkeBox>
|
|
34
|
+
);
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export default UploadField;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
|
-
import { isObject, isFunction } from 'lodash';
|
|
2
|
+
import { isObject, isFunction, isArray } from 'lodash';
|
|
3
3
|
import { VevProps } from '@vev/react';
|
|
4
4
|
import { flattenObject } from './generate-title';
|
|
5
5
|
|
|
@@ -8,7 +8,6 @@ export const generateImage = (
|
|
|
8
8
|
schema?: VevProps | string,
|
|
9
9
|
): string | ReactNode | undefined => {
|
|
10
10
|
let image: string | ReactNode | undefined;
|
|
11
|
-
|
|
12
11
|
if (isObject(schema) && schema?.preview) {
|
|
13
12
|
if (isFunction(schema.preview)) {
|
|
14
13
|
({ image } = schema.preview(data as VevProps));
|
|
@@ -18,10 +17,10 @@ export const generateImage = (
|
|
|
18
17
|
}
|
|
19
18
|
|
|
20
19
|
if (!image) {
|
|
21
|
-
const values =
|
|
20
|
+
const values = !isArray(data) ? flattenObject(data) : data || [];
|
|
22
21
|
|
|
23
22
|
for (const value of values) {
|
|
24
|
-
const data: string[] = Object.values(value || {});
|
|
23
|
+
const data: string[] = Object.values(value || {}) as string[];
|
|
25
24
|
const imageInArr = data.find(
|
|
26
25
|
(child: string) => typeof child === 'string' && child.includes('cdn-cgi/image'),
|
|
27
26
|
);
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import React, { ReactNode } from 'react';
|
|
2
|
+
import { SchemaFieldTypes } from '@vev/utils';
|
|
3
|
+
|
|
4
|
+
export type SilkeFormSchemaExtendedField = {
|
|
5
|
+
type: keyof SchemaFieldTypes;
|
|
6
|
+
field: (props: unknown) => JSX.Element;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
type SilkeSchemaScopeProps = {
|
|
10
|
+
context: SilkeFormSchemaExtendedField[];
|
|
11
|
+
children?: ReactNode;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const SilkeExtendedFields = React.createContext<SilkeFormSchemaExtendedField[]>([]);
|
|
15
|
+
|
|
16
|
+
export function useExtendedFields() {
|
|
17
|
+
return React.useContext(SilkeExtendedFields);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function SilkeExtendedFieldsContext({ context, children }: SilkeSchemaScopeProps) {
|
|
21
|
+
return <SilkeExtendedFields.Provider value={context}>{children}</SilkeExtendedFields.Provider>;
|
|
22
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { SchemaFieldComponents, VevProps } from '@vev/react';
|
|
2
2
|
import { isFunction } from 'lodash';
|
|
3
3
|
import React, { useEffect, useState } from 'react';
|
|
4
|
-
import { SilkeBox, useFormField } from '..';
|
|
4
|
+
import { SilkeBox, useExtendedFields, useFormField } from '..';
|
|
5
5
|
import { SilkeNotification } from '../silke-notification';
|
|
6
6
|
import { safeEvalFunction } from './safe-eval';
|
|
7
7
|
import { isEvalCallback, useStorageField } from './schema-utils';
|
|
@@ -17,6 +17,8 @@ import ToggleField from './fields/toggle-field';
|
|
|
17
17
|
import LinkField from './fields/link-field';
|
|
18
18
|
import LayoutField from './fields/layout-field';
|
|
19
19
|
import IconField from './fields/icon-field';
|
|
20
|
+
import EventField from './fields/event-field';
|
|
21
|
+
import UploadField from './fields/upload-field';
|
|
20
22
|
|
|
21
23
|
type SilkeSchemaFieldProps = {
|
|
22
24
|
field: VevProps;
|
|
@@ -24,7 +26,7 @@ type SilkeSchemaFieldProps = {
|
|
|
24
26
|
noPad?: boolean;
|
|
25
27
|
};
|
|
26
28
|
|
|
27
|
-
const SCHEMA_FIELD_COMPONENTS: SchemaFieldComponents = {
|
|
29
|
+
const SCHEMA_FIELD_COMPONENTS: Partial<SchemaFieldComponents> = {
|
|
28
30
|
string: StringField,
|
|
29
31
|
number: NumberField,
|
|
30
32
|
array: ArrayField,
|
|
@@ -35,9 +37,13 @@ const SCHEMA_FIELD_COMPONENTS: SchemaFieldComponents = {
|
|
|
35
37
|
link: LinkField,
|
|
36
38
|
layout: LayoutField,
|
|
37
39
|
icon: IconField,
|
|
40
|
+
event: EventField,
|
|
41
|
+
upload: UploadField,
|
|
38
42
|
};
|
|
39
43
|
|
|
40
44
|
export function SilkeSchemaField({ field, value: fieldValue, noPad }: SilkeSchemaFieldProps) {
|
|
45
|
+
const extendedFields = useExtendedFields();
|
|
46
|
+
|
|
41
47
|
const { value, onChange } =
|
|
42
48
|
field.storage && field.name
|
|
43
49
|
? // eslint-disable-next-line react-hooks/rules-of-hooks
|
|
@@ -47,8 +53,16 @@ export function SilkeSchemaField({ field, value: fieldValue, noPad }: SilkeSchem
|
|
|
47
53
|
|
|
48
54
|
const context = useSchemaContext();
|
|
49
55
|
const [hidden, setHidden] = useState(false);
|
|
56
|
+
let Field = (field.component || SCHEMA_FIELD_COMPONENTS[field.type]) as any;
|
|
50
57
|
|
|
51
|
-
|
|
58
|
+
if (!Field) {
|
|
59
|
+
const extendedField = extendedFields.find((extField) => extField.type === field.type);
|
|
60
|
+
if (extendedField) {
|
|
61
|
+
Field = extendedField.field;
|
|
62
|
+
} else {
|
|
63
|
+
console.warn(`Could not find field type ${field.type}`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
52
66
|
|
|
53
67
|
useEffect(() => {
|
|
54
68
|
const checkHidden = async () => {
|
|
@@ -86,10 +100,9 @@ export function SilkeSchemaField({ field, value: fieldValue, noPad }: SilkeSchem
|
|
|
86
100
|
if (isEvalCallback(field.onChange)) {
|
|
87
101
|
value = await safeEvalFunction(field.onChange.value, value, context);
|
|
88
102
|
} else if (isFunction(field.onChange)) {
|
|
89
|
-
// @ts-ignore
|
|
90
|
-
value = (await field.onChange(value, context)) as any;
|
|
103
|
+
// @ts-expect-error - ignore
|
|
104
|
+
value = (await field.onChange(value as any, context)) as any;
|
|
91
105
|
}
|
|
92
|
-
|
|
93
106
|
onChange(value);
|
|
94
107
|
}}
|
|
95
108
|
/>
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
@use "../../variables" as *;
|
|
2
|
+
|
|
2
3
|
.icon {
|
|
3
4
|
// font-size: 1.14285714286em;
|
|
4
5
|
// font-size: 1.14em;
|
|
5
6
|
svg {
|
|
6
|
-
vertical-align:
|
|
7
|
+
vertical-align: sub;
|
|
7
8
|
height: 1.125em;
|
|
8
9
|
width: 1.125em;
|
|
9
10
|
}
|
|
@@ -16,6 +17,6 @@ img.icon {
|
|
|
16
17
|
}
|
|
17
18
|
|
|
18
19
|
.emoji {
|
|
19
|
-
// this
|
|
20
|
+
// this fontsize works for emojis for a magical reason
|
|
20
21
|
font-size: 1.14285714286em;
|
|
21
22
|
}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { EmojiType, IEmojiIcon } from '@vev/utils';
|
|
2
|
-
import { isObject } from 'lodash';
|
|
2
|
+
import { isObject, isString } from 'lodash';
|
|
3
3
|
import React, { HTMLAttributes } from 'react';
|
|
4
4
|
import { SilkeIconDefinitions } from '../../icons';
|
|
5
5
|
import styles from './silke-icon.scss';
|
|
6
6
|
import { SilkeShape } from './silke-shape';
|
|
7
7
|
|
|
8
8
|
export type SilkeIcons = keyof typeof SilkeIconDefinitions | null | IEmojiIcon;
|
|
9
|
+
|
|
9
10
|
interface SilkeIconProps extends HTMLAttributes<HTMLElement> {
|
|
10
11
|
icon: SilkeIcons | React.ReactElement;
|
|
11
12
|
}
|
|
@@ -21,13 +22,16 @@ export function SilkeIcon({ icon, className, color, ...rest }: SilkeIconProps):
|
|
|
21
22
|
</span>
|
|
22
23
|
);
|
|
23
24
|
}
|
|
25
|
+
if (isString(icon) && /^https?:\/\//.test(icon)) {
|
|
26
|
+
icon = { type: EmojiType.upload, value: { url: icon } };
|
|
27
|
+
}
|
|
24
28
|
|
|
25
29
|
if (isObject(icon)) {
|
|
26
30
|
switch (icon.type) {
|
|
27
31
|
case EmojiType.icon:
|
|
28
|
-
return <SilkeShape shape={icon.value} />;
|
|
32
|
+
return <SilkeShape {...rest} className={cl} shape={icon.value} />;
|
|
29
33
|
case EmojiType.upload:
|
|
30
|
-
return <img className={cl} src={icon.value.url} />;
|
|
34
|
+
return <img {...rest} className={cl} src={icon.value.url} />;
|
|
31
35
|
}
|
|
32
36
|
|
|
33
37
|
cl += ' ' + styles.emoji;
|
|
@@ -4,16 +4,17 @@ import { isArray } from 'lodash';
|
|
|
4
4
|
|
|
5
5
|
interface ShapePreviewProps {
|
|
6
6
|
shape: IWidgetIcon | IShapePath;
|
|
7
|
+
className?: string;
|
|
7
8
|
}
|
|
8
9
|
|
|
9
|
-
export function SilkeShape({ shape }: ShapePreviewProps) {
|
|
10
|
+
export function SilkeShape({ shape, className = 'fill' }: ShapePreviewProps) {
|
|
10
11
|
if (!shape) return null;
|
|
11
12
|
|
|
12
13
|
if (!isArray(shape) && shape.type) return <img src={shape.value} />;
|
|
13
14
|
|
|
14
15
|
const [width, height, ...path] = isArray(shape) ? shape : (shape.value as IShapePath);
|
|
15
16
|
return (
|
|
16
|
-
<svg className=
|
|
17
|
+
<svg className={className} style={{ background: undefined }} viewBox={`0 0 ${width} ${height}`}>
|
|
17
18
|
{path.map((d, index) => (
|
|
18
19
|
<path key={index} d={d} fill="blawhitek" />
|
|
19
20
|
))}
|
|
@@ -95,7 +95,7 @@ export default function EmojiTab({ onSelect }: TabProps) {
|
|
|
95
95
|
}, [emojis, filtered, onSelect]);
|
|
96
96
|
|
|
97
97
|
return (
|
|
98
|
-
<ButtonContext size="base" kind="
|
|
98
|
+
<ButtonContext size="base" kind="ghost">
|
|
99
99
|
<SilkeToolbar size="m">
|
|
100
100
|
<SilkeSearchField
|
|
101
101
|
placeholder="Search emoji..."
|
|
@@ -118,7 +118,7 @@ export default function EmojiTab({ onSelect }: TabProps) {
|
|
|
118
118
|
)}
|
|
119
119
|
{filtered.map((category) => (
|
|
120
120
|
<Fragment key={category.id}>
|
|
121
|
-
<SilkeText tag="small" color="
|
|
121
|
+
<SilkeText tag="small" color="neutral-80">
|
|
122
122
|
{category.name}
|
|
123
123
|
</SilkeText>
|
|
124
124
|
|
|
@@ -54,7 +54,7 @@ export default function IconsTab({ onSelect }: TabProps) {
|
|
|
54
54
|
}, [query, icons]);
|
|
55
55
|
|
|
56
56
|
return (
|
|
57
|
-
<ButtonContext size="base" kind="
|
|
57
|
+
<ButtonContext size="base" kind="ghost">
|
|
58
58
|
<SilkeToolbar size="base">
|
|
59
59
|
<SilkeSearchField
|
|
60
60
|
placeholder="Search icons..."
|
|
@@ -66,7 +66,7 @@ export function SilkeIconPicker(props: SilkeIconPickerProps) {
|
|
|
66
66
|
targetOrigin="top-left"
|
|
67
67
|
onToggleOpen={setOpen}
|
|
68
68
|
>
|
|
69
|
-
<SilkeBox column bg="
|
|
69
|
+
<SilkeBox column bg="neutral-20" style={{ width: 456, height: 320, borderRadius: 8 }}>
|
|
70
70
|
{!singleType && (
|
|
71
71
|
<SilkeTabs>
|
|
72
72
|
<SilkeTab
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { createContext, useContext } from 'react';
|
|
2
|
+
|
|
3
|
+
export type SilkeIframeContextModel = { doc?: Document; win?: Window };
|
|
4
|
+
export const SilkeIframeContext = createContext<SilkeIframeContextModel>({});
|
|
5
|
+
|
|
6
|
+
export const useSilkeIframeContext = () => useContext(SilkeIframeContext);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
import { useSilkeIframeContext } from './silke-iframe-context';
|
|
3
|
+
|
|
4
|
+
type SilkeIframeCssLinkProps = { href: string };
|
|
5
|
+
|
|
6
|
+
export function SilkeIframeCssLink({ href }: SilkeIframeCssLinkProps) {
|
|
7
|
+
const { doc } = useSilkeIframeContext();
|
|
8
|
+
useEffect(() => {
|
|
9
|
+
const head = doc?.head;
|
|
10
|
+
if (head) {
|
|
11
|
+
const link = doc.createElement('link');
|
|
12
|
+
link.href = href;
|
|
13
|
+
link.rel = 'stylesheet';
|
|
14
|
+
head.appendChild(link);
|
|
15
|
+
|
|
16
|
+
return () => link.remove();
|
|
17
|
+
}
|
|
18
|
+
}, [href, doc]);
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# Iframe portal
|
|
2
|
+
|
|
3
|
+
Allows you to write jsx to render inside an iframe.
|
|
4
|
+
WARNING: it's possible to escape the iframe and execute code in the parent window
|
|
5
|
+
|
|
6
|
+
```js
|
|
7
|
+
const [counter, setCounter] = React.useState(0);
|
|
8
|
+
<SilkeBox column>
|
|
9
|
+
<SilkeIframePortal autoResize style={{ border: "2px solid white" }}>
|
|
10
|
+
<SilkeIframeCssLink href="https://cdn.vev.design/fontawesome/6.1.1/css/all.min.css" />
|
|
11
|
+
<SilkeIframeCssLink href="https://fonts.googleapis.com/css?family=Source+Code+Pro:300,400,600,700,900&display=swap" />
|
|
12
|
+
<h1>
|
|
13
|
+
<i class="fa-regular fa-hand-sparkles"></i>
|
|
14
|
+
</h1>
|
|
15
|
+
<style>{"body{color:white;font-family:'Source Code Pro';}"}</style>
|
|
16
|
+
<h1>This header is rendered inside an iframe</h1>
|
|
17
|
+
<h1>Counter inside iframe: {counter}</h1>
|
|
18
|
+
<SilkeButton
|
|
19
|
+
label="Increment counter inside iframe"
|
|
20
|
+
onClick={() => setCounter((c) => c + 1)}
|
|
21
|
+
/>
|
|
22
|
+
<p>
|
|
23
|
+
Styles will not be synced into the iframe, so silke components will have
|
|
24
|
+
no style
|
|
25
|
+
</p>
|
|
26
|
+
<SilkeIframeScript>{`console.log("hello from iframe")`}</SilkeIframeScript>
|
|
27
|
+
</SilkeIframePortal>
|
|
28
|
+
<h1>Counter outside iframe: {counter}</h1>
|
|
29
|
+
<SilkeButton
|
|
30
|
+
label="Increment counter outside iframe"
|
|
31
|
+
onClick={() => setCounter((c) => c + 1)}
|
|
32
|
+
/>
|
|
33
|
+
</SilkeBox>;
|
|
34
|
+
```
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import React, { HTMLAttributes, useCallback, useEffect, useRef, useState } from 'react';
|
|
2
|
+
import { createPortal } from 'react-dom';
|
|
3
|
+
import { SilkeIframeContext, SilkeIframeContextModel } from './silke-iframe-context';
|
|
4
|
+
|
|
5
|
+
type SilkeIframePortalProps = Omit<HTMLAttributes<HTMLIFrameElement>, 'sandbox'> & {
|
|
6
|
+
children: React.ReactNode;
|
|
7
|
+
/** Override default srcDoc */
|
|
8
|
+
srcDoc?: string;
|
|
9
|
+
autoResize?: boolean;
|
|
10
|
+
bodyStyle?: React.CSSProperties;
|
|
11
|
+
};
|
|
12
|
+
const DEFAULT_SRC_DOC =
|
|
13
|
+
'<html><head><style>html,body{margin:0;overflow:hidden;}</style></head><body></body></html>';
|
|
14
|
+
export function SilkeIframePortal({
|
|
15
|
+
bodyStyle,
|
|
16
|
+
children,
|
|
17
|
+
style,
|
|
18
|
+
srcDoc,
|
|
19
|
+
autoResize,
|
|
20
|
+
onLoad,
|
|
21
|
+
...rest
|
|
22
|
+
}: SilkeIframePortalProps) {
|
|
23
|
+
const iframeRef = useRef<HTMLIFrameElement>(null);
|
|
24
|
+
const [innerElement, setInnerElement] = useState<HTMLDivElement>();
|
|
25
|
+
const [context, setContext] = useState<SilkeIframeContextModel>({});
|
|
26
|
+
|
|
27
|
+
const handleLoad: React.ReactEventHandler<HTMLIFrameElement> = useCallback((e) => {
|
|
28
|
+
const iframe = e.currentTarget;
|
|
29
|
+
const doc = iframe.contentDocument;
|
|
30
|
+
const win = iframe.contentWindow;
|
|
31
|
+
|
|
32
|
+
if (doc && win) {
|
|
33
|
+
const innerElement = doc.createElement('div');
|
|
34
|
+
doc.body.appendChild(innerElement);
|
|
35
|
+
|
|
36
|
+
setInnerElement(innerElement);
|
|
37
|
+
setContext({ doc, win });
|
|
38
|
+
}
|
|
39
|
+
onLoad?.(e);
|
|
40
|
+
}, []);
|
|
41
|
+
|
|
42
|
+
const body = context.doc?.body;
|
|
43
|
+
useEffect(() => {
|
|
44
|
+
if (body) {
|
|
45
|
+
Object.assign(body.style, bodyStyle);
|
|
46
|
+
}
|
|
47
|
+
}, [bodyStyle, body]);
|
|
48
|
+
|
|
49
|
+
useEffect(() => {
|
|
50
|
+
const iframe = iframeRef.current;
|
|
51
|
+
if (iframe && body && autoResize) {
|
|
52
|
+
const handleResize = () => {
|
|
53
|
+
const { height } = body.getBoundingClientRect();
|
|
54
|
+
iframe.style.height = `${height}px`;
|
|
55
|
+
};
|
|
56
|
+
const resizeObserver = new ResizeObserver(handleResize);
|
|
57
|
+
handleResize();
|
|
58
|
+
|
|
59
|
+
resizeObserver.observe(body);
|
|
60
|
+
return () => resizeObserver.disconnect();
|
|
61
|
+
}
|
|
62
|
+
}, [body, autoResize]);
|
|
63
|
+
|
|
64
|
+
return (
|
|
65
|
+
<SilkeIframeContext.Provider value={context}>
|
|
66
|
+
<iframe
|
|
67
|
+
srcDoc={srcDoc || DEFAULT_SRC_DOC}
|
|
68
|
+
style={{ border: '0', ...style }}
|
|
69
|
+
{...rest}
|
|
70
|
+
ref={iframeRef}
|
|
71
|
+
sandbox="allow-same-origin allow-scripts allow-forms allow-presentation"
|
|
72
|
+
onLoad={handleLoad}
|
|
73
|
+
/>
|
|
74
|
+
{innerElement && createPortal(children, innerElement)}
|
|
75
|
+
</SilkeIframeContext.Provider>
|
|
76
|
+
);
|
|
77
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
import { useSilkeIframeContext } from './silke-iframe-context';
|
|
3
|
+
|
|
4
|
+
type SilkeIframeScriptProps = { src?: string; children?: string };
|
|
5
|
+
|
|
6
|
+
export function SilkeIframeScript({ src, children }: SilkeIframeScriptProps) {
|
|
7
|
+
const { doc } = useSilkeIframeContext();
|
|
8
|
+
useEffect(() => {
|
|
9
|
+
const body = doc?.body;
|
|
10
|
+
if (body) {
|
|
11
|
+
const script = doc.createElement('script');
|
|
12
|
+
if (src) script.src = src;
|
|
13
|
+
else if (children) script.innerHTML = children;
|
|
14
|
+
body.appendChild(script);
|
|
15
|
+
|
|
16
|
+
return () => script.remove();
|
|
17
|
+
}
|
|
18
|
+
}, [src, children, doc]);
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
@@ -4,11 +4,11 @@
|
|
|
4
4
|
.silke-link {
|
|
5
5
|
text-decoration: underline;
|
|
6
6
|
cursor: pointer;
|
|
7
|
-
color: var(--color-
|
|
7
|
+
color: var(--color-accent-50);
|
|
8
8
|
|
|
9
9
|
&:focus-visible {
|
|
10
10
|
outline: none;
|
|
11
|
-
box-shadow: 0 0 0 2px var(--color-neutral-
|
|
11
|
+
box-shadow: 0 0 0 2px var(--color-neutral-100);
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
&:hover {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { HTMLAttributes
|
|
1
|
+
import React, { HTMLAttributes } from 'react';
|
|
2
2
|
import './silke-link.scss';
|
|
3
3
|
import { LinkProps, Link } from 'react-router-dom';
|
|
4
4
|
import { SilkeIcon, SilkeIcons } from '../silke-icon';
|
|
@@ -23,11 +23,10 @@ const getClassNames = (className?: string, standalone?: boolean): string => {
|
|
|
23
23
|
interface LinkChildProps {
|
|
24
24
|
external?: boolean;
|
|
25
25
|
icon?: SilkeIcons;
|
|
26
|
+
children?: React.ReactNode;
|
|
26
27
|
}
|
|
27
28
|
|
|
28
|
-
const LinkChild:
|
|
29
|
-
props: PropsWithChildren<LinkChildProps>,
|
|
30
|
-
) => {
|
|
29
|
+
const LinkChild = (props: LinkChildProps) => {
|
|
31
30
|
const { children, icon, external } = props;
|
|
32
31
|
const displayIcon = !!(icon || external);
|
|
33
32
|
|
|
@@ -45,7 +44,9 @@ const LinkChild: React.FunctionComponent<LinkChildProps> = (
|
|
|
45
44
|
);
|
|
46
45
|
};
|
|
47
46
|
|
|
48
|
-
interface SilkeLinkProps
|
|
47
|
+
interface SilkeLinkProps
|
|
48
|
+
extends Omit<React.AnchorHTMLAttributes<HTMLAnchorElement>, 'children'>,
|
|
49
|
+
LinkChildProps {
|
|
49
50
|
standalone?: boolean;
|
|
50
51
|
}
|
|
51
52
|
|
|
@@ -61,7 +62,7 @@ export const SilkeLink: React.FunctionComponent<SilkeLinkProps> = (props: SilkeL
|
|
|
61
62
|
);
|
|
62
63
|
};
|
|
63
64
|
|
|
64
|
-
interface SilkeRouterLinkProps extends LinkProps, LinkChildProps {
|
|
65
|
+
interface SilkeRouterLinkProps extends Omit<LinkProps, 'children'>, LinkChildProps {
|
|
65
66
|
standalone?: boolean;
|
|
66
67
|
}
|
|
67
68
|
|
|
@@ -83,9 +84,7 @@ export interface SilkeButtonLinkProps extends HTMLAttributes<HTMLButtonElement>
|
|
|
83
84
|
icon?: SilkeIcons;
|
|
84
85
|
}
|
|
85
86
|
|
|
86
|
-
export const SilkeButtonLink:
|
|
87
|
-
props: SilkeButtonLinkProps,
|
|
88
|
-
) => {
|
|
87
|
+
export const SilkeButtonLink = (props: SilkeButtonLinkProps) => {
|
|
89
88
|
const { className, standalone, icon, children, ...rest } = props;
|
|
90
89
|
|
|
91
90
|
return (
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './silke-list-card';
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
## List Item
|
|
2
|
+
|
|
3
|
+
## Variants
|
|
4
|
+
|
|
5
|
+
```js
|
|
6
|
+
const list = [1, 2, 3].map((i) => ({ label: "Item 1" }));
|
|
7
|
+
|
|
8
|
+
<SilkeBox column gap="m">
|
|
9
|
+
<SilkeListCard title="Title placeholder" />
|
|
10
|
+
<SilkeListCard title="Title placeholder" image={ipsum.image()} />
|
|
11
|
+
<SilkeListCard
|
|
12
|
+
title="Title placeholder"
|
|
13
|
+
subtitle="Subtitle placeholder"
|
|
14
|
+
image={ipsum.image()}
|
|
15
|
+
/>
|
|
16
|
+
<SilkeListCard
|
|
17
|
+
title="Title placeholder"
|
|
18
|
+
subtitle="Subtitle placeholder"
|
|
19
|
+
image={ipsum.image()}
|
|
20
|
+
tag={{
|
|
21
|
+
label: "Tag",
|
|
22
|
+
kind: "green",
|
|
23
|
+
}}
|
|
24
|
+
/>
|
|
25
|
+
<SilkeListCard
|
|
26
|
+
title="Title placeholder"
|
|
27
|
+
subtitle="Subtitle placeholder"
|
|
28
|
+
image={ipsum.image()}
|
|
29
|
+
tag={{
|
|
30
|
+
label: "Tag",
|
|
31
|
+
kind: "green",
|
|
32
|
+
}}
|
|
33
|
+
menu={list}
|
|
34
|
+
/>
|
|
35
|
+
</SilkeBox>;
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## States
|
|
39
|
+
|
|
40
|
+
```js
|
|
41
|
+
const list = [1, 2, 3].map((i) => ({ label: "Item 1" }));
|
|
42
|
+
|
|
43
|
+
<SilkeBox gap="m" column>
|
|
44
|
+
<SilkeListCard title="Default" image={ipsum.image()} />
|
|
45
|
+
<SilkeListCard title="Hover" image={ipsum.image()} state="hover" />
|
|
46
|
+
<SilkeListCard title="Focus" image={ipsum.image()} state="focus" />
|
|
47
|
+
<SilkeListCard title="Disabled" image={ipsum.image()} state="disabled" />
|
|
48
|
+
<SilkeListCard title="Selected" image={ipsum.image()} state="selected" />
|
|
49
|
+
</SilkeBox>;
|
|
50
|
+
```
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
|
|
2
|
+
.card {
|
|
3
|
+
border-radius: var(--border-radius-small);
|
|
4
|
+
line-height: 1.25;
|
|
5
|
+
justify-content: space-between;
|
|
6
|
+
}
|
|
7
|
+
.image {
|
|
8
|
+
border-radius: var(--border-radius-tiny);
|
|
9
|
+
overflow: hidden;
|
|
10
|
+
width: 32px;
|
|
11
|
+
height: 32px;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// States
|
|
15
|
+
|
|
16
|
+
.hover,
|
|
17
|
+
.card:hover {
|
|
18
|
+
background-color: var(--color-surface-2);
|
|
19
|
+
transition: 200ms;
|
|
20
|
+
cursor: pointer;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.card:active {
|
|
24
|
+
outline: none;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.selected {
|
|
28
|
+
outline: 1px solid var(--color-accent-30);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.disabled {
|
|
32
|
+
span {
|
|
33
|
+
color: var(--color-neutral-60);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
img {
|
|
37
|
+
opacity: 40%;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
.card:focus {
|
|
43
|
+
outline: none;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
.focus,
|
|
47
|
+
.card:focus-visible::before {
|
|
48
|
+
border: 1px solid var(--color-neutral-70);
|
|
49
|
+
position: absolute;
|
|
50
|
+
border-radius: var(--border-radius-small);
|
|
51
|
+
top: -4px;
|
|
52
|
+
left: -4px;
|
|
53
|
+
right: -4px;
|
|
54
|
+
bottom: -4px;
|
|
55
|
+
content: "";
|
|
56
|
+
z-index: 1;
|
|
57
|
+
}
|