@xerios/design-system 0.1.1 → 0.1.3

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 (47) hide show
  1. package/CHANGELOG.md +133 -0
  2. package/README.md +12 -8
  3. package/dist/components/Button.svelte +0 -7
  4. package/dist/components/Button.svelte.d.ts +1 -13
  5. package/dist/components/CollapsibleAdvanced.svelte +1 -1
  6. package/dist/components/Dialogs.svelte +12 -0
  7. package/dist/components/WorkingBorder.svelte +10 -8
  8. package/dist/components/empty/EmptyError.svelte +61 -12
  9. package/dist/components/empty/EmptyError.svelte.d.ts +2 -1
  10. package/dist/components/filters/FilterChip.svelte +2 -2
  11. package/dist/components/filters/OptionList.svelte +29 -13
  12. package/dist/components/filters/Panel.svelte +1 -1
  13. package/dist/components/icons.d.ts +3 -0
  14. package/dist/components/icons.js +3 -0
  15. package/dist/components/inputs/ButtonGroup.svelte +4 -1
  16. package/dist/components/inputs/Calendar.svelte +232 -172
  17. package/dist/components/inputs/Calendar.svelte.d.ts +2 -0
  18. package/dist/components/inputs/DateField.svelte +209 -92
  19. package/dist/components/inputs/DateField.svelte.d.ts +16 -10
  20. package/dist/components/inputs/DateInput.svelte +22 -9
  21. package/dist/components/inputs/DateInput.svelte.d.ts +3 -0
  22. package/dist/components/inputs/DatePicker.svelte +63 -38
  23. package/dist/components/inputs/DatePicker.svelte.d.ts +5 -2
  24. package/dist/components/inputs/DateRangePicker.svelte +69 -39
  25. package/dist/components/inputs/DateRangePicker.svelte.d.ts +5 -2
  26. package/dist/components/inputs/DateRangeSelect.svelte +26 -25
  27. package/dist/components/inputs/RadioGroup.svelte +3 -1
  28. package/dist/components/inputs/Segmented.svelte +4 -1
  29. package/dist/components/inputs/Select.svelte +18 -8
  30. package/dist/components/inputs/TextArea.svelte +1 -1
  31. package/dist/components/scroll/ScrollButton.svelte +260 -0
  32. package/dist/components/scroll/ScrollButton.svelte.d.ts +61 -0
  33. package/dist/components/scroll/ScrollMore.svelte +57 -0
  34. package/dist/components/scroll/ScrollMore.svelte.d.ts +28 -0
  35. package/dist/components/scroll/ScrollToTop.svelte +57 -0
  36. package/dist/components/scroll/ScrollToTop.svelte.d.ts +22 -0
  37. package/dist/css/atoms.css +13 -9
  38. package/dist/css/base.css +1 -2
  39. package/dist/css/effects.css +259 -16
  40. package/dist/css/tokens.css +99 -72
  41. package/dist/index.d.ts +3 -0
  42. package/dist/index.js +3 -0
  43. package/dist/lib/dates.d.ts +38 -5
  44. package/dist/lib/dates.js +88 -19
  45. package/dist/lib/edge-glow.d.ts +11 -0
  46. package/dist/lib/edge-glow.js +251 -0
  47. package/package.json +5 -3
@@ -1,27 +1,31 @@
1
1
  <script>
2
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.
3
+ * The field the date pickers share: a label, a button showing the value for reading ('3–18 Nov', see formatSpan in
4
+ * lib/dates.js) that opens a panel under it, and the error bubble. The panel starts with a box holding the picker's
5
+ * typed inputs (DateInput) and a clear button while there is a value; the picker's Calendar follows. DatePicker and
6
+ * DateRangePicker fill it; use those.
6
7
  *
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}
8
+ * <DateField {id} {label} bind:open {onopen} text={formatShort(value)} hasValue={!!value} onclear={() => (value = '')} {error}>
9
+ * {#snippet inputs(close)}<DateInput bind:value id="{id}-typed" data-autofocus … />{/snippet}
9
10
  * {#snippet panel(close)}<Calendar … onpick={(day) => ((value = day), close())} />{/snippet}
10
11
  * </DateField>
11
12
  *
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.
13
+ * id: the button's (the label points at it). text: the value as the button shows it; placeholder in its place while
14
+ * it is '' ("Choose a date"). longText: the value with more said (the year), shown instead of text while the button
15
+ * has room for it in full. open (bindable). onopen(): runs as it opens (set the calendar and the inputs on the
16
+ * value). show(): opens it with the focus on the panel's [data-autofocus] element (its text selected, so typing
17
+ * replaces it), else its first focusable day. inputs(close): the typed inputs, in the box at the top of the panel.
18
+ * hasValue + onclear: the clear button at the end of that box (the focus goes to its first input). panel(close): the
19
+ * rest of the panel; close() shuts it and puts the focus back on the button. error, info, note, hideLabel, disabled: as on the
20
+ * other fields. Other attributes and attachments go to the button.
21
+ * Keyboard: Enter, Space, ArrowDown or ArrowUp on the button opens the panel with the focus in it; Esc closes it;
22
+ * tabbing out of the panel closes it.
20
23
  */
21
24
  import { tick } from 'svelte'
22
25
  import Icon from '../Icon.svelte'
23
26
  import ErrorMessage from '../ErrorMessage.svelte'
24
27
  import FieldLabel from './FieldLabel.svelte'
28
+ import { invalid } from '../../lib/invalid.js'
25
29
  import { topLayer } from '../../lib/dom.js'
26
30
  import { pop } from '../../lib/motion.js'
27
31
  import { tooltip } from '../../lib/tooltip.js'
@@ -30,28 +34,32 @@
30
34
  * @typedef {object} Props
31
35
  * @property {string} id
32
36
  * @property {string} label
37
+ * @property {string} [text]
38
+ * @property {string} [longText]
39
+ * @property {string} [placeholder]
33
40
  * @property {boolean} [open] bindable
34
41
  * @property {() => void} [onopen]
35
42
  * @property {boolean} [hasValue]
36
43
  * @property {() => void} [onclear]
37
- * @property {string} [calendarLabel]
38
44
  * @property {boolean} [hideLabel]
39
45
  * @property {string} [error]
40
46
  * @property {string} [info]
41
47
  * @property {string} [note] dimmed text after the label, e.g. '(optional)'
42
48
  * @property {boolean} [disabled]
43
- * @property {import('svelte').Snippet} inputs
49
+ * @property {import('svelte').Snippet<[() => void]>} inputs
44
50
  * @property {import('svelte').Snippet<[() => void]>} panel
45
51
  */
46
- /** @type {Props & Omit<import('svelte/elements').HTMLAttributes<HTMLDivElement>, keyof Props>} */
52
+ /** @type {Props & Omit<import('svelte/elements').HTMLButtonAttributes, keyof Props>} */
47
53
  let {
48
54
  id,
49
55
  label,
56
+ text = '',
57
+ longText = '',
58
+ placeholder = 'Choose a date',
50
59
  open = $bindable(false),
51
60
  onopen,
52
61
  hasValue = false,
53
62
  onclear,
54
- calendarLabel = 'Choose a date',
55
63
  hideLabel = false,
56
64
  error = '',
57
65
  info = '',
@@ -68,98 +76,100 @@
68
76
  /** @type {HTMLButtonElement | undefined} */
69
77
  let button = $state()
70
78
  /** @type {HTMLDivElement | undefined} */
71
- let box = $state()
79
+ let entry = $state()
72
80
  /** @type {HTMLDivElement | undefined} */
73
81
  let sheet = $state()
74
82
 
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) {
83
+ // The long text, when there is one that says more than text.
84
+ const long = $derived(text && longText && longText !== text ? longText : '')
85
+ /** Whether the long text doesn't fit, so the short one shows in its place. */
86
+ let tight = $state(false)
87
+ /** Attachment for the long text: measures whether it fits, again as the button resizes, the text changes (the
88
+ * argument) or the fonts load. Both texts keep their place in the layout, so a button sized by its content takes
89
+ * the long one's width and shows it. @param {string} _text */
90
+ const fit = (_text) => (/** @type {HTMLElement} */ node) => {
91
+ const check = () => (tight = node.scrollWidth > node.clientWidth)
92
+ const observer = new ResizeObserver(check)
93
+ observer.observe(node)
94
+ void document.fonts?.ready.then(check)
95
+ return () => observer.disconnect()
96
+ }
97
+
98
+ /** Opens the panel (if it isn't) with the focus on its [data-autofocus] element, else its focus day. */
99
+ export async function show() {
81
100
  if (disabled) return
82
101
  if (!open) {
83
102
  onopen?.()
84
103
  open = true
85
104
  }
86
- if (!focus) return
87
105
  await tick()
88
106
  const target = /** @type {HTMLElement | null | undefined} */ (sheet?.querySelector('[data-autofocus], [tabindex="0"]'))
89
107
  target?.focus()
108
+ if (target instanceof HTMLInputElement) target.select()
90
109
  }
91
- async function close(refocus = true) {
110
+ /** Closes the panel; with refocus, the focus goes back on the button (at once, so a Tab moves on from there). */
111
+ function close(refocus = true) {
92
112
  open = false
93
- if (refocus) {
94
- await tick()
95
- button?.focus()
96
- }
113
+ if (refocus) button?.focus()
97
114
  }
98
115
 
99
116
  /** @param {KeyboardEvent} e */
100
- function onPanelKey(e) {
101
- if (e.key !== 'Escape') return
117
+ function onButtonKey(e) {
118
+ if (e.key !== 'ArrowDown' && e.key !== 'ArrowUp') return
102
119
  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)
120
+ void show()
110
121
  }
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
122
+ /** @param {KeyboardEvent} e */
123
+ function onPanelKey(e) {
124
+ if (e.key !== 'Escape' || e.defaultPrevented) return
114
125
  e.preventDefault()
115
126
  e.stopPropagation()
116
- void close(false)
127
+ close()
117
128
  }
118
- /** Tabbing out of the panel closes it. @param {FocusEvent} e */
129
+ /** Tabbing out of the panel closes it; the focus moving into a layer opened from it (a Select's list) doesn't.
130
+ * @param {FocusEvent} e */
119
131
  function onfocusout(e) {
120
- const to = /** @type {Node | null} */ (e.relatedTarget)
121
- if (to && !sheet?.contains(to) && !box?.contains(to)) void close(false)
132
+ const to = /** @type {Element | null} */ (e.relatedTarget)
133
+ if (to && !sheet?.contains(to) && !to.closest?.('[data-floating]')) close(false)
122
134
  }
123
- /** A press outside the field and its panel closes it. @param {PointerEvent} e */
135
+ /** A press outside the field and its panel closes it. The label counts as the button, and a layer opened from the
136
+ * panel (a Select's list, a tip) as the panel. @param {PointerEvent} e */
124
137
  const outside = (e) => {
125
138
  const target = /** @type {Element} */ (e.target)
126
- if (open && !sheet?.contains(target) && !box?.contains(target) && !target.closest?.(`label[for="${id}"]`)) void close(false)
139
+ if (open && !sheet?.contains(target) && !button?.contains(target) && !target.closest?.(`label[for="${id}"], [data-floating], .tooltip`)) close(false)
127
140
  }
128
141
  </script>
129
142
 
130
143
  <svelte:document onpointerdowncapture={outside} />
131
144
 
132
- <div class={['field', className]} {...rest}>
145
+ <div class="field">
133
146
  <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>
147
+ <button
148
+ {id}
149
+ bind:this={button}
150
+ type="button"
151
+ class={['trigger', className]}
152
+ style:anchor-name={anchor}
153
+ {...rest}
154
+ {disabled}
155
+ aria-haspopup="dialog"
156
+ aria-expanded={open}
157
+ aria-labelledby="{id}-label {id}"
158
+ {@attach invalid(error && `${id}-error`)}
159
+ onclick={() => (open ? close() : show())}
160
+ onkeydown={onButtonKey}
161
+ >
162
+ <span class="icon"><Icon name="calendar" size="sm" /></span>
163
+ <span class="value" class:placeholder={!text} class:stack={long}>
164
+ {#if long}
165
+ <span class="long" class:hide={tight} {@attach fit(long)}>{long}</span>
166
+ <span class="short" class:hide={!tight}>{text}</span>
167
+ {:else}
168
+ {text || placeholder}
169
+ {/if}
170
+ </span>
171
+ {#if !disabled}<span class="caret" class:flip={open}><Icon name="caretDown" size="sm" /></span>{/if}
172
+ </button>
163
173
  {#if open}
164
174
  <div
165
175
  bind:this={sheet}
@@ -170,14 +180,30 @@
170
180
  data-floating
171
181
  style:position-anchor={anchor}
172
182
  {@attach topLayer(button)}
173
- transition:pop={{ from: box }}
183
+ transition:pop={{ from: button }}
174
184
  onkeydown={onPanelKey}
175
185
  {onfocusout}
176
186
  >
177
- {@render panel(() => void close())}
187
+ <div bind:this={entry} class="entry field-box">
188
+ {@render inputs(() => close())}
189
+ <!-- Kept in place while there is nothing to clear (hidden and disabled), so the box doesn't change width as a
190
+ value comes and goes. -->
191
+ {#if onclear}
192
+ <button
193
+ type="button"
194
+ class="clear"
195
+ class:hidden={!hasValue}
196
+ disabled={!hasValue}
197
+ aria-label="Clear {label}"
198
+ {@attach tooltip('Clear')}
199
+ onclick={() => (onclear(), entry?.querySelector('input')?.focus())}><Icon name="x" size="sm" /></button
200
+ >
201
+ {/if}
202
+ </div>
203
+ {@render panel(() => close())}
178
204
  </div>
179
205
  {/if}
180
- <ErrorMessage floating id="{id}-error" message={error} ondismiss={() => box?.querySelector('input')?.focus()} />
206
+ <ErrorMessage floating id="{id}-error" message={error} ondismiss={() => button?.focus()} />
181
207
  </div>
182
208
 
183
209
  <style>
@@ -188,17 +214,107 @@
188
214
  gap: 3px;
189
215
  min-width: 0;
190
216
  }
191
- .box {
217
+ /* Raised like Select's button: pressed to open a panel. */
218
+ .trigger {
192
219
  display: flex;
193
220
  align-items: center;
194
- gap: 2px;
221
+ gap: 6px;
222
+ min-width: 120px;
223
+ max-width: 100%;
195
224
  min-height: 32px;
196
- padding-inline: var(--space-1);
225
+ padding: 0 8px;
226
+ border: 1px solid var(--line-strong);
227
+ border-radius: var(--r);
228
+ background: var(--control-2);
229
+ color: var(--fg);
230
+ font: var(--w-medium) 13px var(--font-data);
231
+ font-variant-numeric: tabular-nums;
232
+ text-align: left;
233
+ cursor: pointer;
234
+ --raise: var(--shadow-btn);
235
+ box-shadow: var(--raise);
236
+ transition:
237
+ background-color var(--dur) var(--ease-out),
238
+ border-color var(--dur) var(--ease-out),
239
+ box-shadow var(--dur) var(--ease-out);
240
+ }
241
+ .trigger:hover:not(:disabled) {
242
+ background: var(--control-3);
243
+ }
244
+ .trigger[aria-expanded='true'] {
245
+ background: var(--control-4);
246
+ box-shadow: none;
247
+ }
248
+ .trigger:disabled {
249
+ --raise: 0 0 transparent;
250
+ background: none;
251
+ border-color: var(--line);
252
+ cursor: default;
253
+ }
254
+ /* Focused, it sits flat inside the ring, as Select's does. */
255
+ .trigger:focus-visible {
256
+ border-color: var(--accent-line);
257
+ box-shadow: var(--ring);
258
+ outline: none;
259
+ }
260
+ .trigger:global([aria-invalid='true']) {
261
+ border-color: var(--danger);
262
+ }
263
+ .trigger:global([aria-invalid='true']):focus-visible {
264
+ box-shadow: 0 0 0 2px color-mix(in lch, var(--danger) 30%, transparent);
197
265
  }
198
- .box.disabled {
199
- opacity: 0.5;
266
+ .icon {
267
+ flex: none;
268
+ display: inline-flex;
269
+ color: var(--muted);
270
+ }
271
+ .value {
272
+ flex: 1 1 auto;
273
+ min-width: 0;
274
+ overflow: clip;
275
+ text-overflow: ellipsis;
276
+ white-space: nowrap;
277
+ }
278
+ /* The long and short text in one cell, one of them hidden: the long one wide enough to size a button that grows with
279
+ its content, and measured (left unclipped) to tell whether it fits. */
280
+ .stack {
281
+ display: grid;
282
+ }
283
+ .stack > span {
284
+ grid-area: 1 / 1;
285
+ min-width: 0;
286
+ white-space: nowrap;
287
+ }
288
+ .short {
289
+ overflow: clip;
290
+ text-overflow: ellipsis;
291
+ }
292
+ .hide {
293
+ visibility: hidden;
294
+ }
295
+ .placeholder {
296
+ font-family: var(--font-body);
297
+ color: var(--muted);
298
+ }
299
+ .caret {
300
+ flex: none;
301
+ display: inline-flex;
302
+ color: var(--muted);
303
+ transition: rotate var(--dur) var(--ease-out);
304
+ }
305
+ .caret.flip {
306
+ rotate: 180deg;
307
+ }
308
+ /* The typed inputs' box, at the top of the panel, with the clear button at its end. */
309
+ .entry {
310
+ display: flex;
311
+ align-items: center;
312
+ gap: 2px;
313
+ min-height: 32px;
314
+ margin-block-end: var(--space-2);
315
+ padding-inline-end: 4px;
200
316
  }
201
- .tool {
317
+ .clear {
202
318
  display: inline-grid;
203
319
  place-items: center;
204
320
  flex: none;
@@ -210,15 +326,16 @@
210
326
  background: none;
211
327
  color: var(--muted);
212
328
  }
213
- .tool.hidden {
329
+ .clear.hidden {
214
330
  visibility: hidden;
215
331
  }
216
- .tool:hover:not(:disabled),
217
- .tool[aria-expanded='true'] {
332
+ .clear:hover:not(:disabled) {
218
333
  background: var(--control-3);
219
334
  color: var(--fg-2);
220
335
  }
221
336
  /* Anchored under the field, flipping above or to its other side when there's no room. */
337
+ /* No user-select here: the panel holds the typed inputs, and Safari won't type in a field under it (Calendar and the
338
+ hints set their own). */
222
339
  .panel {
223
340
  position: fixed;
224
341
  z-index: calc(var(--z-overlay) + 1);
@@ -228,8 +345,8 @@
228
345
  flip-inline,
229
346
  flip-block flip-inline;
230
347
  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). */
348
+ /* A touch to the left of the field, so the panel's content lines up under the field's own (mirrored when it flips
349
+ to end at the field's right edge: a flip swaps the inline margins too). */
233
350
  margin-inline-start: calc(var(--space-1) * -1);
234
351
  margin-block: 4px;
235
352
  padding: var(--space-3);
@@ -1,13 +1,16 @@
1
1
  export default DateField;
2
2
  type DateField = {
3
3
  $on?(type: string, callback: (e: any) => void): () => void;
4
- $set?(props: Partial<Props & Omit<HTMLAttributes<HTMLDivElement>, keyof Props>>): void;
4
+ $set?(props: Partial<Props & Omit<HTMLButtonAttributes, keyof Props>>): void;
5
5
  } & {
6
- show: (focus?: boolean | undefined) => Promise<void>;
6
+ show: () => Promise<void>;
7
7
  };
8
8
  declare const DateField: import("svelte").Component<{
9
9
  id: string;
10
10
  label: string;
11
+ text?: string | undefined;
12
+ longText?: string | undefined;
13
+ placeholder?: string | undefined;
11
14
  /**
12
15
  * bindable
13
16
  */
@@ -15,7 +18,6 @@ declare const DateField: import("svelte").Component<{
15
18
  onopen?: (() => void) | undefined;
16
19
  hasValue?: boolean | undefined;
17
20
  onclear?: (() => void) | undefined;
18
- calendarLabel?: string | undefined;
19
21
  hideLabel?: boolean | undefined;
20
22
  error?: string | undefined;
21
23
  info?: string | undefined;
@@ -24,11 +26,14 @@ declare const DateField: import("svelte").Component<{
24
26
  */
25
27
  note?: string | undefined;
26
28
  disabled?: boolean | undefined;
27
- inputs: import("svelte").Snippet;
29
+ inputs: import("svelte").Snippet<[() => void]>;
28
30
  panel: import("svelte").Snippet<[() => void]>;
29
- } & Omit<import("svelte/elements").HTMLAttributes<HTMLDivElement>, keyof {
31
+ } & Omit<import("svelte/elements").HTMLButtonAttributes, keyof {
30
32
  id: string;
31
33
  label: string;
34
+ text?: string | undefined;
35
+ longText?: string | undefined;
36
+ placeholder?: string | undefined;
32
37
  /**
33
38
  * bindable
34
39
  */
@@ -36,7 +41,6 @@ declare const DateField: import("svelte").Component<{
36
41
  onopen?: (() => void) | undefined;
37
42
  hasValue?: boolean | undefined;
38
43
  onclear?: (() => void) | undefined;
39
- calendarLabel?: string | undefined;
40
44
  hideLabel?: boolean | undefined;
41
45
  error?: string | undefined;
42
46
  info?: string | undefined;
@@ -45,14 +49,17 @@ declare const DateField: import("svelte").Component<{
45
49
  */
46
50
  note?: string | undefined;
47
51
  disabled?: boolean | undefined;
48
- inputs: import("svelte").Snippet;
52
+ inputs: import("svelte").Snippet<[() => void]>;
49
53
  panel: import("svelte").Snippet<[() => void]>;
50
54
  }>, {
51
- show: (focus?: boolean) => Promise<void>;
55
+ show: () => Promise<void>;
52
56
  }, "open">;
53
57
  type Props = {
54
58
  id: string;
55
59
  label: string;
60
+ text?: string | undefined;
61
+ longText?: string | undefined;
62
+ placeholder?: string | undefined;
56
63
  /**
57
64
  * bindable
58
65
  */
@@ -60,7 +67,6 @@ type Props = {
60
67
  onopen?: (() => void) | undefined;
61
68
  hasValue?: boolean | undefined;
62
69
  onclear?: (() => void) | undefined;
63
- calendarLabel?: string | undefined;
64
70
  hideLabel?: boolean | undefined;
65
71
  error?: string | undefined;
66
72
  info?: string | undefined;
@@ -69,6 +75,6 @@ type Props = {
69
75
  */
70
76
  note?: string | undefined;
71
77
  disabled?: boolean | undefined;
72
- inputs: import("svelte").Snippet;
78
+ inputs: import("svelte").Snippet<[() => void]>;
73
79
  panel: import("svelte").Snippet<[() => void]>;
74
80
  };
@@ -1,8 +1,9 @@
1
1
  <script>
2
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.
3
+ * A typed day, the text part of DatePicker and DateRangePicker, in their panels (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, with any-date-parser: numbers day
5
+ * first with any separators ('18.11.26', '18/11' for this year), ISO, month names ('18 Nov') or words ('tomorrow',
6
+ * '3 days ago'). See parseInput in lib/dates.js.
6
7
  *
7
8
  * <DateInput bind:value {id} {min} {max} errorId={problem && `${id}-error`} onopen={openCalendar} onproblem={(m) => (problem = m)} />
8
9
  *
@@ -10,7 +11,10 @@
10
11
  * it may be (or null for any).
11
12
  * onproblem(message): what is wrong with what was typed ('' once it reads); the picker shows it as the field's error.
12
13
  * 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
+ * focus moving onto it (focus true). oncommit(day, enter): after what was typed reads and becomes the value (day ''
15
+ * when emptied), enter true when Enter did it (the pickers then close, or move to the next input). Leaving the input
16
+ * without an edit reads nothing.
17
+ * errorId: as the invalid attachment's.
14
18
  * Esc puts back the value's text after an edit. Other attributes (aria-labelledby, placeholder…) go to the <input>.
15
19
  */
16
20
  import { composing } from '../../lib/dom.js'
@@ -27,9 +31,10 @@
27
31
  * @property {string | false | null | undefined} [errorId]
28
32
  * @property {(focus: boolean) => void} [onopen]
29
33
  * @property {(message: string) => void} [onproblem]
34
+ * @property {(day: string, enter: boolean) => void} [oncommit]
30
35
  */
31
36
  /** @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()
37
+ let { value = $bindable(''), id, min = null, max = null, allowed = null, errorId, onopen, onproblem, oncommit, placeholder, ...rest } = $props()
33
38
 
34
39
  const format = inputFormat()
35
40
  // As wide as a date takes (the format, or a longer placeholder), in the data font's even-width characters: an input
@@ -44,12 +49,16 @@
44
49
  // The text in the box: the value's, until it is edited (a writable derived: picking a day elsewhere resets it).
45
50
  let text = $derived(value ? formatInput(value) : '')
46
51
 
47
- /** Reads what was typed; a day that reads becomes the value, anything else is reported and left to fix. */
48
- function commit() {
52
+ /** Reads what was typed; a day that reads becomes the value, anything else is reported and left to fix.
53
+ * @param {boolean} [enter] */
54
+ function commit(enter = false) {
49
55
  const typed = text.trim()
56
+ // Left without an edit: nothing to read (Enter still confirms what is there).
57
+ if (!enter && typed === (value ? formatInput(value) : '')) return
50
58
  if (!typed) {
51
59
  onproblem?.('')
52
60
  if (value) value = ''
61
+ oncommit?.('', enter)
53
62
  return
54
63
  }
55
64
  const day = parseInput(typed)
@@ -63,13 +72,17 @@
63
72
  onproblem?.('')
64
73
  value = day
65
74
  text = formatInput(day)
75
+ oncommit?.(day, enter)
66
76
  }
67
77
 
68
78
  /** @param {KeyboardEvent} e */
69
79
  function onkeydown(e) {
70
80
  // Enter and Esc inside an IME composition belong to the input method.
71
81
  if (composing(e)) return
72
- if (e.key === 'Enter') commit()
82
+ if (e.key === 'Enter') {
83
+ e.preventDefault()
84
+ commit(true)
85
+ }
73
86
  else if (e.key === 'ArrowDown') {
74
87
  e.preventDefault()
75
88
  onopen?.(true)
@@ -92,7 +105,7 @@
92
105
  style:--chars={chars}
93
106
  {@attach invalid(errorId)}
94
107
  {@attach showFormat}
95
- onblur={commit}
108
+ onblur={() => commit()}
96
109
  onclick={() => onopen?.(false)}
97
110
  {onkeydown}
98
111
  />
@@ -15,6 +15,7 @@ declare const DateInput: import("svelte").Component<{
15
15
  errorId?: string | false | null | undefined;
16
16
  onopen?: ((focus: boolean) => void) | undefined;
17
17
  onproblem?: ((message: string) => void) | undefined;
18
+ oncommit?: ((day: string, enter: boolean) => void) | undefined;
18
19
  } & Omit<import("svelte/elements").HTMLInputAttributes, keyof {
19
20
  /**
20
21
  * bindable
@@ -27,6 +28,7 @@ declare const DateInput: import("svelte").Component<{
27
28
  errorId?: string | false | null | undefined;
28
29
  onopen?: ((focus: boolean) => void) | undefined;
29
30
  onproblem?: ((message: string) => void) | undefined;
31
+ oncommit?: ((day: string, enter: boolean) => void) | undefined;
30
32
  }>, {}, "value">;
31
33
  type Props = {
32
34
  /**
@@ -40,4 +42,5 @@ type Props = {
40
42
  errorId?: string | false | null | undefined;
41
43
  onopen?: ((focus: boolean) => void) | undefined;
42
44
  onproblem?: ((message: string) => void) | undefined;
45
+ oncommit?: ((day: string, enter: boolean) => void) | undefined;
43
46
  };