@vev/silke 1.0.28 → 1.0.29

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.
Files changed (239) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/index.js +49 -48
  3. package/dist/silke/src/components/index.d.ts +1 -1
  4. package/dist/silke/src/components/silke-autocomplete-field/autocomplete-item.d.ts +2 -1
  5. package/dist/silke/src/components/silke-autocomplete-field/autocomplete-tags.d.ts +2 -1
  6. package/dist/silke/src/components/silke-autocomplete-field/silke-autocomplete-field.d.ts +3 -1
  7. package/dist/silke/src/components/silke-autocomplete-field/silke-autocomplete-popup.d.ts +1 -0
  8. package/dist/silke/src/components/silke-box/silke-box.d.ts +3 -2
  9. package/dist/silke/src/components/silke-breadcrumbs/silke-breadcrumb.d.ts +1 -1
  10. package/dist/silke/src/components/silke-button/silke-big-button.d.ts +4 -1
  11. package/dist/silke/src/components/silke-button/silke-button.d.ts +1 -1
  12. package/dist/silke/src/components/silke-button/silke-dropdown-button.d.ts +2 -1
  13. package/dist/silke/src/components/silke-color-picker/color.d.ts +5 -0
  14. package/dist/silke/src/components/silke-color-picker/silke-color-info.d.ts +3 -1
  15. package/dist/silke/src/components/silke-color-swatches/silke-swatches.d.ts +2 -1
  16. package/dist/silke/src/components/silke-conditions-input/index.d.ts +2 -0
  17. package/dist/silke/src/components/silke-conditions-input/silke-conditions-input-options.d.ts +8 -0
  18. package/dist/silke/src/components/silke-conditions-input/silke-conditions-input.d.ts +19 -0
  19. package/dist/silke/src/components/silke-conditions-input/silke-conditions-tag.d.ts +11 -0
  20. package/dist/silke/src/components/silke-conditions-input/types.d.ts +13 -0
  21. package/dist/silke/src/components/silke-conditions-input/utils.d.ts +11 -0
  22. package/dist/silke/src/components/silke-context-menu/silke-context-menu-item.d.ts +1 -1
  23. package/dist/silke/src/components/silke-css-number-field/silke-css-context.d.ts +5 -1
  24. package/dist/silke/src/components/silke-css-number-field/silke-css-number-field.d.ts +3 -1
  25. package/dist/silke/src/components/silke-form/form-types.d.ts +3 -3
  26. package/dist/silke/src/components/silke-form-schema/fields/array-field-inline.d.ts +2 -1
  27. package/dist/silke/src/components/silke-form-schema/fields/array-field-modal.d.ts +3 -2
  28. package/dist/silke/src/components/silke-form-schema/fields/array-field.d.ts +1 -1
  29. package/dist/silke/src/components/silke-form-schema/fields/event-field.d.ts +1 -1
  30. package/dist/silke/src/components/silke-form-schema/fields/icon-field.d.ts +1 -1
  31. package/dist/silke/src/components/silke-form-schema/fields/image-field.d.ts +1 -1
  32. package/dist/silke/src/components/silke-form-schema/fields/layout-field.d.ts +1 -1
  33. package/dist/silke/src/components/silke-form-schema/fields/object-field.d.ts +1 -1
  34. package/dist/silke/src/components/silke-form-schema/fields/string-field.d.ts +1 -1
  35. package/dist/silke/src/components/silke-form-schema/fields/toggle-field.d.ts +1 -1
  36. package/dist/silke/src/components/silke-form-schema/fields/utils/generate-image.d.ts +1 -1
  37. package/dist/silke/src/components/silke-form-schema/fields/utils/generate-title.d.ts +1 -1
  38. package/dist/silke/src/components/silke-form-schema/fields/video-field.d.ts +1 -1
  39. package/dist/silke/src/components/silke-form-schema/silke-form-schema.d.ts +5 -0
  40. package/dist/silke/src/components/silke-form-schema/silke-schema-field.d.ts +3 -1
  41. package/dist/silke/src/components/silke-form-schema/silke-schema-fields.d.ts +2 -0
  42. package/dist/silke/src/components/silke-modal/silke-modal.d.ts +2 -1
  43. package/dist/silke/src/components/silke-notification/silke-notification.d.ts +1 -1
  44. package/dist/silke/src/components/silke-radio-button/silke-radio-button-group.d.ts +1 -1
  45. package/dist/silke/src/components/silke-slider/silke-slider.d.ts +1 -0
  46. package/dist/silke/src/components/silke-sortable-list/silke-nested-sortable-utils.d.ts +1 -0
  47. package/dist/silke/src/components/silke-sortable-list/silke-sortable-item-wrapper.d.ts +2 -1
  48. package/dist/silke/src/components/silke-sortable-list/silke-sortable-list.d.ts +2 -1
  49. package/dist/silke/src/components/silke-table/silke-table.d.ts +2 -1
  50. package/dist/silke/src/components/silke-table/table-row.d.ts +3 -1
  51. package/dist/silke/src/components/silke-table/table-types.d.ts +1 -1
  52. package/dist/silke/src/components/silke-tag/silke-tag.d.ts +1 -1
  53. package/dist/silke/src/components/silke-text-field/silke-text-field-outline.d.ts +3 -1
  54. package/dist/silke/src/components/silke-text-field/text-field-context.d.ts +4 -1
  55. package/dist/silke/src/components/silke-tile/index.d.ts +0 -1
  56. package/dist/silke/src/components/silke-tooltip/silke-definition-tooltip.d.ts +2 -1
  57. package/dist/silke/src/components/silke-tooltip/silke-icon-tooltip.d.ts +2 -1
  58. package/dist/silke/src/components/silke-tooltip/silke-tooltip.d.ts +6 -1
  59. package/dist/silke/src/components/silke-variables-wrapper/silke-variables-wrapper-form.d.ts +4 -3
  60. package/dist/silke/src/components/silke-variables-wrapper/silke-variables-wrapper.d.ts +5 -1
  61. package/dist/silke/src/icons.d.ts +74 -2
  62. package/dist/silke/src/silke-theme-provider.d.ts +1 -1
  63. package/dist/styles.css +1419 -1157
  64. package/dist/utils/src/types/context.d.ts +1 -0
  65. package/dist/utils/src/types/index.d.ts +1 -0
  66. package/dist/utils/src/types/manifest.d.ts +2 -0
  67. package/dist/utils/src/types/qwiker.d.ts +46 -0
  68. package/dist/utils/src/types/vev-plugin.d.ts +12 -0
  69. package/dist/utils/src/types/vev-props.d.ts +23 -2
  70. package/dist/utils/src/types/widget-manifest.d.ts +1 -0
  71. package/dist/utils/src/utils/index.d.ts +1 -0
  72. package/dist/utils/src/utils/variable.d.ts +3 -0
  73. package/package.json +15 -8
  74. package/project.json +21 -0
  75. package/public/index.html +2 -2
  76. package/src/_variables.scss +19 -5
  77. package/src/components/index.ts +1 -1
  78. package/src/components/silke-autocomplete-field/autocomplete-item.tsx +18 -12
  79. package/src/components/silke-autocomplete-field/autocomplete-tags.tsx +3 -0
  80. package/src/components/silke-autocomplete-field/silke-autocomplete-field.mdx +15 -15
  81. package/src/components/silke-autocomplete-field/silke-autocomplete-field.tsx +33 -25
  82. package/src/components/silke-autocomplete-field/silke-autocomplete-popup.tsx +40 -20
  83. package/src/components/silke-box/silke-box.mdx +13 -9
  84. package/src/components/silke-box/silke-box.scss +12 -3
  85. package/src/components/silke-box/silke-box.tsx +18 -2
  86. package/src/components/silke-breadcrumbs/silke-breadcrumb.tsx +2 -2
  87. package/src/components/silke-button/silke-big-button.scss +0 -5
  88. package/src/components/silke-button/silke-big-button.tsx +15 -4
  89. package/src/components/silke-button/silke-button.mdx +34 -17
  90. package/src/components/silke-button/silke-button.scss +28 -31
  91. package/src/components/silke-button/silke-button.tsx +2 -2
  92. package/src/components/silke-button/silke-dropdown-button.tsx +7 -3
  93. package/src/components/silke-button/silke-file-select-button.tsx +1 -0
  94. package/src/components/silke-card/silke-card-grid.tsx +1 -1
  95. package/src/components/silke-card/silke-card.mdx +16 -26
  96. package/src/components/silke-card/silke-card.scss +10 -3
  97. package/src/components/silke-card/silke-card.tsx +7 -4
  98. package/src/components/silke-checkbox/silke-checkbox.mdx +2 -11
  99. package/src/components/silke-code-snippet/silke-code-snippet.mdx +27 -22
  100. package/src/components/silke-color-palettes/silke-color-palette.mdx +2 -2
  101. package/src/components/silke-color-picker/color.ts +12 -0
  102. package/src/components/silke-color-picker/silke-color-info.tsx +27 -8
  103. package/src/components/silke-color-picker/silke-color-picker-button.tsx +1 -1
  104. package/src/components/silke-color-picker/silke-color-picker.mdx +9 -13
  105. package/src/components/silke-color-picker/silke-color-picker.tsx +23 -6
  106. package/src/components/silke-color-swatches/silke-color-swatch-button.tsx +1 -1
  107. package/src/components/silke-color-swatches/silke-swatches.tsx +10 -7
  108. package/src/components/silke-conditions-input/index.ts +2 -0
  109. package/src/components/silke-conditions-input/silke-conditions-input-options.tsx +87 -0
  110. package/src/components/silke-conditions-input/silke-conditions-input.mdx +88 -0
  111. package/src/components/silke-conditions-input/silke-conditions-input.scss +29 -0
  112. package/src/components/silke-conditions-input/silke-conditions-input.tsx +290 -0
  113. package/src/components/silke-conditions-input/silke-conditions-tag.tsx +80 -0
  114. package/src/components/silke-conditions-input/types.ts +23 -0
  115. package/src/components/silke-conditions-input/utils.ts +181 -0
  116. package/src/components/silke-content-column/silke-content-column.scss +1 -1
  117. package/src/components/silke-context-menu/silke-context-menu-item.tsx +3 -0
  118. package/src/components/silke-context-menu/silke-context-menu.mdx +4 -4
  119. package/src/components/silke-context-menu/silke-context-menu.scss +9 -7
  120. package/src/components/silke-context-menu/silke-context-menu.tsx +1 -1
  121. package/src/components/silke-css-number-field/silke-css-context.tsx +6 -1
  122. package/src/components/silke-css-number-field/silke-css-number-field.mdx +221 -91
  123. package/src/components/silke-css-number-field/silke-css-number-field.scss +10 -3
  124. package/src/components/silke-css-number-field/silke-css-number-field.tsx +52 -8
  125. package/src/components/silke-css-number-field/utils.ts +2 -1
  126. package/src/components/silke-divider/silke-divider.mdx +1 -2
  127. package/src/components/silke-drawer/silke-drawer.mdx +4 -11
  128. package/src/components/silke-form/form-types.ts +5 -3
  129. package/src/components/silke-form/silke-form.mdx +4 -16
  130. package/src/components/silke-form-schema/fields/array-field-inline.tsx +12 -2
  131. package/src/components/silke-form-schema/fields/array-field-modal.tsx +10 -6
  132. package/src/components/silke-form-schema/fields/array-field.tsx +25 -6
  133. package/src/components/silke-form-schema/fields/event-field.tsx +18 -7
  134. package/src/components/silke-form-schema/fields/icon-field.tsx +21 -3
  135. package/src/components/silke-form-schema/fields/image-field.tsx +21 -3
  136. package/src/components/silke-form-schema/fields/layout-field.tsx +8 -1
  137. package/src/components/silke-form-schema/fields/link-field.tsx +5 -1
  138. package/src/components/silke-form-schema/fields/number-field.tsx +144 -13
  139. package/src/components/silke-form-schema/fields/object-field.tsx +10 -1
  140. package/src/components/silke-form-schema/fields/select-field.tsx +15 -1
  141. package/src/components/silke-form-schema/fields/string-field.tsx +115 -20
  142. package/src/components/silke-form-schema/fields/toggle-field.tsx +14 -2
  143. package/src/components/silke-form-schema/fields/upload-field.tsx +3 -1
  144. package/src/components/silke-form-schema/fields/utils/generate-image.ts +4 -1
  145. package/src/components/silke-form-schema/fields/utils/generate-title.ts +2 -1
  146. package/src/components/silke-form-schema/fields/video-field.tsx +22 -4
  147. package/src/components/silke-form-schema/silke-form-schema.mdx +227 -160
  148. package/src/components/silke-form-schema/silke-form-schema.tsx +5 -0
  149. package/src/components/silke-form-schema/silke-schema-field.tsx +23 -6
  150. package/src/components/silke-form-schema/silke-schema-fields.tsx +3 -1
  151. package/src/components/silke-gradient-picker/silke-gradient-picker.mdx +1 -1
  152. package/src/components/silke-icon/silke-icon.mdx +3 -6
  153. package/src/components/silke-icon/silke-icon.scss +2 -0
  154. package/src/components/silke-icon-picker/silke-icon-picker.tsx +5 -5
  155. package/src/components/silke-iframe-portal/silke-iframe-portal.mdx +6 -15
  156. package/src/components/silke-image/silke-image.mdx +28 -0
  157. package/src/components/silke-image/silke-image.scss +1 -0
  158. package/src/components/silke-link/silke-link.mdx +62 -39
  159. package/src/components/silke-link/silke-link.scss +3 -2
  160. package/src/components/silke-list/silke-list.mdx +12 -10
  161. package/src/components/silke-list-card/silke-list-card.mdx +7 -11
  162. package/src/components/silke-loader/silke-loader.mdx +1 -1
  163. package/src/components/silke-loader/silke-loader.tsx +1 -4
  164. package/src/components/silke-modal/silke-modal.mdx +1 -5
  165. package/src/components/silke-modal/silke-modal.scss +0 -2
  166. package/src/components/silke-modal/silke-modal.tsx +3 -1
  167. package/src/components/silke-navigation-link/silke-navigation-link.mdx +21 -22
  168. package/src/components/silke-navigation-link/silke-navigation-link.scss +2 -2
  169. package/src/components/silke-notification/silke-notification.mdx +35 -67
  170. package/src/components/silke-notification/silke-notification.tsx +2 -1
  171. package/src/components/silke-object-field/silke-object-field.mdx +3 -10
  172. package/src/components/silke-object-field/silke-object-field.tsx +2 -2
  173. package/src/components/silke-overflow-menu/silke-overflow-menu.mdx +2 -2
  174. package/src/components/silke-overflow-menu/silke-overflow-menu.tsx +2 -1
  175. package/src/components/silke-popover/silke-popover.mdx +14 -22
  176. package/src/components/silke-popover/silke-popover.tsx +21 -15
  177. package/src/components/silke-progress-indicator/silke-progress-indicator.mdx +33 -36
  178. package/src/components/silke-radio-button/silke-radio-button-group.tsx +1 -1
  179. package/src/components/silke-radio-button/silke-radio-button.mdx +1 -7
  180. package/src/components/silke-radio-button/silke-radio-button.scss +1 -0
  181. package/src/components/silke-search-field/silke-search-field.mdx +4 -12
  182. package/src/components/silke-select-field/silke-select-field.mdx +10 -10
  183. package/src/components/silke-slider/silke-slider.mdx +59 -22
  184. package/src/components/silke-slider/silke-slider.tsx +23 -10
  185. package/src/components/silke-sortable-list/silke-nested-sortable-item.tsx +3 -3
  186. package/src/components/silke-sortable-list/silke-nested-sortable-utils.ts +1 -0
  187. package/src/components/silke-sortable-list/silke-sortable-item-wrapper.tsx +4 -1
  188. package/src/components/silke-sortable-list/silke-sortable-list.mdx +54 -58
  189. package/src/components/silke-sortable-list/silke-sortable-list.scss +2 -2
  190. package/src/components/silke-sortable-list/silke-sortable-list.tsx +3 -0
  191. package/src/components/silke-table/silke-table.mdx +75 -75
  192. package/src/components/silke-table/silke-table.scss +27 -13
  193. package/src/components/silke-table/silke-table.tsx +13 -3
  194. package/src/components/silke-table/table-row.tsx +6 -1
  195. package/src/components/silke-table/table-types.ts +1 -1
  196. package/src/components/silke-tabs/silke-tabs.mdx +2 -2
  197. package/src/components/silke-tag/silke-tag.mdx +38 -79
  198. package/src/components/silke-tag/silke-tag.scss +12 -5
  199. package/src/components/silke-tag/silke-tag.tsx +1 -0
  200. package/src/components/silke-text/silke-text.mdx +50 -48
  201. package/src/components/silke-text/silke-text.scss +4 -2
  202. package/src/components/silke-text/silke-title.scss +29 -15
  203. package/src/components/silke-text-field/silke-text-field-outline.tsx +9 -1
  204. package/src/components/silke-text-field/silke-text-field.mdx +67 -71
  205. package/src/components/silke-text-field/silke-text-field.scss +4 -3
  206. package/src/components/silke-text-field/silke-text-field.tsx +16 -16
  207. package/src/components/silke-text-field/text-field-context.tsx +7 -2
  208. package/src/components/silke-tile/index.ts +0 -1
  209. package/src/components/silke-tile/silke-tile.mdx +6 -63
  210. package/src/components/silke-tile/silke-tile.tsx +4 -4
  211. package/src/components/silke-toggle/silke-toggle.mdx +5 -29
  212. package/src/components/silke-toggle/silke-toggle.scss +3 -2
  213. package/src/components/silke-toolbar/silke-toolbar.mdx +6 -6
  214. package/src/components/silke-tooltip/silke-definition-tooltip.tsx +3 -0
  215. package/src/components/silke-tooltip/silke-icon-tooltip.tsx +5 -2
  216. package/src/components/silke-tooltip/silke-tooltip.mdx +16 -34
  217. package/src/components/silke-tooltip/silke-tooltip.scss +3 -2
  218. package/src/components/silke-tooltip/silke-tooltip.tsx +15 -4
  219. package/src/components/silke-upload-field/silke-upload-field.tsx +1 -0
  220. package/src/components/silke-variables-wrapper/silke-variables-wrapper-form.tsx +30 -50
  221. package/src/components/silke-variables-wrapper/silke-variables-wrapper.mdx +56 -15
  222. package/src/components/silke-variables-wrapper/silke-variables-wrapper.scss +0 -2
  223. package/src/components/silke-variables-wrapper/silke-variables-wrapper.tsx +107 -44
  224. package/src/docs/data/flux/store.ts +0 -1
  225. package/src/hooks/drag-and-drop/use-drop.tsx +1 -1
  226. package/src/hooks/hooks.mdx +3 -3
  227. package/src/icons.tsx +104 -4
  228. package/src/index.mdx +30 -31
  229. package/src/playground.mdx +58 -47
  230. package/src/silke-theme-provider.tsx +1 -0
  231. package/src/styles/core.scss +10 -14
  232. package/dist/silke/src/components/silke-steps/index.d.ts +0 -1
  233. package/dist/silke/src/components/silke-steps/silke-steps.d.ts +0 -12
  234. package/dist/silke/src/components/silke-tile/silke-tile-select.d.ts +0 -26
  235. package/src/components/silke-steps/index.ts +0 -1
  236. package/src/components/silke-steps/silke-steps.mdx +0 -60
  237. package/src/components/silke-steps/silke-steps.scss +0 -14
  238. package/src/components/silke-steps/silke-steps.tsx +0 -53
  239. package/src/components/silke-tile/silke-tile-select.tsx +0 -100
@@ -0,0 +1,87 @@
1
+ import React, { useEffect, useRef } from 'react';
2
+ import { SilkeBox } from '../silke-box';
3
+ import { SilkeTextSmall } from '../silke-text';
4
+ import { SilkeIcon } from '../silke-icon';
5
+ import { ConditionSuggestion } from './types';
6
+ import styles from './silke-conditions-input.scss';
7
+
8
+ export type SilkeConditionsInputProps = {
9
+ suggestions: ConditionSuggestion[];
10
+ highlightedItem: number;
11
+ onSelect: (value: ConditionSuggestion) => void;
12
+ };
13
+
14
+ export function SilkeConditionsInputOptions(props: SilkeConditionsInputProps) {
15
+ const { suggestions, highlightedItem, onSelect } = props;
16
+ const dropdownRef = useRef<HTMLElement>();
17
+
18
+ useEffect(() => {
19
+ if (highlightedItem !== undefined) {
20
+ dropdownRef.current?.children.item(highlightedItem)?.scrollIntoView(false);
21
+ }
22
+ }, [highlightedItem]);
23
+
24
+ return (
25
+ <SilkeBox
26
+ role="listbox"
27
+ column
28
+ bg="neutral-20"
29
+ style={{ maxHeight: 300 }}
30
+ scroll
31
+ tabIndex={-1}
32
+ ref={dropdownRef}
33
+ className={styles.conditionDropdown}
34
+ >
35
+ {suggestions.map((suggestion, i) => {
36
+ return typeof suggestion === 'string' ? (
37
+ <SilkeBox key={`${suggestion}-${i}`} pad="s">
38
+ <SilkeTextSmall color="neutral-60" weight="strong">
39
+ {suggestion}
40
+ </SilkeTextSmall>
41
+ </SilkeBox>
42
+ ) : (
43
+ <SilkeBox
44
+ data-index={i}
45
+ key={String(suggestion.value)}
46
+ className={styles.suggestion}
47
+ bgHover="surface-2"
48
+ vPad="xs"
49
+ hPad="s"
50
+ bg={i === highlightedItem ? 'surface-2' : undefined}
51
+ onMouseDown={() => {
52
+ onSelect(suggestion);
53
+ }}
54
+ >
55
+ <SilkeBox
56
+ key={`${suggestion.label}-${suggestion.value}`}
57
+ gap="s"
58
+ vAlign="center"
59
+ overflow="hidden"
60
+ fill
61
+ >
62
+ <SilkeBox
63
+ size="xs"
64
+ hAlign
65
+ vAlign
66
+ rounded="tiny"
67
+ style={
68
+ suggestion.type === 'color' ? { backgroundColor: suggestion.subLabel } : undefined
69
+ }
70
+ >
71
+ {suggestion.type !== 'color' && (
72
+ <SilkeIcon color="neutral-70" icon={suggestion.icon || 'add'} />
73
+ )}
74
+ </SilkeBox>
75
+
76
+ <SilkeBox column style={{ minWidth: '0', flex: 1 }}>
77
+ <SilkeTextSmall overflow style={{ marginBottom: '-2px' }}>
78
+ {suggestion.label}
79
+ </SilkeTextSmall>
80
+ </SilkeBox>
81
+ </SilkeBox>
82
+ </SilkeBox>
83
+ );
84
+ })}
85
+ </SilkeBox>
86
+ );
87
+ }
@@ -0,0 +1,88 @@
1
+ # Conditions Input
2
+
3
+ ```js
4
+ const [conditions, setConditions] = React.useState(['{{abc-1}}', '==', 1]);
5
+ // const [conditions, setConditions] = React.useState(["{{abc-1}}","==",1,"AND","vev/device","==","mobile","AND","vev/device","==","mobile","AND","vev/device","==","mobile","AND","vev/device","==","mobile","AND","vev/device","=="]
6
+ // );
7
+
8
+ const systemOptions = [
9
+ {
10
+ value: 'vev/device',
11
+ label: 'Device type',
12
+ type: 'select',
13
+ icon: 'mobile',
14
+ options: ['mobile', 'tablet', 'desktop'],
15
+ },
16
+ { value: 'vev/width', type: 'number', label: 'Viewport width', icon: 'arrows.horizontal' },
17
+ { value: 'vev/height', type: 'number', label: 'Viewport height', icon: 'arrows-up-down' },
18
+ {
19
+ value: 'vev/scrollPixelsY',
20
+ type: 'number',
21
+ label: 'Scrolled pixels',
22
+ icon: 'interaction.mouse',
23
+ },
24
+ {
25
+ value: 'vev/scrollPercentageY',
26
+ type: 'number',
27
+ label: 'Scrolled percentage',
28
+ icon: 'interaction.mouse',
29
+ },
30
+ ];
31
+
32
+ const widgetOptions = [
33
+ {
34
+ name: 'key',
35
+ type: 'select',
36
+ options: {
37
+ items: [
38
+ {
39
+ value: 'Backspace',
40
+ label: 'backspace',
41
+ },
42
+ {
43
+ value: 'Tab',
44
+ label: 'tab',
45
+ },
46
+ {
47
+ value: 'Enter',
48
+ label: 'enter',
49
+ },
50
+ {
51
+ value: 'Shift',
52
+ label: 'shift',
53
+ },
54
+ {
55
+ value: 'Control',
56
+ label: 'ctrl',
57
+ },
58
+ ],
59
+ },
60
+ description: 'Key pressed',
61
+ },
62
+ ];
63
+
64
+ <SilkeCSSContext
65
+ viewport={[1920, 1080]}
66
+ fontSize={18}
67
+ container={[200, 150]}
68
+ variablesv2={[
69
+ { key: 'abc-1', name: 'size-xs', value: '10', unit: 'px', type: 'number' },
70
+ { key: 'abc-2', name: 'size-s', value: '50', unit: 'px', type: 'number' },
71
+ { key: 'abc-3', name: 'size-m', value: '100', unit: 'px', type: 'number' },
72
+ { key: 'abc-4', name: 'primary', value: '#abcdef', type: 'color' },
73
+ { key: 'abc-5', name: 'secondary', value: '#123456', type: 'color' },
74
+ ]}
75
+ >
76
+ <SilkeBox style={{ width: '400px' }}>
77
+ <SilkeConditionsInput
78
+ conditions={conditions}
79
+ systemOptions={systemOptions}
80
+ widgetOptions={widgetOptions}
81
+ label="Enter condition"
82
+ placeholder="Write conditional"
83
+ onChange={setConditions}
84
+ />
85
+ </SilkeBox>
86
+ <pre>Output: {JSON.stringify(conditions)}</pre>
87
+ </SilkeCSSContext>;
88
+ ```
@@ -0,0 +1,29 @@
1
+ .suggestion {
2
+ cursor: pointer;
3
+ min-height: 26px;
4
+ }
5
+
6
+ .inner {
7
+ min-height: 32px;
8
+ column-gap: 4px;
9
+ align-items: center !important;
10
+ cursor: text;
11
+ }
12
+
13
+ .field {
14
+ width: 40px;
15
+ line-height: 24px;
16
+ background-color: transparent;
17
+ font-size: 12px;
18
+ margin: 0;
19
+ padding: 0;
20
+ }
21
+
22
+ .field[data-hidden="true"] {
23
+ position: absolute;
24
+ clip: rect(0,0,0,0);
25
+ }
26
+
27
+ .field[data-empty="true"] {
28
+ width: 100px;
29
+ }
@@ -0,0 +1,290 @@
1
+ import React, { useRef, useState } from 'react';
2
+ import { VevCondition } from '@vev/interactions';
3
+ import { VevProps } from '@vev/utils';
4
+ import {
5
+ SilkeTextFieldOutline,
6
+ SilkeTextFieldOutlineProps,
7
+ } from '../silke-text-field/silke-text-field-outline';
8
+ import { SilkeBox } from '../silke-box';
9
+ import { SilkeText } from '../silke-text';
10
+ import { SilkeTextFieldItem } from '../silke-text-field';
11
+ import { SilkePopover } from '../silke-popover';
12
+ import { SilkeConditionsInputOptions } from './silke-conditions-input-options';
13
+ import { ConditionSuggestion, VevConditionSuggestion } from './types';
14
+ import { useSilkeCSSContext } from '../silke-css-number-field';
15
+ import { SilkeConditionsTag } from './silke-conditions-tag';
16
+ import {
17
+ booleanSuggestions,
18
+ getCombinatorSuggestions,
19
+ getOperatorSuggestions,
20
+ getSuggestions,
21
+ getSystemSuggestionOptions,
22
+ getWidgetOptionType,
23
+ getWidgetSuggestionOptions,
24
+ } from './utils';
25
+ import { SilkeButton } from '../silke-button';
26
+ import styles from './silke-conditions-input.scss';
27
+
28
+ export type SilkeConditionsInputProps = SilkeTextFieldOutlineProps & {
29
+ conditions: VevCondition;
30
+ placeholder?: string;
31
+ label?: string;
32
+ systemOptions?: VevConditionSuggestion[];
33
+ widgetOptions?: VevProps[];
34
+ disabled?: boolean;
35
+ onClear?: () => void;
36
+ onChange: (value: VevCondition) => void;
37
+ };
38
+
39
+ export function SilkeConditionsInput(props: SilkeConditionsInputProps) {
40
+ const { conditions = [], systemOptions, widgetOptions, placeholder, disabled, onChange } = props;
41
+ const [value, setValue] = useState('');
42
+ const [showSuggestions, setShowSuggestions] = useState(false);
43
+ const [highlightedSuggestion, setHighlightedSuggestion] = useState<number>(-1);
44
+ const wrapperRef = useRef<HTMLDivElement>(null);
45
+ const context = useSilkeCSSContext();
46
+ const variables = context.variablesv2;
47
+
48
+ // Determine if we're inputting a, operator or b (or a combinator)
49
+ const currentInputType = React.useMemo(() => {
50
+ if (conditions.length % 4 === 0) return 'a';
51
+ if (conditions.length % 4 === 1) return 'operator';
52
+ if (conditions.length % 4 === 2) return 'b';
53
+ return 'combinator';
54
+ }, [conditions]);
55
+
56
+ // Get suggestions based on current input type
57
+ const suggestionItems: ConditionSuggestion[] = React.useMemo(() => {
58
+ // Check if we should display a list of options (if a is of type select)
59
+ if (currentInputType === 'b') {
60
+ const aValue = conditions[conditions.length - 2];
61
+ const systemItems = getSystemSuggestionOptions(aValue, systemOptions);
62
+ if (systemItems && systemItems.length > 0) {
63
+ return systemItems;
64
+ }
65
+ const widgetItems = getWidgetSuggestionOptions(aValue, widgetOptions);
66
+ if (widgetItems && widgetItems.length > 0) {
67
+ return widgetItems;
68
+ }
69
+
70
+ // Check if A value is of type boolean, if so return true/false as suggestions
71
+ if (getWidgetOptionType(aValue, widgetOptions) === 'boolean') {
72
+ return booleanSuggestions;
73
+ }
74
+
75
+ // If we have a value, but no suggestions, return any variable suggestions of same type
76
+ return getSuggestions(value || '', variables);
77
+ }
78
+
79
+ if (currentInputType === 'combinator') {
80
+ return getCombinatorSuggestions(value || '');
81
+ }
82
+ if (currentInputType === 'operator') {
83
+ // Check if A value is of type boolean, if so limit operators to is/is not
84
+ const onlyTrueFalse =
85
+ getWidgetOptionType(conditions[conditions.length - 1], widgetOptions) === 'boolean';
86
+ return getOperatorSuggestions(value || '', onlyTrueFalse);
87
+ }
88
+
89
+ return getSuggestions(value || '', variables, systemOptions, widgetOptions);
90
+ }, [currentInputType, value, conditions, variables, systemOptions, widgetOptions]);
91
+
92
+ const handleBackspace = (e: React.KeyboardEvent<HTMLDivElement>) => {
93
+ // If we have a value in the input field, abort!
94
+ if (value) return;
95
+
96
+ // Otherwise, delete last item in the condition
97
+ e.stopPropagation();
98
+ e.preventDefault();
99
+
100
+ // Check if command key is pressed
101
+ if (e.metaKey) {
102
+ onClear();
103
+ return;
104
+ }
105
+ const newConditions = conditions.slice(0, -1);
106
+ onChange(newConditions);
107
+ };
108
+
109
+ // A new item has been selected/added
110
+ const handleAddItem = (item: string | number | boolean, isBlurEvent?: boolean) => {
111
+ const newConditions = [...conditions, item];
112
+ onChange(newConditions);
113
+
114
+ // Set focus back to input (if not a blur event)
115
+ if (!isBlurEvent) focusInput();
116
+ };
117
+
118
+ // A new suggestion has been selected/added
119
+ const handleAddSuggestion = (item: ConditionSuggestion, isBlurEvent?: boolean) => {
120
+ const newItems = [typeof item === 'string' ? item : item.value];
121
+ const prefix = typeof item === 'string' ? null : item.prefix || null;
122
+ const suffix = typeof item === 'string' ? null : item.suffix || null;
123
+ if (prefix) newItems.unshift(prefix);
124
+ if (suffix) newItems.push(suffix);
125
+
126
+ const newConditions = [...conditions, ...newItems];
127
+ onChange(newConditions);
128
+
129
+ // Set focus back to input (if not a blur event)
130
+ if (!isBlurEvent) focusInput();
131
+ };
132
+
133
+ const focusInput = () => {
134
+ // Find <input> element in SilkeTextField
135
+ const input = wrapperRef.current?.querySelector('input');
136
+ if (input) {
137
+ setTimeout(() => input.focus());
138
+ }
139
+ };
140
+
141
+ const onChangeValue = (newValue: string) => {
142
+ setValue(newValue);
143
+ setHighlightedSuggestion(1);
144
+ };
145
+
146
+ const onClear = () => {
147
+ onChange([]);
148
+ props.onClear?.();
149
+ };
150
+
151
+ const selectNext = React.useCallback(() => {
152
+ if (highlightedSuggestion === -1 || highlightedSuggestion + 1 >= suggestionItems.length) {
153
+ setHighlightedSuggestion(1);
154
+ } else {
155
+ if (typeof suggestionItems[highlightedSuggestion + 1] === 'string') {
156
+ if (highlightedSuggestion + 2 >= suggestionItems.length) {
157
+ setHighlightedSuggestion(1);
158
+ } else {
159
+ setHighlightedSuggestion(highlightedSuggestion + 2);
160
+ }
161
+ } else {
162
+ setHighlightedSuggestion(highlightedSuggestion + 1);
163
+ }
164
+ }
165
+ }, [highlightedSuggestion, suggestionItems]);
166
+
167
+ const selectPrev = React.useCallback(() => {
168
+ if (highlightedSuggestion === -1 || highlightedSuggestion - 1 === -1) {
169
+ setHighlightedSuggestion(suggestionItems.length - 1);
170
+ } else {
171
+ if (typeof suggestionItems[highlightedSuggestion - 1] === 'string') {
172
+ if (highlightedSuggestion - 2 < 0) {
173
+ setHighlightedSuggestion(suggestionItems.length - 1);
174
+ } else {
175
+ setHighlightedSuggestion(highlightedSuggestion - 2);
176
+ }
177
+ } else {
178
+ setHighlightedSuggestion(highlightedSuggestion - 1);
179
+ }
180
+ }
181
+ }, [highlightedSuggestion, suggestionItems]);
182
+
183
+ const onConfirmSelected = () => {
184
+ const suggestedItem = suggestionItems[highlightedSuggestion];
185
+ if (suggestedItem) {
186
+ handleAddSuggestion(suggestedItem);
187
+ onChangeValue('');
188
+ } else if (value) {
189
+ handleAddItem(value);
190
+ onChangeValue('');
191
+ }
192
+ };
193
+
194
+ const onFocusInput = () => {
195
+ setShowSuggestions(true);
196
+ setHighlightedSuggestion(1);
197
+ };
198
+
199
+ const onBlurInput = () => {
200
+ // Check if we should add the current value as a new item
201
+ if (value) {
202
+ handleAddItem(value, true);
203
+ onChangeValue('');
204
+ }
205
+
206
+ setShowSuggestions(false);
207
+ setHighlightedSuggestion(-1);
208
+ };
209
+
210
+ return (
211
+ <SilkeBox style={{ width: '100%' }}>
212
+ <SilkeTextFieldOutline onClick={focusInput} ref={wrapperRef} size="xs" {...props}>
213
+ <SilkeBox className={styles.inner} wrap align="start" fill vPad="xs" hPad="s">
214
+ <SilkeTextFieldItem>
215
+ <SilkeText color="neutral-60" size="small">
216
+ If
217
+ </SilkeText>
218
+ </SilkeTextFieldItem>
219
+ {conditions?.map((condition, index) => (
220
+ <SilkeConditionsTag
221
+ key={index}
222
+ condition={condition}
223
+ variables={variables}
224
+ widgetOptions={widgetOptions}
225
+ systemOptions={systemOptions}
226
+ />
227
+ ))}
228
+
229
+ <input
230
+ value={value}
231
+ className={styles.field}
232
+ placeholder={!value && !conditions.length ? placeholder : undefined}
233
+ disabled={disabled}
234
+ data-empty={!value && !conditions.length}
235
+ data-hidden={!showSuggestions}
236
+ onChange={(e) => onChangeValue(e.target.value)}
237
+ onKeyDown={(e: React.KeyboardEvent<HTMLDivElement>) => {
238
+ switch (e.key) {
239
+ case 'Enter': {
240
+ onConfirmSelected();
241
+ break;
242
+ }
243
+ case ' ': {
244
+ e.preventDefault();
245
+ onConfirmSelected();
246
+ break;
247
+ }
248
+ case 'ArrowUp':
249
+ selectPrev();
250
+ break;
251
+ case 'ArrowDown': {
252
+ selectNext();
253
+ break;
254
+ }
255
+ case 'Backspace': {
256
+ handleBackspace(e);
257
+ break;
258
+ }
259
+ }
260
+ }}
261
+ onFocus={onFocusInput}
262
+ onBlur={onBlurInput}
263
+ />
264
+ </SilkeBox>
265
+
266
+ {Boolean(conditions.length) && (
267
+ <SilkeTextFieldItem vAlign="start" hPad="xs" vPad="xs">
268
+ <SilkeButton size="s" icon="close" kind="ghost" onClick={onClear} />
269
+ </SilkeTextFieldItem>
270
+ )}
271
+ </SilkeTextFieldOutline>
272
+
273
+ <SilkePopover
274
+ hide={!showSuggestions}
275
+ anchor={wrapperRef}
276
+ anchorOrigin="bottom-left"
277
+ targetOrigin="top-left"
278
+ matchAnchorWidth
279
+ >
280
+ <SilkeConditionsInputOptions
281
+ suggestions={suggestionItems}
282
+ highlightedItem={highlightedSuggestion}
283
+ onSelect={handleAddSuggestion}
284
+ />
285
+ </SilkePopover>
286
+ </SilkeBox>
287
+ );
288
+ }
289
+
290
+ SilkeConditionsInput.displayName = 'SilkeConditionsInput';
@@ -0,0 +1,80 @@
1
+ import React from 'react';
2
+ import { SilkeBox } from '../silke-box';
3
+ import { SilkeText } from '../silke-text';
4
+ import { SilkeColor } from '../../silke-theme-provider';
5
+ import { VevConditionSuggestion } from './types';
6
+ import { VevCondition } from '@vev/interactions';
7
+ import { VevProps } from '@vev/utils';
8
+ import { isWidgetOption } from './utils';
9
+
10
+ export type SilkeConditionsTagProps = {
11
+ condition: VevCondition[0];
12
+ variables: any[];
13
+ systemOptions?: VevConditionSuggestion[];
14
+ widgetOptions?: VevProps[];
15
+ };
16
+
17
+ export function SilkeConditionsTag(props: SilkeConditionsTagProps) {
18
+ const { condition, variables, systemOptions } = props;
19
+
20
+ const getTagDisplayText = (label: string | number | boolean) => {
21
+ if (typeof label === 'boolean') {
22
+ return label.toString();
23
+ }
24
+
25
+ if (typeof label === 'number') {
26
+ return label.toString();
27
+ }
28
+
29
+ // Check for system
30
+ if (typeof label === 'string' && label.startsWith('vev/')) {
31
+ const match = systemOptions?.find((v) => v.value === label);
32
+ return match ? match.label : label;
33
+ }
34
+
35
+ // Check for variables
36
+ if (typeof label === 'string' && label.startsWith('{{')) {
37
+ const match = variables?.find((v) => v.key === label.replace('{{', '').replace('}}', ''));
38
+ return match ? match.name : label;
39
+ }
40
+
41
+ // Check for AND/OR
42
+ if (typeof label === 'string' && (label === 'AND' || label === 'OR')) {
43
+ return label.toLowerCase();
44
+ }
45
+
46
+ return label;
47
+ };
48
+
49
+ const getTagColor = (label: string | number | boolean): SilkeColor => {
50
+ if (typeof label === 'number') {
51
+ return 'neutral-60';
52
+ }
53
+
54
+ // Check for system
55
+ if (typeof label === 'string' && label.startsWith('{{')) {
56
+ return 'success-30';
57
+ }
58
+
59
+ // Check for variables
60
+ if (typeof label === 'string' && label.startsWith('vev/')) {
61
+ return 'support-tertiary-40';
62
+ }
63
+
64
+ // Check for widgetOptions
65
+ const match = isWidgetOption(label, props.widgetOptions);
66
+ if (match) {
67
+ return 'success-30';
68
+ }
69
+
70
+ return 'neutral-100';
71
+ };
72
+
73
+ return (
74
+ <SilkeBox align="center">
75
+ <SilkeText size="small" color={getTagColor(condition)}>
76
+ {getTagDisplayText(condition)}
77
+ </SilkeText>
78
+ </SilkeBox>
79
+ );
80
+ }
@@ -0,0 +1,23 @@
1
+ import { SilkeCSSContextType } from '../silke-css-number-field';
2
+ import { SilkeIcons } from '../silke-icon';
3
+
4
+ // Internal types
5
+ export type VevConditionSuggestion = {
6
+ type:
7
+ | SilkeCSSContextType['variablesv2'][0]['type']
8
+ | 'system'
9
+ | 'widget'
10
+ | 'operator'
11
+ | 'combinator'
12
+ | 'select'
13
+ | 'boolean';
14
+ label: string;
15
+ value: string | number | boolean;
16
+ prefix?: string | number | boolean;
17
+ suffix?: string | number | boolean;
18
+ subLabel?: string;
19
+ icon?: SilkeIcons;
20
+ options?: string[];
21
+ };
22
+
23
+ export type ConditionSuggestion = VevConditionSuggestion | string;