@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,142 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
/**
|
|
3
|
+
* The search field at the top of a floating list (Select's, OptionList's): flat on the list's surface, with a hairline
|
|
4
|
+
* under it from edge to edge. A combobox that keeps the focus while the arrow keys move through the list it controls,
|
|
5
|
+
* so the list's own key handler goes in `onkeydown`. lib/list-search.js decides when a list gets one and what matches.
|
|
6
|
+
*
|
|
7
|
+
* <ListSearch bind:this={field} value={query} oninput={(q) => (query = q)} label="Region" controls="{id}-list"
|
|
8
|
+
* active="{id}-opt-{active}" onkeydown={onListKey} />
|
|
9
|
+
*
|
|
10
|
+
* value: the text. oninput(text): as it is typed or cleared. label: the accessible name (the list's).
|
|
11
|
+
* controls: the listbox's id. active: the id of the option the keyboard is on (aria-activedescendant), if any.
|
|
12
|
+
* placeholder: default "Filter…". onkeydown: the list's keys (arrows, Enter…); keys that edit text are the field's.
|
|
13
|
+
* focus(): puts the focus in it.
|
|
14
|
+
* With text in it, a ✕ at its end clears it (as a search TextField's does) and keeps the focus in the field; it is
|
|
15
|
+
* left out of the tab order, since Tab belongs to the list around it, and Esc does the same from the keyboard.
|
|
16
|
+
* Keyboard: Esc with text clears it (and goes no further); with none, Esc is left to the list around it.
|
|
17
|
+
* Other attributes and attachments go to the <input>.
|
|
18
|
+
*/
|
|
19
|
+
import Icon from '../Icon.svelte'
|
|
20
|
+
import { composing } from '../../lib/dom.js'
|
|
21
|
+
import { tooltip } from '../../lib/tooltip.js'
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @typedef {object} Props
|
|
25
|
+
* @property {string} value
|
|
26
|
+
* @property {(text: string) => void} oninput
|
|
27
|
+
* @property {string} label
|
|
28
|
+
* @property {string} controls
|
|
29
|
+
* @property {string} [active]
|
|
30
|
+
* @property {string} [placeholder]
|
|
31
|
+
* @property {(e: KeyboardEvent) => void} [onkeydown]
|
|
32
|
+
*/
|
|
33
|
+
/** @type {Props & Omit<import('svelte/elements').HTMLInputAttributes, keyof Props>} */
|
|
34
|
+
let { value, oninput, label, controls, active, placeholder = 'Filter…', onkeydown, class: className, ...rest } = $props()
|
|
35
|
+
/** @type {HTMLInputElement | undefined} */
|
|
36
|
+
let input = $state()
|
|
37
|
+
|
|
38
|
+
export function focus() {
|
|
39
|
+
input?.focus({ preventScroll: true })
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** @param {KeyboardEvent} e */
|
|
43
|
+
function keydown(e) {
|
|
44
|
+
if (composing(e)) return
|
|
45
|
+
if (e.key === 'Escape' && value) {
|
|
46
|
+
e.preventDefault()
|
|
47
|
+
e.stopPropagation()
|
|
48
|
+
oninput('')
|
|
49
|
+
return
|
|
50
|
+
}
|
|
51
|
+
onkeydown?.(e)
|
|
52
|
+
}
|
|
53
|
+
</script>
|
|
54
|
+
|
|
55
|
+
<div class="list-search">
|
|
56
|
+
<input
|
|
57
|
+
bind:this={input}
|
|
58
|
+
class={['list-search-input', className]}
|
|
59
|
+
type="text"
|
|
60
|
+
role="combobox"
|
|
61
|
+
aria-label={label}
|
|
62
|
+
aria-expanded="true"
|
|
63
|
+
aria-controls={controls}
|
|
64
|
+
aria-autocomplete="list"
|
|
65
|
+
aria-activedescendant={active}
|
|
66
|
+
autocomplete="off"
|
|
67
|
+
spellcheck="false"
|
|
68
|
+
{placeholder}
|
|
69
|
+
{...rest}
|
|
70
|
+
{value}
|
|
71
|
+
oninput={(e) => oninput(e.currentTarget.value)}
|
|
72
|
+
onkeydown={keydown}
|
|
73
|
+
/>
|
|
74
|
+
<!-- Pointer only: mousedown would take the focus out of the field. Esc clears from the keyboard. Kept in place while
|
|
75
|
+
there is nothing to clear (hidden), so a list sized to its content doesn't widen as the first letter is typed. -->
|
|
76
|
+
<button
|
|
77
|
+
type="button"
|
|
78
|
+
class="clear"
|
|
79
|
+
class:hidden={!value}
|
|
80
|
+
disabled={!value}
|
|
81
|
+
tabindex="-1"
|
|
82
|
+
aria-label="Clear {label} filter"
|
|
83
|
+
{@attach tooltip('Clear')}
|
|
84
|
+
onmousedown={(e) => e.preventDefault()}
|
|
85
|
+
onclick={() => {
|
|
86
|
+
oninput('')
|
|
87
|
+
input?.focus({ preventScroll: true })
|
|
88
|
+
}}><Icon name="x" size="sm" /></button
|
|
89
|
+
>
|
|
90
|
+
</div>
|
|
91
|
+
|
|
92
|
+
<style>
|
|
93
|
+
/* Flat on the list's surface, with a hairline under it from edge to edge. */
|
|
94
|
+
.list-search {
|
|
95
|
+
flex: none;
|
|
96
|
+
display: flex;
|
|
97
|
+
align-items: center;
|
|
98
|
+
gap: var(--space-1);
|
|
99
|
+
min-height: 36px;
|
|
100
|
+
padding: 0 6px 0 var(--space-3);
|
|
101
|
+
border-bottom: 1px solid var(--line);
|
|
102
|
+
}
|
|
103
|
+
.list-search-input {
|
|
104
|
+
flex: 1;
|
|
105
|
+
min-width: 0;
|
|
106
|
+
align-self: stretch;
|
|
107
|
+
padding: 0;
|
|
108
|
+
border: 0;
|
|
109
|
+
border-radius: 0;
|
|
110
|
+
background: none;
|
|
111
|
+
color: var(--fg);
|
|
112
|
+
font: inherit;
|
|
113
|
+
font-size: 13px;
|
|
114
|
+
user-select: text;
|
|
115
|
+
}
|
|
116
|
+
.list-search-input::placeholder {
|
|
117
|
+
color: var(--muted);
|
|
118
|
+
}
|
|
119
|
+
.list-search-input:focus {
|
|
120
|
+
outline: none;
|
|
121
|
+
}
|
|
122
|
+
.clear {
|
|
123
|
+
display: inline-grid;
|
|
124
|
+
place-items: center;
|
|
125
|
+
flex: none;
|
|
126
|
+
width: 24px;
|
|
127
|
+
height: 24px;
|
|
128
|
+
padding: 0;
|
|
129
|
+
border: 0;
|
|
130
|
+
border-radius: 50%;
|
|
131
|
+
background: none;
|
|
132
|
+
color: var(--muted);
|
|
133
|
+
cursor: pointer;
|
|
134
|
+
}
|
|
135
|
+
.clear.hidden {
|
|
136
|
+
visibility: hidden;
|
|
137
|
+
}
|
|
138
|
+
.clear:hover {
|
|
139
|
+
color: var(--fg);
|
|
140
|
+
background: var(--control-3);
|
|
141
|
+
}
|
|
142
|
+
</style>
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export default ListSearch;
|
|
2
|
+
type ListSearch = {
|
|
3
|
+
$on?(type: string, callback: (e: any) => void): () => void;
|
|
4
|
+
$set?(props: Partial<Props & Omit<HTMLInputAttributes, keyof Props>>): void;
|
|
5
|
+
} & {
|
|
6
|
+
focus: () => void;
|
|
7
|
+
};
|
|
8
|
+
declare const ListSearch: import("svelte").Component<{
|
|
9
|
+
value: string;
|
|
10
|
+
oninput: (text: string) => void;
|
|
11
|
+
label: string;
|
|
12
|
+
controls: string;
|
|
13
|
+
active?: string | undefined;
|
|
14
|
+
placeholder?: string | undefined;
|
|
15
|
+
onkeydown?: ((e: KeyboardEvent) => void) | undefined;
|
|
16
|
+
} & Omit<import("svelte/elements").HTMLInputAttributes, keyof {
|
|
17
|
+
value: string;
|
|
18
|
+
oninput: (text: string) => void;
|
|
19
|
+
label: string;
|
|
20
|
+
controls: string;
|
|
21
|
+
active?: string | undefined;
|
|
22
|
+
placeholder?: string | undefined;
|
|
23
|
+
onkeydown?: ((e: KeyboardEvent) => void) | undefined;
|
|
24
|
+
}>, {
|
|
25
|
+
focus: () => void;
|
|
26
|
+
}, "">;
|
|
27
|
+
type Props = {
|
|
28
|
+
value: string;
|
|
29
|
+
oninput: (text: string) => void;
|
|
30
|
+
label: string;
|
|
31
|
+
controls: string;
|
|
32
|
+
active?: string | undefined;
|
|
33
|
+
placeholder?: string | undefined;
|
|
34
|
+
onkeydown?: ((e: KeyboardEvent) => void) | undefined;
|
|
35
|
+
};
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import Icon from '../Icon.svelte'
|
|
3
|
+
import { tooltip } from '../../lib/tooltip.js'
|
|
4
|
+
import { radioKeys } from '../../lib/roving.js'
|
|
5
|
+
import Tooltip from '../Tooltip.svelte'
|
|
6
|
+
import { motion, durations, easings } from '../../lib/motion.js'
|
|
7
|
+
/**
|
|
8
|
+
* Single choice shown as a joined switch: one track, the chosen segment raised on it (radio group with roving
|
|
9
|
+
* focus). Same options shape as Segmented ({ value, label, icon?, hint?, info? }; `info` adds an ⓘ with that text as a hover tooltip). `fill` stretches it to its container
|
|
10
|
+
* with equal-width segments. `pill` rounds the track and segments fully (toolbar view switchers).
|
|
11
|
+
* When the choice changes, the raised thumb slides from the old segment to the new one (instantly under reduced motion).
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* @typedef {{ value: any, label: string, icon?: string, hint?: string, info?: string }} Option
|
|
15
|
+
* @typedef {object} Props
|
|
16
|
+
* @property {any} value
|
|
17
|
+
* @property {Option[]} options
|
|
18
|
+
* @property {string} label
|
|
19
|
+
* @property {(value: any) => void} onchange
|
|
20
|
+
* @property {boolean} [iconOnly]
|
|
21
|
+
* @property {boolean} [fill]
|
|
22
|
+
* @property {boolean} [pill]
|
|
23
|
+
*/
|
|
24
|
+
/** @type {Props & Omit<import('svelte/elements').HTMLAttributes<HTMLDivElement>, keyof Props>} */
|
|
25
|
+
let { value, options, label, onchange, fill = false, iconOnly = false, pill = false, class: className, ...rest } = $props()
|
|
26
|
+
const uid = $props.id()
|
|
27
|
+
let group
|
|
28
|
+
|
|
29
|
+
// Where the thumb sat before this change: read before the DOM updates, so the new thumb can slide in from there.
|
|
30
|
+
let from = null
|
|
31
|
+
$effect.pre(() => {
|
|
32
|
+
void value
|
|
33
|
+
from = group?.querySelector('.thumb')?.getBoundingClientRect() ?? null
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
/** Intro for the new thumb: starts on the old thumb's box and eases its edges onto its own (no scaling, so radii hold). */
|
|
37
|
+
function slide(node) {
|
|
38
|
+
const to = node.getBoundingClientRect()
|
|
39
|
+
if (!from || !to.width) return { duration: 0 }
|
|
40
|
+
const l = from.left - to.left,
|
|
41
|
+
t = from.top - to.top,
|
|
42
|
+
r = to.right - from.right,
|
|
43
|
+
b = to.bottom - from.bottom
|
|
44
|
+
return { duration: motion(durations.short4), easing: easings.standard.standard, css: (_, u) => `inset: ${u * t}px ${u * r}px ${u * b}px ${u * l}px;` }
|
|
45
|
+
}
|
|
46
|
+
</script>
|
|
47
|
+
|
|
48
|
+
<div bind:this={group} class={['group', className]} class:fill class:pill role="radiogroup" aria-label={label} {...rest} {@attach radioKeys}>
|
|
49
|
+
{#each options as o, i (o.value)}
|
|
50
|
+
<button
|
|
51
|
+
type="button"
|
|
52
|
+
role="radio"
|
|
53
|
+
aria-checked={o.value === value}
|
|
54
|
+
tabindex={o.value === value ? 0 : -1}
|
|
55
|
+
onclick={() => onchange(o.value)}
|
|
56
|
+
{@attach tooltip(iconOnly ? o.label + (o.hint ? ` (${o.hint})` : '') : o.hint)}
|
|
57
|
+
aria-label={iconOnly ? o.label : undefined}
|
|
58
|
+
aria-describedby={o.info ? `${uid}-info-${i}` : undefined}
|
|
59
|
+
>{#if o.value === value}<span class="thumb" aria-hidden="true" in:slide></span>{/if}{#if o.icon}<Icon name={o.icon} size="sm" />{/if}{#if !iconOnly}<span
|
|
60
|
+
class="text">{o.label}</span
|
|
61
|
+
>{/if}{#if o.info}<Tooltip focusable={false}>{#snippet tip()}{o.info}{/snippet}<span class="info"><Icon name="infoCircle" size="sm" /></span></Tooltip
|
|
62
|
+
>{/if}</button
|
|
63
|
+
>
|
|
64
|
+
{/each}
|
|
65
|
+
<!-- The ⓘ's text, as each option's description: the tooltip only opens on hover. -->
|
|
66
|
+
{#each options as o, i (o.value)}
|
|
67
|
+
{#if o.info}<span id="{uid}-info-{i}" class="sr-only">{o.info}</span>{/if}
|
|
68
|
+
{/each}
|
|
69
|
+
</div>
|
|
70
|
+
|
|
71
|
+
<style>
|
|
72
|
+
.group {
|
|
73
|
+
display: inline-grid;
|
|
74
|
+
grid-auto-flow: column;
|
|
75
|
+
grid-auto-columns: auto;
|
|
76
|
+
gap: 2px;
|
|
77
|
+
/* As wide as its options: a grid or column-flex parent would otherwise stretch the track past them (`fill` stretches it on purpose). */
|
|
78
|
+
width: fit-content;
|
|
79
|
+
max-width: 100%;
|
|
80
|
+
padding: 2px;
|
|
81
|
+
/* A clear track under a hairline, so only the raised thumb is filled and casts a shadow. */
|
|
82
|
+
border-radius: var(--r);
|
|
83
|
+
background: transparent;
|
|
84
|
+
box-shadow: inset 0 0 0 1px var(--line);
|
|
85
|
+
/* The thumb sits at z-index -1 in here: under every segment's content, even while it slides across them. */
|
|
86
|
+
isolation: isolate;
|
|
87
|
+
}
|
|
88
|
+
.group.fill {
|
|
89
|
+
display: grid;
|
|
90
|
+
grid-auto-columns: minmax(0, 1fr);
|
|
91
|
+
width: 100%;
|
|
92
|
+
}
|
|
93
|
+
.group.pill,
|
|
94
|
+
.pill button {
|
|
95
|
+
border-radius: var(--r-pill);
|
|
96
|
+
}
|
|
97
|
+
button {
|
|
98
|
+
position: relative;
|
|
99
|
+
display: inline-flex;
|
|
100
|
+
align-items: center;
|
|
101
|
+
justify-content: center;
|
|
102
|
+
gap: 6px;
|
|
103
|
+
min-width: 0;
|
|
104
|
+
min-height: 26px;
|
|
105
|
+
padding: 0 10px;
|
|
106
|
+
border: 0;
|
|
107
|
+
border-radius: calc(var(--r) - 2px);
|
|
108
|
+
background: none;
|
|
109
|
+
color: var(--fg);
|
|
110
|
+
font-size: 12px;
|
|
111
|
+
line-height: 14px;
|
|
112
|
+
font-weight: var(--w-medium);
|
|
113
|
+
cursor: pointer;
|
|
114
|
+
white-space: nowrap;
|
|
115
|
+
transition:
|
|
116
|
+
color var(--dur) var(--ease-out),
|
|
117
|
+
background-color var(--dur) var(--ease-out),
|
|
118
|
+
box-shadow var(--dur) var(--ease-out);
|
|
119
|
+
}
|
|
120
|
+
button:not([aria-checked='true']):hover {
|
|
121
|
+
background: var(--control-2);
|
|
122
|
+
}
|
|
123
|
+
[aria-checked='true'] {
|
|
124
|
+
color: var(--fg);
|
|
125
|
+
}
|
|
126
|
+
/* The raised surface behind the chosen segment; its own element so it can slide between segments. */
|
|
127
|
+
.thumb {
|
|
128
|
+
position: absolute;
|
|
129
|
+
inset: 0;
|
|
130
|
+
z-index: -1;
|
|
131
|
+
border-radius: inherit;
|
|
132
|
+
pointer-events: none;
|
|
133
|
+
/* Filled like ButtonGroup's chosen option (--control-4) and raised (--shadow-btn), with a hairline for an edge. */
|
|
134
|
+
background: var(--control-4);
|
|
135
|
+
box-shadow:
|
|
136
|
+
inset 0 0 0 1px var(--line),
|
|
137
|
+
var(--shadow-btn);
|
|
138
|
+
}
|
|
139
|
+
button :global(.icon) {
|
|
140
|
+
flex: none;
|
|
141
|
+
}
|
|
142
|
+
.info {
|
|
143
|
+
display: inline-flex;
|
|
144
|
+
color: var(--muted);
|
|
145
|
+
}
|
|
146
|
+
.text {
|
|
147
|
+
min-width: 0;
|
|
148
|
+
overflow: clip;
|
|
149
|
+
text-overflow: ellipsis;
|
|
150
|
+
}
|
|
151
|
+
</style>
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
export default RadioGroup;
|
|
2
|
+
type RadioGroup = {
|
|
3
|
+
$on?(type: string, callback: (e: any) => void): () => void;
|
|
4
|
+
$set?(props: Partial<Props & Omit<HTMLAttributes<HTMLDivElement>, keyof Props>>): void;
|
|
5
|
+
};
|
|
6
|
+
declare const RadioGroup: import("svelte").Component<{
|
|
7
|
+
value: any;
|
|
8
|
+
options: {
|
|
9
|
+
value: any;
|
|
10
|
+
label: string;
|
|
11
|
+
icon?: string;
|
|
12
|
+
hint?: string;
|
|
13
|
+
info?: string;
|
|
14
|
+
}[];
|
|
15
|
+
label: string;
|
|
16
|
+
onchange: (value: any) => void;
|
|
17
|
+
iconOnly?: boolean | undefined;
|
|
18
|
+
fill?: boolean | undefined;
|
|
19
|
+
pill?: boolean | undefined;
|
|
20
|
+
} & Omit<import("svelte/elements").HTMLAttributes<HTMLDivElement>, keyof {
|
|
21
|
+
value: any;
|
|
22
|
+
options: {
|
|
23
|
+
value: any;
|
|
24
|
+
label: string;
|
|
25
|
+
icon?: string;
|
|
26
|
+
hint?: string;
|
|
27
|
+
info?: string;
|
|
28
|
+
}[];
|
|
29
|
+
label: string;
|
|
30
|
+
onchange: (value: any) => void;
|
|
31
|
+
iconOnly?: boolean | undefined;
|
|
32
|
+
fill?: boolean | undefined;
|
|
33
|
+
pill?: boolean | undefined;
|
|
34
|
+
}>, {}, "">;
|
|
35
|
+
type Props = {
|
|
36
|
+
value: any;
|
|
37
|
+
options: {
|
|
38
|
+
value: any;
|
|
39
|
+
label: string;
|
|
40
|
+
icon?: string;
|
|
41
|
+
hint?: string;
|
|
42
|
+
info?: string;
|
|
43
|
+
}[];
|
|
44
|
+
label: string;
|
|
45
|
+
onchange: (value: any) => void;
|
|
46
|
+
iconOnly?: boolean | undefined;
|
|
47
|
+
fill?: boolean | undefined;
|
|
48
|
+
pill?: boolean | undefined;
|
|
49
|
+
};
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
/**
|
|
3
|
+
* The ready-made spans of the range pickers, as quiet buttons (part of DateRangePicker and DateRangeSelect; use those).
|
|
4
|
+
*
|
|
5
|
+
* <RangeShortcuts items={[{ label: 'Last 7 days', range: [from, to] }]} {value} onpick={(range) => (value = range)} />
|
|
6
|
+
*
|
|
7
|
+
* items: [{ label, range }], range [from, to], or null to show it disabled (the span isn't available).
|
|
8
|
+
* value: the current [from, to]; the shortcut giving it is marked current. onpick(range).
|
|
9
|
+
* vertical: a column (a wrapping row from 480px down); otherwise a wrapping row.
|
|
10
|
+
* Keyboard: each is a button in the tab order. Other attributes go to the group.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @typedef {object} Props
|
|
15
|
+
* @property {{ label: string, range: [string, string] | null }[]} items
|
|
16
|
+
* @property {[string, string]} value
|
|
17
|
+
* @property {(range: [string, string]) => void} onpick
|
|
18
|
+
* @property {boolean} [vertical]
|
|
19
|
+
*/
|
|
20
|
+
/** @type {Props & Omit<import('svelte/elements').HTMLAttributes<HTMLDivElement>, keyof Props>} */
|
|
21
|
+
let { items, value, onpick, vertical = false, class: className, ...rest } = $props()
|
|
22
|
+
</script>
|
|
23
|
+
|
|
24
|
+
<div class={['shortcuts', className]} class:vertical role="group" aria-label="Shortcuts" {...rest}>
|
|
25
|
+
{#each items as item (item.label)}
|
|
26
|
+
{@const range = item.range}
|
|
27
|
+
<button
|
|
28
|
+
type="button"
|
|
29
|
+
class="shortcut"
|
|
30
|
+
disabled={!range}
|
|
31
|
+
aria-current={range && range[0] === value[0] && range[1] === value[1] ? 'true' : undefined}
|
|
32
|
+
onclick={() => range && onpick(range)}>{item.label}</button
|
|
33
|
+
>
|
|
34
|
+
{/each}
|
|
35
|
+
</div>
|
|
36
|
+
|
|
37
|
+
<style>
|
|
38
|
+
.shortcuts {
|
|
39
|
+
display: flex;
|
|
40
|
+
flex-wrap: wrap;
|
|
41
|
+
gap: 2px;
|
|
42
|
+
}
|
|
43
|
+
.vertical {
|
|
44
|
+
flex-direction: column;
|
|
45
|
+
flex-wrap: nowrap;
|
|
46
|
+
}
|
|
47
|
+
.shortcut {
|
|
48
|
+
min-height: 24px;
|
|
49
|
+
padding: 0 var(--space-2);
|
|
50
|
+
border: 0;
|
|
51
|
+
border-radius: var(--r);
|
|
52
|
+
background: none;
|
|
53
|
+
color: var(--fg);
|
|
54
|
+
font: var(--w-medium) 12px var(--font-body);
|
|
55
|
+
text-align: start;
|
|
56
|
+
white-space: nowrap;
|
|
57
|
+
transition: background-color var(--dur-fast) var(--ease-out);
|
|
58
|
+
}
|
|
59
|
+
.shortcut:hover:not(:disabled) {
|
|
60
|
+
background: var(--control-3);
|
|
61
|
+
}
|
|
62
|
+
.shortcut[aria-current='true'] {
|
|
63
|
+
background: var(--accent-soft);
|
|
64
|
+
}
|
|
65
|
+
.shortcut:disabled {
|
|
66
|
+
color: var(--faint);
|
|
67
|
+
cursor: default;
|
|
68
|
+
}
|
|
69
|
+
.shortcut:focus-visible {
|
|
70
|
+
outline: 2px solid var(--accent);
|
|
71
|
+
outline-offset: -2px;
|
|
72
|
+
}
|
|
73
|
+
@media (pointer: coarse) {
|
|
74
|
+
.shortcut {
|
|
75
|
+
min-height: 44px;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
@media (max-width: 480px) {
|
|
79
|
+
.vertical {
|
|
80
|
+
flex-direction: row;
|
|
81
|
+
flex-wrap: wrap;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
@media (forced-colors: active) {
|
|
85
|
+
.shortcut[aria-current='true'] {
|
|
86
|
+
outline: 1px solid Highlight;
|
|
87
|
+
outline-offset: -1px;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
</style>
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export default RangeShortcuts;
|
|
2
|
+
type RangeShortcuts = {
|
|
3
|
+
$on?(type: string, callback: (e: any) => void): () => void;
|
|
4
|
+
$set?(props: Partial<Props & Omit<HTMLAttributes<HTMLDivElement>, keyof Props>>): void;
|
|
5
|
+
};
|
|
6
|
+
declare const RangeShortcuts: import("svelte").Component<{
|
|
7
|
+
items: {
|
|
8
|
+
label: string;
|
|
9
|
+
range: [string, string] | null;
|
|
10
|
+
}[];
|
|
11
|
+
value: [string, string];
|
|
12
|
+
onpick: (range: [string, string]) => void;
|
|
13
|
+
vertical?: boolean | undefined;
|
|
14
|
+
} & Omit<import("svelte/elements").HTMLAttributes<HTMLDivElement>, keyof {
|
|
15
|
+
items: {
|
|
16
|
+
label: string;
|
|
17
|
+
range: [string, string] | null;
|
|
18
|
+
}[];
|
|
19
|
+
value: [string, string];
|
|
20
|
+
onpick: (range: [string, string]) => void;
|
|
21
|
+
vertical?: boolean | undefined;
|
|
22
|
+
}>, {}, "">;
|
|
23
|
+
type Props = {
|
|
24
|
+
items: {
|
|
25
|
+
label: string;
|
|
26
|
+
range: [string, string] | null;
|
|
27
|
+
}[];
|
|
28
|
+
value: [string, string];
|
|
29
|
+
onpick: (range: [string, string]) => void;
|
|
30
|
+
vertical?: boolean | undefined;
|
|
31
|
+
};
|