@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.
- package/LICENSE +21 -0
- package/README.md +403 -2
- package/dist/components/AnchorHeading.svelte +79 -0
- package/dist/components/AnchorHeading.svelte.d.ts +28 -0
- package/dist/components/Breadcrumbs.svelte +216 -0
- package/dist/components/Breadcrumbs.svelte.d.ts +37 -0
- package/dist/components/Button.svelte +178 -0
- package/dist/components/Button.svelte.d.ts +58 -0
- package/dist/components/Canvas.svelte +248 -0
- package/dist/components/Canvas.svelte.d.ts +91 -0
- package/dist/components/Collapsible.svelte +139 -0
- package/dist/components/Collapsible.svelte.d.ts +52 -0
- package/dist/components/CollapsibleAdvanced.svelte +174 -0
- package/dist/components/CollapsibleAdvanced.svelte.d.ts +43 -0
- package/dist/components/DashOutline.svelte +47 -0
- package/dist/components/DashOutline.svelte.d.ts +6 -0
- package/dist/components/Dialogs.svelte +123 -0
- package/dist/components/Dialogs.svelte.d.ts +6 -0
- package/dist/components/Drawer.svelte +231 -0
- package/dist/components/Drawer.svelte.d.ts +62 -0
- package/dist/components/ErrorMessage.svelte +140 -0
- package/dist/components/ErrorMessage.svelte.d.ts +41 -0
- package/dist/components/Icon.svelte +94 -0
- package/dist/components/Icon.svelte.d.ts +33 -0
- package/dist/components/InfoTip.svelte +183 -0
- package/dist/components/InfoTip.svelte.d.ts +28 -0
- package/dist/components/Md.svelte +28 -0
- package/dist/components/Md.svelte.d.ts +11 -0
- package/dist/components/Modal.svelte +91 -0
- package/dist/components/Modal.svelte.d.ts +41 -0
- package/dist/components/Notice.svelte +50 -0
- package/dist/components/Notice.svelte.d.ts +30 -0
- package/dist/components/Popover.svelte +212 -0
- package/dist/components/Popover.svelte.d.ts +70 -0
- package/dist/components/Shimmer.svelte +27 -0
- package/dist/components/Shimmer.svelte.d.ts +22 -0
- package/dist/components/Splitter.svelte +152 -0
- package/dist/components/Splitter.svelte.d.ts +41 -0
- package/dist/components/Table.svelte +448 -0
- package/dist/components/Table.svelte.d.ts +268 -0
- package/dist/components/Toast.svelte +273 -0
- package/dist/components/Toast.svelte.d.ts +31 -0
- package/dist/components/Tooltip.svelte +97 -0
- package/dist/components/Tooltip.svelte.d.ts +19 -0
- package/dist/components/WorkingBorder.svelte +105 -0
- package/dist/components/WorkingBorder.svelte.d.ts +26 -0
- package/dist/components/empty/Empty.svelte +55 -0
- package/dist/components/empty/Empty.svelte.d.ts +39 -0
- package/dist/components/empty/EmptyError.svelte +47 -0
- package/dist/components/empty/EmptyError.svelte.d.ts +28 -0
- package/dist/components/empty/index.d.ts +18 -0
- package/dist/components/empty/index.js +10 -0
- package/dist/components/filters/DateFilter.svelte +59 -0
- package/dist/components/filters/DateFilter.svelte.d.ts +23 -0
- package/dist/components/filters/FilterBar.svelte +342 -0
- package/dist/components/filters/FilterBar.svelte.d.ts +283 -0
- package/dist/components/filters/FilterChip.svelte +235 -0
- package/dist/components/filters/FilterChip.svelte.d.ts +68 -0
- package/dist/components/filters/OptionList.svelte +352 -0
- package/dist/components/filters/OptionList.svelte.d.ts +91 -0
- package/dist/components/filters/Panel.svelte +123 -0
- package/dist/components/filters/Panel.svelte.d.ts +25 -0
- package/dist/components/filters/index.d.ts +288 -0
- package/dist/components/filters/index.js +12 -0
- package/dist/components/icons.d.ts +54 -0
- package/dist/components/icons.js +58 -0
- package/dist/components/inputs/ButtonGroup.svelte +104 -0
- package/dist/components/inputs/ButtonGroup.svelte.d.ts +40 -0
- package/dist/components/inputs/Calendar.svelte +535 -0
- package/dist/components/inputs/Calendar.svelte.d.ts +45 -0
- package/dist/components/inputs/DateField.svelte +247 -0
- package/dist/components/inputs/DateField.svelte.d.ts +74 -0
- package/dist/components/inputs/DateInput.svelte +118 -0
- package/dist/components/inputs/DateInput.svelte.d.ts +43 -0
- package/dist/components/inputs/DatePicker.svelte +102 -0
- package/dist/components/inputs/DatePicker.svelte.d.ts +67 -0
- package/dist/components/inputs/DateRangePicker.svelte +208 -0
- package/dist/components/inputs/DateRangePicker.svelte.d.ts +76 -0
- package/dist/components/inputs/DateRangeSelect.svelte +548 -0
- package/dist/components/inputs/DateRangeSelect.svelte.d.ts +70 -0
- package/dist/components/inputs/FieldLabel.svelte +43 -0
- package/dist/components/inputs/FieldLabel.svelte.d.ts +28 -0
- package/dist/components/inputs/ListSearch.svelte +142 -0
- package/dist/components/inputs/ListSearch.svelte.d.ts +35 -0
- package/dist/components/inputs/RadioGroup.svelte +153 -0
- package/dist/components/inputs/RadioGroup.svelte.d.ts +49 -0
- package/dist/components/inputs/RangeShortcuts.svelte +90 -0
- package/dist/components/inputs/RangeShortcuts.svelte.d.ts +31 -0
- package/dist/components/inputs/RangeSlider.svelte +225 -0
- package/dist/components/inputs/RangeSlider.svelte.d.ts +37 -0
- package/dist/components/inputs/SearchField.svelte +24 -0
- package/dist/components/inputs/SearchField.svelte.d.ts +41 -0
- package/dist/components/inputs/Segmented.svelte +76 -0
- package/dist/components/inputs/Segmented.svelte.d.ts +43 -0
- package/dist/components/inputs/Select.svelte +552 -0
- package/dist/components/inputs/Select.svelte.d.ts +100 -0
- package/dist/components/inputs/Slider.svelte +177 -0
- package/dist/components/inputs/Slider.svelte.d.ts +33 -0
- package/dist/components/inputs/SliderTicks.svelte +62 -0
- package/dist/components/inputs/SliderTicks.svelte.d.ts +23 -0
- package/dist/components/inputs/Switch.svelte +120 -0
- package/dist/components/inputs/Switch.svelte.d.ts +31 -0
- package/dist/components/inputs/TagInput.svelte +296 -0
- package/dist/components/inputs/TagInput.svelte.d.ts +61 -0
- package/dist/components/inputs/TextArea.svelte +86 -0
- package/dist/components/inputs/TextArea.svelte.d.ts +56 -0
- package/dist/components/inputs/TextField.svelte +170 -0
- package/dist/components/inputs/TextField.svelte.d.ts +80 -0
- package/dist/components/menu/ContextMenu.svelte +25 -0
- package/dist/components/menu/ContextMenu.svelte.d.ts +26 -0
- package/dist/components/menu/MenuButton.svelte +46 -0
- package/dist/components/menu/MenuButton.svelte.d.ts +16 -0
- package/dist/components/menu/MenuList.svelte +319 -0
- package/dist/components/menu/MenuList.svelte.d.ts +30 -0
- package/dist/components/metadata/Metadata.svelte +38 -0
- package/dist/components/metadata/Metadata.svelte.d.ts +31 -0
- package/dist/components/metadata/MetadataRow.svelte +84 -0
- package/dist/components/metadata/MetadataRow.svelte.d.ts +26 -0
- package/dist/components/metadata/index.d.ts +8 -0
- package/dist/components/metadata/index.js +13 -0
- package/dist/components/side-menu/SideMenu.svelte +138 -0
- package/dist/components/side-menu/SideMenu.svelte.d.ts +25 -0
- package/dist/components/side-menu/SideMenuGroup.svelte +108 -0
- package/dist/components/side-menu/SideMenuGroup.svelte.d.ts +31 -0
- package/dist/components/side-menu/SideMenuItem.svelte +221 -0
- package/dist/components/side-menu/SideMenuItem.svelte.d.ts +46 -0
- package/dist/components/side-menu/context.d.ts +1 -0
- package/dist/components/side-menu/context.js +3 -0
- package/dist/components/side-menu/index.d.ts +62 -0
- package/dist/components/side-menu/index.js +15 -0
- package/dist/components/tiles/Tile.svelte +419 -0
- package/dist/components/tiles/Tile.svelte.d.ts +58 -0
- package/dist/components/tiles/TileGroup.svelte +135 -0
- package/dist/components/tiles/TileGroup.svelte.d.ts +45 -0
- package/dist/components/tiles/context.d.ts +35 -0
- package/dist/components/tiles/context.js +14 -0
- package/dist/components/tiles/index.d.ts +6 -0
- package/dist/components/tiles/index.js +13 -0
- package/dist/components/upload/FileCard.svelte +301 -0
- package/dist/components/upload/FileCard.svelte.d.ts +127 -0
- package/dist/components/upload/Thumb.svelte +274 -0
- package/dist/components/upload/Thumb.svelte.d.ts +101 -0
- package/dist/components/upload/UploadFile.svelte +123 -0
- package/dist/components/upload/UploadFile.svelte.d.ts +48 -0
- package/dist/components/upload/UploadFiles.svelte +177 -0
- package/dist/components/upload/UploadFiles.svelte.d.ts +50 -0
- package/dist/components/upload/UploadFolder.svelte +153 -0
- package/dist/components/upload/UploadFolder.svelte.d.ts +63 -0
- package/dist/components/upload/UploadImage.svelte +137 -0
- package/dist/components/upload/UploadImage.svelte.d.ts +52 -0
- package/dist/components/upload/UploadImages.svelte +172 -0
- package/dist/components/upload/UploadImages.svelte.d.ts +52 -0
- package/dist/components/upload/UploadZone.svelte +130 -0
- package/dist/components/upload/UploadZone.svelte.d.ts +41 -0
- package/dist/components/upload/common.d.ts +31 -0
- package/dist/components/upload/common.js +103 -0
- package/dist/components/upload/context.d.ts +18 -0
- package/dist/components/upload/context.js +10 -0
- package/dist/components/upload/index.d.ts +16 -0
- package/dist/components/upload/index.js +18 -0
- package/dist/css/atoms.css +892 -0
- package/dist/css/base.css +333 -0
- package/dist/css/effects.css +430 -0
- package/dist/css/index.css +10 -0
- package/dist/css/tokens.css +296 -0
- package/dist/fonts.d.ts +1 -0
- package/dist/fonts.js +7 -0
- package/dist/index.d.ts +68 -0
- package/dist/index.js +77 -0
- package/dist/lib/announce.d.ts +8 -0
- package/dist/lib/announce.js +48 -0
- package/dist/lib/controls.d.ts +10 -0
- package/dist/lib/controls.js +42 -0
- package/dist/lib/dates.d.ts +104 -0
- package/dist/lib/dates.js +235 -0
- package/dist/lib/dialogs.svelte.d.ts +8 -0
- package/dist/lib/dialogs.svelte.js +45 -0
- package/dist/lib/dom.d.ts +34 -0
- package/dist/lib/dom.js +90 -0
- package/dist/lib/field-errors.svelte.d.ts +40 -0
- package/dist/lib/field-errors.svelte.js +89 -0
- package/dist/lib/files.d.ts +74 -0
- package/dist/lib/files.js +215 -0
- package/dist/lib/inline-md.d.ts +1 -0
- package/dist/lib/inline-md.js +36 -0
- package/dist/lib/invalid.d.ts +4 -0
- package/dist/lib/invalid.js +35 -0
- package/dist/lib/list-search.d.ts +9 -0
- package/dist/lib/list-search.js +27 -0
- package/dist/lib/menu.svelte.d.ts +39 -0
- package/dist/lib/menu.svelte.js +98 -0
- package/dist/lib/morph.svelte.d.ts +17 -0
- package/dist/lib/morph.svelte.js +46 -0
- package/dist/lib/motion.d.ts +115 -0
- package/dist/lib/motion.js +174 -0
- package/dist/lib/observe.d.ts +36 -0
- package/dist/lib/observe.js +142 -0
- package/dist/lib/reveal.d.ts +7 -0
- package/dist/lib/reveal.js +28 -0
- package/dist/lib/roving.d.ts +16 -0
- package/dist/lib/roving.js +35 -0
- package/dist/lib/runs.d.ts +18 -0
- package/dist/lib/runs.js +25 -0
- package/dist/lib/scroll-fade.d.ts +4 -0
- package/dist/lib/scroll-fade.js +71 -0
- package/dist/lib/spotlight.d.ts +4 -0
- package/dist/lib/spotlight.js +109 -0
- package/dist/lib/ticks.d.ts +12 -0
- package/dist/lib/ticks.js +24 -0
- package/dist/lib/tooltip.d.ts +4 -0
- package/dist/lib/tooltip.js +110 -0
- package/dist/lib/validity.d.ts +16 -0
- package/dist/lib/validity.js +36 -0
- package/package.json +69 -3
|
@@ -0,0 +1,548 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
/**
|
|
3
|
+
* A span between two of a given list of dates, picked from that list: a compact range picker for when only some
|
|
4
|
+
* days or moments can be chosen, at irregular times (say, when a job ran). No calendar and no typing.
|
|
5
|
+
*
|
|
6
|
+
* <DateRangeSelect bind:value={span} dates={runs} id="runs" label="Runs" />
|
|
7
|
+
*
|
|
8
|
+
* value (bindable): [from, to], each one of `dates`, from ≤ to (equal for one date); ['', ''] for none.
|
|
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.
|
|
15
|
+
* shortcuts: ready-made spans above the list, [{ label, range(dates) }], range given the dates oldest first and
|
|
16
|
+
* returning [from, to], or null to show it disabled. Default: Most recent, Last 3, This month (dateListShortcuts in
|
|
17
|
+
* lib/dates.js); [] for none. One press sets it and closes.
|
|
18
|
+
* placeholder: the button's text with no value. error, info, note, hideLabel, disabled: as Select's.
|
|
19
|
+
* The button opens a panel with the shortcuts and the list. The first press in the list starts a new span, the second
|
|
20
|
+
* ends it (either way round; the same date again picks it alone) and closes; the dates between are tinted as the
|
|
21
|
+
* pointer or the keyboard moves. Closing before the second press keeps the old span. A hint at the top of the panel says which
|
|
22
|
+
* press is next, read out as it changes.
|
|
23
|
+
* Keyboard: ArrowDown, ArrowUp, Enter or Space on the button opens the panel with the focus on the list. In the list,
|
|
24
|
+
* ArrowUp / ArrowDown move a date, PageUp / PageDown ten, Home / End to the newest / oldest, Enter or Space picks.
|
|
25
|
+
* Esc closes; Tab and Shift+Tab move between the shortcuts and the list, and close the panel past either end.
|
|
26
|
+
* Other attributes and attachments go to the button.
|
|
27
|
+
*/
|
|
28
|
+
import { tick } from 'svelte'
|
|
29
|
+
import Icon from '../Icon.svelte'
|
|
30
|
+
import ErrorMessage from '../ErrorMessage.svelte'
|
|
31
|
+
import FieldLabel from './FieldLabel.svelte'
|
|
32
|
+
import RangeShortcuts from './RangeShortcuts.svelte'
|
|
33
|
+
import { invalid } from '../../lib/invalid.js'
|
|
34
|
+
import { topLayer } from '../../lib/dom.js'
|
|
35
|
+
import { pop } from '../../lib/motion.js'
|
|
36
|
+
import { reveal } from '../../lib/reveal.js'
|
|
37
|
+
import DashOutline from '../DashOutline.svelte'
|
|
38
|
+
import { compare, dateListShortcuts, dayOf, formatWhen, monthRuns, today } from '../../lib/dates.js'
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* @typedef {object} Props
|
|
42
|
+
* @property {[string, string]} [value] bindable
|
|
43
|
+
* @property {string[]} dates
|
|
44
|
+
* @property {string} id
|
|
45
|
+
* @property {string} label
|
|
46
|
+
* @property {{ label: string, range: (dates: string[]) => [string, string] | null }[]} [shortcuts]
|
|
47
|
+
* @property {string} [placeholder]
|
|
48
|
+
* @property {boolean} [hideLabel]
|
|
49
|
+
* @property {string} [error]
|
|
50
|
+
* @property {string} [info]
|
|
51
|
+
* @property {string} [note] dimmed text after the label, e.g. '(optional)'
|
|
52
|
+
* @property {boolean} [disabled]
|
|
53
|
+
*/
|
|
54
|
+
/** @type {Props & Omit<import('svelte/elements').HTMLButtonAttributes, keyof Props>} */
|
|
55
|
+
let {
|
|
56
|
+
value = $bindable(['', '']),
|
|
57
|
+
dates,
|
|
58
|
+
id,
|
|
59
|
+
label,
|
|
60
|
+
shortcuts = dateListShortcuts(),
|
|
61
|
+
placeholder = 'Choose dates',
|
|
62
|
+
hideLabel = false,
|
|
63
|
+
error = '',
|
|
64
|
+
info = '',
|
|
65
|
+
note = '',
|
|
66
|
+
disabled = false,
|
|
67
|
+
class: className,
|
|
68
|
+
...rest
|
|
69
|
+
} = $props()
|
|
70
|
+
|
|
71
|
+
const uid = $props.id()
|
|
72
|
+
const anchor = `--date-list-${uid}`
|
|
73
|
+
/** @type {HTMLButtonElement | undefined} */
|
|
74
|
+
let button = $state()
|
|
75
|
+
/** @type {HTMLDivElement | undefined} */
|
|
76
|
+
let sheet = $state()
|
|
77
|
+
/** @type {HTMLUListElement | undefined} */
|
|
78
|
+
let list = $state()
|
|
79
|
+
let open = $state(false)
|
|
80
|
+
/** The index in `newest` that holds the keyboard. */
|
|
81
|
+
let active = $state(0)
|
|
82
|
+
/** The first date of a span being chosen, until the second press. */
|
|
83
|
+
let first = $state(/** @type {string | null} */ (null))
|
|
84
|
+
/** The date under the pointer or the keyboard while choosing the second. */
|
|
85
|
+
let pointed = $state(/** @type {string | null} */ (null))
|
|
86
|
+
|
|
87
|
+
const oldest = $derived([...new Set(dates)].toSorted(compare))
|
|
88
|
+
const newest = $derived(oldest.toReversed())
|
|
89
|
+
/** The list's months, newest first; headed only when there is more than one. */
|
|
90
|
+
const months = $derived(monthRuns(newest))
|
|
91
|
+
const presets = $derived(shortcuts.map(({ label: name, range }) => ({ label: name, range: range(oldest) })))
|
|
92
|
+
/** The span drawn in the list: the one being chosen, else the value. */
|
|
93
|
+
const span = $derived(
|
|
94
|
+
/** @type {[string, string] | null} */ (first ? [first, pointed ?? first].toSorted(compare) : value[0] && value[1] ? [value[0], value[1]] : null),
|
|
95
|
+
)
|
|
96
|
+
/** How many dates fall on each (local) day. */
|
|
97
|
+
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)}`) : '')
|
|
112
|
+
const empty = $derived(!newest.length)
|
|
113
|
+
|
|
114
|
+
async function show() {
|
|
115
|
+
if (disabled || empty) return
|
|
116
|
+
first = null
|
|
117
|
+
pointed = null
|
|
118
|
+
active = Math.max(0, newest.indexOf(value[1]))
|
|
119
|
+
open = true
|
|
120
|
+
await tick()
|
|
121
|
+
const el = /** @type {HTMLElement | null | undefined} */ (list?.querySelector(`[data-i="${active}"]`))
|
|
122
|
+
if (list && el) list.scrollTop = el.offsetTop - (list.clientHeight - el.offsetHeight) / 2
|
|
123
|
+
list?.focus()
|
|
124
|
+
}
|
|
125
|
+
/** Closes the panel; with refocus, the focus goes back on the button (at once, so a Tab moves on from there). */
|
|
126
|
+
function close(refocus = true) {
|
|
127
|
+
open = false
|
|
128
|
+
if (refocus) button?.focus()
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/** @param {[string, string]} range */
|
|
132
|
+
function choose(range) {
|
|
133
|
+
value = range
|
|
134
|
+
first = null
|
|
135
|
+
close()
|
|
136
|
+
}
|
|
137
|
+
/** @param {string} day */
|
|
138
|
+
function pick(day) {
|
|
139
|
+
if (!first) {
|
|
140
|
+
first = day
|
|
141
|
+
pointed = day
|
|
142
|
+
return
|
|
143
|
+
}
|
|
144
|
+
choose(/** @type {[string, string]} */ ([first, day].toSorted(compare)))
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Attachment on the span's band: lays it behind the rows from the span's later end (on top, newest first) to its
|
|
149
|
+
* earlier one, measured, since a month's heading can sit between them. Runs again whenever the span changes.
|
|
150
|
+
* @param {[string, string] | null} _span @param {string | null} _first
|
|
151
|
+
*/
|
|
152
|
+
const band = (_span, _first) => (/** @type {HTMLElement} */ node) => {
|
|
153
|
+
// After the rows have taken their new classes (they come after the band, so they update after it).
|
|
154
|
+
tick().then(() => {
|
|
155
|
+
const top = /** @type {HTMLElement | null} */ (list?.querySelector('.span-top'))
|
|
156
|
+
const bottom = /** @type {HTMLElement | null} */ (list?.querySelector('.span-bottom'))
|
|
157
|
+
node.hidden = !top || !bottom
|
|
158
|
+
if (!top || !bottom) return
|
|
159
|
+
node.style.top = `${top.offsetTop}px`
|
|
160
|
+
node.style.height = `${bottom.offsetTop + bottom.offsetHeight - top.offsetTop}px`
|
|
161
|
+
})
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/** @param {number} i */
|
|
165
|
+
function moveTo(i) {
|
|
166
|
+
active = Math.min(Math.max(i, 0), newest.length - 1)
|
|
167
|
+
if (first) pointed = newest[active]
|
|
168
|
+
reveal(list, list?.querySelector(`[data-i="${active}"]`))
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/** @param {KeyboardEvent} e */
|
|
172
|
+
function onButtonKey(e) {
|
|
173
|
+
if (['ArrowDown', 'ArrowUp', 'Enter', ' '].includes(e.key)) {
|
|
174
|
+
e.preventDefault()
|
|
175
|
+
void show()
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
/** @param {KeyboardEvent} e */
|
|
179
|
+
function onListKey(e) {
|
|
180
|
+
const to = { ArrowDown: active + 1, ArrowUp: active - 1, PageDown: active + 10, PageUp: active - 10, Home: 0, End: newest.length - 1 }[e.key]
|
|
181
|
+
if (to !== undefined) moveTo(to)
|
|
182
|
+
else if (e.key === 'Enter' || e.key === ' ') pick(newest[active])
|
|
183
|
+
else return
|
|
184
|
+
e.preventDefault()
|
|
185
|
+
}
|
|
186
|
+
/** Esc closes; tabbing past either end of the panel closes it from the button, so the focus moves on from there.
|
|
187
|
+
* @param {KeyboardEvent} e */
|
|
188
|
+
function onPanelKey(e) {
|
|
189
|
+
if (e.key === 'Escape') {
|
|
190
|
+
e.preventDefault()
|
|
191
|
+
e.stopPropagation()
|
|
192
|
+
close()
|
|
193
|
+
} else if (e.key === 'Tab' && sheet) {
|
|
194
|
+
const stops = [...sheet.querySelectorAll('button:not(:disabled), [role="listbox"]')]
|
|
195
|
+
if (e.target === (e.shiftKey ? stops[0] : stops.at(-1))) close()
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
/** A press outside the button and the panel closes it. The label counts as the button. @param {PointerEvent} e */
|
|
199
|
+
function outside(e) {
|
|
200
|
+
const target = /** @type {Element} */ (e.target)
|
|
201
|
+
if (open && !button?.contains(target) && !sheet?.contains(target) && !target.closest?.(`label[for="${id}"]`)) close(false)
|
|
202
|
+
}
|
|
203
|
+
</script>
|
|
204
|
+
|
|
205
|
+
<svelte:document onpointerdowncapture={outside} />
|
|
206
|
+
|
|
207
|
+
{#snippet option(/** @type {string} */ day, /** @type {number} */ i)}
|
|
208
|
+
{@const inSpan = !!span && day >= span[0] && day <= span[1]}
|
|
209
|
+
<!-- While the second press is pending only the first date is solid; the other end is where the pointer is. -->
|
|
210
|
+
{@const edge = !!span && (first ? day === first : day === span[0] || day === span[1])}
|
|
211
|
+
<!-- Keyboard is handled on the listbox (aria-activedescendant pattern); options only take pointer input. -->
|
|
212
|
+
<!-- svelte-ignore a11y_click_events_have_key_events -->
|
|
213
|
+
<li
|
|
214
|
+
id="{id}-opt-{i}"
|
|
215
|
+
data-i={i}
|
|
216
|
+
role="option"
|
|
217
|
+
aria-selected={inSpan}
|
|
218
|
+
class:active={i === active}
|
|
219
|
+
class:edge
|
|
220
|
+
class:between={inSpan && !edge}
|
|
221
|
+
class:span-top={!!span && day === span[1]}
|
|
222
|
+
class:span-bottom={!!span && day === span[0]}
|
|
223
|
+
onpointerenter={() => ((active = i), first && (pointed = day))}
|
|
224
|
+
onclick={() => pick(day)}
|
|
225
|
+
>
|
|
226
|
+
{formatWhen(day)}
|
|
227
|
+
</li>
|
|
228
|
+
{/snippet}
|
|
229
|
+
|
|
230
|
+
<div class="field">
|
|
231
|
+
<FieldLabel for={id} id="{id}-label" {label} {note} {info} {hideLabel} />
|
|
232
|
+
<button
|
|
233
|
+
{id}
|
|
234
|
+
bind:this={button}
|
|
235
|
+
type="button"
|
|
236
|
+
class={['trigger', className]}
|
|
237
|
+
style:anchor-name={anchor}
|
|
238
|
+
{...rest}
|
|
239
|
+
disabled={disabled || empty}
|
|
240
|
+
aria-haspopup="dialog"
|
|
241
|
+
aria-expanded={open}
|
|
242
|
+
aria-labelledby="{id}-label {id}"
|
|
243
|
+
{@attach invalid(error && `${id}-error`)}
|
|
244
|
+
onclick={() => (open ? close() : show())}
|
|
245
|
+
onkeydown={onButtonKey}
|
|
246
|
+
>
|
|
247
|
+
<span class="value" class:placeholder={!shown}>{shown || (empty ? 'No dates' : placeholder)}</span>
|
|
248
|
+
{#if !disabled && !empty}<span class="caret" class:flip={open}><Icon name="caretDown" size="sm" /></span>{/if}
|
|
249
|
+
</button>
|
|
250
|
+
{#if open}
|
|
251
|
+
<div
|
|
252
|
+
bind:this={sheet}
|
|
253
|
+
class="panel"
|
|
254
|
+
role="dialog"
|
|
255
|
+
aria-label={label}
|
|
256
|
+
tabindex="-1"
|
|
257
|
+
data-floating
|
|
258
|
+
style:position-anchor={anchor}
|
|
259
|
+
{@attach topLayer(button)}
|
|
260
|
+
transition:pop={{ from: button }}
|
|
261
|
+
onkeydown={onPanelKey}
|
|
262
|
+
>
|
|
263
|
+
<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>
|
|
265
|
+
{#if shortcuts.length}<RangeShortcuts items={presets} {value} onpick={choose} />{/if}
|
|
266
|
+
</div>
|
|
267
|
+
<ul
|
|
268
|
+
bind:this={list}
|
|
269
|
+
class="list"
|
|
270
|
+
role="listbox"
|
|
271
|
+
tabindex="0"
|
|
272
|
+
aria-multiselectable="true"
|
|
273
|
+
aria-labelledby="{id}-label"
|
|
274
|
+
aria-describedby="{id}-hint"
|
|
275
|
+
aria-activedescendant="{id}-opt-{active}"
|
|
276
|
+
onkeydown={onListKey}
|
|
277
|
+
>
|
|
278
|
+
<!-- The span's band, behind its rows from end to end (see .band). -->
|
|
279
|
+
<li class="band" class:pending={!!first} class:down={!!first && !!span && first === span[1]} role="none" {@attach band(span, first)}>{#if first}<DashOutline />{/if}</li>
|
|
280
|
+
{#if months.length > 1}
|
|
281
|
+
{#each months as month (month.key)}
|
|
282
|
+
<li class="group" role="group" aria-labelledby="{id}-month-{month.key}">
|
|
283
|
+
<div class="group-head" id="{id}-month-{month.key}" data-sticky-head>{month.label}</div>
|
|
284
|
+
<ul role="none">
|
|
285
|
+
{#each month.items as { item: day, index } (day)}{@render option(day, index)}{/each}
|
|
286
|
+
</ul>
|
|
287
|
+
</li>
|
|
288
|
+
{/each}
|
|
289
|
+
{:else}
|
|
290
|
+
{#each newest as day, i (day)}{@render option(day, i)}{/each}
|
|
291
|
+
{/if}
|
|
292
|
+
</ul>
|
|
293
|
+
</div>
|
|
294
|
+
{/if}
|
|
295
|
+
<ErrorMessage floating id="{id}-error" message={error} ondismiss={() => button?.focus()} />
|
|
296
|
+
</div>
|
|
297
|
+
|
|
298
|
+
<style>
|
|
299
|
+
.field {
|
|
300
|
+
position: relative;
|
|
301
|
+
display: flex;
|
|
302
|
+
flex-direction: column;
|
|
303
|
+
gap: 3px;
|
|
304
|
+
min-width: 0;
|
|
305
|
+
}
|
|
306
|
+
/* Raised like Select's button: pressed to open a list. */
|
|
307
|
+
.trigger {
|
|
308
|
+
display: flex;
|
|
309
|
+
align-items: center;
|
|
310
|
+
justify-content: space-between;
|
|
311
|
+
gap: 8px;
|
|
312
|
+
min-width: 120px;
|
|
313
|
+
max-width: 100%;
|
|
314
|
+
min-height: 32px;
|
|
315
|
+
padding: 0 8px 0 10px;
|
|
316
|
+
border: 1px solid var(--line-strong);
|
|
317
|
+
border-radius: var(--r);
|
|
318
|
+
background: var(--control-2);
|
|
319
|
+
color: var(--fg);
|
|
320
|
+
font: var(--w-medium) 13px var(--font-data);
|
|
321
|
+
font-variant-numeric: tabular-nums;
|
|
322
|
+
text-align: left;
|
|
323
|
+
cursor: pointer;
|
|
324
|
+
--raise: var(--shadow-btn);
|
|
325
|
+
box-shadow: var(--raise);
|
|
326
|
+
transition:
|
|
327
|
+
background-color var(--dur) var(--ease-out),
|
|
328
|
+
border-color var(--dur) var(--ease-out),
|
|
329
|
+
box-shadow var(--dur) var(--ease-out);
|
|
330
|
+
}
|
|
331
|
+
.trigger:hover:not(:disabled) {
|
|
332
|
+
background: var(--control-3);
|
|
333
|
+
}
|
|
334
|
+
.trigger[aria-expanded='true'] {
|
|
335
|
+
background: var(--control-4);
|
|
336
|
+
box-shadow: none;
|
|
337
|
+
}
|
|
338
|
+
.trigger:disabled {
|
|
339
|
+
--raise: 0 0 transparent;
|
|
340
|
+
background: none;
|
|
341
|
+
border-color: var(--line);
|
|
342
|
+
cursor: default;
|
|
343
|
+
}
|
|
344
|
+
/* Focused, it sits flat inside the ring, as Select's does. */
|
|
345
|
+
.trigger:focus-visible {
|
|
346
|
+
border-color: var(--accent-line);
|
|
347
|
+
box-shadow: var(--ring);
|
|
348
|
+
outline: none;
|
|
349
|
+
}
|
|
350
|
+
.trigger:global([aria-invalid='true']) {
|
|
351
|
+
border-color: var(--danger);
|
|
352
|
+
}
|
|
353
|
+
.trigger:global([aria-invalid='true']):focus-visible {
|
|
354
|
+
box-shadow: 0 0 0 2px color-mix(in lch, var(--danger) 30%, transparent);
|
|
355
|
+
}
|
|
356
|
+
.value {
|
|
357
|
+
min-width: 0;
|
|
358
|
+
overflow: clip;
|
|
359
|
+
text-overflow: ellipsis;
|
|
360
|
+
white-space: nowrap;
|
|
361
|
+
}
|
|
362
|
+
.placeholder {
|
|
363
|
+
font-family: var(--font-body);
|
|
364
|
+
color: var(--muted);
|
|
365
|
+
}
|
|
366
|
+
.caret {
|
|
367
|
+
flex: none;
|
|
368
|
+
display: inline-flex;
|
|
369
|
+
color: var(--muted);
|
|
370
|
+
transition: rotate var(--dur) var(--ease-out);
|
|
371
|
+
}
|
|
372
|
+
.caret.flip {
|
|
373
|
+
rotate: 180deg;
|
|
374
|
+
}
|
|
375
|
+
/* Anchored under the button, flipping above or to its other side when there's no room. */
|
|
376
|
+
/* A picker: its hint and dates are chrome, not text to copy (base.css). */
|
|
377
|
+
.panel {
|
|
378
|
+
user-select: none;
|
|
379
|
+
-webkit-user-select: none;
|
|
380
|
+
position: fixed;
|
|
381
|
+
z-index: calc(var(--z-overlay) + 1);
|
|
382
|
+
position-area: block-end span-inline-end;
|
|
383
|
+
position-try-fallbacks:
|
|
384
|
+
flip-block,
|
|
385
|
+
flip-inline,
|
|
386
|
+
flip-block flip-inline;
|
|
387
|
+
position-visibility: anchors-visible;
|
|
388
|
+
/* 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
|
|
389
|
+
end at the field's right edge: a flip swaps the inline margins too). */
|
|
390
|
+
margin-inline-start: calc(var(--space-1) * -1);
|
|
391
|
+
display: flex;
|
|
392
|
+
flex-direction: column;
|
|
393
|
+
width: max-content;
|
|
394
|
+
min-width: max(anchor-size(width), 224px);
|
|
395
|
+
max-width: calc(100dvw - 32px);
|
|
396
|
+
margin-block: 4px;
|
|
397
|
+
overflow: hidden;
|
|
398
|
+
border: 1px solid transparent;
|
|
399
|
+
background:
|
|
400
|
+
linear-gradient(var(--elevated), var(--elevated)) padding-box,
|
|
401
|
+
var(--edge-grad-float);
|
|
402
|
+
border-radius: var(--r-lg);
|
|
403
|
+
box-shadow: var(--shadow);
|
|
404
|
+
color: var(--fg);
|
|
405
|
+
}
|
|
406
|
+
/* The hint and the shortcuts above the list, with a hairline under them from edge to edge (as Select's search). */
|
|
407
|
+
.top {
|
|
408
|
+
flex: none;
|
|
409
|
+
display: grid;
|
|
410
|
+
gap: var(--space-1);
|
|
411
|
+
padding: var(--space-2) 4px;
|
|
412
|
+
border-bottom: 1px solid var(--line);
|
|
413
|
+
}
|
|
414
|
+
.hint {
|
|
415
|
+
margin: 0;
|
|
416
|
+
padding: 2px var(--space-2) 0;
|
|
417
|
+
}
|
|
418
|
+
.list {
|
|
419
|
+
flex: 1 1 auto;
|
|
420
|
+
min-height: 0;
|
|
421
|
+
max-height: min(280px, calc(100dvh - 160px));
|
|
422
|
+
margin: 0;
|
|
423
|
+
padding: 4px;
|
|
424
|
+
overflow-y: auto;
|
|
425
|
+
overscroll-behavior: contain;
|
|
426
|
+
list-style: none;
|
|
427
|
+
/* Positioned: the options' offsetTop (opening on the value) counts from the list. */
|
|
428
|
+
position: relative;
|
|
429
|
+
--head: 26px;
|
|
430
|
+
}
|
|
431
|
+
.list ul {
|
|
432
|
+
margin: 0;
|
|
433
|
+
padding: 0;
|
|
434
|
+
list-style: none;
|
|
435
|
+
}
|
|
436
|
+
/* A month's heading, kept at the top while its dates scroll under it, across the list's whole width (as Select's
|
|
437
|
+
group headings). It sticks at the list's content edge, 4px below its top: that strip is filled too. */
|
|
438
|
+
.group-head {
|
|
439
|
+
position: sticky;
|
|
440
|
+
top: 0;
|
|
441
|
+
z-index: 1;
|
|
442
|
+
display: flex;
|
|
443
|
+
align-items: center;
|
|
444
|
+
min-height: var(--head);
|
|
445
|
+
margin-inline: -4px;
|
|
446
|
+
padding: 0 10px 0 12px;
|
|
447
|
+
background: var(--elevated);
|
|
448
|
+
box-shadow: 0 -4px 0 var(--elevated);
|
|
449
|
+
color: var(--muted);
|
|
450
|
+
font: var(--w-medium) 12px var(--font-body);
|
|
451
|
+
}
|
|
452
|
+
/* A hairline between months, edge to edge. */
|
|
453
|
+
.group + .group {
|
|
454
|
+
margin-top: 4px;
|
|
455
|
+
margin-inline: -4px;
|
|
456
|
+
padding: 4px 4px 0;
|
|
457
|
+
border-top: 1px solid var(--line);
|
|
458
|
+
}
|
|
459
|
+
.list:focus {
|
|
460
|
+
outline: none;
|
|
461
|
+
}
|
|
462
|
+
/* Rows as Select's: 32px, the pointer's or keyboard's row filled (.active, which the pointer moves too). */
|
|
463
|
+
[role='option'] {
|
|
464
|
+
display: flex;
|
|
465
|
+
align-items: center;
|
|
466
|
+
min-height: 32px;
|
|
467
|
+
padding: 0 10px;
|
|
468
|
+
border-radius: var(--r-sm);
|
|
469
|
+
color: var(--fg);
|
|
470
|
+
font: 13px var(--font-data);
|
|
471
|
+
font-variant-numeric: tabular-nums;
|
|
472
|
+
white-space: nowrap;
|
|
473
|
+
cursor: pointer;
|
|
474
|
+
}
|
|
475
|
+
.active {
|
|
476
|
+
background: var(--control-3);
|
|
477
|
+
}
|
|
478
|
+
/* Rows paint above the span's band (which is positioned). */
|
|
479
|
+
[role='option'] {
|
|
480
|
+
position: relative;
|
|
481
|
+
}
|
|
482
|
+
/* The span, one rounded block (Linear's timeline bars): its ends solid, and between them a band of the brand colour
|
|
483
|
+
that blends out of each end, strongest beside it and easing off in the middle. The rows between stay clear, so the
|
|
484
|
+
row under the pointer lights up on top of it. */
|
|
485
|
+
.band {
|
|
486
|
+
position: absolute;
|
|
487
|
+
inset-inline: 4px;
|
|
488
|
+
border-radius: var(--r-sm);
|
|
489
|
+
background: linear-gradient(
|
|
490
|
+
color-mix(in srgb, var(--brand) 24%, transparent),
|
|
491
|
+
color-mix(in srgb, var(--brand) 8%, transparent) 50%,
|
|
492
|
+
color-mix(in srgb, var(--brand) 24%, transparent)
|
|
493
|
+
);
|
|
494
|
+
pointer-events: none;
|
|
495
|
+
}
|
|
496
|
+
/* While the second press is pending, the span is only proposed: the band is Linear's tail, a dashed outline (what a
|
|
497
|
+
suggestion looks like here; DashOutline's spaced dashes) and a tint that fades in from the first date towards the
|
|
498
|
+
pointer. */
|
|
499
|
+
.band.pending {
|
|
500
|
+
background: linear-gradient(
|
|
501
|
+
to top,
|
|
502
|
+
color-mix(in srgb, var(--brand) 0%, transparent),
|
|
503
|
+
color-mix(in srgb, var(--brand) 20%, transparent)
|
|
504
|
+
);
|
|
505
|
+
}
|
|
506
|
+
.band.pending.down {
|
|
507
|
+
background: linear-gradient(
|
|
508
|
+
to bottom,
|
|
509
|
+
color-mix(in srgb, var(--brand) 0%, transparent),
|
|
510
|
+
color-mix(in srgb, var(--brand) 20%, transparent)
|
|
511
|
+
);
|
|
512
|
+
}
|
|
513
|
+
.between {
|
|
514
|
+
color: var(--fg);
|
|
515
|
+
}
|
|
516
|
+
.edge {
|
|
517
|
+
background: var(--brand);
|
|
518
|
+
color: var(--accent-ink);
|
|
519
|
+
}
|
|
520
|
+
/* The span reads as one block: newest first, its later end rounds off only on top and its earlier end only at the
|
|
521
|
+
bottom, joining the square rows between (one date alone stays round all over). */
|
|
522
|
+
.span-top:not(.span-bottom) {
|
|
523
|
+
border-end-start-radius: 0;
|
|
524
|
+
border-end-end-radius: 0;
|
|
525
|
+
}
|
|
526
|
+
.span-bottom:not(.span-top) {
|
|
527
|
+
border-start-start-radius: 0;
|
|
528
|
+
border-start-end-radius: 0;
|
|
529
|
+
}
|
|
530
|
+
@media (pointer: coarse) {
|
|
531
|
+
[role='option'] {
|
|
532
|
+
min-height: 44px;
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
@media (forced-colors: active) {
|
|
536
|
+
.panel {
|
|
537
|
+
border-color: CanvasText;
|
|
538
|
+
}
|
|
539
|
+
.edge {
|
|
540
|
+
background: Highlight;
|
|
541
|
+
color: HighlightText;
|
|
542
|
+
}
|
|
543
|
+
.between {
|
|
544
|
+
outline: 1px solid Highlight;
|
|
545
|
+
outline-offset: -1px;
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
</style>
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
export default DateRangeSelect;
|
|
2
|
+
type DateRangeSelect = {
|
|
3
|
+
$on?(type: string, callback: (e: any) => void): () => void;
|
|
4
|
+
$set?(props: Partial<Props & Omit<HTMLButtonAttributes, keyof Props>>): void;
|
|
5
|
+
};
|
|
6
|
+
declare const DateRangeSelect: import("svelte").Component<{
|
|
7
|
+
/**
|
|
8
|
+
* bindable
|
|
9
|
+
*/
|
|
10
|
+
value?: [string, string] | undefined;
|
|
11
|
+
dates: string[];
|
|
12
|
+
id: string;
|
|
13
|
+
label: string;
|
|
14
|
+
shortcuts?: {
|
|
15
|
+
label: string;
|
|
16
|
+
range: (dates: string[]) => [string, string] | null;
|
|
17
|
+
}[] | undefined;
|
|
18
|
+
placeholder?: 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
|
+
} & Omit<import("svelte/elements").HTMLButtonAttributes, keyof {
|
|
28
|
+
/**
|
|
29
|
+
* bindable
|
|
30
|
+
*/
|
|
31
|
+
value?: [string, string] | undefined;
|
|
32
|
+
dates: string[];
|
|
33
|
+
id: string;
|
|
34
|
+
label: string;
|
|
35
|
+
shortcuts?: {
|
|
36
|
+
label: string;
|
|
37
|
+
range: (dates: string[]) => [string, string] | null;
|
|
38
|
+
}[] | undefined;
|
|
39
|
+
placeholder?: 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
|
+
}>, {}, "value">;
|
|
49
|
+
type Props = {
|
|
50
|
+
/**
|
|
51
|
+
* bindable
|
|
52
|
+
*/
|
|
53
|
+
value?: [string, string] | undefined;
|
|
54
|
+
dates: string[];
|
|
55
|
+
id: string;
|
|
56
|
+
label: string;
|
|
57
|
+
shortcuts?: {
|
|
58
|
+
label: string;
|
|
59
|
+
range: (dates: string[]) => [string, string] | null;
|
|
60
|
+
}[] | undefined;
|
|
61
|
+
placeholder?: string | undefined;
|
|
62
|
+
hideLabel?: boolean | undefined;
|
|
63
|
+
error?: string | undefined;
|
|
64
|
+
info?: string | undefined;
|
|
65
|
+
/**
|
|
66
|
+
* dimmed text after the label, e.g. '(optional)'
|
|
67
|
+
*/
|
|
68
|
+
note?: string | undefined;
|
|
69
|
+
disabled?: boolean | undefined;
|
|
70
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
/**
|
|
3
|
+
* A field's label: its text, an optional dimmed note after it ("(optional)"), and an optional ⓘ with help text. The
|
|
4
|
+
* fields (TextField, Select, TagInput…) all draw theirs with it; use it for a custom control so its label matches.
|
|
5
|
+
*
|
|
6
|
+
* <FieldLabel for="name" label="Name" note="(optional)" info="What people call you." />
|
|
7
|
+
* <input id="name" />
|
|
8
|
+
* <FieldLabel id="plan-label" label="Plan" /> (no `for`: a <span>, for a group named with aria-labelledby)
|
|
9
|
+
*
|
|
10
|
+
* label: the text. for: the control's id; without it the label is a <span>. id: the label's own id.
|
|
11
|
+
* note: dimmed text after the label (.label-note), read by screen readers as part of the name.
|
|
12
|
+
* info: help text behind an ⓘ after the label (InfoTip, named "About {label}"); the two then sit in a .field-head row.
|
|
13
|
+
* hideLabel: the label is kept for screen readers only; an ⓘ stays visible.
|
|
14
|
+
* Other attributes, the class and attachments go to the label element.
|
|
15
|
+
* Keyboard: the ⓘ is a tab stop and opens its tip on focus (see InfoTip).
|
|
16
|
+
*
|
|
17
|
+
* @typedef {object} Props
|
|
18
|
+
* @property {string} label
|
|
19
|
+
* @property {string} [for]
|
|
20
|
+
* @property {string} [note]
|
|
21
|
+
* @property {string} [info]
|
|
22
|
+
* @property {boolean} [hideLabel]
|
|
23
|
+
*/
|
|
24
|
+
import InfoTip from '../InfoTip.svelte'
|
|
25
|
+
|
|
26
|
+
/** @type {Props & Omit<import('svelte/elements').HTMLLabelAttributes, keyof Props>} */
|
|
27
|
+
let { label, for: htmlFor, note = '', info = '', hideLabel = false, class: className, ...rest } = $props()
|
|
28
|
+
</script>
|
|
29
|
+
|
|
30
|
+
{#snippet text()}
|
|
31
|
+
<svelte:element
|
|
32
|
+
this={htmlFor ? 'label' : 'span'}
|
|
33
|
+
for={htmlFor}
|
|
34
|
+
class={['field-label', hideLabel && 'sr-only', className]}
|
|
35
|
+
{...rest}>{label}{#if note}{' '}<span class="label-note">{note}</span>{/if}</svelte:element
|
|
36
|
+
>
|
|
37
|
+
{/snippet}
|
|
38
|
+
|
|
39
|
+
{#if info}
|
|
40
|
+
<div class="field-head">{@render text()}<InfoTip lines={[{ text: info }]} label="About {label}" /></div>
|
|
41
|
+
{:else}
|
|
42
|
+
{@render text()}
|
|
43
|
+
{/if}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export default FieldLabel;
|
|
2
|
+
/**
|
|
3
|
+
* A field's label: its text, an optional dimmed note after it ("(optional)"), and an optional ⓘ with help text. The
|
|
4
|
+
* fields (TextField, Select, TagInput…) all draw theirs with it; use it for a custom control so its label matches.
|
|
5
|
+
*
|
|
6
|
+
* <FieldLabel for="name" label="Name" note="(optional)" info="What people call you." />
|
|
7
|
+
* <input id="name" />
|
|
8
|
+
* <FieldLabel id="plan-label" label="Plan" /> (no `for`: a <span>, for a group named with aria-labelledby)
|
|
9
|
+
*
|
|
10
|
+
* label: the text. for: the control's id; without it the label is a <span>. id: the label's own id.
|
|
11
|
+
* note: dimmed text after the label (.label-note), read by screen readers as part of the name.
|
|
12
|
+
* info: help text behind an ⓘ after the label (InfoTip, named "About {label}"); the two then sit in a .field-head row.
|
|
13
|
+
* hideLabel: the label is kept for screen readers only; an ⓘ stays visible.
|
|
14
|
+
* Other attributes, the class and attachments go to the label element.
|
|
15
|
+
* Keyboard: the ⓘ is a tab stop and opens its tip on focus (see InfoTip).
|
|
16
|
+
*/
|
|
17
|
+
export type Props = {
|
|
18
|
+
label: string;
|
|
19
|
+
for?: string | undefined;
|
|
20
|
+
note?: string | undefined;
|
|
21
|
+
info?: string | undefined;
|
|
22
|
+
hideLabel?: boolean | undefined;
|
|
23
|
+
};
|
|
24
|
+
type FieldLabel = {
|
|
25
|
+
$on?(type: string, callback: (e: any) => void): () => void;
|
|
26
|
+
$set?(props: Partial<Props & Omit<HTMLLabelAttributes, keyof Props>>): void;
|
|
27
|
+
};
|
|
28
|
+
declare const FieldLabel: import("svelte").Component<Props & Omit<import("svelte/elements").HTMLLabelAttributes, keyof Props>, {}, "">;
|