@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,177 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
/**
|
|
3
|
+
* Range slider. Drag, click the track, or use arrows / PageUp / PageDown / Home / End.
|
|
4
|
+
*
|
|
5
|
+
* <Slider bind:value={opacity} min={0} max={1} step={0.05} id="opacity" label="Opacity" format={(v) => `${Math.round(v * 100)}%`} />
|
|
6
|
+
*
|
|
7
|
+
* format: how the value reads, beside the track (on the right) and to screen readers.
|
|
8
|
+
* ticks: a mark under the track at each stop. 'auto' (default): when there are 3 to 11 stops (1–5, 0–10, 0–100 in
|
|
9
|
+
* tens), so a few values to aim for show where they are; true, always; false, never (lib/ticks.js).
|
|
10
|
+
* note, info, hideLabel: as on the other fields (see FieldLabel). Other attributes (class…) and attachments go to the
|
|
11
|
+
* slider itself (role="slider").
|
|
12
|
+
*
|
|
13
|
+
* @typedef {object} Props
|
|
14
|
+
* @property {number} [value] bindable
|
|
15
|
+
* @property {number} [min]
|
|
16
|
+
* @property {number} [max]
|
|
17
|
+
* @property {number} [step]
|
|
18
|
+
* @property {string} id
|
|
19
|
+
* @property {string} label
|
|
20
|
+
* @property {(value: number) => string} [format]
|
|
21
|
+
* @property {string} [note]
|
|
22
|
+
* @property {string} [info]
|
|
23
|
+
* @property {boolean} [hideLabel]
|
|
24
|
+
* @property {'auto' | boolean} [ticks]
|
|
25
|
+
*/
|
|
26
|
+
import FieldLabel from './FieldLabel.svelte'
|
|
27
|
+
import SliderTicks from './SliderTicks.svelte'
|
|
28
|
+
|
|
29
|
+
/** @type {Props & Omit<import('svelte/elements').HTMLAttributes<HTMLDivElement>, keyof Props>} */
|
|
30
|
+
let {
|
|
31
|
+
value = $bindable(0),
|
|
32
|
+
min = 0,
|
|
33
|
+
max = 100,
|
|
34
|
+
step = 1,
|
|
35
|
+
id,
|
|
36
|
+
label,
|
|
37
|
+
format = (v) => String(v),
|
|
38
|
+
note = '',
|
|
39
|
+
info = '',
|
|
40
|
+
hideLabel = false,
|
|
41
|
+
ticks = 'auto',
|
|
42
|
+
class: className,
|
|
43
|
+
...rest
|
|
44
|
+
} = $props()
|
|
45
|
+
let track = $state()
|
|
46
|
+
let dragging = $state(false)
|
|
47
|
+
const pct = $derived(((value - min) / (max - min)) * 100)
|
|
48
|
+
|
|
49
|
+
const snap = (v) => Math.min(max, Math.max(min, Math.round((v - min) / step) * step + min))
|
|
50
|
+
const fromPointer = (e) => {
|
|
51
|
+
const r = track.getBoundingClientRect()
|
|
52
|
+
value = snap(min + ((e.clientX - r.left) / r.width) * (max - min))
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function down(e) {
|
|
56
|
+
if (e.button !== 0) return
|
|
57
|
+
dragging = true
|
|
58
|
+
e.currentTarget.setPointerCapture(e.pointerId)
|
|
59
|
+
e.currentTarget.focus()
|
|
60
|
+
fromPointer(e)
|
|
61
|
+
}
|
|
62
|
+
function onkeydown(e) {
|
|
63
|
+
const big = step * Math.max(1, Math.round((max - min) / step / 10))
|
|
64
|
+
const next = {
|
|
65
|
+
ArrowRight: value + step,
|
|
66
|
+
ArrowUp: value + step,
|
|
67
|
+
ArrowLeft: value - step,
|
|
68
|
+
ArrowDown: value - step,
|
|
69
|
+
PageUp: value + big,
|
|
70
|
+
PageDown: value - big,
|
|
71
|
+
Home: min,
|
|
72
|
+
End: max,
|
|
73
|
+
}[e.key]
|
|
74
|
+
if (next === undefined) return
|
|
75
|
+
e.preventDefault()
|
|
76
|
+
value = snap(next)
|
|
77
|
+
}
|
|
78
|
+
</script>
|
|
79
|
+
|
|
80
|
+
<div class="field">
|
|
81
|
+
<FieldLabel id="{id}-label" {label} {note} {info} {hideLabel} />
|
|
82
|
+
<div class="row">
|
|
83
|
+
<div
|
|
84
|
+
{id}
|
|
85
|
+
class={['slider', className]}
|
|
86
|
+
{...rest}
|
|
87
|
+
class:dragging
|
|
88
|
+
role="slider"
|
|
89
|
+
tabindex="0"
|
|
90
|
+
aria-labelledby="{id}-label"
|
|
91
|
+
aria-valuemin={min}
|
|
92
|
+
aria-valuemax={max}
|
|
93
|
+
aria-valuenow={value}
|
|
94
|
+
aria-valuetext={format(value)}
|
|
95
|
+
style:--pct="{pct}%"
|
|
96
|
+
onpointerdown={down}
|
|
97
|
+
onpointermove={(e) => dragging && fromPointer(e)}
|
|
98
|
+
onpointerup={() => (dragging = false)}
|
|
99
|
+
onpointercancel={() => (dragging = false)}
|
|
100
|
+
{onkeydown}
|
|
101
|
+
>
|
|
102
|
+
<div class="track" bind:this={track}><div class="fill"></div></div>
|
|
103
|
+
<SliderTicks {min} {max} {step} {ticks} on={(v) => v <= value} />
|
|
104
|
+
<div class="thumb"></div>
|
|
105
|
+
</div>
|
|
106
|
+
<output for={id}>{format(value)}</output>
|
|
107
|
+
</div>
|
|
108
|
+
</div>
|
|
109
|
+
|
|
110
|
+
<style>
|
|
111
|
+
.field {
|
|
112
|
+
display: flex;
|
|
113
|
+
flex-direction: column;
|
|
114
|
+
gap: 3px;
|
|
115
|
+
}
|
|
116
|
+
/* The track, then the value on its right. The gap clears the thumb, which overhangs the track's end by half its width. */
|
|
117
|
+
.row {
|
|
118
|
+
display: flex;
|
|
119
|
+
align-items: center;
|
|
120
|
+
gap: var(--space-3);
|
|
121
|
+
}
|
|
122
|
+
output {
|
|
123
|
+
font: var(--w-medium) 12px var(--font-data);
|
|
124
|
+
font-variant-numeric: tabular-nums;
|
|
125
|
+
color: var(--fg-2);
|
|
126
|
+
white-space: nowrap;
|
|
127
|
+
}
|
|
128
|
+
.slider {
|
|
129
|
+
position: relative;
|
|
130
|
+
width: 180px;
|
|
131
|
+
height: 32px;
|
|
132
|
+
display: flex;
|
|
133
|
+
align-items: center;
|
|
134
|
+
cursor: pointer;
|
|
135
|
+
/* Horizontal drags are the slider's; vertical ones still scroll the page. */
|
|
136
|
+
touch-action: pan-y;
|
|
137
|
+
border-radius: 6px;
|
|
138
|
+
}
|
|
139
|
+
.slider:focus-visible {
|
|
140
|
+
outline: 2px solid var(--accent);
|
|
141
|
+
outline-offset: 2px;
|
|
142
|
+
}
|
|
143
|
+
.track {
|
|
144
|
+
position: relative;
|
|
145
|
+
width: 100%;
|
|
146
|
+
height: 4px;
|
|
147
|
+
border-radius: var(--r-pill);
|
|
148
|
+
background: var(--control-4);
|
|
149
|
+
overflow: clip;
|
|
150
|
+
}
|
|
151
|
+
.fill {
|
|
152
|
+
position: absolute;
|
|
153
|
+
inset: 0 auto 0 0;
|
|
154
|
+
width: var(--pct);
|
|
155
|
+
background: var(--brand);
|
|
156
|
+
}
|
|
157
|
+
.thumb {
|
|
158
|
+
position: absolute;
|
|
159
|
+
left: var(--pct);
|
|
160
|
+
top: 50%;
|
|
161
|
+
width: 14px;
|
|
162
|
+
height: 14px;
|
|
163
|
+
translate: -50% -50%;
|
|
164
|
+
scale: 1;
|
|
165
|
+
border-radius: 50%;
|
|
166
|
+
background: var(--knob);
|
|
167
|
+
border: 0;
|
|
168
|
+
box-shadow:
|
|
169
|
+
0 0 0 1px var(--knob-ring),
|
|
170
|
+
var(--knob-shadow);
|
|
171
|
+
transition: scale var(--dur-fast) var(--ease-out);
|
|
172
|
+
}
|
|
173
|
+
.slider:hover .thumb,
|
|
174
|
+
.dragging .thumb {
|
|
175
|
+
scale: 1.12;
|
|
176
|
+
}
|
|
177
|
+
</style>
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export default Slider;
|
|
2
|
+
/**
|
|
3
|
+
* Range slider. Drag, click the track, or use arrows / PageUp / PageDown / Home / End.
|
|
4
|
+
*
|
|
5
|
+
* <Slider bind:value={opacity} min={0} max={1} step={0.05} id="opacity" label="Opacity" format={(v) => `${Math.round(v * 100)}%`} />
|
|
6
|
+
*
|
|
7
|
+
* format: how the value reads, beside the track (on the right) and to screen readers.
|
|
8
|
+
* ticks: a mark under the track at each stop. 'auto' (default): when there are 3 to 11 stops (1–5, 0–10, 0–100 in
|
|
9
|
+
* tens), so a few values to aim for show where they are; true, always; false, never (lib/ticks.js).
|
|
10
|
+
* note, info, hideLabel: as on the other fields (see FieldLabel). Other attributes (class…) and attachments go to the
|
|
11
|
+
* slider itself (role="slider").
|
|
12
|
+
*/
|
|
13
|
+
export type Props = {
|
|
14
|
+
/**
|
|
15
|
+
* bindable
|
|
16
|
+
*/
|
|
17
|
+
value?: number | undefined;
|
|
18
|
+
min?: number | undefined;
|
|
19
|
+
max?: number | undefined;
|
|
20
|
+
step?: number | undefined;
|
|
21
|
+
id: string;
|
|
22
|
+
label: string;
|
|
23
|
+
format?: ((value: number) => string) | undefined;
|
|
24
|
+
note?: string | undefined;
|
|
25
|
+
info?: string | undefined;
|
|
26
|
+
hideLabel?: boolean | undefined;
|
|
27
|
+
ticks?: boolean | "auto" | undefined;
|
|
28
|
+
};
|
|
29
|
+
type Slider = {
|
|
30
|
+
$on?(type: string, callback: (e: any) => void): () => void;
|
|
31
|
+
$set?(props: Partial<Props & Omit<HTMLAttributes<HTMLDivElement>, keyof Props>>): void;
|
|
32
|
+
};
|
|
33
|
+
declare const Slider: import("svelte").Component<Props & Omit<import("svelte/elements").HTMLAttributes<HTMLDivElement>, keyof Props>, {}, "value">;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
/**
|
|
3
|
+
* The tick marks under a slider's track, one per stop (part of Slider and RangeSlider; use those). Which values get one
|
|
4
|
+
* comes from sliderTicks in lib/ticks.js; the ticks inside the chosen value or span take the accent, like the fill.
|
|
5
|
+
* Decorative: the slider's own value text says where it is.
|
|
6
|
+
*
|
|
7
|
+
* <SliderTicks {min} {max} {step} ticks="auto" on={(v) => v <= value} />
|
|
8
|
+
*
|
|
9
|
+
* min, max, step: the slider's. ticks: 'auto' (a few stops only), true or false. on(value): whether that tick is
|
|
10
|
+
* inside the chosen part.
|
|
11
|
+
*
|
|
12
|
+
* @typedef {object} Props
|
|
13
|
+
* @property {number} min
|
|
14
|
+
* @property {number} max
|
|
15
|
+
* @property {number} step
|
|
16
|
+
* @property {'auto' | boolean} [ticks]
|
|
17
|
+
* @property {(value: number) => boolean} on
|
|
18
|
+
*/
|
|
19
|
+
import { sliderTicks } from '../../lib/ticks.js'
|
|
20
|
+
|
|
21
|
+
/** @type {Props} */
|
|
22
|
+
let { min, max, step, ticks = 'auto', on } = $props()
|
|
23
|
+
const marks = $derived(sliderTicks(min, max, step, ticks))
|
|
24
|
+
</script>
|
|
25
|
+
|
|
26
|
+
{#if marks.length}
|
|
27
|
+
<div class="ticks" aria-hidden="true">
|
|
28
|
+
{#each marks as v (v)}<span class="tick" class:on={on(v)} style:left="{((v - min) / (max - min)) * 100}%"></span>{/each}
|
|
29
|
+
</div>
|
|
30
|
+
{/if}
|
|
31
|
+
|
|
32
|
+
<style>
|
|
33
|
+
/* Under the track, clear of the thumb's edge; presses go through to the slider. */
|
|
34
|
+
.ticks {
|
|
35
|
+
position: absolute;
|
|
36
|
+
inset-inline: 0;
|
|
37
|
+
top: calc(50% + 6px);
|
|
38
|
+
height: 4px;
|
|
39
|
+
pointer-events: none;
|
|
40
|
+
}
|
|
41
|
+
.tick {
|
|
42
|
+
position: absolute;
|
|
43
|
+
top: 0;
|
|
44
|
+
width: 2px;
|
|
45
|
+
height: 4px;
|
|
46
|
+
translate: -50% 0;
|
|
47
|
+
border-radius: var(--r-pill);
|
|
48
|
+
background: var(--line-strong);
|
|
49
|
+
transition: background-color var(--dur-fast) var(--ease-out);
|
|
50
|
+
}
|
|
51
|
+
.tick.on {
|
|
52
|
+
background: var(--accent);
|
|
53
|
+
}
|
|
54
|
+
@media (forced-colors: active) {
|
|
55
|
+
.tick {
|
|
56
|
+
background: CanvasText;
|
|
57
|
+
}
|
|
58
|
+
.tick.on {
|
|
59
|
+
background: Highlight;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
</style>
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export default SliderTicks;
|
|
2
|
+
/**
|
|
3
|
+
* The tick marks under a slider's track, one per stop (part of Slider and RangeSlider; use those). Which values get one
|
|
4
|
+
* comes from sliderTicks in lib/ticks.js; the ticks inside the chosen value or span take the accent, like the fill.
|
|
5
|
+
* Decorative: the slider's own value text says where it is.
|
|
6
|
+
*
|
|
7
|
+
* <SliderTicks {min} {max} {step} ticks="auto" on={(v) => v <= value} />
|
|
8
|
+
*
|
|
9
|
+
* min, max, step: the slider's. ticks: 'auto' (a few stops only), true or false. on(value): whether that tick is
|
|
10
|
+
* inside the chosen part.
|
|
11
|
+
*/
|
|
12
|
+
export type Props = {
|
|
13
|
+
min: number;
|
|
14
|
+
max: number;
|
|
15
|
+
step: number;
|
|
16
|
+
ticks?: boolean | "auto" | undefined;
|
|
17
|
+
on: (value: number) => boolean;
|
|
18
|
+
};
|
|
19
|
+
type SliderTicks = {
|
|
20
|
+
$on?(type: string, callback: (e: any) => void): () => void;
|
|
21
|
+
$set?(props: Partial<Props>): void;
|
|
22
|
+
};
|
|
23
|
+
declare const SliderTicks: import("svelte").Component<Props, {}, "">;
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
/** On/off switch. `hint`: a short state note after the label, shown in parentheses outside the button (so clicking it
|
|
3
|
+
* doesn't toggle) and given to it as its description. Other props and attachments go to the button, e.g. {@attach tooltip('…')} when a short label needs explaining. */
|
|
4
|
+
/**
|
|
5
|
+
* @typedef {object} Props
|
|
6
|
+
* @property {boolean} [checked] bindable
|
|
7
|
+
* @property {string} id
|
|
8
|
+
* @property {string} label
|
|
9
|
+
* @property {string | null} [hint]
|
|
10
|
+
*/
|
|
11
|
+
/** @type {Props & Omit<import('svelte/elements').HTMLButtonAttributes, keyof Props>} */
|
|
12
|
+
let { checked = $bindable(false), id, label, hint = null, class: className, ...rest } = $props()
|
|
13
|
+
</script>
|
|
14
|
+
|
|
15
|
+
<span class="row">
|
|
16
|
+
<button
|
|
17
|
+
{id}
|
|
18
|
+
type="button"
|
|
19
|
+
class={['switch', className]}
|
|
20
|
+
role="switch"
|
|
21
|
+
aria-checked={checked}
|
|
22
|
+
aria-describedby={hint != null ? `${id}-hint` : undefined}
|
|
23
|
+
{...rest}
|
|
24
|
+
onclick={() => (checked = !checked)}
|
|
25
|
+
>
|
|
26
|
+
<span class="knob" aria-hidden="true"></span>
|
|
27
|
+
<span class="text">{label}</span>
|
|
28
|
+
</button>
|
|
29
|
+
{#if hint != null}<span class="hint" id="{id}-hint">({hint})</span>{/if}
|
|
30
|
+
</span>
|
|
31
|
+
|
|
32
|
+
<style>
|
|
33
|
+
/* fit-content: a grid or column parent would otherwise stretch the switch across the row, so a click in the empty space
|
|
34
|
+
beside the label would toggle it. The hint sits beside the button, centred on it: the button's own baseline comes from
|
|
35
|
+
the empty knob (its first item), so baseline alignment would drop the hint to the knob's bottom edge. */
|
|
36
|
+
.row {
|
|
37
|
+
display: inline-flex;
|
|
38
|
+
align-items: center;
|
|
39
|
+
gap: 6px;
|
|
40
|
+
width: fit-content;
|
|
41
|
+
max-width: 100%;
|
|
42
|
+
}
|
|
43
|
+
.switch {
|
|
44
|
+
display: inline-flex;
|
|
45
|
+
align-items: center;
|
|
46
|
+
gap: 8px;
|
|
47
|
+
min-width: 0;
|
|
48
|
+
text-align: left;
|
|
49
|
+
min-height: 32px;
|
|
50
|
+
padding: 0 2px;
|
|
51
|
+
background: none;
|
|
52
|
+
border: 0;
|
|
53
|
+
cursor: pointer;
|
|
54
|
+
font-size: 13px;
|
|
55
|
+
color: var(--fg-2);
|
|
56
|
+
}
|
|
57
|
+
.knob {
|
|
58
|
+
position: relative;
|
|
59
|
+
width: 28px;
|
|
60
|
+
height: 16px;
|
|
61
|
+
border-radius: var(--r-pill);
|
|
62
|
+
background: var(--control-4);
|
|
63
|
+
/* Sunken, like the fields: the track the knob slides in. */
|
|
64
|
+
box-shadow:
|
|
65
|
+
inset 0 0 0 1px var(--line),
|
|
66
|
+
var(--sunken-shadow);
|
|
67
|
+
transition:
|
|
68
|
+
background var(--dur) var(--ease-out),
|
|
69
|
+
box-shadow var(--dur) var(--ease-out),
|
|
70
|
+
filter var(--dur) var(--ease-out);
|
|
71
|
+
flex: none;
|
|
72
|
+
}
|
|
73
|
+
.knob::after {
|
|
74
|
+
content: '';
|
|
75
|
+
position: absolute;
|
|
76
|
+
top: 2px;
|
|
77
|
+
left: 2px;
|
|
78
|
+
width: 12px;
|
|
79
|
+
height: 12px;
|
|
80
|
+
border-radius: 50%;
|
|
81
|
+
background: var(--knob);
|
|
82
|
+
box-shadow: var(--knob-shadow);
|
|
83
|
+
translate: 0 0;
|
|
84
|
+
transition: translate var(--dur) var(--ease-out);
|
|
85
|
+
}
|
|
86
|
+
[aria-checked='true'] .knob {
|
|
87
|
+
background: var(--brand);
|
|
88
|
+
box-shadow: none;
|
|
89
|
+
}
|
|
90
|
+
[aria-checked='true'] .knob::after {
|
|
91
|
+
translate: 12px 0;
|
|
92
|
+
}
|
|
93
|
+
/* Hover (when it can act): the label comes forward, an off track firms up its hairline, an on track brightens. */
|
|
94
|
+
.switch {
|
|
95
|
+
transition: color var(--dur) var(--ease-out);
|
|
96
|
+
}
|
|
97
|
+
.switch:hover:not(:disabled) {
|
|
98
|
+
color: var(--fg);
|
|
99
|
+
}
|
|
100
|
+
.switch:hover:not(:disabled):not([aria-checked='true']) .knob {
|
|
101
|
+
box-shadow:
|
|
102
|
+
inset 0 0 0 1px var(--line-float),
|
|
103
|
+
var(--sunken-shadow);
|
|
104
|
+
}
|
|
105
|
+
.switch:hover:not(:disabled)[aria-checked='true'] .knob {
|
|
106
|
+
filter: brightness(1.1);
|
|
107
|
+
}
|
|
108
|
+
.switch:focus-visible {
|
|
109
|
+
outline: none;
|
|
110
|
+
}
|
|
111
|
+
.switch:focus-visible .knob {
|
|
112
|
+
outline: 2px solid var(--accent);
|
|
113
|
+
outline-offset: 2px;
|
|
114
|
+
}
|
|
115
|
+
.hint {
|
|
116
|
+
font: var(--w-medium) 12px var(--font-data);
|
|
117
|
+
font-variant-numeric: tabular-nums;
|
|
118
|
+
color: var(--muted);
|
|
119
|
+
}
|
|
120
|
+
</style>
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export default Switch;
|
|
2
|
+
type Switch = {
|
|
3
|
+
$on?(type: string, callback: (e: any) => void): () => void;
|
|
4
|
+
$set?(props: Partial<Props & Omit<HTMLButtonAttributes, keyof Props>>): void;
|
|
5
|
+
};
|
|
6
|
+
declare const Switch: import("svelte").Component<{
|
|
7
|
+
/**
|
|
8
|
+
* bindable
|
|
9
|
+
*/
|
|
10
|
+
checked?: boolean | undefined;
|
|
11
|
+
id: string;
|
|
12
|
+
label: string;
|
|
13
|
+
hint?: string | null | undefined;
|
|
14
|
+
} & Omit<import("svelte/elements").HTMLButtonAttributes, keyof {
|
|
15
|
+
/**
|
|
16
|
+
* bindable
|
|
17
|
+
*/
|
|
18
|
+
checked?: boolean | undefined;
|
|
19
|
+
id: string;
|
|
20
|
+
label: string;
|
|
21
|
+
hint?: string | null | undefined;
|
|
22
|
+
}>, {}, "checked">;
|
|
23
|
+
type Props = {
|
|
24
|
+
/**
|
|
25
|
+
* bindable
|
|
26
|
+
*/
|
|
27
|
+
checked?: boolean | undefined;
|
|
28
|
+
id: string;
|
|
29
|
+
label: string;
|
|
30
|
+
hint?: string | null | undefined;
|
|
31
|
+
};
|