@vev/silke 1.0.10 → 1.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (191) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/dist/chunk-4MB64AQL.js +22 -0
  3. package/dist/chunk-4MB64AQL.js.LEGAL.txt +8 -0
  4. package/dist/chunk-4MB64AQL.js.map +7 -0
  5. package/dist/index.js +9 -25
  6. package/dist/index.js.LEGAL.txt +6 -9
  7. package/dist/index.js.map +4 -4
  8. package/dist/silke-code-editor-HZRG3D6C.js +23 -0
  9. package/dist/silke-code-editor-HZRG3D6C.js.map +7 -0
  10. package/dist/styles.css +4338 -2599
  11. package/esbuild.config.mjs +2 -1
  12. package/jest.config.js +2 -1
  13. package/package.json +12 -8
  14. package/src/_variables.scss +121 -1
  15. package/src/components/index.ts +6 -0
  16. package/src/components/silke-autocomplete-field/autocomplete-item.tsx +15 -13
  17. package/src/components/silke-autocomplete-field/autocomplete-tags.tsx +14 -7
  18. package/src/components/silke-autocomplete-field/silke-autocomplete-field.mdx +31 -4
  19. package/src/components/silke-autocomplete-field/silke-autocomplete-field.scss +8 -6
  20. package/src/components/silke-autocomplete-field/silke-autocomplete-field.tsx +64 -23
  21. package/src/components/silke-box/silke-box.scss +21 -47
  22. package/src/components/silke-box/silke-box.tsx +23 -31
  23. package/src/components/silke-breadcrumbs/silke-breadcrumb.scss +3 -3
  24. package/src/components/silke-button/index.ts +3 -1
  25. package/src/components/silke-button/silke-big-button.scss +38 -0
  26. package/src/components/silke-button/silke-big-button.tsx +49 -0
  27. package/src/components/silke-button/silke-button-set.tsx +15 -3
  28. package/src/components/silke-button/silke-button.mdx +41 -19
  29. package/src/components/silke-button/silke-button.scss +97 -90
  30. package/src/components/silke-button/silke-button.tsx +20 -5
  31. package/src/components/silke-button/silke-file-select-button.tsx +86 -0
  32. package/src/components/silke-card/silke-card-grid.tsx +9 -9
  33. package/src/components/silke-card/silke-card.mdx +23 -9
  34. package/src/components/silke-card/silke-card.scss +92 -39
  35. package/src/components/silke-card/silke-card.tsx +50 -27
  36. package/src/components/silke-checkbox/silke-checkbox.scss +39 -17
  37. package/src/components/silke-checkbox/silke-checkbox.tsx +4 -1
  38. package/src/components/silke-code-editor/index.tsx +12 -0
  39. package/src/components/silke-code-editor/silke-code-editor.mdx +97 -0
  40. package/src/components/silke-code-editor/silke-code-editor.tsx +52 -0
  41. package/src/components/silke-code-snippet/silke-code-snippet.scss +2 -10
  42. package/src/components/silke-code-snippet/silke-code-snippet.tsx +10 -3
  43. package/src/components/silke-color-palettes/silke-color-palette.tsx +11 -2
  44. package/src/components/silke-color-picker/color-picker.scss +10 -6
  45. package/src/components/silke-color-picker/silke-color-info.tsx +14 -4
  46. package/src/components/silke-color-picker/silke-color-picker-button.tsx +4 -3
  47. package/src/components/silke-color-picker/silke-color-picker.tsx +4 -2
  48. package/src/components/silke-color-picker/silke-opacity-slider.tsx +11 -12
  49. package/src/components/silke-color-swatches/silke-color-swatch-button.tsx +10 -4
  50. package/src/components/silke-color-swatches/silke-swatches.tsx +2 -2
  51. package/src/components/silke-content-column/index.ts +1 -0
  52. package/src/components/silke-content-column/silke-content-column.mdx +7 -0
  53. package/src/components/silke-content-column/silke-content-column.scss +39 -0
  54. package/src/components/silke-content-column/silke-content-column.tsx +14 -0
  55. package/src/components/silke-context-menu/silke-context-menu-item.tsx +9 -4
  56. package/src/components/silke-context-menu/silke-context-menu.mdx +16 -12
  57. package/src/components/silke-context-menu/silke-context-menu.scss +16 -0
  58. package/src/components/silke-context-menu/silke-context-menu.tsx +62 -39
  59. package/src/components/silke-css-number-field/silke-css-context.tsx +1 -0
  60. package/src/components/silke-css-number-field/silke-css-number-field.scss +18 -3
  61. package/src/components/silke-css-number-field/silke-css-number-field.tsx +32 -13
  62. package/src/components/silke-css-number-field/utils.ts +2 -0
  63. package/src/components/silke-divider/silke-divider.scss +4 -2
  64. package/src/components/silke-drawer/silke-drawer.scss +3 -3
  65. package/src/components/silke-drawer/silke-drawer.tsx +3 -3
  66. package/src/components/silke-form/silke-form.tsx +1 -9
  67. package/src/components/silke-form-schema/fields/array-field-inline.tsx +2 -3
  68. package/src/components/silke-form-schema/fields/array-field-modal.tsx +1 -1
  69. package/src/components/silke-form-schema/fields/array-field.tsx +2 -2
  70. package/src/components/silke-form-schema/fields/event-field.tsx +120 -0
  71. package/src/components/silke-form-schema/fields/icon-field.tsx +1 -1
  72. package/src/components/silke-form-schema/fields/image-field.tsx +1 -1
  73. package/src/components/silke-form-schema/fields/link-field.tsx +8 -1
  74. package/src/components/silke-form-schema/fields/number-field.tsx +24 -8
  75. package/src/components/silke-form-schema/fields/object-field.tsx +1 -1
  76. package/src/components/silke-form-schema/fields/select-field.tsx +9 -2
  77. package/src/components/silke-form-schema/fields/styles.scss +2 -2
  78. package/src/components/silke-form-schema/fields/toggle-field.tsx +14 -13
  79. package/src/components/silke-form-schema/fields/upload-field.tsx +37 -0
  80. package/src/components/silke-form-schema/fields/utils/generate-image.ts +3 -4
  81. package/src/components/silke-form-schema/fields/utils/generate-title.ts +1 -3
  82. package/src/components/silke-form-schema/index.ts +1 -0
  83. package/src/components/silke-form-schema/silke-extended-fields-context.tsx +22 -0
  84. package/src/components/silke-form-schema/silke-schema-field.tsx +19 -6
  85. package/src/components/silke-icon/silke-icon.scss +3 -2
  86. package/src/components/silke-icon/silke-icon.tsx +7 -3
  87. package/src/components/silke-icon/silke-shape.tsx +3 -2
  88. package/src/components/silke-icon-picker/emoji-tab.tsx +2 -2
  89. package/src/components/silke-icon-picker/icons-tab.tsx +1 -1
  90. package/src/components/silke-icon-picker/silke-icon-picker.tsx +1 -1
  91. package/src/components/silke-iframe-portal/index.ts +4 -0
  92. package/src/components/silke-iframe-portal/silke-iframe-context.ts +6 -0
  93. package/src/components/silke-iframe-portal/silke-iframe-css-link.tsx +20 -0
  94. package/src/components/silke-iframe-portal/silke-iframe-portal.mdx +34 -0
  95. package/src/components/silke-iframe-portal/silke-iframe-portal.tsx +77 -0
  96. package/src/components/silke-iframe-portal/silke-iframe-script.tsx +20 -0
  97. package/src/components/silke-link/silke-link.scss +2 -2
  98. package/src/components/silke-link/silke-link.tsx +8 -9
  99. package/src/components/silke-list/silke-list.scss +1 -1
  100. package/src/components/silke-list-card/index.ts +1 -0
  101. package/src/components/silke-list-card/silke-list-card.mdx +50 -0
  102. package/src/components/silke-list-card/silke-list-card.scss +57 -0
  103. package/src/components/silke-list-card/silke-list-card.tsx +65 -0
  104. package/src/components/silke-loader/index.ts +1 -0
  105. package/src/components/silke-loader/silke-loader-overlay.tsx +63 -0
  106. package/src/components/silke-loader/silke-loader.scss +112 -0
  107. package/src/components/silke-loader/silke-loader.tsx +1 -0
  108. package/src/components/silke-modal/silke-confirmation-modal.tsx +1 -1
  109. package/src/components/silke-modal/silke-modal.mdx +1 -1
  110. package/src/components/silke-modal/silke-modal.scss +16 -10
  111. package/src/components/silke-modal/silke-modal.tsx +65 -47
  112. package/src/components/silke-navigation-link/silke-navigation-link.scss +69 -41
  113. package/src/components/silke-navigation-link/silke-navigation-link.tsx +26 -14
  114. package/src/components/silke-notification/confetti.tsx +164 -0
  115. package/src/components/silke-notification/silke-notification.mdx +137 -20
  116. package/src/components/silke-notification/silke-notification.scss +116 -89
  117. package/src/components/silke-notification/silke-notification.tsx +44 -113
  118. package/src/components/silke-object-field/silke-object-field.tsx +1 -1
  119. package/src/components/silke-overflow-menu/silke-overflow-menu.mdx +2 -2
  120. package/src/components/silke-overflow-menu/silke-overflow-menu.scss +12 -4
  121. package/src/components/silke-overflow-menu/silke-overflow-menu.tsx +53 -30
  122. package/src/components/silke-popover/silke-popover.mdx +2 -2
  123. package/src/components/silke-popover/silke-popover.tsx +23 -5
  124. package/src/components/silke-progress-indicator/silke-progress-indicator.scss +5 -5
  125. package/src/components/silke-radio-button/silke-radio-button-group.tsx +1 -1
  126. package/src/components/silke-radio-button/silke-radio-button.scss +24 -9
  127. package/src/components/silke-search-field/silke-search-field.tsx +10 -5
  128. package/src/components/silke-select-field/silke-select-field.mdx +11 -5
  129. package/src/components/silke-skeleton/silke-skeleton.scss +2 -2
  130. package/src/components/silke-slider/range-slider.scss +13 -10
  131. package/src/components/silke-slider/silke-slider.tsx +5 -0
  132. package/src/components/silke-sortable-list/silke-nested-sortable-item.tsx +105 -0
  133. package/src/components/silke-sortable-list/silke-nested-sortable-list.scss +37 -25
  134. package/src/components/silke-sortable-list/silke-nested-sortable-list.tsx +180 -127
  135. package/src/components/silke-sortable-list/silke-nested-sortable-utils.ts +53 -23
  136. package/src/components/silke-sortable-list/silke-sortable-item-wrapper.tsx +1 -1
  137. package/src/components/silke-sortable-list/silke-sortable-list.mdx +12 -16
  138. package/src/components/silke-sortable-list/silke-sortable-list.scss +39 -29
  139. package/src/components/silke-sortable-list/silke-sortable-list.tsx +27 -15
  140. package/src/components/silke-steps/index.ts +1 -0
  141. package/src/components/silke-steps/silke-steps.mdx +60 -0
  142. package/src/components/silke-steps/silke-steps.scss +14 -0
  143. package/src/components/silke-steps/silke-steps.tsx +53 -0
  144. package/src/components/silke-table/silke-table.mdx +44 -13
  145. package/src/components/silke-table/silke-table.scss +19 -9
  146. package/src/components/silke-table/silke-table.tsx +80 -71
  147. package/src/components/silke-table/table-row.tsx +11 -6
  148. package/src/components/silke-tabs/silke-tab.tsx +4 -0
  149. package/src/components/silke-tabs/silke-tabs.scss +18 -15
  150. package/src/components/silke-tabs/silke-tabs.tsx +4 -7
  151. package/src/components/silke-tag/silke-tag.mdx +36 -2
  152. package/src/components/silke-tag/silke-tag.scss +49 -30
  153. package/src/components/silke-tag/silke-tag.tsx +21 -6
  154. package/src/components/silke-text/silke-text-types.ts +2 -1
  155. package/src/components/silke-text/silke-text.mdx +28 -20
  156. package/src/components/silke-text/silke-text.scss +8 -7
  157. package/src/components/silke-text/silke-title.scss +1 -1
  158. package/src/components/silke-text-field/silke-text-field-outline.tsx +4 -4
  159. package/src/components/silke-text-field/silke-text-field.mdx +32 -14
  160. package/src/components/silke-text-field/silke-text-field.scss +41 -23
  161. package/src/components/silke-text-field/silke-text-field.tsx +13 -5
  162. package/src/components/silke-text-field/text-field-context.tsx +1 -1
  163. package/src/components/silke-theme-editor/index.ts +1 -0
  164. package/src/components/silke-theme-editor/silke-theme-editor.tsx +165 -0
  165. package/src/components/silke-tile/silke-tile.scss +13 -18
  166. package/src/components/silke-tile/silke-tile.tsx +11 -17
  167. package/src/components/silke-toggle/silke-toggle.scss +17 -9
  168. package/src/components/silke-toggle/silke-toggle.tsx +1 -1
  169. package/src/components/silke-toolbar/silke-toolbar.scss +1 -1
  170. package/src/components/silke-tooltip/silke-definition-tooltip.tsx +14 -6
  171. package/src/components/silke-tooltip/silke-icon-tooltip.tsx +48 -34
  172. package/src/components/silke-tooltip/silke-interactive-tooltip.tsx +5 -3
  173. package/src/components/silke-tooltip/silke-tooltip.mdx +69 -2
  174. package/src/components/silke-tooltip/silke-tooltip.scss +71 -46
  175. package/src/components/silke-tooltip/silke-tooltip.tsx +142 -52
  176. package/src/components/silke-tooltip/utils.ts +93 -0
  177. package/src/components/silke-upload-field/silke-upload-field.mdx +14 -0
  178. package/src/components/silke-upload-field/silke-upload-field.scss +26 -17
  179. package/src/components/silke-upload-field/silke-upload-field.tsx +37 -14
  180. package/src/docs/app.tsx +118 -25
  181. package/src/docs/components/code-block/code-block.scss +0 -2
  182. package/src/docs/components/code-block/code-block.tsx +17 -9
  183. package/src/hooks/drag-and-drop/use-drag.tsx +5 -1
  184. package/src/hooks/drag-and-drop/use-drop.tsx +5 -4
  185. package/src/icons.tsx +194 -10
  186. package/src/index.mdx +66 -1
  187. package/src/main.tsx +5 -2
  188. package/src/silke-theme-provider.tsx +51 -3
  189. package/src/styles/core.scss +56 -91
  190. package/webpack.docs.ts +1 -3
  191. package/webpack.config.ts +0 -131
@@ -1,79 +1,169 @@
1
- import React from 'react';
2
- import { PopoverAnchor, PopoverOrigin, SilkePopover } from '../silke-popover';
1
+ import { clamp } from 'lodash';
2
+ import React, { useLayoutEffect, useMemo, useRef } from 'react';
3
3
  import { SilkeBox } from '../silke-box';
4
+ import { PopoverAnchor, PopoverOrigin, SilkePopover } from '../silke-popover';
5
+ import { SilkeTitle } from '../silke-text';
4
6
  import styles from './silke-tooltip.scss';
7
+ import { createTooltipPath } from './utils';
5
8
 
6
- type TooltipKinds = 'default' | 'light';
9
+ export type SilkeTooltipSize = 'tiny' | 'small' | 'base' | 'large' | 'auto';
10
+ export type SilkeTooltipKind = 'default' | 'info';
7
11
  export type TooltipHorizontalPosition = 'center' | 'left' | 'right';
12
+ let CLIP_PATH_ID = 0;
8
13
 
9
- const ORIGINS: Record<TooltipHorizontalPosition, [anchor: PopoverOrigin, target: PopoverOrigin]> = {
10
- center: ['bottom-center', 'top-center'],
11
- left: ['bottom-left', 'top-left'],
12
- right: ['bottom-right', 'top-right'],
13
- };
14
+ function getOppositeOrigin(origin: PopoverOrigin = 'bottom-center'): PopoverOrigin {
15
+ const [v, h] = origin.split('-');
16
+ if (v === 'bottom') return ('top-' + h) as PopoverOrigin;
17
+ if (v === 'top') return ('bottom-' + h) as PopoverOrigin;
18
+
19
+ if (h === 'left') return (v + '-right') as PopoverOrigin;
20
+ if (h === 'right') return (v + '-left') as PopoverOrigin;
21
+
22
+ return origin;
23
+ }
24
+
25
+ export type SilkeTooltipProps = {
26
+ kind?: SilkeTooltipKind;
27
+ noArrow?: boolean;
14
28
 
15
- interface SilkeTooltipProps {
16
29
  /**
17
30
  * Element to show on
18
31
  */
19
32
  anchor: PopoverAnchor;
20
- /**
21
- * Controls alignment of the tip relative to anchor
22
- */
23
- hPos?: TooltipHorizontalPosition;
24
- icon?: React.ReactNode;
25
- kind?: TooltipKinds;
33
+ image?: string;
26
34
  show: boolean;
27
- tooltip?: React.ReactNode;
28
- }
35
+ size?: SilkeTooltipSize;
36
+ targetOrigin?: PopoverOrigin;
37
+ anchorOrigin?: PopoverOrigin;
38
+ title?: string;
39
+ children?: React.ReactNode;
40
+ };
29
41
 
30
42
  /**
31
43
  * Tooltip component. Needs an anchor, shows a little tip.
32
44
  */
33
45
  export function SilkeTooltip({
46
+ kind,
34
47
  anchor,
35
- hPos = 'center',
36
- icon,
37
- kind = 'default',
48
+ anchorOrigin,
49
+ targetOrigin,
38
50
  show,
39
- tooltip,
51
+ children,
52
+ noArrow,
53
+ image,
54
+ size,
55
+ title,
40
56
  }: SilkeTooltipProps) {
57
+ const targetRef = useRef<HTMLDivElement>(null);
58
+ const pathRef = useRef<SVGPathElement>(null);
59
+ const clipPathRef = useRef<SVGPathElement>(null);
60
+ const clipPathId = useMemo(() => 'silke-clip-path-' + CLIP_PATH_ID++, []);
61
+
62
+ const anchorItem = 'current' in anchor ? anchor.current : anchor;
63
+
64
+ if (!kind) kind = size ? 'info' : 'default';
65
+ if (!size && (kind === 'info' || image)) size = 'base';
66
+
67
+ useLayoutEffect(() => {
68
+ if (!show) return;
69
+
70
+ const tooltipEl = targetRef.current;
71
+ if (tooltipEl) {
72
+ const updatePath = () => {
73
+ const anchorRect = [0, 0, 0, 0];
74
+ if ('current' in anchor) {
75
+ const anchorEl = anchor.current;
76
+ if (anchorEl) {
77
+ const rect = anchorEl.getBoundingClientRect();
78
+ anchorRect[0] = rect.left;
79
+ anchorRect[1] = rect.top;
80
+ anchorRect[2] = rect.width;
81
+ anchorRect[3] = rect.height;
82
+ } else return;
83
+ } else if (Array.isArray(anchor)) {
84
+ anchorRect[0] = anchor[0] || 0;
85
+ anchorRect[1] = anchor[1] || 0;
86
+ }
87
+
88
+ const { top, left, width, height, bottom, right } = tooltipEl.getBoundingClientRect();
89
+ if (!width || !height || bottom < 0) return;
90
+ let pointDir: 'up' | 'down' | 'left' | 'right' = 'up';
91
+ let offset = 0.5;
92
+
93
+ if (bottom < anchorRect[1]) {
94
+ pointDir = 'down';
95
+ } else if (right < anchorRect[0]) {
96
+ pointDir = 'right';
97
+ } else if (left > anchorRect[0] + anchorRect[2]) {
98
+ pointDir = 'left';
99
+ }
100
+ if (pointDir === 'down' || pointDir === 'up') {
101
+ offset = clamp((anchorRect[0] - left + anchorRect[2] / 2) / width, 0, 1);
102
+ } else {
103
+ offset = clamp((anchorRect[1] - top + anchorRect[3] / 2) / height, 0, 1);
104
+ }
105
+
106
+ const d = createTooltipPath(pointDir, offset, width, height, kind === 'info' ? 8 : 4);
107
+ clipPathRef.current?.setAttribute('d', d);
108
+ pathRef.current?.setAttribute('d', d);
109
+ };
110
+
111
+ const observer = new ResizeObserver(updatePath);
112
+ observer.observe(tooltipEl);
113
+ updatePath();
114
+
115
+ setTimeout(updatePath, 50);
116
+
117
+ const interval = setInterval(updatePath, 500);
118
+
119
+ return () => {
120
+ observer.disconnect();
121
+ clearInterval(interval);
122
+ };
123
+ }
124
+ }, [show, anchor, noArrow, anchorItem, children, kind]);
125
+
126
+ if (!show) return null;
127
+
128
+ if (!anchorOrigin) anchorOrigin = 'bottom-center';
129
+ if (!targetOrigin) targetOrigin = getOppositeOrigin(anchorOrigin);
130
+ const [anchorV, anchorH] = anchorOrigin.split('-');
131
+
132
+ let cl = styles.root;
133
+ cl += ' ' + styles[kind || 'default'];
134
+
135
+ if (size) cl += ' ' + styles[size];
136
+
41
137
  return (
42
138
  <SilkePopover
43
139
  anchor={anchor}
44
140
  hide={!show}
45
- anchorOrigin={ORIGINS[hPos][0]}
46
- targetOrigin={ORIGINS[hPos][1]}
47
- offsetY={4}
141
+ anchorOrigin={anchorOrigin}
142
+ targetOrigin={targetOrigin}
143
+ offsetY={anchorV === 'center' ? 0 : anchorV === 'top' ? -6 : 6}
144
+ offsetX={anchorH === 'center' ? 0 : anchorH === 'left' ? -6 : 6}
48
145
  >
49
- <Arrow kind={kind} position={hPos} />
50
- <SilkeBox
51
- className={kind === 'light' ? styles.light : styles.container}
52
- column
53
- vPad="s"
54
- hPad="m"
55
- gap="s"
56
- hAlign="start"
57
- vAlign="center"
58
- >
59
- {tooltip}
60
- </SilkeBox>
146
+ <div className={cl} ref={targetRef}>
147
+ <svg>
148
+ <defs>
149
+ <clipPath id={clipPathId}>
150
+ <path ref={clipPathRef} />
151
+ </clipPath>
152
+ </defs>
153
+ <path ref={pathRef} />
154
+ </svg>
155
+ <SilkeBox column style={{ clipPath: `url(#${clipPathId})` }}>
156
+ {image && <img className={styles.img} src={image} alt="" />}
157
+ <SilkeBox column className={styles.content}>
158
+ {title && (
159
+ <SilkeTitle kind="xxs" weight="strong">
160
+ {title}
161
+ </SilkeTitle>
162
+ )}
163
+ {children}
164
+ </SilkeBox>
165
+ </SilkeBox>
166
+ </div>
61
167
  </SilkePopover>
62
168
  );
63
169
  }
64
-
65
- const ARROW_POS_CLASS_NAME: Record<TooltipHorizontalPosition, string> = {
66
- center: styles.arrow,
67
- left: styles.leftArrow,
68
- right: styles.rightArrow,
69
- };
70
-
71
- const Arrow = ({ kind, position }: { kind: TooltipKinds; position: TooltipHorizontalPosition }) => (
72
- <div
73
- className={
74
- ARROW_POS_CLASS_NAME[position] +
75
- ' ' +
76
- (kind === 'light' ? styles.arrowLight : styles.arrowDark)
77
- }
78
- />
79
- );
@@ -0,0 +1,93 @@
1
+ // export function createTooltipPath(angleInRad: number, width: number, height: number, br = 8) {
2
+ // const lw = width - 2 * br;
3
+ // const lh = height - 2 * br;
4
+ // let topLine = `l ${lw} 0`;
5
+ // let bottomLine = `l -${lw} 0`;
6
+ // let rightLine = `l 0 ${lh}`;
7
+ // let leftLine = `l 0 -${lh}`;
8
+ // const topRightCorner = `c ${br} 0 ${br} ${br} ${br} ${br}`;
9
+ // const bottomRightCorner = `c 0 ${br} -${br} ${br} -${br} ${br}`;
10
+ // const bottomLeftCorner = `c -${br} 0 -${br} -${br} -${br} -${br}`;
11
+ // const topLeftCorner = `c 0 -${br} ${br} -${br} ${br} -${br}`;
12
+
13
+ // // let angle = (Math.atan2(pointAt[1], pointAt[0]) * 180) / Math.PI;
14
+ // let angle = angleInRad * (180 / Math.PI);
15
+ // if (angle < 0) angle = 360 + angle;
16
+ // angle = (angle + 45) % 360;
17
+ // const a = 8;
18
+ // const percent = (Math.abs(angle) % 90) / 90;
19
+ // const verticalCP = a + (lh - a * 2) * percent;
20
+ // const verticalTop = verticalCP;
21
+ // const verticalBottom = lh - verticalCP;
22
+ // const horizontalCP = a + (lw - a * 2) * percent;
23
+ // const horizontalTop = horizontalCP;
24
+ // const horizontalBottom = lw - horizontalCP;
25
+
26
+ // if (angle > 0 && angle < 90) {
27
+ // // Arrow on right line
28
+
29
+ // rightLine = `l 0 ${verticalTop - a} l ${a} ${a} l -${a} ${a} l 0 ${verticalBottom - a}`;
30
+ // } else if (angle >= 90 && angle < 180) {
31
+ // // Arrow on bottom line
32
+
33
+ // bottomLine = `l -${horizontalTop - a} 0 l -${a} ${a} l -${a} -${a} l -${
34
+ // horizontalBottom - a
35
+ // } 0`;
36
+ // } else if (angle >= 180 && angle < 270) {
37
+ // // Arrow on left line
38
+ // leftLine = `l 0 -${verticalTop - a} l -${a} -${a} l ${a} -${a} l 0 -${verticalBottom - a}`;
39
+ // } else {
40
+ // // Arrow on top line
41
+ // topLine = `l ${horizontalTop - a} 0 l ${a} -${a} l ${a} ${a} l ${horizontalBottom - a} 0`;
42
+ // }
43
+
44
+ // return `M ${br} 0 ${topLine} ${topRightCorner} ${rightLine} ${bottomRightCorner} ${bottomLine} ${bottomLeftCorner} ${leftLine} ${topLeftCorner}`;
45
+ // }
46
+
47
+ export function createTooltipPath(
48
+ pointDir: 'up' | 'down' | 'left' | 'right',
49
+ offset: number,
50
+ width: number,
51
+ height: number,
52
+ br = 8,
53
+ ) {
54
+ const lw = width - 2 * br;
55
+ const lh = height - 2 * br;
56
+ let topLine = `l ${lw} 0`;
57
+ let bottomLine = `l -${lw} 0`;
58
+ let rightLine = `l 0 ${lh}`;
59
+ let leftLine = `l 0 -${lh}`;
60
+ const topRightCorner = `c ${br} 0 ${br} ${br} ${br} ${br}`;
61
+ const bottomRightCorner = `c 0 ${br} -${br} ${br} -${br} ${br}`;
62
+ const bottomLeftCorner = `c -${br} 0 -${br} -${br} -${br} -${br}`;
63
+ const topLeftCorner = `c 0 -${br} ${br} -${br} ${br} -${br}`;
64
+
65
+ if (pointDir === 'left' || pointDir === 'down') offset = 1 - offset;
66
+
67
+ const a = 8;
68
+ const verticalCP = a + (lh - a * 2) * offset;
69
+ const verticalTop = verticalCP;
70
+ const verticalBottom = lh - verticalCP;
71
+ const horizontalCP = a + (lw - a * 2) * offset;
72
+ const horizontalTop = horizontalCP;
73
+ const horizontalBottom = lw - horizontalCP;
74
+
75
+ if (pointDir === 'right') {
76
+ // Arrow on right line
77
+ rightLine = `l 0 ${verticalTop - a} l ${a} ${a} l -${a} ${a} l 0 ${verticalBottom - a}`;
78
+ } else if (pointDir === 'down') {
79
+ // Arrow on bottom line
80
+
81
+ bottomLine = `l -${horizontalTop - a} 0 l -${a} ${a} l -${a} -${a} l -${
82
+ horizontalBottom - a
83
+ } 0`;
84
+ } else if (pointDir === 'left') {
85
+ // Arrow on left line
86
+ leftLine = `l 0 -${verticalTop - a} l -${a} -${a} l ${a} -${a} l 0 -${verticalBottom - a}`;
87
+ } else {
88
+ // Arrow on top line
89
+ topLine = `l ${horizontalTop - a} 0 l ${a} -${a} l ${a} ${a} l ${horizontalBottom - a} 0`;
90
+ }
91
+
92
+ return `M ${br} 0 ${topLine} ${topRightCorner} ${rightLine} ${bottomRightCorner} ${bottomLine} ${bottomLeftCorner} ${leftLine} ${topLeftCorner}`;
93
+ }
@@ -1,5 +1,19 @@
1
1
  # File Upload
2
2
 
3
+ ## Single file
4
+
5
+ ```js
6
+ const [file, setFile] = React.useState();
7
+ <>
8
+ <SilkeUploadField
9
+ label="Upload field"
10
+ help="Any file type and any size"
11
+ value={file}
12
+ onChange={setFile}
13
+ />
14
+ </>;
15
+ ```
16
+
3
17
  ## Single file upload
4
18
 
5
19
  ```js
@@ -9,38 +9,41 @@
9
9
  }
10
10
 
11
11
  &.over .drop,
12
- input:focus + .drop {
13
- border: 2px solid var(--color-brand-primary-soft);
12
+ input:focus + .drop,
13
+ input:hover + .drop {
14
+ background-color: var(--color-surface-3);
15
+ cursor: pointer;
16
+ transition: 200ms background-color;
14
17
  }
15
18
 
16
19
  &.invalid .drop {
17
- border-color: var(--color-feedback-warning-spark);
18
- color: var(--color-feedback-warning-spark);
20
+ border-color: var(--color-error-30);
21
+ color: var(--color-error-30);
19
22
  cursor: not-allowed;
20
23
  }
21
-
22
- &:hover {
23
- .drop {
24
- text-decoration: underline;
25
- }
26
- }
27
24
  }
28
25
 
29
26
  .drop {
30
- border: 1px dashed var(--color-neutral-high-soft);
31
- width: 256px;
32
- height: 96px;
33
- color: var(--color-brand-primary-soft);
27
+ color: var(--color-accent-50);
28
+ text-align: center;
29
+ border-radius: var(--border-radius-small);
30
+ }
31
+
32
+ .icon {
33
+ color: var(--color-neutral-100);
34
+ font-size: 24px;
34
35
  }
35
36
 
36
37
  .item {
37
- background: var(--color-neutral-low-light);
38
- width: 256px;
38
+ background-color: rgba(var(--color-accent-30-rgb), 0.32);
39
39
  padding: $space-xxs $space-xxs $space-xxs $space-m;
40
+ border-radius: var(--border-radius-small);
40
41
 
41
42
  &.error {
42
- background-color: var(--color-feedback-warning-spark);
43
+ background-color: var(--color-error-20);
44
+ border-radius: var(--border-radius-small);
43
45
  }
46
+
44
47
  .loader {
45
48
  pointer-events: none;
46
49
  position: absolute;
@@ -48,5 +51,11 @@
48
51
  bottom: 0;
49
52
  left: 0;
50
53
  right: 0;
54
+ border-radius: var(--border-radius-small);
55
+ overflow: hidden;
56
+ }
57
+
58
+ &.complete {
59
+ background-color: var(--color-success-10);
51
60
  }
52
61
  }
@@ -7,7 +7,9 @@ import { BoxLabelProps, SilkeBox } from '../silke-box';
7
7
  import { SilkeButton } from '../silke-button';
8
8
  import { FormFieldProps, FormValidator } from '../silke-form';
9
9
  import { SilkeSkeleton } from '../silke-skeleton';
10
- import { SilkeText } from '../silke-text';
10
+ import { SilkeText, SilkeTitle } from '../silke-text';
11
+ import { SilkeIcon } from '../silke-icon';
12
+
11
13
  import styles from './silke-upload-field.scss';
12
14
 
13
15
  export type FileModel = {
@@ -40,7 +42,10 @@ type SingleField = { multiple?: false | undefined } & BaseProps &
40
42
  FormFieldProps<FileModel | string>;
41
43
  type MultipleField = { multiple: true } & BaseProps & FormFieldProps<(FileModel | string)[]>;
42
44
 
43
- type SilkeUploadFieldProps = SingleField | MultipleField;
45
+ type SilkeUploadFieldProps = (SingleField | MultipleField) & {
46
+ dropzoneStyle?: React.CSSProperties;
47
+ fileItemStyle?: React.CSSProperties;
48
+ };
44
49
 
45
50
  const validate: FormValidator<SilkeUploadFieldProps> = (props, value) => {
46
51
  if (props.required && value === undefined) return 'Required';
@@ -66,6 +71,8 @@ export function SilkeUploadField(props: SilkeUploadFieldProps) {
66
71
  onFocus,
67
72
  onBlur,
68
73
  onChange,
74
+ dropzoneStyle,
75
+ fileItemStyle,
69
76
  } = useFormField(props, validate);
70
77
  const ref = useRef<HTMLLabelElement>(null);
71
78
  const pendingRef = useRef<PendingFile[]>([]);
@@ -99,13 +106,13 @@ export function SilkeUploadField(props: SilkeUploadFieldProps) {
99
106
  const uploadFiles: PendingFile[] = [];
100
107
  // takes the acceptable file extensions (string), cleans them, and formats them into an array.
101
108
  const regParts = accept?.split(',').map((r) => r.trim().replace('/*', '/.*'));
102
- // regex explained:
109
+ // regex explained:
103
110
  // ^: assert position at start of line.
104
111
  // .: matches any character.
105
112
  // *: matches previous token between zero and unlimited times.
106
113
  // (regParts.join('|')): matches any of the string values in regParts[]. '|' acts like an "or".
107
114
  // $: asserts position at the end of a line.
108
- const regToMatchAcceptableFileTypes = regParts && `^.*(${regParts.join('|')})$`
115
+ const regToMatchAcceptableFileTypes = regParts && `^.*(${regParts.join('|')})$`;
109
116
  const acceptReg = regToMatchAcceptableFileTypes && new RegExp(regToMatchAcceptableFileTypes);
110
117
 
111
118
  for (let i = 0; i < fileLen; i++) {
@@ -160,11 +167,8 @@ export function SilkeUploadField(props: SilkeUploadFieldProps) {
160
167
  if (dropState) cl += ' ' + styles[dropState];
161
168
  return (
162
169
  <SilkeBox column gap="s">
170
+ <SilkeText weight="strong">{label}</SilkeText>
163
171
  <SilkeBox tag="label" column gap="s" className={cl} onFocus={onFocus} onBlur={onBlur}>
164
- <SilkeText weight="strong">{label}</SilkeText>
165
- {help && !error && <SilkeText color="secondary">{help}</SilkeText>}
166
- {error && <SilkeText color="error">{error}</SilkeText>}
167
-
168
172
  <input
169
173
  type="file"
170
174
  accept={accept}
@@ -174,8 +178,23 @@ export function SilkeUploadField(props: SilkeUploadFieldProps) {
174
178
  multiple={multiple}
175
179
  onChange={(e) => handleFiles(e.currentTarget.files)}
176
180
  />
177
- <SilkeBox pad="s" className={styles.drop} ref={ref}>
178
- Drag and drop files here, or click to upload.
181
+ <SilkeBox
182
+ pad="m"
183
+ gap="m"
184
+ className={styles.drop}
185
+ ref={ref}
186
+ column
187
+ bg="surface-2"
188
+ style={dropzoneStyle}
189
+ >
190
+ <SilkeIcon icon="file" className={styles.icon} />
191
+ <SilkeBox column>
192
+ <SilkeTitle kind="xs">
193
+ Select a file <span style={{ color: 'white' }}>drag and drop here</span>
194
+ </SilkeTitle>
195
+ {help && !error && <SilkeText color="neutral-80">{help}</SilkeText>}
196
+ {error && <SilkeText color="error-30">{error}</SilkeText>}
197
+ </SilkeBox>
179
198
  </SilkeBox>
180
199
  </SilkeBox>
181
200
  {value &&
@@ -189,10 +208,11 @@ export function SilkeUploadField(props: SilkeUploadFieldProps) {
189
208
  />
190
209
  ))
191
210
  ) : (
192
- <SilkeFileItem file={value} onRemove={() => onChange(null)} />
211
+ <SilkeFileItem file={value} onRemove={() => onChange(null)} style={fileItemStyle} />
193
212
  ))}
194
213
  {pending.map((p, key) => (
195
214
  <SilkeFileItem
215
+ style={fileItemStyle}
196
216
  key={key}
197
217
  file={p}
198
218
  loading
@@ -213,21 +233,24 @@ type FileItemProps = {
213
233
  error?: string;
214
234
  file: string | FileModel | PendingFile;
215
235
  onRemove: () => void;
236
+ style?: React.CSSProperties;
216
237
  };
217
238
 
218
- function SilkeFileItem({ file, error, loading, onRemove }: FileItemProps) {
239
+ function SilkeFileItem({ file, error, loading, onRemove, style }: FileItemProps) {
219
240
  if (isString(file)) {
220
241
  file = { name: last(file.split('/')) || 'Untitled', size: 0, type: 'test', url: file };
221
242
  }
222
243
 
223
244
  let cl = styles.item;
224
245
  if (error) cl += ' ' + styles.error;
246
+ if (!error && !loading) cl += ' ' + styles.complete;
247
+
225
248
  return (
226
- <SilkeBox className={cl} vAlign="center" title={error}>
249
+ <SilkeBox style={style} className={cl} vAlign="center" title={error}>
227
250
  <SilkeText overflow flex>
228
251
  {file.name}
229
252
  </SilkeText>
230
- <SilkeButton icon="close" kind="plain" size="base" onClick={onRemove} />
253
+ <SilkeButton icon="close" kind="ghost" size="base" onClick={onRemove} />
231
254
  {!error && loading && <SilkeSkeleton className={styles.loader} />}
232
255
  </SilkeBox>
233
256
  );