@vev/silke 1.1.9 → 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 +162 -77
- package/CHANGELOG.md +40 -0
- package/dist/index.js +47 -40
- package/dist/index.js.LEGAL.txt +1 -1
- package/dist/index.js.map +7 -0
- package/dist/styles.css +1596 -1013
- 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 +18 -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/number-field.tsx +114 -4
- 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 +65 -4
- package/tsconfig.build.tsbuildinfo +0 -1
|
@@ -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"',
|
|
@@ -4,9 +4,9 @@ import { SilkeBox } from '../silke-box';
|
|
|
4
4
|
import { SilkeButton } from '../silke-button';
|
|
5
5
|
import ButtonContext from '../silke-button/context';
|
|
6
6
|
import { SilkeSearchField } from '../silke-search-field';
|
|
7
|
-
import { SilkeToolbar } from '../silke-toolbar';
|
|
8
7
|
import { SilkeVirtualGrid } from '../silke-virtual';
|
|
9
8
|
import { TabProps } from './utils';
|
|
9
|
+
import styles from './styles.scss';
|
|
10
10
|
|
|
11
11
|
let iconsPromise: Promise<IShape[]>;
|
|
12
12
|
|
|
@@ -31,7 +31,7 @@ function isIconMatch(icon: IShape, reg: RegExp) {
|
|
|
31
31
|
return false;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
export default function IconsTab({ onSelect }: TabProps) {
|
|
34
|
+
export default function IconsTab({ onSelect, extra }: TabProps) {
|
|
35
35
|
const [icons, setIcons] = useState<IShape[] | null>(null);
|
|
36
36
|
const [query, setQuery] = useState('');
|
|
37
37
|
useEffect(() => {
|
|
@@ -55,25 +55,26 @@ export default function IconsTab({ onSelect }: TabProps) {
|
|
|
55
55
|
|
|
56
56
|
return (
|
|
57
57
|
<ButtonContext size="base" kind="ghost">
|
|
58
|
-
<
|
|
58
|
+
<SilkeBox gap="s" vAlign="center" hPad="m" vPad="xs">
|
|
59
59
|
<SilkeSearchField
|
|
60
|
-
placeholder="Search icons
|
|
60
|
+
placeholder="Search icons"
|
|
61
61
|
autoFocus
|
|
62
62
|
flex
|
|
63
63
|
size="base"
|
|
64
|
+
kind="default"
|
|
64
65
|
search={query}
|
|
65
66
|
onChange={setQuery}
|
|
66
67
|
onReset={() => setQuery('')}
|
|
67
68
|
/>
|
|
69
|
+
{extra}
|
|
68
70
|
<SilkeButton
|
|
69
|
-
label="Randomize"
|
|
70
71
|
icon="random"
|
|
71
72
|
onClick={() =>
|
|
72
73
|
icons &&
|
|
73
74
|
onSelect({ type: 1, value: icons[Math.round(Math.random() * (icons.length - 1))].path })
|
|
74
75
|
}
|
|
75
76
|
/>
|
|
76
|
-
</
|
|
77
|
+
</SilkeBox>
|
|
77
78
|
<SilkeBox column gap="s" pad="m" flex scroll>
|
|
78
79
|
{!icons && (
|
|
79
80
|
<SilkeBox gap="xxs">
|
|
@@ -82,7 +83,7 @@ export default function IconsTab({ onSelect }: TabProps) {
|
|
|
82
83
|
<SilkeButton icon="history" loading />
|
|
83
84
|
</SilkeBox>
|
|
84
85
|
)}
|
|
85
|
-
<SilkeVirtualGrid items={filtered} cell={[32, 32]}>
|
|
86
|
+
<SilkeVirtualGrid items={filtered} cell={[32, 32]} className={styles.iconGrid}>
|
|
86
87
|
{(shape) => (
|
|
87
88
|
<SilkeButton
|
|
88
89
|
icon={{ type: 1, value: shape.path }}
|
|
@@ -1,21 +1,26 @@
|
|
|
1
1
|
import { EmojiType, IEmojiIcon } from '@vev/utils';
|
|
2
|
-
import React, { useState } from 'react';
|
|
2
|
+
import React, { useContext, useState } from 'react';
|
|
3
3
|
import { useFormField } from '../../hooks/form';
|
|
4
4
|
import { SilkeBox } from '../silke-box';
|
|
5
|
-
import { SilkeButtonProps } from '../silke-button';
|
|
5
|
+
import { SilkeButton, SilkeButtonProps } from '../silke-button';
|
|
6
6
|
import { FormFieldProps, FormValidator } from '../silke-form';
|
|
7
|
-
import {
|
|
7
|
+
import { getFieldContext } from '../silke-form/form-context';
|
|
8
|
+
import { SilkeIcon, SilkeIcons } from '../silke-icon/silke-icon';
|
|
8
9
|
import { SilkeOverflowMenu } from '../silke-overflow-menu';
|
|
9
10
|
import { SilkeTab, SilkeTabs } from '../silke-tabs';
|
|
10
11
|
import { SilkeText } from '../silke-text';
|
|
12
|
+
import { ColorSwatchSection } from './color-swatch-section';
|
|
11
13
|
import EmojiTab from './emoji-tab';
|
|
12
14
|
import IconsTab from './icons-tab';
|
|
15
|
+
import styles from './styles.scss';
|
|
13
16
|
import UploadTab from './upload-tab';
|
|
14
17
|
|
|
15
18
|
type SilkeIconPickerProps = {
|
|
16
19
|
fallback?: SilkeIcons;
|
|
17
20
|
required?: boolean;
|
|
18
21
|
type?: 'emojis' | 'icon' | 'upload';
|
|
22
|
+
colorName?: string;
|
|
23
|
+
presetColors?: string[];
|
|
19
24
|
} & FormFieldProps<IEmojiIcon> &
|
|
20
25
|
Omit<SilkeButtonProps, 'icon' | 'type' | 'onChange'>;
|
|
21
26
|
|
|
@@ -36,6 +41,8 @@ export function SilkeIconPicker(props: SilkeIconPickerProps) {
|
|
|
36
41
|
type: singleType,
|
|
37
42
|
title,
|
|
38
43
|
onChange,
|
|
44
|
+
colorName,
|
|
45
|
+
presetColors,
|
|
39
46
|
} = useFormField(props, validate);
|
|
40
47
|
const [type, setType] = useState<EmojiType>(
|
|
41
48
|
singleType === 'emojis'
|
|
@@ -47,16 +54,31 @@ export function SilkeIconPicker(props: SilkeIconPickerProps) {
|
|
|
47
54
|
: EmojiType.emoji,
|
|
48
55
|
);
|
|
49
56
|
const [open, setOpen] = useState(false);
|
|
57
|
+
const formContext = useContext(getFieldContext());
|
|
58
|
+
const hasColor = !!(colorName && presetColors && presetColors.length > 0);
|
|
59
|
+
const colorValue = hasColor ? formContext.value[colorName!] : undefined;
|
|
50
60
|
|
|
51
61
|
const handleSelect = (icon: IEmojiIcon | null) => {
|
|
52
|
-
setOpen(false);
|
|
53
62
|
onChange(icon);
|
|
54
63
|
};
|
|
55
64
|
|
|
65
|
+
const baseIcon = value || fallback || 'emoji.add';
|
|
66
|
+
const triggerIcon = colorValue ? (
|
|
67
|
+
<div className={styles.colorPreview}>
|
|
68
|
+
<div className={styles.colorPreviewBg} style={{ backgroundColor: colorValue }} />
|
|
69
|
+
<span>
|
|
70
|
+
<SilkeIcon icon={baseIcon} />
|
|
71
|
+
</span>
|
|
72
|
+
</div>
|
|
73
|
+
) : baseIcon;
|
|
74
|
+
const colorExtra = hasColor ? (
|
|
75
|
+
<ColorSwatchSection colorName={colorName!} presetColors={presetColors!} />
|
|
76
|
+
) : undefined;
|
|
77
|
+
|
|
56
78
|
const button = (
|
|
57
79
|
<SilkeOverflowMenu
|
|
58
80
|
size={size}
|
|
59
|
-
icon={
|
|
81
|
+
icon={triggerIcon}
|
|
60
82
|
open={open}
|
|
61
83
|
kind={kind || 'secondary'}
|
|
62
84
|
name={name}
|
|
@@ -66,34 +88,39 @@ export function SilkeIconPicker(props: SilkeIconPickerProps) {
|
|
|
66
88
|
targetOrigin="top-left"
|
|
67
89
|
onToggleOpen={setOpen}
|
|
68
90
|
>
|
|
69
|
-
<SilkeBox column bg="
|
|
91
|
+
<SilkeBox column bg="neutral-10" shadow="level2" rounded="small" overflow="hidden" className={styles.pickerPanel}>
|
|
92
|
+
<SilkeBox column flex overflow="hidden">
|
|
70
93
|
{!singleType && (
|
|
71
|
-
<
|
|
72
|
-
<
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
94
|
+
<SilkeBox pad="m" vAlign="center" hAlign="spread">
|
|
95
|
+
<SilkeTabs>
|
|
96
|
+
<SilkeTab
|
|
97
|
+
label="Emoji"
|
|
98
|
+
active={type === EmojiType.emoji}
|
|
99
|
+
onClick={() => setType(EmojiType.emoji)}
|
|
100
|
+
/>
|
|
101
|
+
<SilkeTab
|
|
102
|
+
label="Icons"
|
|
103
|
+
active={type === EmojiType.icon}
|
|
104
|
+
onClick={() => setType(EmojiType.icon)}
|
|
105
|
+
/>
|
|
106
|
+
<SilkeTab
|
|
107
|
+
label="Upload"
|
|
108
|
+
active={type === EmojiType.upload}
|
|
109
|
+
onClick={() => setType(EmojiType.upload)}
|
|
110
|
+
/>
|
|
111
|
+
</SilkeTabs>
|
|
112
|
+
<SilkeButton size="s" kind="ghost" icon="close" onClick={() => setOpen(false)} />
|
|
113
|
+
</SilkeBox>
|
|
88
114
|
)}
|
|
89
115
|
{type === EmojiType.emoji ? (
|
|
90
|
-
<EmojiTab icon={value} onSelect={handleSelect} />
|
|
116
|
+
<EmojiTab icon={value} onSelect={handleSelect} extra={colorExtra} />
|
|
91
117
|
) : type === EmojiType.icon ? (
|
|
92
|
-
<IconsTab icon={value} onSelect={handleSelect} />
|
|
118
|
+
<IconsTab icon={value} onSelect={handleSelect} extra={colorExtra} />
|
|
93
119
|
) : (
|
|
94
120
|
<UploadTab icon={value} onSelect={handleSelect} />
|
|
95
121
|
)}
|
|
96
122
|
</SilkeBox>
|
|
123
|
+
</SilkeBox>
|
|
97
124
|
</SilkeOverflowMenu>
|
|
98
125
|
);
|
|
99
126
|
if (!label) return button;
|
|
@@ -1,4 +1,69 @@
|
|
|
1
1
|
@use '../../variables' as *;
|
|
2
|
+
|
|
3
|
+
.pickerPanel {
|
|
4
|
+
width: 352px;
|
|
5
|
+
height: 320px;
|
|
6
|
+
border: 1px solid var(--color-surface-3);
|
|
7
|
+
}
|
|
8
|
+
|
|
2
9
|
.emojiButton {
|
|
3
|
-
font-size
|
|
10
|
+
// Override .icon font-size set by silke-button (12px)
|
|
11
|
+
// to render emojis at a readable size within 32px cells
|
|
12
|
+
span {
|
|
13
|
+
font-size: 24px !important;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.iconGrid {
|
|
18
|
+
display: flex;
|
|
19
|
+
flex-direction: column;
|
|
20
|
+
gap: $space-xs;
|
|
21
|
+
|
|
22
|
+
> div {
|
|
23
|
+
justify-content: space-evenly;
|
|
24
|
+
gap: $space-xs;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
.colorPreview {
|
|
29
|
+
position: relative;
|
|
30
|
+
display: flex;
|
|
31
|
+
align-items: center;
|
|
32
|
+
justify-content: center;
|
|
33
|
+
width: 24px;
|
|
34
|
+
height: 24px;
|
|
35
|
+
border-radius: var(--border-radius-tiny);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
.colorPreviewBg {
|
|
39
|
+
position: absolute;
|
|
40
|
+
inset: 0;
|
|
41
|
+
opacity: var(--opacity-level-light);
|
|
42
|
+
border-radius: inherit;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
.colorSwatchTrigger {
|
|
46
|
+
position: relative;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
.colorSwatchTriggerActive > button[type='button'] {
|
|
50
|
+
background: var(--color-surface-2);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
.colorSwatchGrid {
|
|
54
|
+
display: grid;
|
|
55
|
+
grid-template-columns: repeat(5, auto);
|
|
56
|
+
gap: $space-xxs;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.colorSwatchDropdown {
|
|
60
|
+
position: absolute;
|
|
61
|
+
top: 100%;
|
|
62
|
+
right: 0;
|
|
63
|
+
margin-top: $space-xs;
|
|
64
|
+
z-index: 100;
|
|
65
|
+
|
|
66
|
+
> * {
|
|
67
|
+
border: 1px solid var(--color-surface-3);
|
|
68
|
+
}
|
|
4
69
|
}
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
background-color: transparent;
|
|
7
7
|
width: 100%;
|
|
8
8
|
cursor: pointer;
|
|
9
|
+
text-align: left;
|
|
9
10
|
}
|
|
10
11
|
.item:focus {
|
|
11
12
|
outline: none;
|
|
@@ -19,6 +20,15 @@
|
|
|
19
20
|
background: var(--color-surface-1);
|
|
20
21
|
color: var(--color-neutral-100);
|
|
21
22
|
}
|
|
23
|
+
.item[data-highlight='true'] {
|
|
24
|
+
background-color: var(--color-surface-2);
|
|
25
|
+
color: var(--color-neutral-100);
|
|
26
|
+
}
|
|
27
|
+
.item[data-disabled='true'] {
|
|
28
|
+
opacity: 0.5;
|
|
29
|
+
pointer-events: none;
|
|
30
|
+
cursor: default;
|
|
31
|
+
}
|
|
22
32
|
.item[data-no-icon='true'] .body {
|
|
23
33
|
padding-left: $space-xs;
|
|
24
34
|
}
|
|
@@ -21,11 +21,15 @@ type SilkeListItemProps = {
|
|
|
21
21
|
size?: 's' | 'base';
|
|
22
22
|
tag?: SilkeTagProps;
|
|
23
23
|
active?: boolean;
|
|
24
|
+
highlight?: boolean;
|
|
25
|
+
disabled?: boolean;
|
|
24
26
|
gap?: boolean;
|
|
25
27
|
maxHeight?: number;
|
|
26
28
|
children?: React.ReactNode;
|
|
27
29
|
alwaysShowChildren?: boolean;
|
|
28
30
|
onClick?: (e: React.MouseEvent<HTMLButtonElement | HTMLAnchorElement>) => void;
|
|
31
|
+
onMouseDown?: (e: React.MouseEvent<HTMLButtonElement | HTMLAnchorElement>) => void;
|
|
32
|
+
onMouseEnter?: () => void;
|
|
29
33
|
onSelect?: () => void;
|
|
30
34
|
} & Omit<React.ComponentProps<typeof SilkeBox>, 'children' | 'tag'>;
|
|
31
35
|
|
|
@@ -37,12 +41,16 @@ export const SilkeListItem = ({
|
|
|
37
41
|
link,
|
|
38
42
|
tag,
|
|
39
43
|
active,
|
|
44
|
+
highlight,
|
|
45
|
+
disabled,
|
|
40
46
|
size,
|
|
41
47
|
gap,
|
|
42
48
|
maxHeight,
|
|
43
49
|
children,
|
|
44
50
|
alwaysShowChildren,
|
|
45
51
|
onClick,
|
|
52
|
+
onMouseDown,
|
|
53
|
+
onMouseEnter,
|
|
46
54
|
onSelect,
|
|
47
55
|
...rest
|
|
48
56
|
}: SilkeListItemProps) => {
|
|
@@ -87,18 +95,22 @@ export const SilkeListItem = ({
|
|
|
87
95
|
const commonProps = {
|
|
88
96
|
rounded: 'small' as const,
|
|
89
97
|
gap: size === 's' ? 'xs' : 's',
|
|
90
|
-
bgHover: 'surface-2',
|
|
91
|
-
vPad: 'xs',
|
|
98
|
+
bgHover: disabled ? undefined : 'surface-2',
|
|
99
|
+
vPad: size === 's' ? undefined : 'xs',
|
|
92
100
|
vAlign: 'center',
|
|
93
101
|
hPad: 'xs',
|
|
94
|
-
|
|
102
|
+
minHeight: size === 's' ? 's' : 'base',
|
|
95
103
|
className: styles.item,
|
|
96
104
|
'data-size': size,
|
|
97
105
|
'data-active': active,
|
|
106
|
+
'data-highlight': highlight,
|
|
107
|
+
'data-disabled': disabled,
|
|
98
108
|
'data-has-children': hasChildren,
|
|
99
109
|
'data-no-icon': !icon,
|
|
100
110
|
'data-pad-body-right': size !== 's' && noContentRight,
|
|
101
111
|
'data-always-show-children': alwaysShowChildren,
|
|
112
|
+
onMouseEnter,
|
|
113
|
+
onMouseDown,
|
|
102
114
|
onClick: (e: React.MouseEvent<HTMLButtonElement | HTMLAnchorElement>) => {
|
|
103
115
|
if (!hasSubItems) {
|
|
104
116
|
onClick?.(e);
|
|
@@ -116,6 +128,7 @@ export const SilkeListItem = ({
|
|
|
116
128
|
|
|
117
129
|
const buttonProps = {
|
|
118
130
|
tag: 'button',
|
|
131
|
+
type: 'button',
|
|
119
132
|
...commonProps,
|
|
120
133
|
} as BoxButtonProps;
|
|
121
134
|
|
|
@@ -69,6 +69,24 @@ const items = [
|
|
|
69
69
|
</SilkeBox>;
|
|
70
70
|
```
|
|
71
71
|
|
|
72
|
+
## With icons and sublabels
|
|
73
|
+
|
|
74
|
+
```js
|
|
75
|
+
const items = [
|
|
76
|
+
{ label: 'Home', subLabel: 'Main landing page', icon: 'fa-fal fa-home' },
|
|
77
|
+
{ label: 'Blog', subLabel: 'Latest posts and updates', icon: 'fa-fal fa-newspaper' },
|
|
78
|
+
{ label: 'Settings', subLabel: 'Manage your preferences', icon: 'fa-fal fa-cog' },
|
|
79
|
+
'divider',
|
|
80
|
+
{ label: 'Heading 1', subLabel: 'Large section heading', icon: 'text.h1', groupLabel: 'Text blocks' },
|
|
81
|
+
{ label: 'Heading 2', subLabel: 'Medium section heading', icon: 'text.h2', groupLabel: 'Text blocks' },
|
|
82
|
+
{ label: 'Paragraph', subLabel: 'Plain text block', icon: 'text.p', groupLabel: 'Text blocks' },
|
|
83
|
+
{ label: 'Bullet list', subLabel: 'Unordered list', icon: 'list.check', groupLabel: 'Lists' },
|
|
84
|
+
{ label: 'Numbered list', subLabel: 'Ordered list', icon: 'list.ol', groupLabel: 'Lists' },
|
|
85
|
+
];
|
|
86
|
+
|
|
87
|
+
<SilkeList items={items} />
|
|
88
|
+
```
|
|
89
|
+
|
|
72
90
|
## With link
|
|
73
91
|
|
|
74
92
|
```js
|