@vev/silke 1.0.22 → 1.0.24
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 +16 -0
- package/dist/index.js +22 -22
- package/dist/index.js.map +4 -4
- package/dist/silke/src/components/silke-autocomplete-field/silke-autocomplete-field.d.ts +4 -0
- package/dist/silke/src/components/silke-breadcrumbs/silke-breadcrumb.d.ts +2 -1
- package/dist/silke/src/components/silke-button/index.d.ts +1 -0
- package/dist/silke/src/components/silke-button/silke-button.d.ts +2 -0
- package/dist/silke/src/components/silke-button/silke-dropdown-button.d.ts +17 -0
- package/dist/silke/src/components/silke-card/silke-card.d.ts +1 -1
- package/dist/silke/src/components/silke-color-swatches/silke-swatches.d.ts +2 -1
- package/dist/silke/src/components/silke-context-menu/silke-context-menu.d.ts +3 -1
- package/dist/silke/src/components/silke-css-number-field/index.d.ts +1 -0
- package/dist/silke/src/components/silke-css-number-field/silke-css-context.d.ts +7 -0
- package/dist/silke/src/components/silke-css-number-field/silke-css-number-field.d.ts +3 -0
- package/dist/silke/src/components/silke-css-number-field/variable-picker.d.ts +17 -0
- package/dist/silke/src/components/silke-form-schema/fields/video-field.d.ts +4 -0
- package/dist/silke/src/components/silke-link/silke-link.d.ts +1 -0
- package/dist/silke/src/components/silke-navigation-link/silke-navigation-link.d.ts +6 -1
- package/dist/silke/src/components/silke-text/silke-text.d.ts +1 -4
- package/dist/silke/src/components/silke-text-field/silke-text-field-outline.d.ts +3 -0
- package/dist/silke/src/hooks/drag-and-drop/use-drop.d.ts +2 -1
- package/dist/silke/src/icons.d.ts +8 -0
- package/dist/silke-code-editor-LK4ESGQO.js +25 -0
- package/dist/silke-code-editor-LK4ESGQO.js.map +7 -0
- package/dist/styles.css +995 -880
- package/dist/utils/src/types/context.d.ts +3 -1
- package/dist/utils/src/types/interaction.d.ts +8 -4
- package/dist/utils/src/types/vev-plugin.d.ts +10 -1
- package/dist/utils/src/types/vev-props.d.ts +6 -0
- package/esbuild.config.mjs +2 -4
- package/package.json +3 -3
- package/src/components/silke-autocomplete-field/silke-autocomplete-field.scss +6 -0
- package/src/components/silke-autocomplete-field/silke-autocomplete-field.tsx +25 -2
- package/src/components/silke-breadcrumbs/silke-breadcrumb.scss +11 -4
- package/src/components/silke-breadcrumbs/silke-breadcrumb.tsx +26 -6
- package/src/components/silke-button/index.ts +1 -0
- package/src/components/silke-button/silke-button.scss +0 -4
- package/src/components/silke-button/silke-button.tsx +8 -0
- package/src/components/silke-button/silke-dropdown-button.tsx +148 -0
- package/src/components/silke-color-picker/silke-color-picker.tsx +1 -0
- package/src/components/silke-color-swatches/silke-swatches.tsx +38 -6
- package/src/components/silke-context-menu/silke-context-menu.mdx +32 -0
- package/src/components/silke-context-menu/silke-context-menu.scss +6 -0
- package/src/components/silke-context-menu/silke-context-menu.tsx +22 -0
- package/src/components/silke-css-number-field/index.ts +1 -0
- package/src/components/silke-css-number-field/silke-css-context.tsx +17 -1
- package/src/components/silke-css-number-field/silke-css-number-field.mdx +30 -0
- package/src/components/silke-css-number-field/silke-css-number-field.scss +14 -2
- package/src/components/silke-css-number-field/silke-css-number-field.tsx +113 -13
- package/src/components/silke-css-number-field/variable-picker.tsx +181 -0
- package/src/components/silke-form-schema/fields/video-field.tsx +52 -0
- package/src/components/silke-form-schema/silke-schema-field.tsx +3 -1
- package/src/components/silke-image/silke-image.scss +1 -0
- package/src/components/silke-link/silke-link.mdx +3 -0
- package/src/components/silke-link/silke-link.scss +5 -1
- package/src/components/silke-link/silke-link.tsx +15 -3
- package/src/components/silke-modal/silke-modal.tsx +2 -0
- package/src/components/silke-navigation-link/silke-navigation-link.scss +67 -11
- package/src/components/silke-navigation-link/silke-navigation-link.tsx +171 -51
- package/src/components/silke-overflow-menu/silke-overflow-menu.scss +1 -1
- package/src/components/silke-overflow-menu/silke-overflow-menu.tsx +1 -1
- package/src/components/silke-text-field/silke-text-field-outline.tsx +69 -47
- package/src/components/silke-text-field/silke-text-field.scss +63 -0
- package/src/components/silke-text-field/silke-text-field.tsx +6 -0
- package/src/hooks/drag-and-drop/use-drop.tsx +3 -1
- package/src/icons.tsx +12 -2
- package/dist/silke-code-editor-B2CVBA63.js +0 -25
- package/dist/silke-code-editor-B2CVBA63.js.map +0 -7
- /package/dist/{silke-code-editor-B2CVBA63.js.LEGAL.txt → silke-code-editor-LK4ESGQO.js.LEGAL.txt} +0 -0
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { IProjectMenu } from '../types';
|
|
1
|
+
import { IProjectMenu, VideoType } from '../types';
|
|
2
2
|
import { ImageType, ShapeType, VevEvent } from '.';
|
|
3
3
|
export type SchemaActions = {
|
|
4
4
|
imageLibraryOpen: (onImageSelect: (image: ImageType) => void) => void;
|
|
5
5
|
imageLibraryClose: () => void;
|
|
6
6
|
shapeLibraryOpen: (onShapeSelect: (shape: ShapeType) => void) => void;
|
|
7
7
|
shapeLibraryClose: () => void;
|
|
8
|
+
videoLibraryOpen: (onVideoSelect: (video: VideoType) => void) => void;
|
|
9
|
+
videoLibraryClose: () => void;
|
|
8
10
|
uploadFile(file: File | string): Promise<{
|
|
9
11
|
name: string;
|
|
10
12
|
url: string;
|
|
@@ -9,13 +9,15 @@ export declare enum TRIGGER_SCOPE {
|
|
|
9
9
|
export declare enum EVENT_SCOPE {
|
|
10
10
|
ELEMENT = "element",
|
|
11
11
|
PAGE = "page",
|
|
12
|
-
|
|
12
|
+
VARIABLE = "variable",
|
|
13
|
+
EXTERNAL = "external",
|
|
14
|
+
TRACKING = "tracking"
|
|
13
15
|
}
|
|
14
16
|
export type VevDispatchEvent = {
|
|
15
17
|
type?: string;
|
|
16
18
|
contentKey?: string;
|
|
17
19
|
instanceKeyChain?: string;
|
|
18
|
-
args?:
|
|
20
|
+
args?: Record<string, string>;
|
|
19
21
|
};
|
|
20
22
|
export type TriggerItem = {
|
|
21
23
|
label: string;
|
|
@@ -59,7 +61,9 @@ export declare enum GLOBAL_EVENT_TYPES {
|
|
|
59
61
|
DOWNLOAD_FILE = "DOWNLOAD_FILE",
|
|
60
62
|
SEND_EMAIL = "SEND_EMAIL",
|
|
61
63
|
CALL_PHONE = "CALL_PHONE",
|
|
62
|
-
SEND_SMS = "SEND_SMS"
|
|
64
|
+
SEND_SMS = "SEND_SMS",
|
|
65
|
+
TRACK = "TRACK",
|
|
66
|
+
SET_VARIABLE = "SET_VARIABLE"
|
|
63
67
|
}
|
|
64
68
|
export declare const GLOBAL_EVENTS: TriggerItem[];
|
|
65
69
|
export type VevTriggerType = NATIVE_TRIGGER_TYPES | CUSTOM_TRIGGER_TYPES | string;
|
|
@@ -75,7 +79,7 @@ export type ProjectInteraction = {
|
|
|
75
79
|
event?: VevDispatchEvent;
|
|
76
80
|
trigger?: VevTrigger;
|
|
77
81
|
disabled?: boolean;
|
|
78
|
-
updated
|
|
82
|
+
updated: number;
|
|
79
83
|
deleted?: number;
|
|
80
84
|
};
|
|
81
85
|
export type InteractionMap = {
|
|
@@ -24,6 +24,7 @@ type MetaData = Record<string, string>;
|
|
|
24
24
|
export interface BaseProjectAsset {
|
|
25
25
|
key: string;
|
|
26
26
|
mimeType: string;
|
|
27
|
+
updated: number;
|
|
27
28
|
url: string;
|
|
28
29
|
filename?: string;
|
|
29
30
|
metaData?: MetaData;
|
|
@@ -61,7 +62,15 @@ export interface EditorPlugin<T> {
|
|
|
61
62
|
icon?: string;
|
|
62
63
|
oauthConfig?: OAuthConfig;
|
|
63
64
|
}
|
|
64
|
-
export type
|
|
65
|
+
export type EditorPluginAssetSourceFilterField = {
|
|
66
|
+
label: string;
|
|
67
|
+
value: string;
|
|
68
|
+
fields: {
|
|
69
|
+
label: string;
|
|
70
|
+
value: string;
|
|
71
|
+
}[];
|
|
72
|
+
};
|
|
73
|
+
export type EditorPluginAssetSourceFilterFields = EditorPluginAssetSourceFilterField[];
|
|
65
74
|
export interface EditorPluginAssetSource extends EditorPlugin<ProjectAsset[] | EditorPluginAssetSourceFilterFields> {
|
|
66
75
|
type: EditorPluginType.ASSET_SOURCE;
|
|
67
76
|
}
|
|
@@ -8,6 +8,10 @@ export type ImageType = {
|
|
|
8
8
|
url: string;
|
|
9
9
|
key: string;
|
|
10
10
|
};
|
|
11
|
+
export type VideoType = {
|
|
12
|
+
url: string;
|
|
13
|
+
key: string;
|
|
14
|
+
};
|
|
11
15
|
export type ShapeType = {
|
|
12
16
|
key: string;
|
|
13
17
|
name: string;
|
|
@@ -69,6 +73,7 @@ export type NumberField = BaseField<'number', number> & {
|
|
|
69
73
|
};
|
|
70
74
|
export type BooleanField = BaseField<'boolean', boolean>;
|
|
71
75
|
export type ImageField = BaseField<'image', ImageType>;
|
|
76
|
+
export type VideoField = BaseField<'video', VideoType>;
|
|
72
77
|
export type IconField = BaseField<'icon', ShapeType>;
|
|
73
78
|
export type SelectFieldItem = {
|
|
74
79
|
label: string;
|
|
@@ -126,6 +131,7 @@ export type SchemaFieldTypes = {
|
|
|
126
131
|
object: ObjectField;
|
|
127
132
|
number: NumberField;
|
|
128
133
|
image: ImageField;
|
|
134
|
+
video: VideoField;
|
|
129
135
|
icon: IconField;
|
|
130
136
|
boolean: BooleanField;
|
|
131
137
|
select: SelectField;
|
package/esbuild.config.mjs
CHANGED
|
@@ -52,9 +52,7 @@ async function buildSilke(watch) {
|
|
|
52
52
|
setup(build) {
|
|
53
53
|
build.onResolve({ filter: /\.raw\..+$/i }, (args) => {
|
|
54
54
|
return {
|
|
55
|
-
path: path.isAbsolute(args.path)
|
|
56
|
-
? args.path
|
|
57
|
-
: path.join(args.resolveDir, args.path),
|
|
55
|
+
path: path.isAbsolute(args.path) ? args.path : path.join(args.resolveDir, args.path),
|
|
58
56
|
namespace: 'raw-loader',
|
|
59
57
|
};
|
|
60
58
|
});
|
|
@@ -68,7 +66,7 @@ async function buildSilke(watch) {
|
|
|
68
66
|
},
|
|
69
67
|
esbuildSassModulesPlugin(),
|
|
70
68
|
],
|
|
71
|
-
}
|
|
69
|
+
};
|
|
72
70
|
|
|
73
71
|
if (watch) {
|
|
74
72
|
// don't minify
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vev/silke",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.24",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/silke/src/index.d.ts",
|
|
@@ -32,8 +32,8 @@
|
|
|
32
32
|
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.10",
|
|
33
33
|
"@uiw/codemirror-theme-dracula": "^4.12.3",
|
|
34
34
|
"@uiw/react-codemirror": "^4.12.3",
|
|
35
|
-
"@vev/react": "0.1.
|
|
36
|
-
"@vev/utils": "1.2.
|
|
35
|
+
"@vev/react": "0.1.8",
|
|
36
|
+
"@vev/utils": "1.2.4",
|
|
37
37
|
"classnames": ">=2.2.0",
|
|
38
38
|
"flux": "^4.0.4",
|
|
39
39
|
"lodash": "^4.17.21",
|
|
@@ -79,6 +79,10 @@ export type SilkeAutocompleteFieldProps<T = any, U extends Entry<T> = any> = (
|
|
|
79
79
|
*/
|
|
80
80
|
sort?: (one: Entry<T>, other: Entry<T>) => number;
|
|
81
81
|
onSearch?: (value: string) => void;
|
|
82
|
+
/**
|
|
83
|
+
* Called when dropdown closes for any reason
|
|
84
|
+
*/
|
|
85
|
+
onClose?: () => void;
|
|
82
86
|
};
|
|
83
87
|
|
|
84
88
|
const autocompleteValidator: FormValidator<SilkeAutocompleteFieldProps> = (props, value) => {
|
|
@@ -168,6 +172,10 @@ export function SilkeAutocompleteField<T>(props: SilkeAutocompleteFieldProps<T>)
|
|
|
168
172
|
onClick,
|
|
169
173
|
onMouseDown,
|
|
170
174
|
hAlign,
|
|
175
|
+
onClose,
|
|
176
|
+
showVariableDot,
|
|
177
|
+
hasActiveVariable,
|
|
178
|
+
onVariableClick,
|
|
171
179
|
...form
|
|
172
180
|
} = useFormField(props, autocompleteValidator);
|
|
173
181
|
const context = useTextFieldContext();
|
|
@@ -257,7 +265,10 @@ export function SilkeAutocompleteField<T>(props: SilkeAutocompleteFieldProps<T>)
|
|
|
257
265
|
|
|
258
266
|
useEffect(() => {
|
|
259
267
|
if (autoFocus && !disabled) setOpen(true);
|
|
260
|
-
else if (disabled)
|
|
268
|
+
else if (disabled) {
|
|
269
|
+
setOpen(false);
|
|
270
|
+
onClose && onClose();
|
|
271
|
+
}
|
|
261
272
|
}, [autoFocus, disabled]);
|
|
262
273
|
|
|
263
274
|
useEffect(() => {
|
|
@@ -281,7 +292,7 @@ export function SilkeAutocompleteField<T>(props: SilkeAutocompleteFieldProps<T>)
|
|
|
281
292
|
else form.onChange('');
|
|
282
293
|
setSearchText('');
|
|
283
294
|
setPrevSearchText('');
|
|
284
|
-
|
|
295
|
+
onClose && onClose();
|
|
285
296
|
setOpen(false);
|
|
286
297
|
};
|
|
287
298
|
|
|
@@ -377,6 +388,7 @@ export function SilkeAutocompleteField<T>(props: SilkeAutocompleteFieldProps<T>)
|
|
|
377
388
|
resetSearchText();
|
|
378
389
|
handleChange(item.value);
|
|
379
390
|
setOpen(false);
|
|
391
|
+
onClose && onClose();
|
|
380
392
|
|
|
381
393
|
setHighlight(undefined);
|
|
382
394
|
}
|
|
@@ -417,6 +429,7 @@ export function SilkeAutocompleteField<T>(props: SilkeAutocompleteFieldProps<T>)
|
|
|
417
429
|
}
|
|
418
430
|
inputField.current?.focus();
|
|
419
431
|
setOpen(false);
|
|
432
|
+
onClose && onClose();
|
|
420
433
|
break;
|
|
421
434
|
}
|
|
422
435
|
case 'ArrowUp':
|
|
@@ -434,6 +447,7 @@ export function SilkeAutocompleteField<T>(props: SilkeAutocompleteFieldProps<T>)
|
|
|
434
447
|
case 'Escape': {
|
|
435
448
|
inputField.current?.focus();
|
|
436
449
|
setOpen(false);
|
|
450
|
+
onClose && onClose();
|
|
437
451
|
break;
|
|
438
452
|
}
|
|
439
453
|
}
|
|
@@ -453,6 +467,7 @@ export function SilkeAutocompleteField<T>(props: SilkeAutocompleteFieldProps<T>)
|
|
|
453
467
|
if (open) cl += ' ' + styles.open;
|
|
454
468
|
if (styles[kind]) cl += ' ' + styles[kind];
|
|
455
469
|
if (disabled) cl += ' ' + styles.disabled;
|
|
470
|
+
if (hasActiveVariable) cl += ' ' + styles.activeVariable;
|
|
456
471
|
|
|
457
472
|
return (
|
|
458
473
|
<>
|
|
@@ -472,6 +487,9 @@ export function SilkeAutocompleteField<T>(props: SilkeAutocompleteFieldProps<T>)
|
|
|
472
487
|
data-cy={dataCy}
|
|
473
488
|
labelId={inputId}
|
|
474
489
|
labelUsingAria
|
|
490
|
+
showVariableDot={showVariableDot}
|
|
491
|
+
hasActiveVariable={hasActiveVariable}
|
|
492
|
+
onVariableClick={onVariableClick}
|
|
475
493
|
onClick={onClick}
|
|
476
494
|
onMouseDown={(e: React.MouseEvent<HTMLElement>) => {
|
|
477
495
|
e.preventDefault();
|
|
@@ -583,6 +601,7 @@ export function SilkeAutocompleteField<T>(props: SilkeAutocompleteFieldProps<T>)
|
|
|
583
601
|
matchAnchorWidth
|
|
584
602
|
onRequestClose={() => {
|
|
585
603
|
setOpen(false);
|
|
604
|
+
onClose && onClose();
|
|
586
605
|
}}
|
|
587
606
|
>
|
|
588
607
|
<SilkeBox
|
|
@@ -610,6 +629,10 @@ export function SilkeAutocompleteField<T>(props: SilkeAutocompleteFieldProps<T>)
|
|
|
610
629
|
kind="ghost"
|
|
611
630
|
onFocus={(e) => {
|
|
612
631
|
inputRef.current = e.currentTarget as HTMLInputElement;
|
|
632
|
+
if (props.onFocus) props.onFocus(e);
|
|
633
|
+
}}
|
|
634
|
+
onBlur={(e) => {
|
|
635
|
+
if (props.onBlur) props.onBlur(e);
|
|
613
636
|
}}
|
|
614
637
|
onChange={(text: string) => {
|
|
615
638
|
onSearch?.(text);
|
|
@@ -1,22 +1,29 @@
|
|
|
1
1
|
@use '../../variables' as *;
|
|
2
2
|
.breadbrumbs {
|
|
3
3
|
padding: 0;
|
|
4
|
+
margin: 0;
|
|
5
|
+
align-items: center;
|
|
4
6
|
}
|
|
5
7
|
|
|
6
8
|
.breadbrumb {
|
|
7
9
|
user-select: none;
|
|
8
10
|
|
|
9
11
|
a {
|
|
10
|
-
color: var(--color-
|
|
12
|
+
color: var(--color-neutral-60) !important;
|
|
11
13
|
}
|
|
12
14
|
|
|
13
15
|
a:focus {
|
|
14
16
|
outline: none;
|
|
15
|
-
box-shadow: 0 0 0 2px var(--color-neutral-100);
|
|
16
17
|
}
|
|
17
18
|
|
|
18
19
|
a:hover {
|
|
19
|
-
|
|
20
|
-
|
|
20
|
+
color: var(--color-neutral-60) !important;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.icon{
|
|
24
|
+
[class*="silke-image"],[class*="silke-icon"]{
|
|
25
|
+
font-size: 12px !important;
|
|
26
|
+
|
|
27
|
+
}
|
|
21
28
|
}
|
|
22
29
|
}
|
|
@@ -3,9 +3,11 @@ import { SilkeIcon, SilkeIcons } from '../silke-icon';
|
|
|
3
3
|
import { SilkeBox } from '../silke-box';
|
|
4
4
|
import styles from './silke-breadcrumb.scss';
|
|
5
5
|
import { SilkeText } from '../silke-text';
|
|
6
|
+
import { IEmojiIcon } from '@vev/utils';
|
|
7
|
+
import { SilkeImage } from '../silke-image';
|
|
6
8
|
|
|
7
9
|
type SilkeBreadcrumbProps = {
|
|
8
|
-
icon?: SilkeIcons;
|
|
10
|
+
icon?: IEmojiIcon | SilkeIcons;
|
|
9
11
|
label?: string;
|
|
10
12
|
noSlash?: boolean;
|
|
11
13
|
onClick?: React.MouseEventHandler<HTMLAnchorElement>;
|
|
@@ -16,7 +18,7 @@ export function SilkeBreadcrumb({ icon, label, noSlash, onClick }: SilkeBreadcru
|
|
|
16
18
|
if (onClick) cl += ' ' + styles.interactive;
|
|
17
19
|
const text = <SilkeText overflow>{label}</SilkeText>;
|
|
18
20
|
return (
|
|
19
|
-
<SilkeBox height="s" gap="
|
|
21
|
+
<SilkeBox height="s" gap="xs" vAlign="center" className={cl} tag="li">
|
|
20
22
|
{onClick ? (
|
|
21
23
|
<a
|
|
22
24
|
onClick={(event: React.MouseEvent<HTMLAnchorElement>) => {
|
|
@@ -25,13 +27,31 @@ export function SilkeBreadcrumb({ icon, label, noSlash, onClick }: SilkeBreadcru
|
|
|
25
27
|
}}
|
|
26
28
|
href="#"
|
|
27
29
|
>
|
|
28
|
-
|
|
29
|
-
|
|
30
|
+
<SilkeBox>
|
|
31
|
+
{icon && (
|
|
32
|
+
<SilkeImage
|
|
33
|
+
icon={icon}
|
|
34
|
+
avatar="s"
|
|
35
|
+
style={{ marginRight: 4 }}
|
|
36
|
+
className={styles.icon}
|
|
37
|
+
/>
|
|
38
|
+
)}
|
|
39
|
+
{text}
|
|
40
|
+
</SilkeBox>
|
|
30
41
|
</a>
|
|
31
42
|
) : (
|
|
32
|
-
|
|
43
|
+
<>
|
|
44
|
+
{icon && <SilkeImage icon={icon} avatar="s" className={styles.icon} />}
|
|
45
|
+
{text}
|
|
46
|
+
</>
|
|
47
|
+
)}
|
|
48
|
+
{!noSlash && (
|
|
49
|
+
<SilkeIcon
|
|
50
|
+
icon="chevron.right"
|
|
51
|
+
color="neutral-50"
|
|
52
|
+
style={{ fontSize: 12, fontWeight: 400, paddingTop: 4 }}
|
|
53
|
+
/>
|
|
33
54
|
)}
|
|
34
|
-
{!noSlash && <span>/</span>}
|
|
35
55
|
</SilkeBox>
|
|
36
56
|
);
|
|
37
57
|
}
|
|
@@ -24,6 +24,7 @@ export type SilkeButtonProps = {
|
|
|
24
24
|
/** Show button as in hover state */
|
|
25
25
|
hover?: boolean;
|
|
26
26
|
icon?: SilkeIcons | React.ReactElement;
|
|
27
|
+
leftIcon?: SilkeIcons | React.ReactElement;
|
|
27
28
|
link?: string;
|
|
28
29
|
target?: string;
|
|
29
30
|
} & Omit<BoxButtonProps, 'children' | 'size'>;
|
|
@@ -36,6 +37,7 @@ export const SilkeButton = React.forwardRef(
|
|
|
36
37
|
kind,
|
|
37
38
|
size,
|
|
38
39
|
icon,
|
|
40
|
+
leftIcon,
|
|
39
41
|
focus,
|
|
40
42
|
hover,
|
|
41
43
|
className,
|
|
@@ -76,6 +78,7 @@ export const SilkeButton = React.forwardRef(
|
|
|
76
78
|
rel="button"
|
|
77
79
|
tag={link ? 'link' : 'button'}
|
|
78
80
|
to={link}
|
|
81
|
+
gap="s"
|
|
79
82
|
>
|
|
80
83
|
{loading && (
|
|
81
84
|
<SilkeSkeleton
|
|
@@ -90,6 +93,11 @@ export const SilkeButton = React.forwardRef(
|
|
|
90
93
|
}}
|
|
91
94
|
/>
|
|
92
95
|
)}
|
|
96
|
+
{leftIcon && (
|
|
97
|
+
<span>
|
|
98
|
+
<SilkeIcon icon={leftIcon} />
|
|
99
|
+
</span>
|
|
100
|
+
)}
|
|
93
101
|
{label}
|
|
94
102
|
{icon && (
|
|
95
103
|
<span className={styles.icon}>
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import React, { useCallback, useMemo, useRef, useState } from 'react';
|
|
2
|
+
import { SilkeButton, SilkeButtonProps } from './silke-button';
|
|
3
|
+
import { SilkePopover, SilkePopoverProps } from '../silke-popover';
|
|
4
|
+
import { isBoolean, isFunction } from 'lodash';
|
|
5
|
+
import { generateGuid } from '@vev/utils';
|
|
6
|
+
import styles from '../silke-overflow-menu/silke-overflow-menu.scss';
|
|
7
|
+
import { ButtonContext } from './index';
|
|
8
|
+
import { SilkeBox } from '../silke-box';
|
|
9
|
+
import { SilkeOverflowMenuItem } from '../silke-overflow-menu';
|
|
10
|
+
|
|
11
|
+
export type SilkeDropdownButtonProps = {
|
|
12
|
+
children?: React.ReactNode;
|
|
13
|
+
open?: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* What triggers the opening of the overflow menu
|
|
16
|
+
* @default "click"
|
|
17
|
+
*/
|
|
18
|
+
trigger?: 'click' | 'right-click';
|
|
19
|
+
onToggleOpen?: (open: boolean) => void;
|
|
20
|
+
/** Pass items or children */
|
|
21
|
+
items?:
|
|
22
|
+
| (SilkeOverflowMenuItem | React.ReactElement | 'divider')[]
|
|
23
|
+
| (() => (SilkeOverflowMenuItem | React.ReactElement | 'divider')[]);
|
|
24
|
+
} & SilkeButtonProps &
|
|
25
|
+
Omit<SilkePopoverProps, 'anchor' | 'hide' | 'children' | 'kind'>;
|
|
26
|
+
|
|
27
|
+
export function SilkeDropdownButton({
|
|
28
|
+
children,
|
|
29
|
+
label,
|
|
30
|
+
open: externalOpen,
|
|
31
|
+
icon,
|
|
32
|
+
items = [],
|
|
33
|
+
offsetX,
|
|
34
|
+
offsetY,
|
|
35
|
+
trigger = 'click',
|
|
36
|
+
targetOrigin = 'top-right',
|
|
37
|
+
anchorOrigin = 'bottom-right',
|
|
38
|
+
onClick,
|
|
39
|
+
onMouseDown,
|
|
40
|
+
onToggleOpen,
|
|
41
|
+
...rest
|
|
42
|
+
}: SilkeDropdownButtonProps) {
|
|
43
|
+
const [open, setOpen] = useState(false);
|
|
44
|
+
const ref = useRef<HTMLElement>(null);
|
|
45
|
+
const isOpen = isBoolean(externalOpen) ? externalOpen : open;
|
|
46
|
+
const buttonId = useMemo(() => {
|
|
47
|
+
return 'button-' + generateGuid();
|
|
48
|
+
}, []);
|
|
49
|
+
|
|
50
|
+
const handleToggleOpen = useCallback(
|
|
51
|
+
(e: any) => {
|
|
52
|
+
e?.stopPropagation();
|
|
53
|
+
if (onMouseDown) onMouseDown(e);
|
|
54
|
+
if (isBoolean(externalOpen) && onToggleOpen) {
|
|
55
|
+
// Handle open/close externally
|
|
56
|
+
onToggleOpen(!isOpen);
|
|
57
|
+
} else if (
|
|
58
|
+
isOpen ||
|
|
59
|
+
(trigger === 'click' && !e?.button) ||
|
|
60
|
+
(trigger === 'right-click' && e?.button === 2)
|
|
61
|
+
) {
|
|
62
|
+
// Handle open/close internally
|
|
63
|
+
setOpen(!isOpen);
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
[externalOpen, trigger, isOpen, onToggleOpen],
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
const boxRef = useRef<HTMLDivElement>(null);
|
|
70
|
+
|
|
71
|
+
if (anchorOrigin?.includes('top')) offsetY = (offsetY || 0) - 1;
|
|
72
|
+
else offsetY = (offsetY || 0) + 1;
|
|
73
|
+
|
|
74
|
+
return (
|
|
75
|
+
<>
|
|
76
|
+
<SilkeButton
|
|
77
|
+
ref={ref}
|
|
78
|
+
label={label}
|
|
79
|
+
icon={isOpen ? 'chevron.up' : 'chevron.down'}
|
|
80
|
+
id={buttonId}
|
|
81
|
+
aria-expanded={isOpen}
|
|
82
|
+
aria-label="Menu"
|
|
83
|
+
aria-haspopup="true"
|
|
84
|
+
onMouseDown={handleToggleOpen}
|
|
85
|
+
onContextMenu={trigger === 'right-click' ? (e) => e.preventDefault() : undefined}
|
|
86
|
+
onClick={(e) => {
|
|
87
|
+
e.stopPropagation();
|
|
88
|
+
e.preventDefault();
|
|
89
|
+
if (onClick) onClick(e);
|
|
90
|
+
// Ugly hack to separate mouse and keyboard events
|
|
91
|
+
if (!e.screenX && !e.screenY) handleToggleOpen(e);
|
|
92
|
+
}}
|
|
93
|
+
{...rest}
|
|
94
|
+
/>
|
|
95
|
+
{isOpen && (
|
|
96
|
+
<SilkePopover
|
|
97
|
+
contextId="silke.overflow.menu"
|
|
98
|
+
anchor={ref}
|
|
99
|
+
offsetX={offsetX}
|
|
100
|
+
offsetY={offsetY}
|
|
101
|
+
targetOrigin={targetOrigin}
|
|
102
|
+
anchorOrigin={anchorOrigin}
|
|
103
|
+
onRequestClose={handleToggleOpen}
|
|
104
|
+
>
|
|
105
|
+
<ButtonContext size="base">
|
|
106
|
+
{items && (
|
|
107
|
+
<SilkeBox
|
|
108
|
+
tabIndex={-1}
|
|
109
|
+
column
|
|
110
|
+
pad="xs"
|
|
111
|
+
bg="neutral-20"
|
|
112
|
+
shadow="level2"
|
|
113
|
+
className={styles.menu}
|
|
114
|
+
onClick={() => setOpen(false)}
|
|
115
|
+
ref={boxRef}
|
|
116
|
+
aria-labelledby={buttonId}
|
|
117
|
+
>
|
|
118
|
+
{(isFunction(items) ? items() : items)?.map((item, index) => {
|
|
119
|
+
return React.isValidElement(item) ? (
|
|
120
|
+
item
|
|
121
|
+
) : item === 'divider' ? (
|
|
122
|
+
<hr key={index} />
|
|
123
|
+
) : (
|
|
124
|
+
<SilkeOverflowMenuItem
|
|
125
|
+
key={index}
|
|
126
|
+
size={rest.size}
|
|
127
|
+
{...item}
|
|
128
|
+
onClick={(e) => {
|
|
129
|
+
e.stopPropagation();
|
|
130
|
+
item.onClick?.(e);
|
|
131
|
+
handleToggleOpen(e);
|
|
132
|
+
}}
|
|
133
|
+
/>
|
|
134
|
+
);
|
|
135
|
+
})}
|
|
136
|
+
</SilkeBox>
|
|
137
|
+
)}
|
|
138
|
+
{children && (
|
|
139
|
+
<div ref={boxRef} tabIndex={-1} aria-labelledby={buttonId}>
|
|
140
|
+
{children}
|
|
141
|
+
</div>
|
|
142
|
+
)}
|
|
143
|
+
</ButtonContext>
|
|
144
|
+
</SilkePopover>
|
|
145
|
+
)}
|
|
146
|
+
</>
|
|
147
|
+
);
|
|
148
|
+
}
|
|
@@ -18,6 +18,7 @@ interface BaseProps<T extends string> {
|
|
|
18
18
|
selected: T;
|
|
19
19
|
hidePalettes?: boolean;
|
|
20
20
|
hideSwatches?: boolean;
|
|
21
|
+
hideVariables?: boolean;
|
|
21
22
|
type?: SilkeSwatchType;
|
|
22
23
|
mode?: 'swatches' | 'palettes';
|
|
23
24
|
onSelect: (color: T, type: 'color' | 'gradient' | 'variable') => void;
|
|
@@ -31,13 +32,19 @@ export function SilkeSwatches({
|
|
|
31
32
|
selected,
|
|
32
33
|
hidePalettes,
|
|
33
34
|
hideSwatches,
|
|
35
|
+
hideVariables,
|
|
34
36
|
gradient,
|
|
35
37
|
mode: desiredMode,
|
|
36
38
|
onSelect,
|
|
37
39
|
...rest
|
|
38
40
|
}: SilkeSwatchesProps) {
|
|
39
|
-
const {
|
|
40
|
-
|
|
41
|
+
const {
|
|
42
|
+
variables = {},
|
|
43
|
+
variablesv2 = [],
|
|
44
|
+
onVariableAdd,
|
|
45
|
+
onVariableDelete,
|
|
46
|
+
} = useSilkeCSSContext();
|
|
47
|
+
const [mode, setMode] = useState<'swatches' | 'palettes' | 'variables'>(
|
|
41
48
|
desiredMode || (hidePalettes ? 'swatches' : hideSwatches ? 'palettes' : 'swatches'),
|
|
42
49
|
);
|
|
43
50
|
|
|
@@ -45,6 +52,19 @@ export function SilkeSwatches({
|
|
|
45
52
|
return rest.swatches || getSwatchesFromVariables(variables);
|
|
46
53
|
}, [rest.swatches, variables]);
|
|
47
54
|
|
|
55
|
+
const colorVariables = React.useMemo(() => {
|
|
56
|
+
return variablesv2.filter((v) => v.type === 'color');
|
|
57
|
+
}, [variablesv2]);
|
|
58
|
+
|
|
59
|
+
const modeOptions = useMemo(() => {
|
|
60
|
+
const options = [
|
|
61
|
+
{ label: 'Swatches', value: 'swatches' },
|
|
62
|
+
{ label: 'Palettes', value: 'palettes' },
|
|
63
|
+
] as { label: string; value: 'swatches' | 'palettes' | 'variables' }[];
|
|
64
|
+
if (colorVariables?.length > 0) options.push({ label: 'Variables', value: 'variables' });
|
|
65
|
+
return options;
|
|
66
|
+
}, [colorVariables]);
|
|
67
|
+
|
|
48
68
|
const selectedSwatch = useMemo(
|
|
49
69
|
() => swatches?.find((v) => isEqual(v, selected)),
|
|
50
70
|
[selected, swatches],
|
|
@@ -62,10 +82,7 @@ export function SilkeSwatches({
|
|
|
62
82
|
{!hidePalettes && !hideSwatches && (
|
|
63
83
|
<SilkeSelectField
|
|
64
84
|
inline
|
|
65
|
-
items={
|
|
66
|
-
{ label: 'Swatches', value: 'swatches' },
|
|
67
|
-
{ label: 'Palettes', value: 'palettes' },
|
|
68
|
-
]}
|
|
85
|
+
items={modeOptions}
|
|
69
86
|
readOnly={hideSwatches || hidePalettes}
|
|
70
87
|
value={mode}
|
|
71
88
|
onChange={setMode as any}
|
|
@@ -126,6 +143,21 @@ export function SilkeSwatches({
|
|
|
126
143
|
))}
|
|
127
144
|
</SilkeBox>
|
|
128
145
|
)}
|
|
146
|
+
{!hideVariables && mode === 'variables' && (
|
|
147
|
+
<SilkeBox column gap="xs">
|
|
148
|
+
{colorVariables.map((v) => (
|
|
149
|
+
<SilkeBox key={v.key} vAlign="center" hAlign="spread">
|
|
150
|
+
<SilkeText tag="small">{v.name}</SilkeText>
|
|
151
|
+
<SilkeBox hAlign="end">
|
|
152
|
+
<SilkeColorSwatchButton
|
|
153
|
+
value={v.value || ''}
|
|
154
|
+
onClick={() => onSelect(`var(--vev-${v.key})`, 'variable')}
|
|
155
|
+
/>
|
|
156
|
+
</SilkeBox>
|
|
157
|
+
</SilkeBox>
|
|
158
|
+
))}
|
|
159
|
+
</SilkeBox>
|
|
160
|
+
)}
|
|
129
161
|
</SilkeBox>
|
|
130
162
|
</ButtonContext>
|
|
131
163
|
);
|
|
@@ -88,3 +88,35 @@ const [pos, setPos] = React.useState([0, 0]);
|
|
|
88
88
|
)}
|
|
89
89
|
</>;
|
|
90
90
|
```
|
|
91
|
+
|
|
92
|
+
## Title and beta tag
|
|
93
|
+
|
|
94
|
+
```js
|
|
95
|
+
const [showContext, setShowContext] = React.useState(false);
|
|
96
|
+
const [pos, setPos] = React.useState([0, 0]);
|
|
97
|
+
|
|
98
|
+
<>
|
|
99
|
+
<SilkeButton
|
|
100
|
+
label="Open context menu"
|
|
101
|
+
onClick={(e) => {
|
|
102
|
+
setPos([e.pageX, e.pageY]);
|
|
103
|
+
setShowContext(true);
|
|
104
|
+
}}
|
|
105
|
+
/>
|
|
106
|
+
{showContext && (
|
|
107
|
+
<SilkeContextMenu
|
|
108
|
+
anchor={pos}
|
|
109
|
+
beta
|
|
110
|
+
title="Context menu"
|
|
111
|
+
onRequestClose={() => setShowContext(false)}
|
|
112
|
+
items={ipsum.list(5, (i) => ({
|
|
113
|
+
label: ipsum.name(),
|
|
114
|
+
items: ipsum.list(5, (j) => ({
|
|
115
|
+
label: ipsum.name(),
|
|
116
|
+
onClick: () => console.log(`Item ${i}-${j} click`),
|
|
117
|
+
})),
|
|
118
|
+
}))}
|
|
119
|
+
/>
|
|
120
|
+
)}
|
|
121
|
+
</>;
|
|
122
|
+
```
|