@xerios/design-system 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +185 -0
- package/dist/components/Button.svelte.d.ts +70 -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 +401 -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 +110 -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 +151 -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 +79 -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 +899 -0
- package/dist/css/base.css +334 -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,552 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import Icon from '../Icon.svelte'
|
|
3
|
+
/**
|
|
4
|
+
* Single-choice dropdown with a listbox popover. Keyboard: arrows, Home/End, type-ahead, Enter, Escape; with a search
|
|
5
|
+
* field the focus stays in it, arrows and Enter work the list, and Home/End, Space and letters are the field's.
|
|
6
|
+
* Options: { value, label, text?, hint?, group? }. `label` shows on the button, `text` (if set) in the list.
|
|
7
|
+
* Consecutive options with the same `group` sit under its heading; a value may appear in more than one group.
|
|
8
|
+
* groupActions: { [group]: { icon, label, run } } puts a small button on that group's heading (e.g. Clear).
|
|
9
|
+
* loading (true or a label like "Checking models…"): the button shows a shimmer on its edge and label and doesn't open.
|
|
10
|
+
* ghost: a flat button with no raised edges (for toolbars and dense rows); the default is raised.
|
|
11
|
+
* disabled: shows the value but doesn't open, flat with no fill or caret (e.g. when there is only one choice).
|
|
12
|
+
* error: a message from the app; the button turns red (aria-invalid, set by lib/invalid.js) and shows it in a bubble underneath, which can be dismissed.
|
|
13
|
+
* info: what the choice is for, behind an ⓘ next to the label (see InfoTip).
|
|
14
|
+
* note: dimmed text after the label, such as '(optional)' (see .label-note); screen readers read it as part of the label.
|
|
15
|
+
* search: 'auto' (default: a ListSearch field at the top of the list when there are more than 8 options), true or
|
|
16
|
+
* false. Typing narrows the list (anywhere in an option's text, ignoring case and accents; lib/list-search.js) and
|
|
17
|
+
* puts the keyboard on the first match; Esc clears the text, then closes. searchPlaceholder: its text ("Filter…").
|
|
18
|
+
* Other attributes (class…) and attachments go to the button.
|
|
19
|
+
*
|
|
20
|
+
* <Select bind:value={region} options={REGIONS} id="region" label="Region" info="Where the files are served from." />
|
|
21
|
+
*/
|
|
22
|
+
import { tick } from 'svelte'
|
|
23
|
+
import ErrorMessage from '../ErrorMessage.svelte'
|
|
24
|
+
import FieldLabel from './FieldLabel.svelte'
|
|
25
|
+
import Shimmer from '../Shimmer.svelte'
|
|
26
|
+
import { tooltip } from '../../lib/tooltip.js'
|
|
27
|
+
import { invalid } from '../../lib/invalid.js'
|
|
28
|
+
import { observeSize } from '../../lib/observe.js'
|
|
29
|
+
import { topLayer } from '../../lib/dom.js' // the list lives in the top layer: no scrolling parent clips it, no modal dialog covers it
|
|
30
|
+
import { pop } from '../../lib/motion.js'
|
|
31
|
+
import ListSearch from './ListSearch.svelte'
|
|
32
|
+
import { matches, wantsSearch } from '../../lib/list-search.js'
|
|
33
|
+
import { reveal } from '../../lib/reveal.js'
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* @typedef {{ value: any, label: string, text?: string, hint?: string, group?: string }} Option
|
|
37
|
+
* @typedef {object} Props
|
|
38
|
+
* @property {any} [value] bindable
|
|
39
|
+
* @property {Option[]} options
|
|
40
|
+
* @property {string} id
|
|
41
|
+
* @property {string} label
|
|
42
|
+
* @property {boolean} [hideLabel]
|
|
43
|
+
* @property {Record<string, { icon: string, label: string, run: () => void }>} [groupActions]
|
|
44
|
+
* @property {boolean | string} [loading]
|
|
45
|
+
* @property {string} [error]
|
|
46
|
+
* @property {string} [info]
|
|
47
|
+
* @property {string} [note] dimmed text after the label, e.g. '(optional)'
|
|
48
|
+
* @property {boolean} [ghost]
|
|
49
|
+
* @property {boolean} [disabled]
|
|
50
|
+
* @property {'auto' | boolean} [search]
|
|
51
|
+
* @property {string} [searchPlaceholder]
|
|
52
|
+
*/
|
|
53
|
+
/** @type {Props & Omit<import('svelte/elements').HTMLButtonAttributes, keyof Props>} */
|
|
54
|
+
let {
|
|
55
|
+
value = $bindable(),
|
|
56
|
+
options,
|
|
57
|
+
id,
|
|
58
|
+
label,
|
|
59
|
+
hideLabel = false,
|
|
60
|
+
groupActions = {},
|
|
61
|
+
loading = false,
|
|
62
|
+
error = '',
|
|
63
|
+
info = '',
|
|
64
|
+
note = '',
|
|
65
|
+
ghost = false,
|
|
66
|
+
disabled = false,
|
|
67
|
+
search = 'auto',
|
|
68
|
+
searchPlaceholder = 'Filter…',
|
|
69
|
+
class: className,
|
|
70
|
+
...rest
|
|
71
|
+
} = $props()
|
|
72
|
+
let open = $state(false)
|
|
73
|
+
let active = $state(0)
|
|
74
|
+
let button = $state(),
|
|
75
|
+
list = $state(),
|
|
76
|
+
listbox = $state(),
|
|
77
|
+
searchField = $state()
|
|
78
|
+
let query = $state('')
|
|
79
|
+
const current = $derived(options.find((o) => o.value === value) ?? options[0])
|
|
80
|
+
const text = (o) => o.text ?? o.label
|
|
81
|
+
const searchable = $derived(wantsSearch(search, options.length))
|
|
82
|
+
// The options the search leaves, each with its index into `options` (what keyboard and ids use).
|
|
83
|
+
const shown = $derived(options.map((o, i) => ({ o, i })).filter(({ o }) => matches(text(o), query)))
|
|
84
|
+
const visible = $derived(shown.map(({ i }) => i))
|
|
85
|
+
// Runs of shown options with the same group.
|
|
86
|
+
const sections = $derived(
|
|
87
|
+
shown.reduce((acc, { o, i }) => {
|
|
88
|
+
const last = acc.at(-1)
|
|
89
|
+
if (last && last.group === (o.group ?? null)) last.items.push({ o, i })
|
|
90
|
+
else acc.push({ group: o.group ?? null, items: [{ o, i }] })
|
|
91
|
+
return acc
|
|
92
|
+
}, []),
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
// The list is anchored to the button in CSS (anchor positioning): it sits below it, flips above or to the other side
|
|
96
|
+
// when there is no room, and follows it while the page scrolls. Each Select needs its own anchor name.
|
|
97
|
+
const uid = $props.id()
|
|
98
|
+
const anchor = `--select-${uid}`
|
|
99
|
+
|
|
100
|
+
// Whether the value on the button is cut off by its ellipsis: then the button's tooltip shows it whole (a native title
|
|
101
|
+
// can't be reached from the keyboard). Checked on resize, and again whenever the value changes.
|
|
102
|
+
let cut = $state(false)
|
|
103
|
+
const watchCut = (_text) => (node) => {
|
|
104
|
+
const check = () => (cut = node.scrollWidth > node.clientWidth)
|
|
105
|
+
const stop = observeSize(node, check)
|
|
106
|
+
check()
|
|
107
|
+
return stop
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
async function show() {
|
|
111
|
+
if (disabled || loading || !options.length) return
|
|
112
|
+
query = ''
|
|
113
|
+
active = Math.max(0, options.indexOf(current))
|
|
114
|
+
open = true
|
|
115
|
+
await tick()
|
|
116
|
+
// Open on the current option: centred in the list when the list scrolls.
|
|
117
|
+
const el = listbox?.querySelector(`[data-i="${active}"]`)
|
|
118
|
+
if (el) listbox.scrollTop = el.offsetTop - (listbox.clientHeight - el.offsetHeight) / 2
|
|
119
|
+
if (searchField) searchField.focus()
|
|
120
|
+
else listbox?.focus()
|
|
121
|
+
}
|
|
122
|
+
/** @param {string} q */
|
|
123
|
+
function narrow(q) {
|
|
124
|
+
query = q
|
|
125
|
+
// The keyboard goes to the first match (back on the current option when the text is cleared).
|
|
126
|
+
active = q ? (visible[0] ?? -1) : Math.max(0, options.indexOf(current))
|
|
127
|
+
tick().then(() => reveal(listbox, listbox?.querySelector(`[data-i="${active}"]`)))
|
|
128
|
+
}
|
|
129
|
+
async function runGroupAction(action) {
|
|
130
|
+
action.run()
|
|
131
|
+
await tick()
|
|
132
|
+
active = Math.min(Math.max(0, options.indexOf(current)), options.length - 1)
|
|
133
|
+
}
|
|
134
|
+
function hide(refocus = true) {
|
|
135
|
+
open = false
|
|
136
|
+
if (refocus) button?.focus()
|
|
137
|
+
}
|
|
138
|
+
function choose(i) {
|
|
139
|
+
value = options[i].value
|
|
140
|
+
hide()
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function onButtonKey(e) {
|
|
144
|
+
if (['ArrowDown', 'ArrowUp', 'Enter', ' '].includes(e.key)) {
|
|
145
|
+
e.preventDefault()
|
|
146
|
+
show()
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
function onListKey(e) {
|
|
150
|
+
// Steps go through the options the search leaves.
|
|
151
|
+
const n = visible.length
|
|
152
|
+
const at = visible.indexOf(active)
|
|
153
|
+
switch (e.key) {
|
|
154
|
+
case 'ArrowDown':
|
|
155
|
+
if (n) active = visible[(at + 1) % n]
|
|
156
|
+
break
|
|
157
|
+
case 'ArrowUp':
|
|
158
|
+
if (n) active = visible[at <= 0 ? n - 1 : at - 1]
|
|
159
|
+
break
|
|
160
|
+
case 'Home':
|
|
161
|
+
case 'End':
|
|
162
|
+
if (searchable) return // the caret's
|
|
163
|
+
if (n) active = e.key === 'Home' ? visible[0] : visible[n - 1]
|
|
164
|
+
break
|
|
165
|
+
case ' ':
|
|
166
|
+
if (searchable) return // a space in the search
|
|
167
|
+
if (at >= 0) choose(active)
|
|
168
|
+
break
|
|
169
|
+
case 'Enter':
|
|
170
|
+
if (at >= 0) choose(active)
|
|
171
|
+
break
|
|
172
|
+
case 'Escape':
|
|
173
|
+
hide()
|
|
174
|
+
break
|
|
175
|
+
case 'Tab':
|
|
176
|
+
hide()
|
|
177
|
+
return // back on the button first, so Tab moves on from there (the list sits at the end of <body>)
|
|
178
|
+
default: {
|
|
179
|
+
if (searchable || e.key.length !== 1) return
|
|
180
|
+
const k = e.key.toLowerCase()
|
|
181
|
+
const order = [...options.keys()].slice(active + 1).concat([...options.keys()].slice(0, active + 1))
|
|
182
|
+
const hit = order.find((i) => text(options[i]).toLowerCase().startsWith(k))
|
|
183
|
+
if (hit == null) return
|
|
184
|
+
active = hit
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
e.preventDefault()
|
|
188
|
+
e.stopPropagation()
|
|
189
|
+
reveal(listbox, listbox?.querySelector(`[data-i="${active}"]`))
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// While open, a press outside closes the list. The label counts as the button (its click toggles the list), so pressing
|
|
193
|
+
// it isn't an outside press.
|
|
194
|
+
const outside = (e) => open && !button.contains(e.target) && !list?.contains(e.target) && !e.target.closest?.(`label[for="${id}"]`) && hide(false)
|
|
195
|
+
</script>
|
|
196
|
+
|
|
197
|
+
<svelte:document onpointerdowncapture={outside} />
|
|
198
|
+
|
|
199
|
+
{#snippet option(o, i)}
|
|
200
|
+
<!-- Keyboard is handled on the listbox (aria-activedescendant pattern); options only take pointer input. -->
|
|
201
|
+
<!-- svelte-ignore a11y_click_events_have_key_events -->
|
|
202
|
+
<li
|
|
203
|
+
id="{id}-opt-{i}"
|
|
204
|
+
data-i={i}
|
|
205
|
+
role="option"
|
|
206
|
+
aria-selected={o.value === value}
|
|
207
|
+
class:active={i === active}
|
|
208
|
+
onpointerenter={() => (active = i)}
|
|
209
|
+
onclick={() => choose(i)}
|
|
210
|
+
>
|
|
211
|
+
<span class="tick"
|
|
212
|
+
>{#if o.value === value}<Icon name="check" size="sm" />{/if}</span
|
|
213
|
+
>
|
|
214
|
+
<span class="label" title={o.label}>{text(o)}</span>
|
|
215
|
+
{#if o.hint}<span class="hint">{o.hint}</span>{/if}
|
|
216
|
+
</li>
|
|
217
|
+
{/snippet}
|
|
218
|
+
|
|
219
|
+
<div class="field">
|
|
220
|
+
<!-- A real label for the trigger button: clicking it activates the button, so it opens the list, as clicking a text
|
|
221
|
+
field's label puts you in the field. -->
|
|
222
|
+
<FieldLabel for={id} id="{id}-label" {label} {note} {info} {hideLabel} />
|
|
223
|
+
<div class="wrap">
|
|
224
|
+
<button
|
|
225
|
+
{id}
|
|
226
|
+
bind:this={button}
|
|
227
|
+
type="button"
|
|
228
|
+
class={['trigger', className]}
|
|
229
|
+
style:anchor-name={anchor}
|
|
230
|
+
{...rest}
|
|
231
|
+
class:shimmer={loading}
|
|
232
|
+
class:ghost
|
|
233
|
+
{disabled}
|
|
234
|
+
aria-haspopup="listbox"
|
|
235
|
+
aria-expanded={open}
|
|
236
|
+
aria-busy={loading || undefined}
|
|
237
|
+
aria-disabled={loading || undefined}
|
|
238
|
+
aria-labelledby="{id}-label {id}"
|
|
239
|
+
{@attach invalid(error && `${id}-error`)}
|
|
240
|
+
onclick={() => (open ? hide() : show())}
|
|
241
|
+
onkeydown={onButtonKey}
|
|
242
|
+
{@attach tooltip(cut && !open ? current?.label : '')}
|
|
243
|
+
>
|
|
244
|
+
{#if loading}
|
|
245
|
+
<Shimmer class="value">{typeof loading === 'string' ? loading : 'Loading…'}</Shimmer>
|
|
246
|
+
{:else}
|
|
247
|
+
<span class="value" {@attach watchCut(current?.label)}>{current?.label ?? ''}</span>
|
|
248
|
+
{/if}
|
|
249
|
+
{#if !disabled}<span class="caret" class:flip={open}><Icon name="caretDown" size="sm" /></span>{/if}
|
|
250
|
+
</button>
|
|
251
|
+
{#if open}
|
|
252
|
+
{@const activeId = visible.includes(active) ? `${id}-opt-${active}` : undefined}
|
|
253
|
+
<div bind:this={list} style:position-anchor={anchor} class="list" data-floating {@attach topLayer(button)} transition:pop={{ from: button }}>
|
|
254
|
+
{#if searchable}
|
|
255
|
+
<ListSearch
|
|
256
|
+
bind:this={searchField}
|
|
257
|
+
value={query}
|
|
258
|
+
oninput={narrow}
|
|
259
|
+
{label}
|
|
260
|
+
controls="{id}-listbox"
|
|
261
|
+
active={activeId}
|
|
262
|
+
placeholder={searchPlaceholder}
|
|
263
|
+
onkeydown={onListKey}
|
|
264
|
+
/>
|
|
265
|
+
{/if}
|
|
266
|
+
<!-- With a search field the focus stays in it: a press on the list mustn't take it (mousedown is what moves it). -->
|
|
267
|
+
<ul
|
|
268
|
+
bind:this={listbox}
|
|
269
|
+
id="{id}-listbox"
|
|
270
|
+
class="options"
|
|
271
|
+
role="listbox"
|
|
272
|
+
tabindex="-1"
|
|
273
|
+
aria-labelledby="{id}-label"
|
|
274
|
+
aria-activedescendant={searchable ? undefined : activeId}
|
|
275
|
+
onkeydown={searchable ? undefined : onListKey}
|
|
276
|
+
onmousedown={searchable ? (e) => e.preventDefault() : undefined}
|
|
277
|
+
>
|
|
278
|
+
{#each sections as sec, si (si)}
|
|
279
|
+
{#if sec.group}
|
|
280
|
+
{@const action = groupActions[sec.group]}
|
|
281
|
+
<li class="group" role="group" aria-labelledby="{id}-group-{si}">
|
|
282
|
+
<!-- Sticky: lib/reveal.js keeps the keyboard's option clear of it. -->
|
|
283
|
+
<div class="group-head" data-sticky-head>
|
|
284
|
+
<span id="{id}-group-{si}">{sec.group}</span>
|
|
285
|
+
{#if action}
|
|
286
|
+
<!-- Pointer only (keeps focus on the listbox, which owns the keyboard). -->
|
|
287
|
+
<button
|
|
288
|
+
type="button"
|
|
289
|
+
class="group-action"
|
|
290
|
+
tabindex="-1"
|
|
291
|
+
aria-label={action.label}
|
|
292
|
+
{@attach tooltip(action.label)}
|
|
293
|
+
onmousedown={(e) => e.preventDefault()}
|
|
294
|
+
onclick={() => runGroupAction(action)}><Icon name={action.icon} size="sm" /></button
|
|
295
|
+
>
|
|
296
|
+
{/if}
|
|
297
|
+
</div>
|
|
298
|
+
<ul role="none">
|
|
299
|
+
{#each sec.items as { o, i } (i)}{@render option(o, i)}{/each}
|
|
300
|
+
</ul>
|
|
301
|
+
</li>
|
|
302
|
+
{:else}
|
|
303
|
+
{#each sec.items as { o, i } (i)}{@render option(o, i)}{/each}
|
|
304
|
+
{/if}
|
|
305
|
+
{/each}
|
|
306
|
+
{#if !shown.length}<li class="empty" role="none">No matches</li>{/if}
|
|
307
|
+
</ul>
|
|
308
|
+
</div>
|
|
309
|
+
{/if}
|
|
310
|
+
</div>
|
|
311
|
+
<ErrorMessage floating id="{id}-error" message={error} ondismiss={() => button?.focus()} />
|
|
312
|
+
</div>
|
|
313
|
+
|
|
314
|
+
<style>
|
|
315
|
+
/* min-width: 0 lets it shrink in a flex or grid parent; otherwise a long value's unwrapped width holds it open and
|
|
316
|
+
the trigger runs past its container instead of cutting the value off. */
|
|
317
|
+
.field {
|
|
318
|
+
position: relative;
|
|
319
|
+
display: flex;
|
|
320
|
+
flex-direction: column;
|
|
321
|
+
gap: 3px;
|
|
322
|
+
min-width: 0;
|
|
323
|
+
max-width: 100%;
|
|
324
|
+
}
|
|
325
|
+
.wrap {
|
|
326
|
+
position: relative;
|
|
327
|
+
}
|
|
328
|
+
.trigger {
|
|
329
|
+
display: flex;
|
|
330
|
+
align-items: center;
|
|
331
|
+
justify-content: space-between;
|
|
332
|
+
gap: 8px;
|
|
333
|
+
min-width: 120px;
|
|
334
|
+
max-width: 100%;
|
|
335
|
+
min-height: 32px;
|
|
336
|
+
text-align: left;
|
|
337
|
+
padding: 0 8px 0 10px;
|
|
338
|
+
font-size: 13px;
|
|
339
|
+
font-weight: var(--w-medium);
|
|
340
|
+
color: var(--fg);
|
|
341
|
+
background: var(--control-2);
|
|
342
|
+
border: 1px solid var(--line-strong);
|
|
343
|
+
border-radius: var(--r);
|
|
344
|
+
cursor: pointer;
|
|
345
|
+
/* Raised (--shadow-btn) like a button: you press it to open, unlike the sunken text fields, on the same faint fill
|
|
346
|
+
as theirs. Open, it sits flat. */
|
|
347
|
+
--raise: var(--shadow-btn);
|
|
348
|
+
box-shadow: var(--raise);
|
|
349
|
+
transition:
|
|
350
|
+
background-color var(--dur) var(--ease-out),
|
|
351
|
+
border-color var(--dur) var(--ease-out),
|
|
352
|
+
box-shadow var(--dur) var(--ease-out);
|
|
353
|
+
}
|
|
354
|
+
.trigger:hover:not([aria-busy], :disabled) {
|
|
355
|
+
background: var(--control-3);
|
|
356
|
+
}
|
|
357
|
+
/* Loading: the working shimmer runs along the hairline and through the label (global .shimmer / .shimmer-text), on an
|
|
358
|
+
outlined box: no fill and no raised edge to drown it out, as a busy Button. */
|
|
359
|
+
.trigger[aria-busy] {
|
|
360
|
+
--raise: 0 0 transparent;
|
|
361
|
+
cursor: progress;
|
|
362
|
+
background: none;
|
|
363
|
+
}
|
|
364
|
+
.trigger[aria-busy] .caret {
|
|
365
|
+
opacity: 0.5;
|
|
366
|
+
}
|
|
367
|
+
.trigger[aria-expanded='true'] {
|
|
368
|
+
background: var(--control-4);
|
|
369
|
+
box-shadow: none;
|
|
370
|
+
}
|
|
371
|
+
/* Ghost: no relief, open or closed (the focus ring still shows). */
|
|
372
|
+
.trigger.ghost {
|
|
373
|
+
--raise: 0 0 transparent;
|
|
374
|
+
}
|
|
375
|
+
/* …and no fill at rest; hover and open fill it as usual. */
|
|
376
|
+
.trigger.ghost:not(:hover, [aria-expanded='true']) {
|
|
377
|
+
background: none;
|
|
378
|
+
}
|
|
379
|
+
/* Disabled: ghost-flat, no fill, a quieter edge; the value stays readable. */
|
|
380
|
+
.trigger:disabled {
|
|
381
|
+
--raise: 0 0 transparent;
|
|
382
|
+
background: none;
|
|
383
|
+
border-color: var(--line);
|
|
384
|
+
cursor: default;
|
|
385
|
+
}
|
|
386
|
+
/* Focused, it sits flat inside the ring: the raise's outer contact ring would draw a dark line through it. */
|
|
387
|
+
.trigger:focus-visible {
|
|
388
|
+
border-color: var(--accent-line);
|
|
389
|
+
box-shadow: var(--ring);
|
|
390
|
+
outline: none;
|
|
391
|
+
}
|
|
392
|
+
/* :global: the attribute is set by the invalid attachment, at runtime, where Svelte can't see it. */
|
|
393
|
+
.trigger:global([aria-invalid='true']) {
|
|
394
|
+
border-color: var(--danger);
|
|
395
|
+
}
|
|
396
|
+
.trigger:global([aria-invalid='true']):focus-visible {
|
|
397
|
+
box-shadow: 0 0 0 2px color-mix(in lch, var(--danger) 30%, transparent);
|
|
398
|
+
}
|
|
399
|
+
/* Long values (model ids…) are cut with an ellipsis on one line; the full text is in the tooltip. */
|
|
400
|
+
.trigger :global(.value),
|
|
401
|
+
.label {
|
|
402
|
+
min-width: 0;
|
|
403
|
+
overflow: clip;
|
|
404
|
+
text-overflow: ellipsis;
|
|
405
|
+
white-space: nowrap;
|
|
406
|
+
}
|
|
407
|
+
.caret {
|
|
408
|
+
flex: none;
|
|
409
|
+
display: inline-flex;
|
|
410
|
+
color: var(--muted);
|
|
411
|
+
rotate: 0deg;
|
|
412
|
+
transition: rotate var(--dur) var(--ease-out);
|
|
413
|
+
}
|
|
414
|
+
.caret.flip {
|
|
415
|
+
rotate: 180deg;
|
|
416
|
+
}
|
|
417
|
+
/* Anchored to the trigger: below it from its left edge, at least as wide; flipped above, or to end at its right edge,
|
|
418
|
+
when it would overflow the window. Hidden while the button is scrolled out of view. */
|
|
419
|
+
.list {
|
|
420
|
+
position: fixed;
|
|
421
|
+
z-index: calc(var(--z-overlay) + 1);
|
|
422
|
+
position-area: block-end span-inline-end;
|
|
423
|
+
position-try-fallbacks:
|
|
424
|
+
flip-block,
|
|
425
|
+
flip-inline,
|
|
426
|
+
flip-block flip-inline;
|
|
427
|
+
position-visibility: anchors-visible;
|
|
428
|
+
/* 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
|
|
429
|
+
end at the field's right edge: a flip swaps the inline margins too). */
|
|
430
|
+
margin-inline-start: calc(var(--space-1) * -1);
|
|
431
|
+
margin-block: 4px;
|
|
432
|
+
display: flex;
|
|
433
|
+
flex-direction: column;
|
|
434
|
+
width: max-content;
|
|
435
|
+
min-width: anchor-size(width);
|
|
436
|
+
max-width: min(max(anchor-size(width), 440px), calc(100dvw - 32px));
|
|
437
|
+
max-height: min(320px, calc(100dvh - 16px));
|
|
438
|
+
overflow: hidden;
|
|
439
|
+
border: 1px solid transparent;
|
|
440
|
+
background:
|
|
441
|
+
linear-gradient(var(--elevated), var(--elevated)) padding-box,
|
|
442
|
+
var(--edge-grad-float);
|
|
443
|
+
border-radius: var(--r-lg);
|
|
444
|
+
box-shadow: var(--shadow);
|
|
445
|
+
}
|
|
446
|
+
/* The options scroll under the search field, which stays put. */
|
|
447
|
+
.options {
|
|
448
|
+
flex: 1 1 auto;
|
|
449
|
+
min-height: 0;
|
|
450
|
+
max-height: 280px;
|
|
451
|
+
margin: 0;
|
|
452
|
+
padding: 4px;
|
|
453
|
+
list-style: none;
|
|
454
|
+
overflow-y: auto;
|
|
455
|
+
overflow-x: hidden;
|
|
456
|
+
overscroll-behavior: contain;
|
|
457
|
+
/* Positioned: the options' offsetTop (opening on the value) counts from the list. */
|
|
458
|
+
position: relative;
|
|
459
|
+
--head: 26px;
|
|
460
|
+
}
|
|
461
|
+
.options:focus {
|
|
462
|
+
outline: none;
|
|
463
|
+
}
|
|
464
|
+
.empty {
|
|
465
|
+
display: block;
|
|
466
|
+
color: var(--muted);
|
|
467
|
+
cursor: default;
|
|
468
|
+
}
|
|
469
|
+
/* The box's edge is a gradient under a transparent border (base.css outlines listboxes; this one wraps the listbox). */
|
|
470
|
+
@media (forced-colors: active) {
|
|
471
|
+
.list {
|
|
472
|
+
border-color: CanvasText;
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
li {
|
|
476
|
+
display: grid;
|
|
477
|
+
grid-template-columns: 14px minmax(0, 1fr) auto;
|
|
478
|
+
gap: 6px;
|
|
479
|
+
align-items: center;
|
|
480
|
+
min-height: 32px;
|
|
481
|
+
padding: 0 10px 0 8px;
|
|
482
|
+
border-radius: var(--r-sm);
|
|
483
|
+
font-size: 13px;
|
|
484
|
+
color: var(--fg);
|
|
485
|
+
cursor: pointer;
|
|
486
|
+
white-space: nowrap;
|
|
487
|
+
}
|
|
488
|
+
li.active {
|
|
489
|
+
background: var(--control-3);
|
|
490
|
+
}
|
|
491
|
+
.tick {
|
|
492
|
+
display: inline-flex;
|
|
493
|
+
color: var(--accent);
|
|
494
|
+
}
|
|
495
|
+
/* Group headings: small muted labels, a hairline between groups. */
|
|
496
|
+
/* Square, and widened over the list's 4px padding so the hairline runs edge to edge. */
|
|
497
|
+
.group {
|
|
498
|
+
display: block;
|
|
499
|
+
margin-inline: -4px;
|
|
500
|
+
padding: 0 4px;
|
|
501
|
+
min-height: 0;
|
|
502
|
+
border-radius: 0;
|
|
503
|
+
cursor: default;
|
|
504
|
+
}
|
|
505
|
+
.group + .group,
|
|
506
|
+
li:not(.group) + .group {
|
|
507
|
+
margin-top: 4px;
|
|
508
|
+
padding-top: 4px;
|
|
509
|
+
border-top: 1px solid var(--line);
|
|
510
|
+
}
|
|
511
|
+
/* A group's heading stays at the top of the list while its options scroll under it (as DateRangeSelect's months do):
|
|
512
|
+
on the list's own surface, across its whole width. */
|
|
513
|
+
.group-head {
|
|
514
|
+
position: sticky;
|
|
515
|
+
top: 0;
|
|
516
|
+
z-index: 1;
|
|
517
|
+
display: flex;
|
|
518
|
+
align-items: center;
|
|
519
|
+
justify-content: space-between;
|
|
520
|
+
gap: 8px;
|
|
521
|
+
min-height: var(--head);
|
|
522
|
+
margin-inline: -4px;
|
|
523
|
+
padding: 0 10px 0 12px;
|
|
524
|
+
background: var(--elevated);
|
|
525
|
+
/* It sticks at the list's content edge, 4px below its top: fill that strip too, so rows don't show through it. */
|
|
526
|
+
box-shadow: 0 -4px 0 var(--elevated);
|
|
527
|
+
font: var(--w-medium) 12px var(--font-body);
|
|
528
|
+
color: var(--muted);
|
|
529
|
+
}
|
|
530
|
+
.group-action {
|
|
531
|
+
display: inline-flex;
|
|
532
|
+
align-items: center;
|
|
533
|
+
justify-content: center;
|
|
534
|
+
width: 20px;
|
|
535
|
+
height: 20px;
|
|
536
|
+
padding: 0;
|
|
537
|
+
border: 0;
|
|
538
|
+
border-radius: var(--r-sm);
|
|
539
|
+
background: none;
|
|
540
|
+
color: var(--muted);
|
|
541
|
+
cursor: pointer;
|
|
542
|
+
}
|
|
543
|
+
.group-action:hover {
|
|
544
|
+
background: var(--control-3);
|
|
545
|
+
color: var(--fg);
|
|
546
|
+
}
|
|
547
|
+
.hint {
|
|
548
|
+
color: var(--faint);
|
|
549
|
+
font: var(--w-medium) 12px var(--font-data);
|
|
550
|
+
font-variant-numeric: tabular-nums;
|
|
551
|
+
}
|
|
552
|
+
</style>
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
export default Select;
|
|
2
|
+
type Select = {
|
|
3
|
+
$on?(type: string, callback: (e: any) => void): () => void;
|
|
4
|
+
$set?(props: Partial<Props & Omit<HTMLButtonAttributes, keyof Props>>): void;
|
|
5
|
+
};
|
|
6
|
+
declare const Select: import("svelte").Component<{
|
|
7
|
+
/**
|
|
8
|
+
* bindable
|
|
9
|
+
*/
|
|
10
|
+
value?: any;
|
|
11
|
+
options: {
|
|
12
|
+
value: any;
|
|
13
|
+
label: string;
|
|
14
|
+
text?: string;
|
|
15
|
+
hint?: string;
|
|
16
|
+
group?: string;
|
|
17
|
+
}[];
|
|
18
|
+
id: string;
|
|
19
|
+
label: string;
|
|
20
|
+
hideLabel?: boolean | undefined;
|
|
21
|
+
groupActions?: Record<string, {
|
|
22
|
+
icon: string;
|
|
23
|
+
label: string;
|
|
24
|
+
run: () => void;
|
|
25
|
+
}> | undefined;
|
|
26
|
+
loading?: string | boolean | undefined;
|
|
27
|
+
error?: string | undefined;
|
|
28
|
+
info?: string | undefined;
|
|
29
|
+
/**
|
|
30
|
+
* dimmed text after the label, e.g. '(optional)'
|
|
31
|
+
*/
|
|
32
|
+
note?: string | undefined;
|
|
33
|
+
ghost?: boolean | undefined;
|
|
34
|
+
disabled?: boolean | undefined;
|
|
35
|
+
search?: boolean | "auto" | undefined;
|
|
36
|
+
searchPlaceholder?: string | undefined;
|
|
37
|
+
} & Omit<import("svelte/elements").HTMLButtonAttributes, keyof {
|
|
38
|
+
/**
|
|
39
|
+
* bindable
|
|
40
|
+
*/
|
|
41
|
+
value?: any;
|
|
42
|
+
options: {
|
|
43
|
+
value: any;
|
|
44
|
+
label: string;
|
|
45
|
+
text?: string;
|
|
46
|
+
hint?: string;
|
|
47
|
+
group?: string;
|
|
48
|
+
}[];
|
|
49
|
+
id: string;
|
|
50
|
+
label: string;
|
|
51
|
+
hideLabel?: boolean | undefined;
|
|
52
|
+
groupActions?: Record<string, {
|
|
53
|
+
icon: string;
|
|
54
|
+
label: string;
|
|
55
|
+
run: () => void;
|
|
56
|
+
}> | undefined;
|
|
57
|
+
loading?: string | boolean | undefined;
|
|
58
|
+
error?: string | undefined;
|
|
59
|
+
info?: string | undefined;
|
|
60
|
+
/**
|
|
61
|
+
* dimmed text after the label, e.g. '(optional)'
|
|
62
|
+
*/
|
|
63
|
+
note?: string | undefined;
|
|
64
|
+
ghost?: boolean | undefined;
|
|
65
|
+
disabled?: boolean | undefined;
|
|
66
|
+
search?: boolean | "auto" | undefined;
|
|
67
|
+
searchPlaceholder?: string | undefined;
|
|
68
|
+
}>, {}, "value">;
|
|
69
|
+
type Props = {
|
|
70
|
+
/**
|
|
71
|
+
* bindable
|
|
72
|
+
*/
|
|
73
|
+
value?: any;
|
|
74
|
+
options: {
|
|
75
|
+
value: any;
|
|
76
|
+
label: string;
|
|
77
|
+
text?: string;
|
|
78
|
+
hint?: string;
|
|
79
|
+
group?: string;
|
|
80
|
+
}[];
|
|
81
|
+
id: string;
|
|
82
|
+
label: string;
|
|
83
|
+
hideLabel?: boolean | undefined;
|
|
84
|
+
groupActions?: Record<string, {
|
|
85
|
+
icon: string;
|
|
86
|
+
label: string;
|
|
87
|
+
run: () => void;
|
|
88
|
+
}> | undefined;
|
|
89
|
+
loading?: string | boolean | undefined;
|
|
90
|
+
error?: string | undefined;
|
|
91
|
+
info?: string | undefined;
|
|
92
|
+
/**
|
|
93
|
+
* dimmed text after the label, e.g. '(optional)'
|
|
94
|
+
*/
|
|
95
|
+
note?: string | undefined;
|
|
96
|
+
ghost?: boolean | undefined;
|
|
97
|
+
disabled?: boolean | undefined;
|
|
98
|
+
search?: boolean | "auto" | undefined;
|
|
99
|
+
searchPlaceholder?: string | undefined;
|
|
100
|
+
};
|