@xerios/design-system 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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 +178 -0
  8. package/dist/components/Button.svelte.d.ts +58 -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 +342 -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 +104 -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 +153 -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 +76 -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 +892 -0
  162. package/dist/css/base.css +333 -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,247 @@
1
+ <script>
2
+ /**
3
+ * The field the date pickers share: a label, a box holding the picker's typed inputs (DateInput), a clear button while
4
+ * there is a value, a calendar button that opens a panel under the box, and the error bubble. DatePicker and
5
+ * DateRangePicker put a Calendar in the panel; use those.
6
+ *
7
+ * <DateField bind:this={field} {id} {label} bind:open {onopen} hasValue={!!value} onclear={() => (value = '')} {error}>
8
+ * {#snippet inputs()}<DateInput bind:value {id} onopen={() => field.show()} … />{/snippet}
9
+ * {#snippet panel(close)}<Calendar … onpick={(day) => ((value = day), close())} />{/snippet}
10
+ * </DateField>
11
+ *
12
+ * id: the first input's (the label points at it). open (bindable). onopen(): runs as it opens (set the calendar on the
13
+ * value). show(focus = true): opens it and, with focus, moves the focus onto the calendar (an input's ArrowDown);
14
+ * a click in an input opens it without, so typing carries on. hasValue + onclear: the clear button. panel(close): the panel's
15
+ * content; close() shuts it and puts the focus back on the calendar button. calendarLabel: that button's name
16
+ * ("Choose a date"). error, info, note, hideLabel, disabled: as on the other fields. Other attributes and attachments go to
17
+ * the field's wrapper.
18
+ * Keyboard: the calendar button or ArrowDown in an input opens the panel with the focus in it; a click in an input opens
19
+ * it too, leaving the focus there; Esc closes it; tabbing out of the field (or the panel) closes it.
20
+ */
21
+ import { tick } from 'svelte'
22
+ import Icon from '../Icon.svelte'
23
+ import ErrorMessage from '../ErrorMessage.svelte'
24
+ import FieldLabel from './FieldLabel.svelte'
25
+ import { topLayer } from '../../lib/dom.js'
26
+ import { pop } from '../../lib/motion.js'
27
+ import { tooltip } from '../../lib/tooltip.js'
28
+
29
+ /**
30
+ * @typedef {object} Props
31
+ * @property {string} id
32
+ * @property {string} label
33
+ * @property {boolean} [open] bindable
34
+ * @property {() => void} [onopen]
35
+ * @property {boolean} [hasValue]
36
+ * @property {() => void} [onclear]
37
+ * @property {string} [calendarLabel]
38
+ * @property {boolean} [hideLabel]
39
+ * @property {string} [error]
40
+ * @property {string} [info]
41
+ * @property {string} [note] dimmed text after the label, e.g. '(optional)'
42
+ * @property {boolean} [disabled]
43
+ * @property {import('svelte').Snippet} inputs
44
+ * @property {import('svelte').Snippet<[() => void]>} panel
45
+ */
46
+ /** @type {Props & Omit<import('svelte/elements').HTMLAttributes<HTMLDivElement>, keyof Props>} */
47
+ let {
48
+ id,
49
+ label,
50
+ open = $bindable(false),
51
+ onopen,
52
+ hasValue = false,
53
+ onclear,
54
+ calendarLabel = 'Choose a date',
55
+ hideLabel = false,
56
+ error = '',
57
+ info = '',
58
+ note = '',
59
+ disabled = false,
60
+ class: className,
61
+ inputs,
62
+ panel,
63
+ ...rest
64
+ } = $props()
65
+
66
+ const uid = $props.id()
67
+ const anchor = `--date-${uid}`
68
+ /** @type {HTMLButtonElement | undefined} */
69
+ let button = $state()
70
+ /** @type {HTMLDivElement | undefined} */
71
+ let box = $state()
72
+ /** @type {HTMLDivElement | undefined} */
73
+ let sheet = $state()
74
+
75
+ /**
76
+ * Opens the panel (if it isn't) and, with `focus`, moves the focus into it: onto its focus day (the element with
77
+ * tabindex 0, or [data-autofocus]). A click in a typed input opens it without, so typing carries on.
78
+ * @param {boolean} [focus]
79
+ */
80
+ export async function show(focus = true) {
81
+ if (disabled) return
82
+ if (!open) {
83
+ onopen?.()
84
+ open = true
85
+ }
86
+ if (!focus) return
87
+ await tick()
88
+ const target = /** @type {HTMLElement | null | undefined} */ (sheet?.querySelector('[data-autofocus], [tabindex="0"]'))
89
+ target?.focus()
90
+ }
91
+ async function close(refocus = true) {
92
+ open = false
93
+ if (refocus) {
94
+ await tick()
95
+ button?.focus()
96
+ }
97
+ }
98
+
99
+ /** @param {KeyboardEvent} e */
100
+ function onPanelKey(e) {
101
+ if (e.key !== 'Escape') return
102
+ e.preventDefault()
103
+ e.stopPropagation()
104
+ void close()
105
+ }
106
+ /** Leaving the field with the focus still in the box (the panel open without it) closes the panel too. @param {FocusEvent} e */
107
+ function onBoxFocusOut(e) {
108
+ const to = /** @type {Node | null} */ (e.relatedTarget)
109
+ if (open && to && !sheet?.contains(to) && !box?.contains(to)) void close(false)
110
+ }
111
+ /** Esc in the box (an input) closes an open panel; the focus stays where it is. @param {KeyboardEvent} e */
112
+ function onBoxKey(e) {
113
+ if (e.key !== 'Escape' || !open || e.defaultPrevented) return
114
+ e.preventDefault()
115
+ e.stopPropagation()
116
+ void close(false)
117
+ }
118
+ /** Tabbing out of the panel closes it. @param {FocusEvent} e */
119
+ function onfocusout(e) {
120
+ const to = /** @type {Node | null} */ (e.relatedTarget)
121
+ if (to && !sheet?.contains(to) && !box?.contains(to)) void close(false)
122
+ }
123
+ /** A press outside the field and its panel closes it. @param {PointerEvent} e */
124
+ const outside = (e) => {
125
+ const target = /** @type {Element} */ (e.target)
126
+ if (open && !sheet?.contains(target) && !box?.contains(target) && !target.closest?.(`label[for="${id}"]`)) void close(false)
127
+ }
128
+ </script>
129
+
130
+ <svelte:document onpointerdowncapture={outside} />
131
+
132
+ <div class={['field', className]} {...rest}>
133
+ <FieldLabel for={id} id="{id}-label" {label} {note} {info} {hideLabel} />
134
+ <!-- The keys and focus are its inputs'; the box only listens for Esc and for the focus leaving. -->
135
+ <!-- svelte-ignore a11y_no_static_element_interactions -->
136
+ <div bind:this={box} class="box field-box" class:disabled style:anchor-name={anchor} onfocusout={onBoxFocusOut} onkeydown={onBoxKey}>
137
+ {@render inputs()}
138
+ <!-- Kept in place while there is nothing to clear (hidden and disabled), so the field doesn't change width as a value
139
+ comes and goes. -->
140
+ {#if onclear}
141
+ <button
142
+ type="button"
143
+ class="tool"
144
+ class:hidden={!hasValue || disabled}
145
+ disabled={!hasValue || disabled}
146
+ aria-label="Clear {label}"
147
+ {@attach tooltip('Clear')}
148
+ onclick={() => (onclear(), box?.querySelector('input')?.focus())}><Icon name="x" size="sm" /></button
149
+ >
150
+ {/if}
151
+ <button
152
+ bind:this={button}
153
+ type="button"
154
+ class="tool"
155
+ {disabled}
156
+ aria-label="{calendarLabel}, {label}"
157
+ aria-haspopup="dialog"
158
+ aria-expanded={open}
159
+ {@attach tooltip(calendarLabel)}
160
+ onclick={() => (open ? close() : show(true))}><Icon name="calendar" size="sm" /></button
161
+ >
162
+ </div>
163
+ {#if open}
164
+ <div
165
+ bind:this={sheet}
166
+ class="panel"
167
+ role="dialog"
168
+ aria-label={label}
169
+ tabindex="-1"
170
+ data-floating
171
+ style:position-anchor={anchor}
172
+ {@attach topLayer(button)}
173
+ transition:pop={{ from: box }}
174
+ onkeydown={onPanelKey}
175
+ {onfocusout}
176
+ >
177
+ {@render panel(() => void close())}
178
+ </div>
179
+ {/if}
180
+ <ErrorMessage floating id="{id}-error" message={error} ondismiss={() => box?.querySelector('input')?.focus()} />
181
+ </div>
182
+
183
+ <style>
184
+ .field {
185
+ position: relative;
186
+ display: flex;
187
+ flex-direction: column;
188
+ gap: 3px;
189
+ min-width: 0;
190
+ }
191
+ .box {
192
+ display: flex;
193
+ align-items: center;
194
+ gap: 2px;
195
+ min-height: 32px;
196
+ padding-inline: var(--space-1);
197
+ }
198
+ .box.disabled {
199
+ opacity: 0.5;
200
+ }
201
+ .tool {
202
+ display: inline-grid;
203
+ place-items: center;
204
+ flex: none;
205
+ width: 24px;
206
+ height: 24px;
207
+ padding: 0;
208
+ border: 0;
209
+ border-radius: 50%;
210
+ background: none;
211
+ color: var(--muted);
212
+ }
213
+ .tool.hidden {
214
+ visibility: hidden;
215
+ }
216
+ .tool:hover:not(:disabled),
217
+ .tool[aria-expanded='true'] {
218
+ background: var(--control-3);
219
+ color: var(--fg-2);
220
+ }
221
+ /* Anchored under the field, flipping above or to its other side when there's no room. */
222
+ .panel {
223
+ position: fixed;
224
+ z-index: calc(var(--z-overlay) + 1);
225
+ position-area: block-end span-inline-end;
226
+ position-try-fallbacks:
227
+ flip-block,
228
+ flip-inline,
229
+ flip-block flip-inline;
230
+ position-visibility: anchors-visible;
231
+ /* A touch to the left of the field, so the list's text lines up under the field's own (mirrored when it flips to
232
+ end at the field's right edge: a flip swaps the inline margins too). */
233
+ margin-inline-start: calc(var(--space-1) * -1);
234
+ margin-block: 4px;
235
+ padding: var(--space-3);
236
+ border: 1px solid var(--line-float);
237
+ border-radius: var(--r-lg);
238
+ background: var(--elevated);
239
+ box-shadow: var(--shadow);
240
+ color: var(--fg);
241
+ }
242
+ @media (forced-colors: active) {
243
+ .panel {
244
+ border-color: CanvasText;
245
+ }
246
+ }
247
+ </style>
@@ -0,0 +1,74 @@
1
+ export default DateField;
2
+ type DateField = {
3
+ $on?(type: string, callback: (e: any) => void): () => void;
4
+ $set?(props: Partial<Props & Omit<HTMLAttributes<HTMLDivElement>, keyof Props>>): void;
5
+ } & {
6
+ show: (focus?: boolean | undefined) => Promise<void>;
7
+ };
8
+ declare const DateField: import("svelte").Component<{
9
+ id: string;
10
+ label: string;
11
+ /**
12
+ * bindable
13
+ */
14
+ open?: boolean | undefined;
15
+ onopen?: (() => void) | undefined;
16
+ hasValue?: boolean | undefined;
17
+ onclear?: (() => void) | undefined;
18
+ calendarLabel?: string | undefined;
19
+ hideLabel?: boolean | undefined;
20
+ error?: string | undefined;
21
+ info?: string | undefined;
22
+ /**
23
+ * dimmed text after the label, e.g. '(optional)'
24
+ */
25
+ note?: string | undefined;
26
+ disabled?: boolean | undefined;
27
+ inputs: import("svelte").Snippet;
28
+ panel: import("svelte").Snippet<[() => void]>;
29
+ } & Omit<import("svelte/elements").HTMLAttributes<HTMLDivElement>, keyof {
30
+ id: string;
31
+ label: string;
32
+ /**
33
+ * bindable
34
+ */
35
+ open?: boolean | undefined;
36
+ onopen?: (() => void) | undefined;
37
+ hasValue?: boolean | undefined;
38
+ onclear?: (() => void) | undefined;
39
+ calendarLabel?: string | undefined;
40
+ hideLabel?: boolean | undefined;
41
+ error?: string | undefined;
42
+ info?: string | undefined;
43
+ /**
44
+ * dimmed text after the label, e.g. '(optional)'
45
+ */
46
+ note?: string | undefined;
47
+ disabled?: boolean | undefined;
48
+ inputs: import("svelte").Snippet;
49
+ panel: import("svelte").Snippet<[() => void]>;
50
+ }>, {
51
+ show: (focus?: boolean) => Promise<void>;
52
+ }, "open">;
53
+ type Props = {
54
+ id: string;
55
+ label: string;
56
+ /**
57
+ * bindable
58
+ */
59
+ open?: boolean | undefined;
60
+ onopen?: (() => void) | undefined;
61
+ hasValue?: boolean | undefined;
62
+ onclear?: (() => void) | undefined;
63
+ calendarLabel?: string | undefined;
64
+ hideLabel?: boolean | undefined;
65
+ error?: string | undefined;
66
+ info?: string | undefined;
67
+ /**
68
+ * dimmed text after the label, e.g. '(optional)'
69
+ */
70
+ note?: string | undefined;
71
+ disabled?: boolean | undefined;
72
+ inputs: import("svelte").Snippet;
73
+ panel: import("svelte").Snippet<[() => void]>;
74
+ };
@@ -0,0 +1,118 @@
1
+ <script>
2
+ /**
3
+ * A typed day, the text part of DatePicker and DateRangePicker (use those). It shows the value as DD/MM/YYYY
4
+ * ('18/11/2026') and reads what is typed when the field is left or Enter is pressed: that form with any
5
+ * separators, two-digit years, or ISO ('2026-11-18'). See lib/dates.js.
6
+ *
7
+ * <DateInput bind:value {id} {min} {max} errorId={problem && `${id}-error`} onopen={openCalendar} onproblem={(m) => (problem = m)} />
8
+ *
9
+ * value (bindable): the ISO day, '' for none. min, max: the range a typed day must fall in. allowed: the only days
10
+ * it may be (or null for any).
11
+ * onproblem(message): what is wrong with what was typed ('' once it reads); the picker shows it as the field's error.
12
+ * onopen(focus): asks for the calendar: a click does (focus false: typing carries on), and ArrowDown does with the
13
+ * focus moving onto it (focus true). errorId: as the invalid attachment's.
14
+ * Esc puts back the value's text after an edit. Other attributes (aria-labelledby, placeholder…) go to the <input>.
15
+ */
16
+ import { composing } from '../../lib/dom.js'
17
+ import { invalid } from '../../lib/invalid.js'
18
+ import { formatDay, formatInput, inputFormat, parseInput, within } from '../../lib/dates.js'
19
+
20
+ /**
21
+ * @typedef {object} Props
22
+ * @property {string} [value] bindable
23
+ * @property {string} id
24
+ * @property {string | null} [min]
25
+ * @property {string | null} [max]
26
+ * @property {string[] | null} [allowed]
27
+ * @property {string | false | null | undefined} [errorId]
28
+ * @property {(focus: boolean) => void} [onopen]
29
+ * @property {(message: string) => void} [onproblem]
30
+ */
31
+ /** @type {Props & Omit<import('svelte/elements').HTMLInputAttributes, keyof Props>} */
32
+ let { value = $bindable(''), id, min = null, max = null, allowed = null, errorId, onopen, onproblem, placeholder, ...rest } = $props()
33
+
34
+ const format = inputFormat()
35
+ // As wide as a date takes (the format, or a longer placeholder), in the data font's even-width characters: an input
36
+ // with no width set takes the browser's default of about 20 characters, far wider than a date.
37
+ const chars = $derived(Math.max(format.placeholder.length, (placeholder ?? '').length))
38
+
39
+ /** Attachment: the format as the placeholder, set in the browser: the server's locale may write dates another way,
40
+ * and a placeholder rendered there would stay (hydration keeps attributes as they came). @param {HTMLInputElement} node */
41
+ function showFormat(node) {
42
+ node.placeholder = placeholder ?? inputFormat().placeholder
43
+ }
44
+ // The text in the box: the value's, until it is edited (a writable derived: picking a day elsewhere resets it).
45
+ let text = $derived(value ? formatInput(value) : '')
46
+
47
+ /** Reads what was typed; a day that reads becomes the value, anything else is reported and left to fix. */
48
+ function commit() {
49
+ const typed = text.trim()
50
+ if (!typed) {
51
+ onproblem?.('')
52
+ if (value) value = ''
53
+ return
54
+ }
55
+ const day = parseInput(typed)
56
+ if (!day) return onproblem?.(`Enter a date as ${format.placeholder}.`)
57
+ if (!within(day, min, max)) {
58
+ const range =
59
+ min && max ? `from ${formatDay(min)} to ${formatDay(max)}` : min ? `from ${formatDay(min)} on` : `up to ${formatDay(/** @type {string} */ (max))}`
60
+ return onproblem?.(`Pick a day ${range}.`)
61
+ }
62
+ if (allowed && !allowed.includes(day)) return onproblem?.(`${formatDay(day)} isn't available. Pick a day from the calendar.`)
63
+ onproblem?.('')
64
+ value = day
65
+ text = formatInput(day)
66
+ }
67
+
68
+ /** @param {KeyboardEvent} e */
69
+ function onkeydown(e) {
70
+ // Enter and Esc inside an IME composition belong to the input method.
71
+ if (composing(e)) return
72
+ if (e.key === 'Enter') commit()
73
+ else if (e.key === 'ArrowDown') {
74
+ e.preventDefault()
75
+ onopen?.(true)
76
+ } else if (e.key === 'Escape' && text !== (value ? formatInput(value) : '')) {
77
+ e.preventDefault()
78
+ e.stopPropagation()
79
+ text = value ? formatInput(value) : ''
80
+ onproblem?.('')
81
+ }
82
+ }
83
+ </script>
84
+
85
+ <input
86
+ {id}
87
+ type="text"
88
+ bind:value={text}
89
+ autocomplete="off"
90
+ spellcheck="false"
91
+ {...rest}
92
+ style:--chars={chars}
93
+ {@attach invalid(errorId)}
94
+ {@attach showFormat}
95
+ onblur={commit}
96
+ onclick={() => onopen?.(false)}
97
+ {onkeydown}
98
+ />
99
+
100
+ <style>
101
+ /* Sized to a date (plus a character for the caret), growing when the field around it is stretched wider. */
102
+ input {
103
+ flex: 1 1 auto;
104
+ width: calc((var(--chars) + 1) * 1ch + 2 * var(--space-2));
105
+ min-width: 0;
106
+ min-height: 30px;
107
+ padding: 0 var(--space-2);
108
+ border: 0;
109
+ background: none;
110
+ color: var(--fg);
111
+ font: 400 13px var(--font-data);
112
+ font-variant-numeric: tabular-nums;
113
+ outline: none;
114
+ }
115
+ input::placeholder {
116
+ color: var(--faint);
117
+ }
118
+ </style>
@@ -0,0 +1,43 @@
1
+ export default DateInput;
2
+ type DateInput = {
3
+ $on?(type: string, callback: (e: any) => void): () => void;
4
+ $set?(props: Partial<Props & Omit<HTMLInputAttributes, keyof Props>>): void;
5
+ };
6
+ declare const DateInput: import("svelte").Component<{
7
+ /**
8
+ * bindable
9
+ */
10
+ value?: string | undefined;
11
+ id: string;
12
+ min?: string | null | undefined;
13
+ max?: string | null | undefined;
14
+ allowed?: string[] | null | undefined;
15
+ errorId?: string | false | null | undefined;
16
+ onopen?: ((focus: boolean) => void) | undefined;
17
+ onproblem?: ((message: string) => void) | undefined;
18
+ } & Omit<import("svelte/elements").HTMLInputAttributes, keyof {
19
+ /**
20
+ * bindable
21
+ */
22
+ value?: string | undefined;
23
+ id: string;
24
+ min?: string | null | undefined;
25
+ max?: string | null | undefined;
26
+ allowed?: string[] | null | undefined;
27
+ errorId?: string | false | null | undefined;
28
+ onopen?: ((focus: boolean) => void) | undefined;
29
+ onproblem?: ((message: string) => void) | undefined;
30
+ }>, {}, "value">;
31
+ type Props = {
32
+ /**
33
+ * bindable
34
+ */
35
+ value?: string | undefined;
36
+ id: string;
37
+ min?: string | null | undefined;
38
+ max?: string | null | undefined;
39
+ allowed?: string[] | null | undefined;
40
+ errorId?: string | false | null | undefined;
41
+ onopen?: ((focus: boolean) => void) | undefined;
42
+ onproblem?: ((message: string) => void) | undefined;
43
+ };
@@ -0,0 +1,102 @@
1
+ <script>
2
+ /**
3
+ * One date: typed, or picked from a calendar under the field.
4
+ *
5
+ * <DatePicker bind:value={due} id="due" label="Due date" min={today()} />
6
+ *
7
+ * value (bindable): an ISO day ('2026-11-18'), or '' for none. min, max: the first and last day allowed.
8
+ * allowed: the only days that can be chosen (ISO days), or null for any; the calendar strikes out the rest and opens
9
+ * on the nearest one, and typing another is the field's error.
10
+ * Typing: DD/MM/YYYY ('18/11/2026'; the placeholder shows it), with any separators, two-digit years or
11
+ * ISO; read when the field is left or Enter is pressed. Something that doesn't read, or falls outside min / max, is
12
+ * the field's error until fixed (Esc puts the value back). placeholder: in place of the format.
13
+ * clearable (default true): a ✕ to empty it. error, info, note, hideLabel, disabled: as on the other fields.
14
+ * A click in the field opens the calendar under it (the focus stays, so typing carries on). Keyboard: ArrowDown in the
15
+ * field, or the calendar button, opens it with the focus on the value (or today); arrows move
16
+ * by day and week, PageUp / PageDown by month (Shift: year), Enter picks and closes, Esc closes.
17
+ * Other attributes and attachments go to the field's wrapper.
18
+ */
19
+ import Calendar from './Calendar.svelte'
20
+ import DateField from './DateField.svelte'
21
+ import DateInput from './DateInput.svelte'
22
+ import { clamp, monthOf, nearest, today, within } from '../../lib/dates.js'
23
+
24
+ /**
25
+ * @typedef {object} Props
26
+ * @property {string} [value] bindable
27
+ * @property {string} id
28
+ * @property {string} label
29
+ * @property {string | null} [min]
30
+ * @property {string | null} [max]
31
+ * @property {string[] | null} [allowed]
32
+ * @property {string} [placeholder]
33
+ * @property {boolean} [clearable]
34
+ * @property {boolean} [hideLabel]
35
+ * @property {string} [error]
36
+ * @property {string} [info]
37
+ * @property {string} [note] dimmed text after the label, e.g. '(optional)'
38
+ * @property {boolean} [disabled]
39
+ */
40
+ /** @type {Props & Omit<import('svelte/elements').HTMLAttributes<HTMLDivElement>, keyof Props>} */
41
+ let { value = $bindable(''), id, label, min = null, max = null, allowed = null, placeholder, clearable = true, error = '', disabled = false, ...field } = $props()
42
+
43
+ /** @type {DateField | undefined} */
44
+ let dateField = $state()
45
+ let open = $state(false)
46
+ let focus = $state(today())
47
+ let month = $state(monthOf(today()))
48
+ /** What's wrong with what was typed, if anything. */
49
+ let typed = $state('')
50
+ const problem = $derived(error || typed)
51
+
52
+ /** Opens on the value, or on today (kept within min and max, and moved to the nearest allowed day). */
53
+ function onopen() {
54
+ const day = clamp(today(), min, max)
55
+ focus = value || (allowed && nearest(day, allowed.filter((d) => within(d, min, max)))) || day
56
+ month = monthOf(focus)
57
+ }
58
+ </script>
59
+
60
+ <DateField
61
+ bind:this={dateField}
62
+ {id}
63
+ {label}
64
+ {disabled}
65
+ bind:open
66
+ {onopen}
67
+ hasValue={!!value}
68
+ onclear={clearable ? () => ((value = ''), (typed = '')) : undefined}
69
+ error={problem}
70
+ {...field}
71
+ >
72
+ {#snippet inputs()}
73
+ <DateInput
74
+ bind:value
75
+ {id}
76
+ {min}
77
+ {max}
78
+ {allowed}
79
+ {placeholder}
80
+ {disabled}
81
+ errorId={problem && `${id}-error`}
82
+ onopen={(toCalendar) => dateField?.show(toCalendar)}
83
+ onproblem={(m) => (typed = m)}
84
+ />
85
+ {/snippet}
86
+ {#snippet panel(close)}
87
+ <Calendar
88
+ bind:month
89
+ bind:focus
90
+ {min}
91
+ {max}
92
+ {allowed}
93
+ {label}
94
+ selected={value ? [value] : []}
95
+ onpick={(day) => {
96
+ value = day
97
+ typed = ''
98
+ close()
99
+ }}
100
+ />
101
+ {/snippet}
102
+ </DateField>
@@ -0,0 +1,67 @@
1
+ export default DatePicker;
2
+ type DatePicker = {
3
+ $on?(type: string, callback: (e: any) => void): () => void;
4
+ $set?(props: Partial<Props & Omit<HTMLAttributes<HTMLDivElement>, keyof Props>>): void;
5
+ };
6
+ declare const DatePicker: import("svelte").Component<{
7
+ /**
8
+ * bindable
9
+ */
10
+ value?: string | undefined;
11
+ id: string;
12
+ label: string;
13
+ min?: string | null | undefined;
14
+ max?: string | null | undefined;
15
+ allowed?: string[] | null | undefined;
16
+ placeholder?: string | undefined;
17
+ clearable?: boolean | undefined;
18
+ hideLabel?: boolean | undefined;
19
+ error?: string | undefined;
20
+ info?: string | undefined;
21
+ /**
22
+ * dimmed text after the label, e.g. '(optional)'
23
+ */
24
+ note?: string | undefined;
25
+ disabled?: boolean | undefined;
26
+ } & Omit<import("svelte/elements").HTMLAttributes<HTMLDivElement>, keyof {
27
+ /**
28
+ * bindable
29
+ */
30
+ value?: string | undefined;
31
+ id: string;
32
+ label: string;
33
+ min?: string | null | undefined;
34
+ max?: string | null | undefined;
35
+ allowed?: string[] | null | undefined;
36
+ placeholder?: string | undefined;
37
+ clearable?: boolean | undefined;
38
+ hideLabel?: boolean | undefined;
39
+ error?: string | undefined;
40
+ info?: string | undefined;
41
+ /**
42
+ * dimmed text after the label, e.g. '(optional)'
43
+ */
44
+ note?: string | undefined;
45
+ disabled?: boolean | undefined;
46
+ }>, {}, "value">;
47
+ type Props = {
48
+ /**
49
+ * bindable
50
+ */
51
+ value?: string | undefined;
52
+ id: string;
53
+ label: string;
54
+ min?: string | null | undefined;
55
+ max?: string | null | undefined;
56
+ allowed?: string[] | null | undefined;
57
+ placeholder?: string | undefined;
58
+ clearable?: boolean | undefined;
59
+ hideLabel?: boolean | undefined;
60
+ error?: string | undefined;
61
+ info?: string | undefined;
62
+ /**
63
+ * dimmed text after the label, e.g. '(optional)'
64
+ */
65
+ note?: string | undefined;
66
+ disabled?: boolean | undefined;
67
+ };