@xerios/design-system 0.0.0-stage → 0.1.1

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 (214) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +403 -2
  3. package/dist/components/AnchorHeading.svelte +79 -0
  4. package/dist/components/AnchorHeading.svelte.d.ts +28 -0
  5. package/dist/components/Breadcrumbs.svelte +216 -0
  6. package/dist/components/Breadcrumbs.svelte.d.ts +37 -0
  7. package/dist/components/Button.svelte +185 -0
  8. package/dist/components/Button.svelte.d.ts +70 -0
  9. package/dist/components/Canvas.svelte +248 -0
  10. package/dist/components/Canvas.svelte.d.ts +91 -0
  11. package/dist/components/Collapsible.svelte +139 -0
  12. package/dist/components/Collapsible.svelte.d.ts +52 -0
  13. package/dist/components/CollapsibleAdvanced.svelte +174 -0
  14. package/dist/components/CollapsibleAdvanced.svelte.d.ts +43 -0
  15. package/dist/components/DashOutline.svelte +47 -0
  16. package/dist/components/DashOutline.svelte.d.ts +6 -0
  17. package/dist/components/Dialogs.svelte +123 -0
  18. package/dist/components/Dialogs.svelte.d.ts +6 -0
  19. package/dist/components/Drawer.svelte +231 -0
  20. package/dist/components/Drawer.svelte.d.ts +62 -0
  21. package/dist/components/ErrorMessage.svelte +140 -0
  22. package/dist/components/ErrorMessage.svelte.d.ts +41 -0
  23. package/dist/components/Icon.svelte +94 -0
  24. package/dist/components/Icon.svelte.d.ts +33 -0
  25. package/dist/components/InfoTip.svelte +183 -0
  26. package/dist/components/InfoTip.svelte.d.ts +28 -0
  27. package/dist/components/Md.svelte +28 -0
  28. package/dist/components/Md.svelte.d.ts +11 -0
  29. package/dist/components/Modal.svelte +91 -0
  30. package/dist/components/Modal.svelte.d.ts +41 -0
  31. package/dist/components/Notice.svelte +50 -0
  32. package/dist/components/Notice.svelte.d.ts +30 -0
  33. package/dist/components/Popover.svelte +212 -0
  34. package/dist/components/Popover.svelte.d.ts +70 -0
  35. package/dist/components/Shimmer.svelte +27 -0
  36. package/dist/components/Shimmer.svelte.d.ts +22 -0
  37. package/dist/components/Splitter.svelte +152 -0
  38. package/dist/components/Splitter.svelte.d.ts +41 -0
  39. package/dist/components/Table.svelte +448 -0
  40. package/dist/components/Table.svelte.d.ts +268 -0
  41. package/dist/components/Toast.svelte +273 -0
  42. package/dist/components/Toast.svelte.d.ts +31 -0
  43. package/dist/components/Tooltip.svelte +97 -0
  44. package/dist/components/Tooltip.svelte.d.ts +19 -0
  45. package/dist/components/WorkingBorder.svelte +105 -0
  46. package/dist/components/WorkingBorder.svelte.d.ts +26 -0
  47. package/dist/components/empty/Empty.svelte +55 -0
  48. package/dist/components/empty/Empty.svelte.d.ts +39 -0
  49. package/dist/components/empty/EmptyError.svelte +47 -0
  50. package/dist/components/empty/EmptyError.svelte.d.ts +28 -0
  51. package/dist/components/empty/index.d.ts +18 -0
  52. package/dist/components/empty/index.js +10 -0
  53. package/dist/components/filters/DateFilter.svelte +59 -0
  54. package/dist/components/filters/DateFilter.svelte.d.ts +23 -0
  55. package/dist/components/filters/FilterBar.svelte +401 -0
  56. package/dist/components/filters/FilterBar.svelte.d.ts +283 -0
  57. package/dist/components/filters/FilterChip.svelte +235 -0
  58. package/dist/components/filters/FilterChip.svelte.d.ts +68 -0
  59. package/dist/components/filters/OptionList.svelte +352 -0
  60. package/dist/components/filters/OptionList.svelte.d.ts +91 -0
  61. package/dist/components/filters/Panel.svelte +123 -0
  62. package/dist/components/filters/Panel.svelte.d.ts +25 -0
  63. package/dist/components/filters/index.d.ts +288 -0
  64. package/dist/components/filters/index.js +12 -0
  65. package/dist/components/icons.d.ts +54 -0
  66. package/dist/components/icons.js +58 -0
  67. package/dist/components/inputs/ButtonGroup.svelte +110 -0
  68. package/dist/components/inputs/ButtonGroup.svelte.d.ts +40 -0
  69. package/dist/components/inputs/Calendar.svelte +535 -0
  70. package/dist/components/inputs/Calendar.svelte.d.ts +45 -0
  71. package/dist/components/inputs/DateField.svelte +247 -0
  72. package/dist/components/inputs/DateField.svelte.d.ts +74 -0
  73. package/dist/components/inputs/DateInput.svelte +118 -0
  74. package/dist/components/inputs/DateInput.svelte.d.ts +43 -0
  75. package/dist/components/inputs/DatePicker.svelte +102 -0
  76. package/dist/components/inputs/DatePicker.svelte.d.ts +67 -0
  77. package/dist/components/inputs/DateRangePicker.svelte +208 -0
  78. package/dist/components/inputs/DateRangePicker.svelte.d.ts +76 -0
  79. package/dist/components/inputs/DateRangeSelect.svelte +548 -0
  80. package/dist/components/inputs/DateRangeSelect.svelte.d.ts +70 -0
  81. package/dist/components/inputs/FieldLabel.svelte +43 -0
  82. package/dist/components/inputs/FieldLabel.svelte.d.ts +28 -0
  83. package/dist/components/inputs/ListSearch.svelte +142 -0
  84. package/dist/components/inputs/ListSearch.svelte.d.ts +35 -0
  85. package/dist/components/inputs/RadioGroup.svelte +151 -0
  86. package/dist/components/inputs/RadioGroup.svelte.d.ts +49 -0
  87. package/dist/components/inputs/RangeShortcuts.svelte +90 -0
  88. package/dist/components/inputs/RangeShortcuts.svelte.d.ts +31 -0
  89. package/dist/components/inputs/RangeSlider.svelte +225 -0
  90. package/dist/components/inputs/RangeSlider.svelte.d.ts +37 -0
  91. package/dist/components/inputs/SearchField.svelte +24 -0
  92. package/dist/components/inputs/SearchField.svelte.d.ts +41 -0
  93. package/dist/components/inputs/Segmented.svelte +79 -0
  94. package/dist/components/inputs/Segmented.svelte.d.ts +43 -0
  95. package/dist/components/inputs/Select.svelte +552 -0
  96. package/dist/components/inputs/Select.svelte.d.ts +100 -0
  97. package/dist/components/inputs/Slider.svelte +177 -0
  98. package/dist/components/inputs/Slider.svelte.d.ts +33 -0
  99. package/dist/components/inputs/SliderTicks.svelte +62 -0
  100. package/dist/components/inputs/SliderTicks.svelte.d.ts +23 -0
  101. package/dist/components/inputs/Switch.svelte +120 -0
  102. package/dist/components/inputs/Switch.svelte.d.ts +31 -0
  103. package/dist/components/inputs/TagInput.svelte +296 -0
  104. package/dist/components/inputs/TagInput.svelte.d.ts +61 -0
  105. package/dist/components/inputs/TextArea.svelte +86 -0
  106. package/dist/components/inputs/TextArea.svelte.d.ts +56 -0
  107. package/dist/components/inputs/TextField.svelte +170 -0
  108. package/dist/components/inputs/TextField.svelte.d.ts +80 -0
  109. package/dist/components/menu/ContextMenu.svelte +25 -0
  110. package/dist/components/menu/ContextMenu.svelte.d.ts +26 -0
  111. package/dist/components/menu/MenuButton.svelte +46 -0
  112. package/dist/components/menu/MenuButton.svelte.d.ts +16 -0
  113. package/dist/components/menu/MenuList.svelte +319 -0
  114. package/dist/components/menu/MenuList.svelte.d.ts +30 -0
  115. package/dist/components/metadata/Metadata.svelte +38 -0
  116. package/dist/components/metadata/Metadata.svelte.d.ts +31 -0
  117. package/dist/components/metadata/MetadataRow.svelte +84 -0
  118. package/dist/components/metadata/MetadataRow.svelte.d.ts +26 -0
  119. package/dist/components/metadata/index.d.ts +8 -0
  120. package/dist/components/metadata/index.js +13 -0
  121. package/dist/components/side-menu/SideMenu.svelte +138 -0
  122. package/dist/components/side-menu/SideMenu.svelte.d.ts +25 -0
  123. package/dist/components/side-menu/SideMenuGroup.svelte +108 -0
  124. package/dist/components/side-menu/SideMenuGroup.svelte.d.ts +31 -0
  125. package/dist/components/side-menu/SideMenuItem.svelte +221 -0
  126. package/dist/components/side-menu/SideMenuItem.svelte.d.ts +46 -0
  127. package/dist/components/side-menu/context.d.ts +1 -0
  128. package/dist/components/side-menu/context.js +3 -0
  129. package/dist/components/side-menu/index.d.ts +62 -0
  130. package/dist/components/side-menu/index.js +15 -0
  131. package/dist/components/tiles/Tile.svelte +419 -0
  132. package/dist/components/tiles/Tile.svelte.d.ts +58 -0
  133. package/dist/components/tiles/TileGroup.svelte +135 -0
  134. package/dist/components/tiles/TileGroup.svelte.d.ts +45 -0
  135. package/dist/components/tiles/context.d.ts +35 -0
  136. package/dist/components/tiles/context.js +14 -0
  137. package/dist/components/tiles/index.d.ts +6 -0
  138. package/dist/components/tiles/index.js +13 -0
  139. package/dist/components/upload/FileCard.svelte +301 -0
  140. package/dist/components/upload/FileCard.svelte.d.ts +127 -0
  141. package/dist/components/upload/Thumb.svelte +274 -0
  142. package/dist/components/upload/Thumb.svelte.d.ts +101 -0
  143. package/dist/components/upload/UploadFile.svelte +123 -0
  144. package/dist/components/upload/UploadFile.svelte.d.ts +48 -0
  145. package/dist/components/upload/UploadFiles.svelte +177 -0
  146. package/dist/components/upload/UploadFiles.svelte.d.ts +50 -0
  147. package/dist/components/upload/UploadFolder.svelte +153 -0
  148. package/dist/components/upload/UploadFolder.svelte.d.ts +63 -0
  149. package/dist/components/upload/UploadImage.svelte +137 -0
  150. package/dist/components/upload/UploadImage.svelte.d.ts +52 -0
  151. package/dist/components/upload/UploadImages.svelte +172 -0
  152. package/dist/components/upload/UploadImages.svelte.d.ts +52 -0
  153. package/dist/components/upload/UploadZone.svelte +130 -0
  154. package/dist/components/upload/UploadZone.svelte.d.ts +41 -0
  155. package/dist/components/upload/common.d.ts +31 -0
  156. package/dist/components/upload/common.js +103 -0
  157. package/dist/components/upload/context.d.ts +18 -0
  158. package/dist/components/upload/context.js +10 -0
  159. package/dist/components/upload/index.d.ts +16 -0
  160. package/dist/components/upload/index.js +18 -0
  161. package/dist/css/atoms.css +899 -0
  162. package/dist/css/base.css +334 -0
  163. package/dist/css/effects.css +430 -0
  164. package/dist/css/index.css +10 -0
  165. package/dist/css/tokens.css +296 -0
  166. package/dist/fonts.d.ts +1 -0
  167. package/dist/fonts.js +7 -0
  168. package/dist/index.d.ts +68 -0
  169. package/dist/index.js +77 -0
  170. package/dist/lib/announce.d.ts +8 -0
  171. package/dist/lib/announce.js +48 -0
  172. package/dist/lib/controls.d.ts +10 -0
  173. package/dist/lib/controls.js +42 -0
  174. package/dist/lib/dates.d.ts +104 -0
  175. package/dist/lib/dates.js +235 -0
  176. package/dist/lib/dialogs.svelte.d.ts +8 -0
  177. package/dist/lib/dialogs.svelte.js +45 -0
  178. package/dist/lib/dom.d.ts +34 -0
  179. package/dist/lib/dom.js +90 -0
  180. package/dist/lib/field-errors.svelte.d.ts +40 -0
  181. package/dist/lib/field-errors.svelte.js +89 -0
  182. package/dist/lib/files.d.ts +74 -0
  183. package/dist/lib/files.js +215 -0
  184. package/dist/lib/inline-md.d.ts +1 -0
  185. package/dist/lib/inline-md.js +36 -0
  186. package/dist/lib/invalid.d.ts +4 -0
  187. package/dist/lib/invalid.js +35 -0
  188. package/dist/lib/list-search.d.ts +9 -0
  189. package/dist/lib/list-search.js +27 -0
  190. package/dist/lib/menu.svelte.d.ts +39 -0
  191. package/dist/lib/menu.svelte.js +98 -0
  192. package/dist/lib/morph.svelte.d.ts +17 -0
  193. package/dist/lib/morph.svelte.js +46 -0
  194. package/dist/lib/motion.d.ts +115 -0
  195. package/dist/lib/motion.js +174 -0
  196. package/dist/lib/observe.d.ts +36 -0
  197. package/dist/lib/observe.js +142 -0
  198. package/dist/lib/reveal.d.ts +7 -0
  199. package/dist/lib/reveal.js +28 -0
  200. package/dist/lib/roving.d.ts +16 -0
  201. package/dist/lib/roving.js +35 -0
  202. package/dist/lib/runs.d.ts +18 -0
  203. package/dist/lib/runs.js +25 -0
  204. package/dist/lib/scroll-fade.d.ts +4 -0
  205. package/dist/lib/scroll-fade.js +71 -0
  206. package/dist/lib/spotlight.d.ts +4 -0
  207. package/dist/lib/spotlight.js +109 -0
  208. package/dist/lib/ticks.d.ts +12 -0
  209. package/dist/lib/ticks.js +24 -0
  210. package/dist/lib/tooltip.d.ts +4 -0
  211. package/dist/lib/tooltip.js +110 -0
  212. package/dist/lib/validity.d.ts +16 -0
  213. package/dist/lib/validity.js +36 -0
  214. package/package.json +69 -3
@@ -0,0 +1,274 @@
1
+ <script>
2
+ import Icon from '../Icon.svelte'
3
+ import { fileSize, preview } from '../../lib/files.js'
4
+ import { invalid } from '../../lib/invalid.js'
5
+ import { tooltip } from '../../lib/tooltip.js'
6
+ import { fade, durations } from '../../lib/motion.js'
7
+ import { morph } from '../../lib/morph.svelte.js'
8
+ /**
9
+ * Internal to Upload (Upload.Image, Upload.Images): an image picker's tile, empty or holding its image. Empty, it is a
10
+ * pill like .btn (an icon and `label`), or with `square` a dashed tile the size of a thumbnail with the icon over the
11
+ * label (the add tile ending a grid). Holding an image, the same box reshapes (lib/morph.svelte.js) into a square
12
+ * thumbnail of it, cropped to fill, with a ✕ in its corner and the name and size under it. Pressing the thumbnail opens
13
+ * the picker again to replace the image, unless `onpick` is left out (a thumbnail in a grid, which only clears).
14
+ * Delete or Backspace on it clears it too. The tooltips of both buttons name the image in full, since the caption may
15
+ * cut its name short. The button stays the same element throughout, so it keeps the focus, and
16
+ * the ✕ hands the focus back to it.
17
+ *
18
+ * @typedef {object} Props
19
+ * @property {File | null} file the image, or null while empty
20
+ * @property {string} [label] the empty state's text
21
+ * @property {string} [icon] the empty state's icon
22
+ * @property {boolean} [square] empty, a thumbnail-sized tile instead of a pill
23
+ * @property {() => void} [onpick] opens the picker; left out, the thumbnail is not a button
24
+ * @property {() => void} [onclear] adds the ✕
25
+ * @property {boolean} [disabled]
26
+ * @property {boolean} [dragging] files are dragged over its drop target
27
+ * @property {string} [id] on the button
28
+ * @property {string | false} [errorId] the id of its error message, while there is one
29
+ * @property {HTMLButtonElement} [main] the button (bindable)
30
+ */
31
+ /** @type {Props} */
32
+ let {
33
+ file,
34
+ label = '',
35
+ icon = 'image',
36
+ square = false,
37
+ onpick,
38
+ onclear,
39
+ disabled = false,
40
+ dragging = false,
41
+ id,
42
+ errorId = false,
43
+ main = $bindable(),
44
+ } = $props()
45
+
46
+ /** @type {HTMLDivElement | undefined} */
47
+ let box = $state()
48
+ morph(
49
+ () => box,
50
+ () => file,
51
+ )
52
+
53
+ function clear() {
54
+ if (disabled) return
55
+ onclear?.()
56
+ main?.focus()
57
+ }
58
+
59
+ /** @param {KeyboardEvent} event */
60
+ function onkeydown(event) {
61
+ if (!file || !onclear || (event.key !== 'Delete' && event.key !== 'Backspace')) return
62
+ event.preventDefault()
63
+ clear()
64
+ }
65
+ </script>
66
+
67
+ {#snippet content()}
68
+ {#if file}
69
+ <img alt="" draggable="false" {@attach preview(file)} in:fade={{ duration: durations.short4 }} />
70
+ {:else}
71
+ <Icon name={icon} size={square ? 'md' : 'sm'} /><span class="label" in:fade={{ duration: durations.short4 }}>{label}</span>
72
+ {/if}
73
+ {/snippet}
74
+
75
+ <div class="thumb">
76
+ <div bind:this={box} class={['tile', file ? 'filled' : square ? 'empty square' : 'empty pill', dragging && 'dragging', disabled && 'disabled']}>
77
+ {#if onpick}
78
+ <button
79
+ bind:this={main}
80
+ type="button"
81
+ class="main"
82
+ {id}
83
+ {disabled}
84
+ aria-label={file?.name}
85
+ {@attach invalid(errorId)}
86
+ {@attach tooltip(file ? 'Replace' : '', { detail: file?.name })}
87
+ onclick={onpick}
88
+ {onkeydown}>{@render content()}</button
89
+ >
90
+ {:else}
91
+ <div class="main">{@render content()}</div>
92
+ {/if}
93
+ {#if file && onclear}
94
+ <button
95
+ type="button"
96
+ class="clear"
97
+ aria-label="Remove {file.name}"
98
+ {disabled}
99
+ {@attach tooltip('Remove', { detail: file.name })}
100
+ onclick={clear}
101
+ in:fade={{ duration: durations.short4 }}><Icon name="x" size="sm" /></button
102
+ >
103
+ {/if}
104
+ </div>
105
+ {#if file}
106
+ <span class="caption" in:fade={{ duration: durations.short4 }}>
107
+ <span class="name">{file.name}</span>
108
+ <span class="detail">{fileSize(file.size)}</span>
109
+ </span>
110
+ {/if}
111
+ </div>
112
+
113
+ <style>
114
+ .thumb {
115
+ display: flex;
116
+ flex-direction: column;
117
+ gap: var(--space-1);
118
+ width: fit-content;
119
+ max-width: 100%;
120
+ }
121
+ /* One box for every state: a pill drawn as .btn is, a dashed add tile, or the thumbnail. lib/morph animates its size
122
+ between them and these transitions the rest. */
123
+ .tile {
124
+ position: relative;
125
+ display: flex;
126
+ min-width: 0;
127
+ border: 1px solid var(--line-strong);
128
+ background: var(--control-1);
129
+ color: var(--fg);
130
+ transition:
131
+ border-radius var(--dur) var(--ease-out),
132
+ border-color var(--dur) var(--ease-out),
133
+ background-color var(--dur) var(--ease-out),
134
+ box-shadow var(--dur) var(--ease-out),
135
+ color var(--dur) var(--ease-out);
136
+ }
137
+ .pill {
138
+ min-height: 28px;
139
+ border-radius: var(--r-sm);
140
+ box-shadow: var(--shadow-btn);
141
+ }
142
+ .square,
143
+ .filled {
144
+ width: 96px;
145
+ height: 96px;
146
+ border-radius: var(--r);
147
+ }
148
+ .square {
149
+ border: 2px dashed var(--line-strong);
150
+ }
151
+ .filled {
152
+ background: var(--control-3);
153
+ }
154
+ .main {
155
+ display: flex;
156
+ flex: 1;
157
+ align-items: center;
158
+ gap: 6px;
159
+ min-width: 0;
160
+ margin: 0;
161
+ padding: 0 11px;
162
+ border: 0;
163
+ border-radius: inherit;
164
+ background: none;
165
+ color: inherit;
166
+ font: inherit;
167
+ font-size: 12px;
168
+ font-weight: var(--w-medium);
169
+ line-height: 14px;
170
+ white-space: nowrap;
171
+ }
172
+ .square .main {
173
+ flex-direction: column;
174
+ justify-content: center;
175
+ gap: var(--space-1);
176
+ padding: var(--space-2);
177
+ text-align: center;
178
+ white-space: normal;
179
+ }
180
+ .filled .main {
181
+ padding: 0;
182
+ }
183
+ button.main {
184
+ cursor: pointer;
185
+ }
186
+ button.main:disabled {
187
+ cursor: default;
188
+ }
189
+ .main > :global(.icon) {
190
+ color: var(--muted);
191
+ transition: color var(--dur) var(--ease-out);
192
+ }
193
+ .empty:has(> button.main:hover:not(:disabled)) {
194
+ background: var(--control-3);
195
+ }
196
+ .empty:has(> button.main:hover:not(:disabled)) .main > :global(.icon) {
197
+ color: inherit;
198
+ }
199
+ .empty:has(> button.main:active:not(:disabled)) {
200
+ background: var(--control-4);
201
+ }
202
+ img {
203
+ display: block;
204
+ width: 100%;
205
+ height: 100%;
206
+ border-radius: calc(var(--r) - 1px);
207
+ object-fit: cover;
208
+ transition: opacity var(--dur) var(--ease-out);
209
+ }
210
+ .filled:has(> button.main:hover:not(:disabled)) img {
211
+ opacity: 0.85;
212
+ }
213
+ /* On a solid disc with a hairline, so it reads over any picture. */
214
+ .clear {
215
+ position: absolute;
216
+ top: var(--space-1);
217
+ right: var(--space-1);
218
+ display: inline-grid;
219
+ place-items: center;
220
+ width: 24px;
221
+ height: 24px;
222
+ padding: 0;
223
+ border: 1px solid var(--line-strong);
224
+ border-radius: var(--r-pill);
225
+ background: var(--surface);
226
+ color: var(--fg-2);
227
+ cursor: pointer;
228
+ transition:
229
+ background-color var(--dur) var(--ease-out),
230
+ color var(--dur) var(--ease-out);
231
+ }
232
+ .clear:hover:not(:disabled) {
233
+ background: linear-gradient(var(--control-4), var(--control-4)), var(--surface);
234
+ color: var(--fg);
235
+ }
236
+ .clear:disabled {
237
+ cursor: default;
238
+ }
239
+ .caption {
240
+ display: grid;
241
+ width: 96px;
242
+ }
243
+ .caption > span {
244
+ overflow: clip;
245
+ text-overflow: ellipsis;
246
+ white-space: nowrap;
247
+ }
248
+ .name {
249
+ color: var(--fg-2);
250
+ font-size: 12px;
251
+ }
252
+ .detail {
253
+ color: var(--muted);
254
+ font-family: var(--font-data);
255
+ font-size: 11px;
256
+ font-variant-numeric: tabular-nums;
257
+ }
258
+ .dragging {
259
+ border-color: var(--accent);
260
+ background: var(--accent-soft);
261
+ }
262
+ .tile:has(> .main:global([aria-invalid='true'])) {
263
+ border-color: var(--danger);
264
+ }
265
+ .disabled {
266
+ opacity: 0.5;
267
+ box-shadow: none;
268
+ }
269
+ @media (pointer: coarse) {
270
+ .pill {
271
+ min-height: 44px;
272
+ }
273
+ }
274
+ </style>
@@ -0,0 +1,101 @@
1
+ export default Thumb;
2
+ type Thumb = {
3
+ $on?(type: string, callback: (e: any) => void): () => void;
4
+ $set?(props: Partial<Props>): void;
5
+ };
6
+ declare const Thumb: import("svelte").Component<{
7
+ /**
8
+ * the image, or null while empty
9
+ */
10
+ file: File | null;
11
+ /**
12
+ * the empty state's text
13
+ */
14
+ label?: string | undefined;
15
+ /**
16
+ * the empty state's icon
17
+ */
18
+ icon?: string | undefined;
19
+ /**
20
+ * empty, a thumbnail-sized tile instead of a pill
21
+ */
22
+ square?: boolean | undefined;
23
+ /**
24
+ * opens the picker; left out, the thumbnail is not a button
25
+ */
26
+ onpick?: (() => void) | undefined;
27
+ /**
28
+ * adds the ✕
29
+ */
30
+ onclear?: (() => void) | undefined;
31
+ disabled?: boolean | undefined;
32
+ /**
33
+ * files are dragged over its drop target
34
+ */
35
+ dragging?: boolean | undefined;
36
+ /**
37
+ * on the button
38
+ */
39
+ id?: string | undefined;
40
+ /**
41
+ * the id of its error message, while there is one
42
+ */
43
+ errorId?: string | false | undefined;
44
+ /**
45
+ * the button (bindable)
46
+ */
47
+ main?: HTMLButtonElement | undefined;
48
+ }, {}, "main">;
49
+ /**
50
+ * Internal to Upload (Upload.Image, Upload.Images): an image picker's tile, empty or holding its image. Empty, it is a
51
+ * pill like .btn (an icon and `label`), or with `square` a dashed tile the size of a thumbnail with the icon over the
52
+ * label (the add tile ending a grid). Holding an image, the same box reshapes (lib/morph.svelte.js) into a square
53
+ * thumbnail of it, cropped to fill, with a ✕ in its corner and the name and size under it. Pressing the thumbnail opens
54
+ * the picker again to replace the image, unless `onpick` is left out (a thumbnail in a grid, which only clears).
55
+ * Delete or Backspace on it clears it too. The tooltips of both buttons name the image in full, since the caption may
56
+ * cut its name short. The button stays the same element throughout, so it keeps the focus, and
57
+ * the ✕ hands the focus back to it.
58
+ */
59
+ type Props = {
60
+ /**
61
+ * the image, or null while empty
62
+ */
63
+ file: File | null;
64
+ /**
65
+ * the empty state's text
66
+ */
67
+ label?: string | undefined;
68
+ /**
69
+ * the empty state's icon
70
+ */
71
+ icon?: string | undefined;
72
+ /**
73
+ * empty, a thumbnail-sized tile instead of a pill
74
+ */
75
+ square?: boolean | undefined;
76
+ /**
77
+ * opens the picker; left out, the thumbnail is not a button
78
+ */
79
+ onpick?: (() => void) | undefined;
80
+ /**
81
+ * adds the ✕
82
+ */
83
+ onclear?: (() => void) | undefined;
84
+ disabled?: boolean | undefined;
85
+ /**
86
+ * files are dragged over its drop target
87
+ */
88
+ dragging?: boolean | undefined;
89
+ /**
90
+ * on the button
91
+ */
92
+ id?: string | undefined;
93
+ /**
94
+ * the id of its error message, while there is one
95
+ */
96
+ errorId?: string | false | undefined;
97
+ /**
98
+ * the button (bindable)
99
+ */
100
+ main?: HTMLButtonElement | undefined;
101
+ };
@@ -0,0 +1,123 @@
1
+ <script>
2
+ import { getContext } from 'svelte'
3
+ import FileCard from './FileCard.svelte'
4
+ import ErrorMessage from '../ErrorMessage.svelte'
5
+ import { rejection, fileFormat } from './common.js'
6
+ import { accepts, droppedFiles, fileDrop, fileSize } from '../../lib/files.js'
7
+ import { announce } from '../../lib/announce.js'
8
+ import { UPLOAD_ZONE } from './context.js'
9
+ /**
10
+ * One file, picked or dropped. The button becomes the file: once one is chosen it reshapes into a card with the file's
11
+ * name and size, which opens the picker again to replace it, and a ✕ that clears it. Import it as Upload.File
12
+ * (components/upload/index.js).
13
+ *
14
+ * <Upload.File bind:file accept=".pdf" />
15
+ * <Upload.File label="Attach the contract" onchange={(file) => save(file)} error={form.errors.contract} />
16
+ *
17
+ * file: the chosen File, or null (bindable). onchange(file): after a pick, a drop or a clear.
18
+ * label: the button's text while empty (default "Choose file"). accept: as on a file input ('.pdf,image/*'). Dropped
19
+ * files are held to it too; a drop with nothing that fits says so under the control. id: on the button, for a
20
+ * <label for>. disabled. error: a message from the app: the control turns red and shows it in a bubble underneath.
21
+ * Other attributes (class…) and attachments go to the wrapping <div>, which is also where files can be dropped.
22
+ *
23
+ * Keyboard: Enter or Space opens the picker (to replace the file, once there is one); Delete or Backspace clears it.
24
+ * Tab reaches the ✕, which clears it and puts the focus back on the button.
25
+ *
26
+ * @typedef {object} Props
27
+ * @property {File | null} [file]
28
+ * @property {(file: File | null) => void} [onchange]
29
+ * @property {string} [label]
30
+ * @property {string} [accept]
31
+ * @property {string} [id]
32
+ * @property {boolean} [disabled]
33
+ * @property {string} [error]
34
+ */
35
+ /** @type {Props & Omit<import('svelte/elements').HTMLAttributes<HTMLDivElement>, keyof Props>} */
36
+ let { file = $bindable(null), onchange, label = 'Choose file', accept = '', id, disabled = false, error = '', class: className, ...rest } = $props()
37
+
38
+ const uid = $props.id()
39
+ /** @type {HTMLInputElement | undefined} */
40
+ let input = $state()
41
+ /** @type {HTMLButtonElement | undefined} */
42
+ let main = $state()
43
+ let dragging = $state(false)
44
+ let rejected = $state('')
45
+ const problem = $derived(error || rejected)
46
+
47
+ // Inside an Upload.Zone, the zone takes the drops and hands them here.
48
+ /** @type {import('./context.js').UploadZoneContext | undefined} */
49
+ const zone = getContext(UPLOAD_ZONE)
50
+ $effect(() => {
51
+ if (zone && !disabled) return zone.register(ondrop, 'Drop a file here')
52
+ })
53
+
54
+ const item = $derived(file && { name: file.name, detail: fileSize(file.size), icon: 'fileBlank', ...fileFormat(file.name) })
55
+
56
+ /** @param {File | null} next */
57
+ function choose(next) {
58
+ rejected = ''
59
+ if (next === file) return
60
+ const had = file
61
+ file = next
62
+ onchange?.(next)
63
+ announce(next ? `${next.name} added` : `${had?.name} removed`)
64
+ }
65
+
66
+ /** @param {import('../../lib/files.js').Dropped} drop */
67
+ function ondrop(drop) {
68
+ if (disabled) return
69
+ const files = droppedFiles(drop)
70
+ const fit = files.find((candidate) => accepts(candidate, accept))
71
+ if (fit) choose(fit)
72
+ else rejected = rejection(accept, files.length > 0)
73
+ }
74
+ </script>
75
+
76
+ <div class={['upload', className]} {...rest} {@attach fileDrop({ ondrop, ondragging: (over) => (dragging = over), disabled: disabled || !!zone })}>
77
+ <FileCard
78
+ bind:main
79
+ {item}
80
+ {label}
81
+ onpick={() => input?.click()}
82
+ onclear={() => choose(null)}
83
+ {disabled}
84
+ dragging={dragging || !!zone?.dragging}
85
+ {id}
86
+ errorId={!!problem && `${uid}-error`}
87
+ />
88
+ <!-- Closing the file chooser fires a cancel event that bubbles: inside a <dialog> it would close the dialog too. -->
89
+ <input
90
+ bind:this={input}
91
+ type="file"
92
+ {accept}
93
+ hidden
94
+ onchange={(event) => {
95
+ const [picked] = event.currentTarget.files ?? []
96
+ event.currentTarget.value = ''
97
+ if (picked) choose(picked)
98
+ }}
99
+ oncancel={(event) => event.stopPropagation()}
100
+ />
101
+ <ErrorMessage
102
+ floating
103
+ id="{uid}-error"
104
+ message={problem}
105
+ ondismiss={() => {
106
+ rejected = ''
107
+ main?.focus()
108
+ }}
109
+ />
110
+ </div>
111
+
112
+ <style>
113
+ /* As wide as what it shows, so the drop target is the control and not the row it sits in. Positioned, for the
114
+ error bubble hanging under it. */
115
+ .upload {
116
+ position: relative;
117
+ display: flex;
118
+ flex-direction: column;
119
+ align-items: flex-start;
120
+ width: fit-content;
121
+ max-width: 100%;
122
+ }
123
+ </style>
@@ -0,0 +1,48 @@
1
+ export default UploadFile;
2
+ type UploadFile = {
3
+ $on?(type: string, callback: (e: any) => void): () => void;
4
+ $set?(props: Partial<Props & Omit<HTMLAttributes<HTMLDivElement>, keyof Props>>): void;
5
+ };
6
+ declare const UploadFile: import("svelte").Component<{
7
+ file?: File | null | undefined;
8
+ onchange?: ((file: File | null) => void) | undefined;
9
+ label?: string | undefined;
10
+ accept?: string | undefined;
11
+ id?: string | undefined;
12
+ disabled?: boolean | undefined;
13
+ error?: string | undefined;
14
+ } & Omit<import("svelte/elements").HTMLAttributes<HTMLDivElement>, keyof {
15
+ file?: File | null | undefined;
16
+ onchange?: ((file: File | null) => void) | undefined;
17
+ label?: string | undefined;
18
+ accept?: string | undefined;
19
+ id?: string | undefined;
20
+ disabled?: boolean | undefined;
21
+ error?: string | undefined;
22
+ }>, {}, "file">;
23
+ /**
24
+ * One file, picked or dropped. The button becomes the file: once one is chosen it reshapes into a card with the file's
25
+ * name and size, which opens the picker again to replace it, and a ✕ that clears it. Import it as Upload.File
26
+ * (components/upload/index.js).
27
+ *
28
+ * <Upload.File bind:file accept=".pdf" />
29
+ * <Upload.File label="Attach the contract" onchange={(file) => save(file)} error={form.errors.contract} />
30
+ *
31
+ * file: the chosen File, or null (bindable). onchange(file): after a pick, a drop or a clear.
32
+ * label: the button's text while empty (default "Choose file"). accept: as on a file input ('.pdf,image/*'). Dropped
33
+ * files are held to it too; a drop with nothing that fits says so under the control. id: on the button, for a
34
+ * <label for>. disabled. error: a message from the app: the control turns red and shows it in a bubble underneath.
35
+ * Other attributes (class…) and attachments go to the wrapping <div>, which is also where files can be dropped.
36
+ *
37
+ * Keyboard: Enter or Space opens the picker (to replace the file, once there is one); Delete or Backspace clears it.
38
+ * Tab reaches the ✕, which clears it and puts the focus back on the button.
39
+ */
40
+ type Props = {
41
+ file?: File | null | undefined;
42
+ onchange?: ((file: File | null) => void) | undefined;
43
+ label?: string | undefined;
44
+ accept?: string | undefined;
45
+ id?: string | undefined;
46
+ disabled?: boolean | undefined;
47
+ error?: string | undefined;
48
+ };