@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,25 +1,30 @@
1
1
  <script>
2
2
  /**
3
- * One date: typed, or picked from a calendar under the field.
3
+ * One date: a button showing it for reading ('18 Nov 2026', dropping this year's number when the button is too narrow
4
+ * for it: '18 Nov'; see formatShort in lib/dates.js) that opens a panel under it, where it is typed or picked from a calendar.
4
5
  *
5
6
  * <DatePicker bind:value={due} id="due" label="Due date" min={today()} />
6
7
  *
7
8
  * value (bindable): an ISO day ('2026-11-18'), or '' for none. min, max: the first and last day allowed.
8
9
  * 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.
10
+ * on the nearest one, and typing another is an error under the input.
11
+ * Typing, in the input at the top of the panel: DD/MM/YYYY ('18/11/2026'; its placeholder shows it) with any
12
+ * separators or a two-digit year, '18/11' for this year, ISO, month names ('18 Nov') or words ('tomorrow', '3 days
13
+ * ago'; parseInput in lib/dates.js); read when the input is left (the calendar moves to the day) or Enter is pressed
14
+ * (which also closes). Something that doesn't read, or falls outside min / max, is shown under the input until fixed
15
+ * (Esc puts the value back). placeholder: the button's text with no value ("Choose a date").
16
+ * weekStart: the day the calendar's weeks start on, 1 Monday (the default) … 7 Sunday, or 'locale' for the user's.
13
17
  * 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
+ * Keyboard: Enter, Space or ArrowDown on the button opens the panel with the focus in the input, its text selected
19
+ * (typing replaces it); ArrowDown or Tab moves on to the calendar, where arrows move by day and week, PageUp / PageDown
20
+ * by month (Shift: year), Enter picks and closes. Esc closes.
21
+ * Other attributes and attachments go to the button.
18
22
  */
19
23
  import Calendar from './Calendar.svelte'
20
24
  import DateField from './DateField.svelte'
21
25
  import DateInput from './DateInput.svelte'
22
- import { clamp, monthOf, nearest, today, within } from '../../lib/dates.js'
26
+ import ErrorMessage from '../ErrorMessage.svelte'
27
+ import { clamp, formatShort, monthOf, nearest, today, within } from '../../lib/dates.js'
23
28
 
24
29
  /**
25
30
  * @typedef {object} Props
@@ -30,6 +35,7 @@
30
35
  * @property {string | null} [max]
31
36
  * @property {string[] | null} [allowed]
32
37
  * @property {string} [placeholder]
38
+ * @property {number | 'locale'} [weekStart]
33
39
  * @property {boolean} [clearable]
34
40
  * @property {boolean} [hideLabel]
35
41
  * @property {string} [error]
@@ -37,20 +43,23 @@
37
43
  * @property {string} [note] dimmed text after the label, e.g. '(optional)'
38
44
  * @property {boolean} [disabled]
39
45
  */
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()
46
+ /** @type {Props & Omit<import('svelte/elements').HTMLButtonAttributes, keyof Props>} */
47
+ let { value = $bindable(''), id, label, min = null, max = null, allowed = null, placeholder, weekStart = 1, clearable = true, error = '', disabled = false, ...field } = $props()
42
48
 
43
- /** @type {DateField | undefined} */
44
- let dateField = $state()
49
+ /** @type {HTMLDivElement | undefined} */
50
+ let calendar = $state()
45
51
  let open = $state(false)
46
52
  let focus = $state(today())
47
53
  let month = $state(monthOf(today()))
48
- /** What's wrong with what was typed, if anything. */
54
+ /** What's wrong with what was typed in the panel, if anything; shown there, under the input. */
49
55
  let typed = $state('')
50
- const problem = $derived(error || typed)
56
+
57
+ /** Moves the focus from the input onto the calendar's focus day. */
58
+ const focusCalendar = () => /** @type {HTMLElement | null | undefined} */ (calendar?.querySelector('[tabindex="0"]'))?.focus()
51
59
 
52
60
  /** Opens on the value, or on today (kept within min and max, and moved to the nearest allowed day). */
53
61
  function onopen() {
62
+ typed = ''
54
63
  const day = clamp(today(), min, max)
55
64
  focus = value || (allowed && nearest(day, allowed.filter((d) => within(d, min, max)))) || day
56
65
  month = monthOf(focus)
@@ -58,45 +67,61 @@
58
67
  </script>
59
68
 
60
69
  <DateField
61
- bind:this={dateField}
62
70
  {id}
63
71
  {label}
64
72
  {disabled}
65
73
  bind:open
66
74
  {onopen}
75
+ text={value ? formatShort(value) : ''}
76
+ longText={value ? formatShort(value, { year: true }) : ''}
77
+ {placeholder}
67
78
  hasValue={!!value}
68
79
  onclear={clearable ? () => ((value = ''), (typed = '')) : undefined}
69
- error={problem}
80
+ {error}
70
81
  {...field}
71
82
  >
72
- {#snippet inputs()}
83
+ {#snippet inputs(close)}
73
84
  <DateInput
74
85
  bind:value
75
- {id}
86
+ id="{id}-typed"
76
87
  {min}
77
88
  {max}
78
89
  {allowed}
79
- {placeholder}
80
- {disabled}
81
- errorId={problem && `${id}-error`}
82
- onopen={(toCalendar) => dateField?.show(toCalendar)}
90
+ aria-label="{label}, typed"
91
+ data-autofocus
92
+ errorId={typed && `${id}-typed-error`}
93
+ onopen={(toCalendar) => toCalendar && focusCalendar()}
83
94
  onproblem={(m) => (typed = m)}
95
+ oncommit={(day, enter) => (enter ? close() : day && ((focus = day), (month = monthOf(day))))}
84
96
  />
85
97
  {/snippet}
86
98
  {#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
- />
99
+ <div class="picker">
100
+ <ErrorMessage id="{id}-typed-error" message={typed} />
101
+ <div bind:this={calendar}>
102
+ <Calendar
103
+ bind:month
104
+ bind:focus
105
+ {min}
106
+ {max}
107
+ {weekStart}
108
+ {allowed}
109
+ {label}
110
+ selected={value ? [value] : []}
111
+ onpick={(day) => {
112
+ value = day
113
+ typed = ''
114
+ close()
115
+ }}
116
+ />
117
+ </div>
118
+ </div>
101
119
  {/snippet}
102
120
  </DateField>
121
+
122
+ <style>
123
+ .picker {
124
+ display: grid;
125
+ gap: var(--space-2);
126
+ }
127
+ </style>
@@ -1,7 +1,7 @@
1
1
  export default DatePicker;
2
2
  type DatePicker = {
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
6
  declare const DatePicker: import("svelte").Component<{
7
7
  /**
@@ -14,6 +14,7 @@ declare const DatePicker: import("svelte").Component<{
14
14
  max?: string | null | undefined;
15
15
  allowed?: string[] | null | undefined;
16
16
  placeholder?: string | undefined;
17
+ weekStart?: number | "locale" | undefined;
17
18
  clearable?: boolean | undefined;
18
19
  hideLabel?: boolean | undefined;
19
20
  error?: string | undefined;
@@ -23,7 +24,7 @@ declare const DatePicker: import("svelte").Component<{
23
24
  */
24
25
  note?: string | undefined;
25
26
  disabled?: boolean | undefined;
26
- } & Omit<import("svelte/elements").HTMLAttributes<HTMLDivElement>, keyof {
27
+ } & Omit<import("svelte/elements").HTMLButtonAttributes, keyof {
27
28
  /**
28
29
  * bindable
29
30
  */
@@ -34,6 +35,7 @@ declare const DatePicker: import("svelte").Component<{
34
35
  max?: string | null | undefined;
35
36
  allowed?: string[] | null | undefined;
36
37
  placeholder?: string | undefined;
38
+ weekStart?: number | "locale" | undefined;
37
39
  clearable?: boolean | undefined;
38
40
  hideLabel?: boolean | undefined;
39
41
  error?: string | undefined;
@@ -55,6 +57,7 @@ type Props = {
55
57
  max?: string | null | undefined;
56
58
  allowed?: string[] | null | undefined;
57
59
  placeholder?: string | undefined;
60
+ weekStart?: number | "locale" | undefined;
58
61
  clearable?: boolean | undefined;
59
62
  hideLabel?: boolean | undefined;
60
63
  error?: string | undefined;
@@ -1,25 +1,30 @@
1
1
  <script>
2
2
  /**
3
- * A span of days: two typed days (from, to) in one field, or two presses on a calendar under it.
3
+ * A span of days: a button showing it for reading ('3–18 Nov 2026', '28 Oct – 3 Nov 2026', dropping this year's number
4
+ * when the button is too narrow for it; see formatSpan in lib/dates.js) that
5
+ * opens a panel under it, where the two ends are typed (from, to) or picked with two presses on a calendar.
4
6
  *
5
7
  * <DateRangePicker bind:value={stay} id="stay" label="Dates" min={today()} />
6
8
  *
7
9
  * value (bindable): [from, to] as ISO days, from ≤ to; ['', ''] for none (either end may be empty while typing).
8
- * min, max: the first and last day allowed. Typing works as DatePicker's, in each end; ends typed the wrong way round
9
- * swap. placeholder, clearable, error, info, note, hideLabel, disabled: as DatePicker's.
10
+ * min, max: the first and last day allowed. Typing works as DatePicker's, in the panel's two inputs; ends typed the
11
+ * wrong way round swap. Enter in the first moves on to the second; Enter in the second closes once both are set.
12
+ * placeholder ("Choose dates"), weekStart, clearable, error, info, note, hideLabel, disabled: as DatePicker's.
10
13
  * On the calendar the first press starts a new range; while choosing the second, the days up to the pointer (or the
11
- * keyboard focus) are tinted, and a second press before the first swaps them. Closing before the second press keeps
12
- * the old range. A hint in the panel says which press is next, read out as it changes. Keyboard: as DatePicker's.
14
+ * keyboard focus) are tinted, and a second press before the first swaps them. Until the second press the inputs show
15
+ * the first day in "from" and nothing in "to" (typing there finishes the range). Closing before the second press keeps
16
+ * the old range. After the first press, screen readers are told to pick the last day. Keyboard: as DatePicker's.
13
17
  * shortcuts: ready-made spans beside the calendar, [{ label, range() }] with range() giving [from, to]; one press sets
14
18
  * it and closes. Default: Last 7, 30, 60 and 90 days, This year (rangeShortcuts in lib/dates.js); [] for
15
19
  * none. A span reaching past min or max is cut to them, and one wholly outside is disabled.
16
- * Other attributes and attachments go to the field's wrapper.
20
+ * Other attributes and attachments go to the button.
17
21
  */
18
22
  import Calendar from './Calendar.svelte'
19
23
  import DateField from './DateField.svelte'
20
24
  import DateInput from './DateInput.svelte'
21
25
  import RangeShortcuts from './RangeShortcuts.svelte'
22
- import { clamp, compare, formatDay, monthOf, rangeShortcuts, today } from '../../lib/dates.js'
26
+ import ErrorMessage from '../ErrorMessage.svelte'
27
+ import { clamp, compare, formatShort, formatSpan, monthOf, rangeShortcuts, today } from '../../lib/dates.js'
23
28
 
24
29
  /**
25
30
  * @typedef {object} Props
@@ -30,6 +35,7 @@
30
35
  * @property {string | null} [max]
31
36
  * @property {{ label: string, range: () => [string, string] }[]} [shortcuts]
32
37
  * @property {string} [placeholder]
38
+ * @property {number | 'locale'} [weekStart]
33
39
  * @property {boolean} [clearable]
34
40
  * @property {boolean} [hideLabel]
35
41
  * @property {string} [error]
@@ -37,7 +43,7 @@
37
43
  * @property {string} [note] dimmed text after the label, e.g. '(optional)'
38
44
  * @property {boolean} [disabled]
39
45
  */
40
- /** @type {Props & Omit<import('svelte/elements').HTMLAttributes<HTMLDivElement>, keyof Props>} */
46
+ /** @type {Props & Omit<import('svelte/elements').HTMLButtonAttributes, keyof Props>} */
41
47
  let {
42
48
  value = $bindable(['', '']),
43
49
  id,
@@ -45,15 +51,16 @@
45
51
  min = null,
46
52
  max = null,
47
53
  shortcuts = rangeShortcuts(),
48
- placeholder,
54
+ placeholder = 'Choose dates',
55
+ weekStart = 1,
49
56
  clearable = true,
50
57
  error = '',
51
58
  disabled = false,
52
59
  ...field
53
60
  } = $props()
54
61
 
55
- /** @type {DateField | undefined} */
56
- let dateField = $state()
62
+ /** @type {HTMLDivElement | undefined} */
63
+ let days = $state()
57
64
  let open = $state(false)
58
65
  let focus = $state(today())
59
66
  let month = $state(monthOf(today()))
@@ -61,9 +68,8 @@
61
68
  let first = $state(/** @type {string | null} */ (null))
62
69
  /** The day under the pointer or focus while choosing the second. */
63
70
  let pointed = $state(/** @type {string | null} */ (null))
64
- /** What's wrong with what was typed in each end. */
71
+ /** What's wrong with what was typed in each end; shown in the panel, under the inputs. */
65
72
  let typed = $state(['', ''])
66
- const problem = $derived(error || typed[0] || typed[1])
67
73
  const tint = $derived(/** @type {[string, string] | null} */ (first ? [first, pointed ?? first] : value[0] && value[1] ? [value[0], value[1]] : null))
68
74
 
69
75
  /** The shortcuts' spans, cut to min and max; null for one wholly outside them. */
@@ -83,13 +89,34 @@
83
89
  close()
84
90
  }
85
91
 
86
- /** Sets one end from typing; ends the wrong way round swap. @param {0 | 1} end @param {string} day */
92
+ /** Sets one end from typing; ends the wrong way round swap. Typed while the calendar's second press is pending, it
93
+ * goes with the first day picked (as the inputs show it). @param {0 | 1} end @param {string} day */
87
94
  function setEnd(end, day) {
88
- const next = /** @type {[string, string]} */ (end === 0 ? [day, value[1]] : [value[0], day])
95
+ const base = first ? [first, ''] : value
96
+ first = null
97
+ const next = /** @type {[string, string]} */ (end === 0 ? [day, base[1]] : [base[0], day])
89
98
  value = next[0] && next[1] && next[0] > next[1] ? [next[1], next[0]] : next
90
99
  }
91
100
 
101
+ /** Moves the focus to an element in the panel (an input's text selected). @param {Element | null | undefined} el */
102
+ function focusOn(el) {
103
+ if (!(el instanceof HTMLElement)) return
104
+ el.focus()
105
+ if (el instanceof HTMLInputElement) el.select()
106
+ }
107
+
108
+ /** After a typed end reads, the calendar moves to the day; then `next` (Enter's step: on to the other input, or
109
+ * closing). @param {string} day @param {(() => void) | null} next */
110
+ function typedEnd(day, next) {
111
+ if (day) {
112
+ focus = day
113
+ month = monthOf(day)
114
+ }
115
+ next?.()
116
+ }
117
+
92
118
  function onopen() {
119
+ typed = ['', '']
93
120
  first = null
94
121
  pointed = null
95
122
  focus = value[0] || clamp(today(), min, max)
@@ -101,52 +128,52 @@
101
128
  if (!first) {
102
129
  first = day
103
130
  pointed = day
131
+ typed = ['', '']
104
132
  return
105
133
  }
106
134
  choose(/** @type {[string, string]} */ ([first, day].toSorted(compare)), close)
107
135
  }
108
136
  </script>
109
137
 
110
- <span id="{id}-from-name" class="sr-only">from</span>
111
- <span id="{id}-to-name" class="sr-only">to</span>
112
138
  <DateField
113
- bind:this={dateField}
114
139
  {id}
115
140
  {label}
116
141
  {disabled}
117
- calendarLabel="Choose dates"
118
142
  bind:open
119
143
  {onopen}
120
- hasValue={!!(value[0] || value[1])}
121
- onclear={clearable ? () => ((value = ['', '']), (typed = ['', ''])) : undefined}
122
- error={problem}
144
+ text={formatSpan(value[0], value[1])}
145
+ longText={formatSpan(value[0], value[1], { year: true })}
146
+ {placeholder}
147
+ hasValue={!!(first || value[0] || value[1])}
148
+ onclear={clearable ? () => ((value = ['', '']), (first = null), (typed = ['', ''])) : undefined}
149
+ {error}
123
150
  {...field}
124
151
  >
125
- {#snippet inputs()}
152
+ {#snippet inputs(close)}
153
+ <!-- While the calendar's second press is pending, the first day shows in "from" and "to" is empty. -->
126
154
  <DateInput
127
- bind:value={() => value[0], (day) => setEnd(0, day)}
128
- {id}
155
+ bind:value={() => first ?? value[0], (day) => setEnd(0, day)}
156
+ id="{id}-from"
129
157
  {min}
130
158
  {max}
131
- {placeholder}
132
- {disabled}
133
- aria-labelledby="{id}-label {id}-from-name"
134
- errorId={(error || typed[0]) && `${id}-error`}
135
- onopen={(toCalendar) => dateField?.show(toCalendar)}
159
+ aria-label="{label}, from"
160
+ data-autofocus
161
+ errorId={typed[0] && `${id}-typed-error`}
162
+ onopen={(toCalendar) => toCalendar && focusOn(days?.querySelector('[tabindex="0"]'))}
136
163
  onproblem={(m) => (typed = [m, typed[1]])}
164
+ oncommit={(day, enter) => typedEnd(day, enter ? () => focusOn(document.getElementById(`${id}-to`)) : null)}
137
165
  />
138
166
  <span class="to" aria-hidden="true">–</span>
139
167
  <DateInput
140
- bind:value={() => value[1], (day) => setEnd(1, day)}
141
- id="{id}-end"
168
+ bind:value={() => (first ? '' : value[1]), (day) => setEnd(1, day)}
169
+ id="{id}-to"
142
170
  {min}
143
171
  {max}
144
- {placeholder}
145
- {disabled}
146
- aria-labelledby="{id}-label {id}-to-name"
147
- errorId={(error || typed[1]) && `${id}-error`}
148
- onopen={(toCalendar) => dateField?.show(toCalendar)}
172
+ aria-label="{label}, to"
173
+ errorId={typed[1] && `${id}-typed-error`}
174
+ onopen={(toCalendar) => toCalendar && focusOn(days?.querySelector('[tabindex="0"]'))}
149
175
  onproblem={(m) => (typed = [typed[0], m])}
176
+ oncommit={(day, enter) => typedEnd(day, enter ? () => (value[0] && value[1] ? close() : focusOn(document.getElementById(`${id}-from`))) : null)}
150
177
  />
151
178
  {/snippet}
152
179
  {#snippet panel(close)}
@@ -154,13 +181,15 @@
154
181
  {#if shortcuts.length}
155
182
  <RangeShortcuts vertical class="presets" items={presets} {value} onpick={(range) => choose(range, close)} />
156
183
  {/if}
157
- <div class="days">
158
- <p class="hint small muted" aria-live="polite">{first ? `From ${formatDay(first)}: pick the last day` : 'Pick the first day'}</p>
184
+ <div class="days" bind:this={days}>
185
+ <ErrorMessage id="{id}-typed-error" message={typed[0] || typed[1]} />
186
+ <p class="sr-only" aria-live="polite">{first ? `From ${formatShort(first)}: pick the last day` : ''}</p>
159
187
  <Calendar
160
188
  bind:month
161
189
  bind:focus
162
190
  {min}
163
191
  {max}
192
+ {weekStart}
164
193
  {label}
165
194
  selected={first ? [first] : value.filter(Boolean)}
166
195
  range={tint}
@@ -177,6 +206,7 @@
177
206
  .to {
178
207
  flex: none;
179
208
  color: var(--muted);
209
+ user-select: none;
180
210
  }
181
211
  .range,
182
212
  .days {
@@ -1,7 +1,7 @@
1
1
  export default DateRangePicker;
2
2
  type DateRangePicker = {
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
6
  declare const DateRangePicker: import("svelte").Component<{
7
7
  /**
@@ -17,6 +17,7 @@ declare const DateRangePicker: import("svelte").Component<{
17
17
  range: () => [string, string];
18
18
  }[] | undefined;
19
19
  placeholder?: string | undefined;
20
+ weekStart?: number | "locale" | undefined;
20
21
  clearable?: boolean | undefined;
21
22
  hideLabel?: boolean | undefined;
22
23
  error?: string | undefined;
@@ -26,7 +27,7 @@ declare const DateRangePicker: import("svelte").Component<{
26
27
  */
27
28
  note?: string | undefined;
28
29
  disabled?: boolean | undefined;
29
- } & Omit<import("svelte/elements").HTMLAttributes<HTMLDivElement>, keyof {
30
+ } & Omit<import("svelte/elements").HTMLButtonAttributes, keyof {
30
31
  /**
31
32
  * bindable
32
33
  */
@@ -40,6 +41,7 @@ declare const DateRangePicker: import("svelte").Component<{
40
41
  range: () => [string, string];
41
42
  }[] | undefined;
42
43
  placeholder?: string | undefined;
44
+ weekStart?: number | "locale" | undefined;
43
45
  clearable?: boolean | undefined;
44
46
  hideLabel?: boolean | undefined;
45
47
  error?: string | undefined;
@@ -64,6 +66,7 @@ type Props = {
64
66
  range: () => [string, string];
65
67
  }[] | undefined;
66
68
  placeholder?: string | undefined;
69
+ weekStart?: number | "locale" | undefined;
67
70
  clearable?: boolean | undefined;
68
71
  hideLabel?: boolean | undefined;
69
72
  error?: string | undefined;
@@ -7,11 +7,13 @@
7
7
  *
8
8
  * value (bindable): [from, to], each one of `dates`, from ≤ to (equal for one date); ['', ''] for none.
9
9
  * dates: ISO days ('2026-11-18') or ISO moments ('2026-11-18T14:30:00Z'), in any order; they are ordered as text, so
10
- * keep to one form and one offset. The list shows them newest first as DD/MM/YYYY, under a heading per month when
11
- * they span more than one (monthRuns in lib/dates.js), moments with the time in the user's
12
- * time zone. The button shows a moment's time only where the day alone is ambiguous: both ends on the same day, or
13
- * another date on that end's day. The year shows once, at the end, when both ends are in the same past year; not at
14
- * all when it is this year; on both ends when they differ.
10
+ * keep to one form and one offset. The list shows them newest first with the month's short name ('18 Nov', the year
11
+ * when it isn't this year), under a heading per month when they span more than one (monthRuns in lib/dates.js),
12
+ * moments with the time in the user's time zone. The button shows the span as briefly as it can be said
13
+ * (formatSpan in lib/dates.js): '3–18 Nov' in one month, '28 Oct – 3 Nov' across months, '14:30–16:00 18 Nov' on one
14
+ * day; a moment's time only where the day alone is ambiguous (both ends on the same day, or another date on that
15
+ * end's day). The year shows once, at the end, when both ends are in the same past year; not at all when it is this
16
+ * year; on both ends when they differ.
15
17
  * shortcuts: ready-made spans above the list, [{ label, range(dates) }], range given the dates oldest first and
16
18
  * returning [from, to], or null to show it disabled. Default: Most recent, Last 3, This month (dateListShortcuts in
17
19
  * lib/dates.js); [] for none. One press sets it and closes.
@@ -35,7 +37,7 @@
35
37
  import { pop } from '../../lib/motion.js'
36
38
  import { reveal } from '../../lib/reveal.js'
37
39
  import DashOutline from '../DashOutline.svelte'
38
- import { compare, dateListShortcuts, dayOf, formatWhen, monthRuns, today } from '../../lib/dates.js'
40
+ import { compare, dateListShortcuts, dayOf, formatShort, formatSpan, monthRuns } from '../../lib/dates.js'
39
41
 
40
42
  /**
41
43
  * @typedef {object} Props
@@ -95,20 +97,13 @@
95
97
  )
96
98
  /** How many dates fall on each (local) day. */
97
99
  const perDay = $derived(oldest.reduce((counts, when) => counts.set(dayOf(when), (counts.get(dayOf(when)) ?? 0) + 1), new Map()))
98
- /**
99
- * One end of the value: its time only when the day alone doesn't tell it apart; its year unless both ends are in
100
- * this year, and only on the last end when both are in the same year.
101
- * @param {string} end @param {string} other @param {boolean} last
102
- */
103
- function formatEnd(end, other, last) {
104
- const year = dayOf(end).slice(0, 4)
105
- const sameYear = year === dayOf(other).slice(0, 4)
106
- return formatWhen(end, {
107
- time: dayOf(end) === dayOf(other) || perDay.get(dayOf(end)) > 1,
108
- year: !sameYear || (last && year !== today().slice(0, 4)),
109
- })
110
- }
111
- const shown = $derived(value[0] && value[1] ? (value[0] === value[1] ? formatEnd(value[0], value[0], true) : `${formatEnd(value[0], value[1], false)} – ${formatEnd(value[1], value[0], true)}`) : '')
100
+ /** The value for reading ('3–18 Nov', '14:30–16:00 18 Nov'; formatSpan in lib/dates.js): an end's time only where
101
+ * the day alone doesn't tell it apart (both ends on one day, or another date on its day). */
102
+ const shown = $derived(
103
+ value[0] && value[1]
104
+ ? formatSpan(value[0], value[1], { time: (end) => (dayOf(value[0]) === dayOf(value[1]) && value[0] !== value[1]) || perDay.get(dayOf(end)) > 1 })
105
+ : '',
106
+ )
112
107
  const empty = $derived(!newest.length)
113
108
 
114
109
  async function show() {
@@ -223,7 +218,7 @@
223
218
  onpointerenter={() => ((active = i), first && (pointed = day))}
224
219
  onclick={() => pick(day)}
225
220
  >
226
- {formatWhen(day)}
221
+ {formatShort(day)}
227
222
  </li>
228
223
  {/snippet}
229
224
 
@@ -244,6 +239,7 @@
244
239
  onclick={() => (open ? close() : show())}
245
240
  onkeydown={onButtonKey}
246
241
  >
242
+ <span class="icon"><Icon name="calendar" size="sm" /></span>
247
243
  <span class="value" class:placeholder={!shown}>{shown || (empty ? 'No dates' : placeholder)}</span>
248
244
  {#if !disabled && !empty}<span class="caret" class:flip={open}><Icon name="caretDown" size="sm" /></span>{/if}
249
245
  </button>
@@ -261,7 +257,7 @@
261
257
  onkeydown={onPanelKey}
262
258
  >
263
259
  <div class="top">
264
- <p class="hint small muted" id="{id}-hint" aria-live="polite">{first ? `From ${formatWhen(first)}: pick the last date` : 'Pick the first date'}</p>
260
+ <p class="hint small muted" id="{id}-hint" aria-live="polite">{first ? `From ${formatShort(first)}: pick the last date` : 'Pick the first date'}</p>
265
261
  {#if shortcuts.length}<RangeShortcuts items={presets} {value} onpick={choose} />{/if}
266
262
  </div>
267
263
  <ul
@@ -307,12 +303,11 @@
307
303
  .trigger {
308
304
  display: flex;
309
305
  align-items: center;
310
- justify-content: space-between;
311
- gap: 8px;
306
+ gap: 6px;
312
307
  min-width: 120px;
313
308
  max-width: 100%;
314
309
  min-height: 32px;
315
- padding: 0 8px 0 10px;
310
+ padding: 0 8px;
316
311
  border: 1px solid var(--line-strong);
317
312
  border-radius: var(--r);
318
313
  background: var(--control-2);
@@ -353,7 +348,13 @@
353
348
  .trigger:global([aria-invalid='true']):focus-visible {
354
349
  box-shadow: 0 0 0 2px color-mix(in lch, var(--danger) 30%, transparent);
355
350
  }
351
+ .icon {
352
+ flex: none;
353
+ display: inline-flex;
354
+ color: var(--muted);
355
+ }
356
356
  .value {
357
+ flex: 1 1 auto;
357
358
  min-width: 0;
358
359
  overflow: clip;
359
360
  text-overflow: ellipsis;
@@ -106,7 +106,8 @@
106
106
  border: 0;
107
107
  border-radius: calc(var(--r) - 2px);
108
108
  background: none;
109
- color: var(--fg);
109
+ /* Unchosen options are dimmed until hovered; the chosen one is clear. */
110
+ color: var(--muted);
110
111
  font-size: 12px;
111
112
  line-height: 14px;
112
113
  font-weight: var(--w-medium);
@@ -119,6 +120,7 @@
119
120
  }
120
121
  button:not([aria-checked='true']):hover {
121
122
  background: var(--control-2);
123
+ color: var(--fg);
122
124
  }
123
125
  [aria-checked='true'] {
124
126
  color: var(--fg);
@@ -57,7 +57,8 @@
57
57
  line-height: 14px;
58
58
  font-weight: var(--w-medium);
59
59
  cursor: pointer;
60
- color: var(--fg);
60
+ /* Unchosen options are dimmed until hovered; the chosen one is clear. */
61
+ color: var(--muted);
61
62
  transition:
62
63
  color var(--dur) var(--ease-out),
63
64
  background-color var(--dur) var(--ease-out),
@@ -65,8 +66,10 @@
65
66
  }
66
67
  button:not([aria-checked='true']):hover {
67
68
  background: var(--control-2);
69
+ color: var(--fg);
68
70
  }
69
71
  [aria-checked='true'] {
72
+ color: var(--fg);
70
73
  background: var(--control-4);
71
74
  box-shadow:
72
75
  inset 0 0 0 1px var(--line),