@stacksjs/components 0.2.867 → 0.2.868
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/dist/AppearancePicker-61r20jpp.stx +351 -0
- package/dist/{Button-sebyqeva.stx → Button-pg8mzsq3.stx} +249 -0
- package/dist/Checkbox-52mhrzkz.stx +417 -0
- package/dist/ColorSwatches-ecfxphjy.stx +287 -0
- package/dist/{NumberInput-axcfj9y8.stx → NumberInput-e2afxyh3.stx} +303 -0
- package/dist/{PasswordInput-8m3109tp.stx → PasswordInput-n2ven456.stx} +315 -0
- package/dist/RadioGroup-ps9kn22f.stx +329 -0
- package/dist/RadioGroupOption-6hyy1bvb.stx +246 -0
- package/dist/{SegmentedControl-fr69q4gb.stx → SegmentedControl-7q0t8c9s.stx} +170 -1
- package/dist/{Select-1cnqbcmg.stx → Select-ygzchedx.stx} +266 -0
- package/dist/SettingsGroup-dkae46k5.stx +200 -0
- package/dist/SettingsPane-jbd1gbdt.stx +50 -0
- package/dist/SettingsPaneHeader-f0cvkqs7.stx +188 -0
- package/dist/SettingsRow-4cxbsf1q.stx +424 -0
- package/dist/SettingsSidebarGroup-p2ygv5yy.stx +108 -0
- package/dist/SettingsSidebarItem-x8fsn3w5.stx +228 -0
- package/dist/SettingsWindow-mm490ymt.stx +537 -0
- package/dist/Slider-j59dgw1c.stx +377 -0
- package/dist/Switch-ga9ap8n8.stx +374 -0
- package/dist/{TextInput-tsvfwxmg.stx → TextInput-tyqzz3jy.stx} +325 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +35 -24
- package/dist/settings/settings.js +757 -0
- package/dist/ui/appearance-picker/AppearancePicker.d.ts +12 -0
- package/dist/ui/appearance-picker/index.d.ts +16 -0
- package/dist/ui/button/Button.d.ts +24 -1
- package/dist/ui/button/index.d.ts +1 -0
- package/dist/ui/checkbox/Checkbox.d.ts +9 -1
- package/dist/ui/checkbox/index.d.ts +1 -0
- package/dist/ui/color-swatches/ColorSwatches.d.ts +26 -0
- package/dist/ui/color-swatches/index.d.ts +18 -0
- package/dist/ui/input/NumberInput.d.ts +11 -1
- package/dist/ui/input/PasswordInput.d.ts +9 -1
- package/dist/ui/input/TextInput.d.ts +12 -1
- package/dist/ui/input/index.d.ts +7 -3
- package/dist/ui/radio-group/RadioGroup.d.ts +14 -2
- package/dist/ui/radio-group/RadioGroupOption.d.ts +6 -1
- package/dist/ui/radio-group/index.d.ts +2 -0
- package/dist/ui/segmented-control/SegmentedControl.d.ts +9 -1
- package/dist/ui/segmented-control/index.d.ts +1 -0
- package/dist/ui/select/Select.d.ts +10 -1
- package/dist/ui/select/index.d.ts +1 -0
- package/dist/ui/settings/SettingsGroup.d.ts +30 -0
- package/dist/ui/settings/SettingsPane.d.ts +19 -0
- package/dist/ui/settings/SettingsPaneHeader.d.ts +20 -0
- package/dist/ui/settings/SettingsRow.d.ts +53 -0
- package/dist/ui/settings/SettingsSidebarGroup.d.ts +11 -0
- package/dist/ui/settings/SettingsSidebarItem.d.ts +22 -0
- package/dist/ui/settings/SettingsWindow.d.ts +22 -0
- package/dist/ui/settings/core.d.ts +146 -0
- package/dist/ui/settings/index.d.ts +73 -0
- package/dist/ui/settings/settings.d.ts +8 -0
- package/dist/ui/settings/view.d.ts +36 -0
- package/dist/ui/slider/Slider.d.ts +24 -0
- package/dist/ui/slider/core.d.ts +33 -0
- package/dist/ui/slider/index.d.ts +20 -0
- package/dist/ui/switch/Switch.d.ts +10 -1
- package/dist/ui/switch/index.d.ts +2 -1
- package/dist/utils/mac-theme.d.ts +24 -0
- package/package.json +8 -3
- package/src/index.ts +6 -0
- package/src/ui/appearance-picker/AppearancePicker.stx +351 -0
- package/src/ui/appearance-picker/README.md +61 -0
- package/src/ui/appearance-picker/index.ts +22 -0
- package/src/ui/button/Button.stx +249 -0
- package/src/ui/button/README.md +21 -0
- package/src/ui/button/index.ts +8 -0
- package/src/ui/checkbox/Checkbox.stx +275 -0
- package/src/ui/checkbox/index.ts +2 -0
- package/src/ui/color-swatches/ColorSwatches.stx +287 -0
- package/src/ui/color-swatches/README.md +66 -0
- package/src/ui/color-swatches/index.ts +25 -0
- package/src/ui/input/NumberInput.stx +303 -0
- package/src/ui/input/PasswordInput.stx +315 -0
- package/src/ui/input/TextInput.stx +325 -0
- package/src/ui/input/index.ts +9 -3
- package/src/ui/radio-group/README.md +17 -0
- package/src/ui/radio-group/RadioGroup.stx +184 -6
- package/src/ui/radio-group/RadioGroupOption.stx +178 -2
- package/src/ui/radio-group/index.ts +4 -0
- package/src/ui/segmented-control/SegmentedControl.stx +170 -1
- package/src/ui/segmented-control/index.ts +2 -0
- package/src/ui/select/README.md +12 -0
- package/src/ui/select/Select.stx +266 -0
- package/src/ui/select/index.ts +2 -0
- package/src/ui/settings/README.md +221 -0
- package/src/ui/settings/SettingsGroup.stx +200 -0
- package/src/ui/settings/SettingsPane.stx +50 -0
- package/src/ui/settings/SettingsPaneHeader.stx +188 -0
- package/src/ui/settings/SettingsRow.stx +424 -0
- package/src/ui/settings/SettingsSidebarGroup.stx +108 -0
- package/src/ui/settings/SettingsSidebarItem.stx +228 -0
- package/src/ui/settings/SettingsWindow.stx +537 -0
- package/src/ui/settings/core.ts +359 -0
- package/src/ui/settings/index.ts +111 -0
- package/src/ui/settings/settings.ts +8 -0
- package/src/ui/settings/view.ts +740 -0
- package/src/ui/slider/README.md +91 -0
- package/src/ui/slider/Slider.stx +377 -0
- package/src/ui/slider/core.ts +120 -0
- package/src/ui/slider/index.ts +34 -0
- package/src/ui/switch/README.md +11 -0
- package/src/ui/switch/Switch.stx +217 -0
- package/src/ui/switch/index.ts +4 -1
- package/src/utils/mac-theme.ts +95 -0
- package/dist/Checkbox-80myyzzm.stx +0 -142
- package/dist/RadioGroup-smqcqgds.stx +0 -151
- package/dist/RadioGroupOption-twcw1b2a.stx +0 -70
- package/dist/Switch-s8yf2rvm.stx +0 -157
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# Slider
|
|
2
|
+
|
|
3
|
+
A value picked along a track, drawn the way macOS draws one: a 4 point track, a white pill for a knob, optional tick marks under the track and an icon at either end.
|
|
4
|
+
|
|
5
|
+
```html
|
|
6
|
+
<script client>
|
|
7
|
+
const size = state(1)
|
|
8
|
+
</script>
|
|
9
|
+
|
|
10
|
+
<Slider
|
|
11
|
+
v-model:value="size"
|
|
12
|
+
min="0"
|
|
13
|
+
max="2"
|
|
14
|
+
step="1"
|
|
15
|
+
ticks
|
|
16
|
+
minIcon="i-f7-textformat-size"
|
|
17
|
+
maxIcon="i-f7-textformat-size"
|
|
18
|
+
label="Text size"
|
|
19
|
+
/>
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Under the drawing is a real `<input type="range">`, stretched over the track and transparent. The pointer, a screen reader and a form all get the browser's own slider, and the drawing follows it.
|
|
23
|
+
|
|
24
|
+
## Props
|
|
25
|
+
|
|
26
|
+
| Prop | Default | What it does |
|
|
27
|
+
|---|---|---|
|
|
28
|
+
| `value` | `min` | The value. `v-model:value` follows the knob as it moves. |
|
|
29
|
+
| `min`, `max` | `0`, `100` | The ends of the range. Given the wrong way round, they are swapped. |
|
|
30
|
+
| `step` | `1` | The distance between two values. `0` allows any value. |
|
|
31
|
+
| `ticks` | none | A number draws that many marks, spread evenly with one at each end. `true` (or the bare attribute) draws one for each step. Fewer than 2 or more than 101 draws none. |
|
|
32
|
+
| `tint` | `neutral` | `neutral` fills the track up to the knob in grey, `accent` in the accent colour. |
|
|
33
|
+
| `minIcon`, `maxIcon` | none | Iconify classes drawn at the low and the high end. |
|
|
34
|
+
| `label` | none | The accessible name. Inside a `<SettingsRow>` it can be left out: the row's label names the slider. |
|
|
35
|
+
| `disabled` | `false` | Dimmed, and it does not move. |
|
|
36
|
+
| `width` | `100%` | A CSS length. In a settings row the default is 220px (the row sets `--stx-slider-width`). |
|
|
37
|
+
| `name` | none | Submits the value in a form under this name. |
|
|
38
|
+
| `id`, `className` | | On the root element. |
|
|
39
|
+
|
|
40
|
+
## Events
|
|
41
|
+
|
|
42
|
+
| Event | Payload | When |
|
|
43
|
+
|---|---|---|
|
|
44
|
+
| `input` | the value | While the knob moves. |
|
|
45
|
+
| `change` | the value | When it is let go, and for each key that moves it. |
|
|
46
|
+
| `update:value` | the value | With `input`. This is what `v-model:value` listens to. |
|
|
47
|
+
|
|
48
|
+
The browser's own `input` and `change` events stop at the component, so a listener hears the component's event once and not the input's as well.
|
|
49
|
+
|
|
50
|
+
## Keys
|
|
51
|
+
|
|
52
|
+
| Key | Moves |
|
|
53
|
+
|---|---|
|
|
54
|
+
| Arrow Right, Arrow Up | one step up |
|
|
55
|
+
| Arrow Left, Arrow Down | one step down |
|
|
56
|
+
| Page Up, Page Down | ten steps |
|
|
57
|
+
| Home, End | to the minimum, to the maximum |
|
|
58
|
+
|
|
59
|
+
With no step, an arrow moves a hundredth of the range.
|
|
60
|
+
|
|
61
|
+
## Exposed
|
|
62
|
+
|
|
63
|
+
`componentApi(target)` gives `value` (the signal) and `setValue(number)`, which snaps what it is given to a step inside the range.
|
|
64
|
+
|
|
65
|
+
## Arithmetic
|
|
66
|
+
|
|
67
|
+
`./core` has no DOM and can be used without the component:
|
|
68
|
+
|
|
69
|
+
```ts
|
|
70
|
+
import { sliderFraction, sliderRange, sliderSnap, sliderTicks } from '@stacksjs/components'
|
|
71
|
+
|
|
72
|
+
const range = sliderRange(0, 10, 4)
|
|
73
|
+
sliderSnap(9.9, range) // 8: a maximum that is not on a step cannot be reached
|
|
74
|
+
sliderFraction(8, range) // 0.8
|
|
75
|
+
sliderTicks(true, range) // [0, 0.4, 0.8]
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Styling
|
|
79
|
+
|
|
80
|
+
Colours come from the Mac theme tokens (`--stx-mac-well`, `--stx-mac-ink-tertiary`, `--stx-mac-accent`, `--stx-mac-knob`, `--stx-mac-focus-ring`), so it follows light, dark (the `dark` class) and more contrast with the rest of the Mac controls. In a window that is not the key window (`data-stx-window-active="false"` on an ancestor, or Craft's `data-craft-window-active='false'` on the root) an accent fill turns grey.
|
|
81
|
+
|
|
82
|
+
Its own variables, set on the slider or anything around it:
|
|
83
|
+
|
|
84
|
+
| Variable | Default |
|
|
85
|
+
|---|---|
|
|
86
|
+
| `--stx-slider-width` | `100%` |
|
|
87
|
+
| `--stx-slider-track-height` | `4px` |
|
|
88
|
+
| `--stx-slider-knob-width`, `--stx-slider-knob-height` | `20px`, `16px` |
|
|
89
|
+
| `--stx-slider-track`, `--stx-slider-fill`, `--stx-slider-tick` | from the theme |
|
|
90
|
+
| `--stx-slider-tick-size`, `--stx-slider-tick-offset` | `2px`, `6px` |
|
|
91
|
+
| `--stx-slider-icon-size` | `15px` |
|
|
@@ -0,0 +1,377 @@
|
|
|
1
|
+
<script server>
|
|
2
|
+
/*
|
|
3
|
+
* <Slider>: a value picked along a track, drawn as a Mac draws it. A thin
|
|
4
|
+
* track, a white pill for a knob, optional tick marks under the track and an
|
|
5
|
+
* icon at either end.
|
|
6
|
+
*
|
|
7
|
+
* <Slider v-model:value="size" min="0" max="2" step="1" ticks
|
|
8
|
+
* minIcon="i-f7-textformat-size" maxIcon="i-f7-textformat-size" label="Text size" />
|
|
9
|
+
*
|
|
10
|
+
* Under the drawing is a real `<input type="range">`, stretched over the
|
|
11
|
+
* track and transparent, so the pointer, the keyboard, a screen reader and a
|
|
12
|
+
* form all get the browser's own slider. The arithmetic is in ./core.
|
|
13
|
+
*
|
|
14
|
+
* `input` is emitted with the value while it moves and `change` when it is
|
|
15
|
+
* let go; `v-model:value` follows it as it moves.
|
|
16
|
+
*/
|
|
17
|
+
const number = (value, fallback) => {
|
|
18
|
+
const parsed = typeof value === 'number' ? value : Number.parseFloat(String(value))
|
|
19
|
+
return Number.isFinite(parsed) ? parsed : fallback
|
|
20
|
+
}
|
|
21
|
+
const low = $num($props.min, 0)
|
|
22
|
+
const high = $num($props.max, 100)
|
|
23
|
+
export const min = Math.min(low, high)
|
|
24
|
+
export const max = Math.max(low, high)
|
|
25
|
+
export const step = Math.max(0, $num($props.step, 1))
|
|
26
|
+
export const value = Math.min(max, Math.max(min, $num($props.value, min)))
|
|
27
|
+
export const fraction = max > min ? (value - min) / (max - min) : 0
|
|
28
|
+
/* A count of marks, or true for one a step. */
|
|
29
|
+
const rawTicks = $props.ticks
|
|
30
|
+
export const ticks = rawTicks === true || rawTicks === '' || rawTicks === 'true'
|
|
31
|
+
? true
|
|
32
|
+
: (rawTicks === undefined || rawTicks === null || rawTicks === false || rawTicks === 'false' ? false : number(rawTicks, 0))
|
|
33
|
+
export const disabled = $bool($props.disabled)
|
|
34
|
+
export const label = $props.label || ''
|
|
35
|
+
export const minIcon = $props.minIcon || ''
|
|
36
|
+
export const maxIcon = $props.maxIcon || ''
|
|
37
|
+
export const tint = $props.tint === 'accent' ? 'accent' : 'neutral'
|
|
38
|
+
export const name = $props.name || ''
|
|
39
|
+
/* A CSS length. Left out, the slider is as wide as it is allowed to be. */
|
|
40
|
+
export const width = $props.width || ''
|
|
41
|
+
export const sliderId = $props.id || `slider-${$uid}`
|
|
42
|
+
export const className = $props.className || ''
|
|
43
|
+
</script>
|
|
44
|
+
|
|
45
|
+
<script client>
|
|
46
|
+
import { sliderFraction, sliderKeyValue, sliderRange, sliderSnap, sliderTicks } from './core'
|
|
47
|
+
|
|
48
|
+
const emit = defineEmits(['input', 'change'])
|
|
49
|
+
|
|
50
|
+
const liveMin = useReactiveProp('min', {{ min }})
|
|
51
|
+
const liveMax = useReactiveProp('max', {{ max }})
|
|
52
|
+
const liveStep = useReactiveProp('step', {{ step }})
|
|
53
|
+
const liveTicks = useReactiveProp('ticks', {{ ticks }})
|
|
54
|
+
const isDisabled = useReactiveProp('disabled', {{ disabled }})
|
|
55
|
+
const spoken = useReactiveProp('label', {{ label }})
|
|
56
|
+
const held = useModel('value', { default: {{ value }} })
|
|
57
|
+
|
|
58
|
+
const range = () => sliderRange(liveMin(), liveMax(), liveStep())
|
|
59
|
+
const current = () => sliderSnap(held(), range())
|
|
60
|
+
const tickMarks = () => sliderTicks(liveTicks(), range())
|
|
61
|
+
const place = fraction => `calc(var(--stx-slider-knob-width) / 2 + ${fraction} * (100% - var(--stx-slider-knob-width)))`
|
|
62
|
+
|
|
63
|
+
function bodyStyle() {
|
|
64
|
+
return `--stx-slider-fraction: ${sliderFraction(current(), range())}`
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function tickStyle(tick) {
|
|
68
|
+
return `left: ${place(tick)}`
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function move(next, settled) {
|
|
72
|
+
const value = sliderSnap(next, range())
|
|
73
|
+
const changed = value !== current()
|
|
74
|
+
if (changed) held.set(value)
|
|
75
|
+
if (changed || !settled) emit('input', value)
|
|
76
|
+
if (settled) emit('change', value)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/*
|
|
80
|
+
* The browser's own events stop here and the component's go out in their
|
|
81
|
+
* place, carrying the value, so a page that listens for `input` hears one
|
|
82
|
+
* thing and not two.
|
|
83
|
+
*/
|
|
84
|
+
function onInput(event) {
|
|
85
|
+
event.stopPropagation()
|
|
86
|
+
if (isDisabled()) return
|
|
87
|
+
move(event.target.value, false)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function onChange(event) {
|
|
91
|
+
event.stopPropagation()
|
|
92
|
+
if (isDisabled()) return
|
|
93
|
+
const value = sliderSnap(event.target.value, range())
|
|
94
|
+
if (value !== current()) held.set(value)
|
|
95
|
+
emit('change', value)
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function onKey(event) {
|
|
99
|
+
if (isDisabled() || event.metaKey || event.ctrlKey || event.altKey) return
|
|
100
|
+
const next = sliderKeyValue(event.key, current(), range())
|
|
101
|
+
if (next === null) return
|
|
102
|
+
event.preventDefault()
|
|
103
|
+
if (next !== current()) move(next, true)
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
defineExpose({
|
|
107
|
+
value: held,
|
|
108
|
+
setValue: (next) => { held.set(sliderSnap(next, range())) },
|
|
109
|
+
})
|
|
110
|
+
</script>
|
|
111
|
+
|
|
112
|
+
<div
|
|
113
|
+
id="{{ sliderId }}"
|
|
114
|
+
data-stx-slider
|
|
115
|
+
data-tint="{{ tint }}"
|
|
116
|
+
@if(disabled)data-disabled@endif
|
|
117
|
+
:data-disabled="isDisabled() ? '' : null"
|
|
118
|
+
class="stx-slider {{ className }}"
|
|
119
|
+
@if(width)style="--stx-slider-width: {{ width }}"@endif
|
|
120
|
+
>
|
|
121
|
+
@if(minIcon)
|
|
122
|
+
<i class="stx-slider-icon {{ minIcon }}" aria-hidden="true"></i>
|
|
123
|
+
@endif
|
|
124
|
+
<span class="stx-slider-body" style="--stx-slider-fraction: {{ fraction }}" :style="bodyStyle()">
|
|
125
|
+
<input
|
|
126
|
+
type="range"
|
|
127
|
+
class="stx-slider-input"
|
|
128
|
+
@if(name)name="{{ name }}"@endif
|
|
129
|
+
min="{{ min }}"
|
|
130
|
+
:min="range().min"
|
|
131
|
+
max="{{ max }}"
|
|
132
|
+
:max="range().max"
|
|
133
|
+
step="{{ step > 0 ? step : 'any' }}"
|
|
134
|
+
:step="range().step > 0 ? range().step : 'any'"
|
|
135
|
+
value="{{ value }}"
|
|
136
|
+
:value="current()"
|
|
137
|
+
@if(label)aria-label="{{ label }}"@endif
|
|
138
|
+
:aria-label="spoken() || null"
|
|
139
|
+
@if(disabled)disabled@endif
|
|
140
|
+
:disabled="isDisabled()"
|
|
141
|
+
@input="onInput($event)"
|
|
142
|
+
@change="onChange($event)"
|
|
143
|
+
@keydown="onKey($event)"
|
|
144
|
+
/>
|
|
145
|
+
<span class="stx-slider-track" aria-hidden="true"><span class="stx-slider-fill"></span></span>
|
|
146
|
+
<span class="stx-slider-ticks" aria-hidden="true"><span :for="tick in tickMarks()" class="stx-slider-tick" :style="tickStyle(tick)"></span></span>
|
|
147
|
+
<span class="stx-slider-knob" aria-hidden="true"></span>
|
|
148
|
+
</span>
|
|
149
|
+
@if(maxIcon)
|
|
150
|
+
<i class="stx-slider-icon {{ maxIcon }}" aria-hidden="true"></i>
|
|
151
|
+
@endif
|
|
152
|
+
</div>
|
|
153
|
+
|
|
154
|
+
<style data-native-exclude>
|
|
155
|
+
:where(:root) {
|
|
156
|
+
--stx-mac-font: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI Variable Text', 'Segoe UI', system-ui, Roboto, 'Helvetica Neue', sans-serif;
|
|
157
|
+
--stx-mac-font-size: 13px;
|
|
158
|
+
--stx-mac-font-size-small: 11px;
|
|
159
|
+
--stx-mac-hairline: 0.5px;
|
|
160
|
+
--stx-mac-focus-ring: 0 0 0 3px color-mix(in srgb, var(--stx-mac-accent) 35%, transparent);
|
|
161
|
+
--stx-mac-card-radius: 12px;
|
|
162
|
+
--stx-mac-control-radius: 6px;
|
|
163
|
+
--stx-mac-row-height: 38px;
|
|
164
|
+
--stx-mac-row-inset: 10px;
|
|
165
|
+
--stx-mac-sidebar-width: 226px;
|
|
166
|
+
--stx-mac-accent: var(--stx-accent, rgb(0, 122, 255));
|
|
167
|
+
--stx-mac-accent-ink: #ffffff;
|
|
168
|
+
--stx-mac-ink: rgba(0, 0, 0, 0.85);
|
|
169
|
+
--stx-mac-ink-secondary: rgba(0, 0, 0, 0.5);
|
|
170
|
+
--stx-mac-ink-tertiary: rgba(0, 0, 0, 0.26);
|
|
171
|
+
--stx-mac-window: #ffffff;
|
|
172
|
+
--stx-mac-sidebar: #f2f1f0;
|
|
173
|
+
--stx-mac-card: rgba(0, 0, 0, 0.04);
|
|
174
|
+
--stx-mac-separator: rgba(0, 0, 0, 0.1);
|
|
175
|
+
--stx-mac-hover: rgba(0, 0, 0, 0.05);
|
|
176
|
+
--stx-mac-selection-inactive: rgba(0, 0, 0, 0.08);
|
|
177
|
+
--stx-mac-well: rgba(0, 0, 0, 0.07);
|
|
178
|
+
--stx-mac-control: #ffffff;
|
|
179
|
+
--stx-mac-control-line: rgba(0, 0, 0, 0.12);
|
|
180
|
+
--stx-mac-control-shadow: 0 0.5px 1.5px rgba(0, 0, 0, 0.14), 0 0 0 0.5px rgba(0, 0, 0, 0.08);
|
|
181
|
+
--stx-mac-switch-on: #34c759;
|
|
182
|
+
--stx-mac-knob: #ffffff;
|
|
183
|
+
--stx-mac-danger: #ff3b30;
|
|
184
|
+
}
|
|
185
|
+
:where(.dark) {
|
|
186
|
+
--stx-mac-accent: var(--stx-accent, #0a84ff);
|
|
187
|
+
--stx-mac-accent-ink: #ffffff;
|
|
188
|
+
--stx-mac-ink: rgba(255, 255, 255, 0.85);
|
|
189
|
+
--stx-mac-ink-secondary: rgba(255, 255, 255, 0.55);
|
|
190
|
+
--stx-mac-ink-tertiary: rgba(255, 255, 255, 0.25);
|
|
191
|
+
--stx-mac-window: #1e1e1e;
|
|
192
|
+
--stx-mac-sidebar: #2a2a2a;
|
|
193
|
+
--stx-mac-card: rgba(255, 255, 255, 0.05);
|
|
194
|
+
--stx-mac-separator: rgba(255, 255, 255, 0.1);
|
|
195
|
+
--stx-mac-hover: rgba(255, 255, 255, 0.06);
|
|
196
|
+
--stx-mac-selection-inactive: rgba(255, 255, 255, 0.1);
|
|
197
|
+
--stx-mac-well: rgba(255, 255, 255, 0.1);
|
|
198
|
+
--stx-mac-control: rgba(255, 255, 255, 0.14);
|
|
199
|
+
--stx-mac-control-line: rgba(255, 255, 255, 0.06);
|
|
200
|
+
--stx-mac-control-shadow: 0 0.5px 1.5px rgba(0, 0, 0, 0.4), inset 0 0.5px 0 rgba(255, 255, 255, 0.12);
|
|
201
|
+
--stx-mac-switch-on: #30d158;
|
|
202
|
+
--stx-mac-knob: #ffffff;
|
|
203
|
+
--stx-mac-danger: #ff453a;
|
|
204
|
+
}
|
|
205
|
+
@media (max-resolution: 1.5dppx) {
|
|
206
|
+
:where(:root) {
|
|
207
|
+
--stx-mac-hairline: 1px;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
@media (prefers-contrast: more) {
|
|
211
|
+
:where(:root) {
|
|
212
|
+
--stx-mac-separator: rgba(0, 0, 0, 0.4);
|
|
213
|
+
--stx-mac-control-line: rgba(0, 0, 0, 0.5);
|
|
214
|
+
--stx-mac-ink-secondary: rgba(0, 0, 0, 0.75);
|
|
215
|
+
--stx-mac-hairline: 1px;
|
|
216
|
+
}
|
|
217
|
+
:where(.dark) {
|
|
218
|
+
--stx-mac-separator: rgba(255, 255, 255, 0.45);
|
|
219
|
+
--stx-mac-control-line: rgba(255, 255, 255, 0.5);
|
|
220
|
+
--stx-mac-ink-secondary: rgba(255, 255, 255, 0.8);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
:where([data-stx-slider]) {
|
|
225
|
+
--stx-slider-track-height: 4px;
|
|
226
|
+
--stx-slider-knob-width: 20px;
|
|
227
|
+
--stx-slider-knob-height: 16px;
|
|
228
|
+
--stx-slider-track: var(--stx-mac-well);
|
|
229
|
+
--stx-slider-fill: var(--stx-mac-ink-tertiary);
|
|
230
|
+
--stx-slider-tick: var(--stx-mac-ink-tertiary);
|
|
231
|
+
--stx-slider-tick-size: 2px;
|
|
232
|
+
--stx-slider-tick-offset: 6px;
|
|
233
|
+
--stx-slider-icon-size: 15px;
|
|
234
|
+
--stx-slider-knob-shadow: 0 0.5px 2.5px rgba(0, 0, 0, 0.28), 0 0 0 0.5px rgba(0, 0, 0, 0.1);
|
|
235
|
+
display: inline-flex;
|
|
236
|
+
flex-direction: row;
|
|
237
|
+
align-items: center;
|
|
238
|
+
gap: 8px;
|
|
239
|
+
box-sizing: border-box;
|
|
240
|
+
width: var(--stx-slider-width, 100%);
|
|
241
|
+
max-width: 100%;
|
|
242
|
+
min-width: 0;
|
|
243
|
+
font-family: var(--stx-mac-font);
|
|
244
|
+
color: var(--stx-mac-ink-secondary);
|
|
245
|
+
cursor: default;
|
|
246
|
+
-webkit-user-select: none;
|
|
247
|
+
user-select: none;
|
|
248
|
+
}
|
|
249
|
+
:where([data-stx-slider][data-tint="accent"]) { --stx-slider-fill: var(--stx-mac-accent); }
|
|
250
|
+
:where(.dark) :where([data-stx-slider]) { --stx-slider-knob-shadow: 0 0.5px 2.5px rgba(0, 0, 0, 0.5), 0 0 0 0.5px rgba(0, 0, 0, 0.3); }
|
|
251
|
+
|
|
252
|
+
/* A window that is not the key window draws no accent. */
|
|
253
|
+
:where([data-stx-window-active="false"]) :where([data-stx-slider][data-tint="accent"]),
|
|
254
|
+
:root[data-craft-window-active='false'] :where([data-stx-slider][data-tint="accent"]) {
|
|
255
|
+
--stx-slider-fill: var(--stx-mac-ink-tertiary);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
:where([data-stx-slider]) > .stx-slider-icon {
|
|
259
|
+
display: block;
|
|
260
|
+
flex: 0 0 auto;
|
|
261
|
+
width: var(--stx-slider-icon-size);
|
|
262
|
+
height: var(--stx-slider-icon-size);
|
|
263
|
+
font-size: var(--stx-slider-icon-size);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
:where([data-stx-slider]) > .stx-slider-body {
|
|
267
|
+
position: relative;
|
|
268
|
+
display: block;
|
|
269
|
+
flex: 1 1 auto;
|
|
270
|
+
min-width: 48px;
|
|
271
|
+
height: var(--stx-slider-knob-height);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/*
|
|
275
|
+
* The browser's slider, over everything and invisible. Its thumb is given
|
|
276
|
+
* the knob's width, so a place on it and a place on the drawing agree.
|
|
277
|
+
*/
|
|
278
|
+
:where([data-stx-slider]) .stx-slider-input {
|
|
279
|
+
position: absolute;
|
|
280
|
+
z-index: 2;
|
|
281
|
+
inset: 0;
|
|
282
|
+
box-sizing: border-box;
|
|
283
|
+
width: 100%;
|
|
284
|
+
height: 100%;
|
|
285
|
+
margin: 0;
|
|
286
|
+
padding: 0;
|
|
287
|
+
border: 0;
|
|
288
|
+
background: transparent;
|
|
289
|
+
opacity: 0;
|
|
290
|
+
cursor: default;
|
|
291
|
+
-webkit-appearance: none;
|
|
292
|
+
appearance: none;
|
|
293
|
+
}
|
|
294
|
+
[data-stx-slider] .stx-slider-input::-webkit-slider-runnable-track { height: 100%; background: transparent; }
|
|
295
|
+
[data-stx-slider] .stx-slider-input::-webkit-slider-thumb {
|
|
296
|
+
width: var(--stx-slider-knob-width);
|
|
297
|
+
height: var(--stx-slider-knob-height);
|
|
298
|
+
-webkit-appearance: none;
|
|
299
|
+
appearance: none;
|
|
300
|
+
}
|
|
301
|
+
[data-stx-slider] .stx-slider-input::-moz-range-thumb {
|
|
302
|
+
width: var(--stx-slider-knob-width);
|
|
303
|
+
height: var(--stx-slider-knob-height);
|
|
304
|
+
border: 0;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
:where([data-stx-slider]) .stx-slider-track {
|
|
308
|
+
position: absolute;
|
|
309
|
+
top: calc(50% - var(--stx-slider-track-height) / 2);
|
|
310
|
+
left: 0;
|
|
311
|
+
right: 0;
|
|
312
|
+
overflow: hidden;
|
|
313
|
+
height: var(--stx-slider-track-height);
|
|
314
|
+
border-radius: calc(var(--stx-slider-track-height) / 2);
|
|
315
|
+
background: var(--stx-slider-track);
|
|
316
|
+
}
|
|
317
|
+
:where([data-stx-slider]) .stx-slider-fill {
|
|
318
|
+
position: absolute;
|
|
319
|
+
top: 0;
|
|
320
|
+
bottom: 0;
|
|
321
|
+
left: 0;
|
|
322
|
+
width: calc(var(--stx-slider-knob-width) / 2 + var(--stx-slider-fraction, 0) * (100% - var(--stx-slider-knob-width)));
|
|
323
|
+
background: var(--stx-slider-fill);
|
|
324
|
+
transition: background-color 150ms ease;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
/* The marks, under the track, where the middle of the knob stops. */
|
|
328
|
+
:where([data-stx-slider]) .stx-slider-ticks {
|
|
329
|
+
position: absolute;
|
|
330
|
+
top: calc(50% + var(--stx-slider-tick-offset));
|
|
331
|
+
left: 0;
|
|
332
|
+
right: 0;
|
|
333
|
+
height: var(--stx-slider-tick-size);
|
|
334
|
+
}
|
|
335
|
+
:where([data-stx-slider]) .stx-slider-tick {
|
|
336
|
+
position: absolute;
|
|
337
|
+
top: 0;
|
|
338
|
+
width: var(--stx-slider-tick-size);
|
|
339
|
+
height: var(--stx-slider-tick-size);
|
|
340
|
+
margin-left: calc(var(--stx-slider-tick-size) / -2);
|
|
341
|
+
border-radius: 50%;
|
|
342
|
+
background: var(--stx-slider-tick);
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
:where([data-stx-slider]) .stx-slider-knob {
|
|
346
|
+
position: absolute;
|
|
347
|
+
z-index: 1;
|
|
348
|
+
top: 0;
|
|
349
|
+
left: calc(var(--stx-slider-fraction, 0) * (100% - var(--stx-slider-knob-width)));
|
|
350
|
+
box-sizing: border-box;
|
|
351
|
+
width: var(--stx-slider-knob-width);
|
|
352
|
+
height: var(--stx-slider-knob-height);
|
|
353
|
+
border-radius: calc(var(--stx-slider-knob-height) / 2);
|
|
354
|
+
background: var(--stx-mac-knob);
|
|
355
|
+
box-shadow: var(--stx-slider-knob-shadow);
|
|
356
|
+
transition: background-color 150ms ease, box-shadow 150ms ease;
|
|
357
|
+
}
|
|
358
|
+
:where([data-stx-slider]) .stx-slider-input:active ~ .stx-slider-knob { background: color-mix(in srgb, var(--stx-mac-knob) 92%, #000000); }
|
|
359
|
+
:where([data-stx-slider]) .stx-slider-input:focus-visible ~ .stx-slider-knob { box-shadow: var(--stx-slider-knob-shadow), var(--stx-mac-focus-ring); }
|
|
360
|
+
|
|
361
|
+
:where([data-stx-slider][data-disabled]) { opacity: 0.45; }
|
|
362
|
+
:where([data-stx-slider][data-disabled]) .stx-slider-input { pointer-events: none; }
|
|
363
|
+
|
|
364
|
+
@media (prefers-reduced-motion: reduce) {
|
|
365
|
+
:where([data-stx-slider]) :is(.stx-slider-fill, .stx-slider-knob) { transition: none; }
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
@media (prefers-contrast: more) {
|
|
369
|
+
:where([data-stx-slider]) {
|
|
370
|
+
--stx-slider-track: var(--stx-mac-ink-tertiary);
|
|
371
|
+
--stx-slider-fill: var(--stx-mac-ink);
|
|
372
|
+
--stx-slider-tick: var(--stx-mac-ink-secondary);
|
|
373
|
+
--stx-slider-knob-shadow: 0 0 0 1px var(--stx-mac-ink);
|
|
374
|
+
}
|
|
375
|
+
:where([data-stx-slider][data-tint="accent"]) { --stx-slider-fill: var(--stx-mac-accent); }
|
|
376
|
+
}
|
|
377
|
+
</style>
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The arithmetic of a slider: where a value sits on the track, which values
|
|
3
|
+
* a step allows, and where the tick marks go. No DOM.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export interface SliderRange {
|
|
7
|
+
min: number
|
|
8
|
+
max: number
|
|
9
|
+
/** The distance between two values the slider can hold. Zero or less means any value. */
|
|
10
|
+
step: number
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** The most tick marks worth drawing. Past this they are a smear, not marks. */
|
|
14
|
+
export const SLIDER_MAX_TICKS = 101
|
|
15
|
+
|
|
16
|
+
function finite(value: unknown, fallback: number): number {
|
|
17
|
+
const number = typeof value === 'number' ? value : Number.parseFloat(String(value))
|
|
18
|
+
return Number.isFinite(number) ? number : fallback
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** A usable range from whatever was passed: numbers, text, the bounds the wrong way round. */
|
|
22
|
+
export function sliderRange(min?: unknown, max?: unknown, step?: unknown): SliderRange {
|
|
23
|
+
const low = finite(min, 0)
|
|
24
|
+
const high = finite(max, 100)
|
|
25
|
+
const size = finite(step, 1)
|
|
26
|
+
return {
|
|
27
|
+
min: Math.min(low, high),
|
|
28
|
+
max: Math.max(low, high),
|
|
29
|
+
step: size > 0 ? size : 0,
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** How many decimal places a number is written with: 0.25 has two. */
|
|
34
|
+
export function sliderDecimals(value: number): number {
|
|
35
|
+
if (!Number.isFinite(value))
|
|
36
|
+
return 0
|
|
37
|
+
const text = String(value).toLowerCase()
|
|
38
|
+
const exponent = text.indexOf('e-')
|
|
39
|
+
if (exponent !== -1)
|
|
40
|
+
return Number.parseInt(text.slice(exponent + 2), 10) + Math.max(0, text.slice(0, exponent).split('.')[1]?.length ?? 0)
|
|
41
|
+
return text.split('.')[1]?.length ?? 0
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* The value the slider holds for a value it was given: inside the range and
|
|
46
|
+
* on a step counted from the minimum. A maximum that is not on a step cannot
|
|
47
|
+
* be reached, as with the browser's own range input.
|
|
48
|
+
*/
|
|
49
|
+
export function sliderSnap(value: unknown, range: SliderRange): number {
|
|
50
|
+
const { min, max, step } = range
|
|
51
|
+
const wanted = Math.min(max, Math.max(min, finite(value, min)))
|
|
52
|
+
if (step <= 0)
|
|
53
|
+
return wanted
|
|
54
|
+
|
|
55
|
+
let steps = Math.round((wanted - min) / step)
|
|
56
|
+
// Half a step short of the count is rounding noise, not a step too far.
|
|
57
|
+
const limit = Math.floor((max - min) / step + 0.0000001)
|
|
58
|
+
if (steps > limit)
|
|
59
|
+
steps = limit
|
|
60
|
+
const places = Math.max(sliderDecimals(step), sliderDecimals(min))
|
|
61
|
+
return Number((min + steps * step).toFixed(Math.min(places, 20)))
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** Where a value sits on the track, from 0 at the minimum to 1 at the maximum. */
|
|
65
|
+
export function sliderFraction(value: unknown, range: SliderRange): number {
|
|
66
|
+
const span = range.max - range.min
|
|
67
|
+
if (span <= 0)
|
|
68
|
+
return 0
|
|
69
|
+
const held = Math.min(range.max, Math.max(range.min, finite(value, range.min)))
|
|
70
|
+
return (held - range.min) / span
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** The value at a place on the track, snapped. */
|
|
74
|
+
export function sliderValueAt(fraction: number, range: SliderRange): number {
|
|
75
|
+
const place = Math.min(1, Math.max(0, Number.isFinite(fraction) ? fraction : 0))
|
|
76
|
+
return sliderSnap(range.min + place * (range.max - range.min), range)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Where the tick marks go, as fractions of the track. A number is that many
|
|
81
|
+
* marks spread evenly, ends included; `true` is one for each step. Nothing
|
|
82
|
+
* for fewer than two marks, or for more than can be told apart.
|
|
83
|
+
*/
|
|
84
|
+
export function sliderTicks(ticks: unknown, range: SliderRange): number[] {
|
|
85
|
+
const span = range.max - range.min
|
|
86
|
+
if (span <= 0 || ticks === false || ticks == null || ticks === '' || ticks === 'false')
|
|
87
|
+
return []
|
|
88
|
+
|
|
89
|
+
if (ticks === true || ticks === 'true') {
|
|
90
|
+
if (range.step <= 0)
|
|
91
|
+
return []
|
|
92
|
+
const count = Math.floor(span / range.step + 0.0000001) + 1
|
|
93
|
+
if (count < 2 || count > SLIDER_MAX_TICKS)
|
|
94
|
+
return []
|
|
95
|
+
return Array.from({ length: count }, (_, index) => Math.min(1, (index * range.step) / span))
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const count = Math.floor(finite(ticks, 0))
|
|
99
|
+
if (count < 2 || count > SLIDER_MAX_TICKS)
|
|
100
|
+
return []
|
|
101
|
+
return Array.from({ length: count }, (_, index) => index / (count - 1))
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** The value a key moves to, or null for a key the slider does not own. */
|
|
105
|
+
export function sliderKeyValue(key: string, value: number, range: SliderRange, page = 10): number | null {
|
|
106
|
+
const step = range.step > 0 ? range.step : (range.max - range.min) / 100
|
|
107
|
+
if (key === 'ArrowRight' || key === 'ArrowUp')
|
|
108
|
+
return sliderSnap(value + step, range)
|
|
109
|
+
if (key === 'ArrowLeft' || key === 'ArrowDown')
|
|
110
|
+
return sliderSnap(value - step, range)
|
|
111
|
+
if (key === 'PageUp')
|
|
112
|
+
return sliderSnap(value + step * page, range)
|
|
113
|
+
if (key === 'PageDown')
|
|
114
|
+
return sliderSnap(value - step * page, range)
|
|
115
|
+
if (key === 'Home')
|
|
116
|
+
return sliderSnap(range.min, range)
|
|
117
|
+
if (key === 'End')
|
|
118
|
+
return sliderSnap(range.max, range)
|
|
119
|
+
return null
|
|
120
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export * from './core'
|
|
2
|
+
export { default as Slider } from './Slider.stx'
|
|
3
|
+
|
|
4
|
+
export interface SliderProps {
|
|
5
|
+
/** The value. `v-model:value` follows the knob as it moves. */
|
|
6
|
+
value?: number
|
|
7
|
+
/** Default 0. */
|
|
8
|
+
min?: number
|
|
9
|
+
/** Default 100. */
|
|
10
|
+
max?: number
|
|
11
|
+
/** The distance between two values it can hold. Default 1; 0 for any value. */
|
|
12
|
+
step?: number
|
|
13
|
+
/** Tick marks under the track: a count spread evenly, or `true` for one a step. */
|
|
14
|
+
ticks?: number | boolean
|
|
15
|
+
disabled?: boolean
|
|
16
|
+
/** The accessible name. Left out inside a `<SettingsRow>`, the row's label names it. */
|
|
17
|
+
label?: string
|
|
18
|
+
/** An Iconify class drawn at the low end. */
|
|
19
|
+
minIcon?: string
|
|
20
|
+
/** An Iconify class drawn at the high end. */
|
|
21
|
+
maxIcon?: string
|
|
22
|
+
/** What the filled part is drawn with. Default `neutral`. */
|
|
23
|
+
tint?: 'accent' | 'neutral'
|
|
24
|
+
/** A CSS length. Default as wide as it is allowed to be, or 220px in a settings row. */
|
|
25
|
+
width?: string
|
|
26
|
+
/** Submits the value in a form under this name. */
|
|
27
|
+
name?: string
|
|
28
|
+
id?: string
|
|
29
|
+
className?: string
|
|
30
|
+
/** While it moves. */
|
|
31
|
+
onInput?: (value: number) => void
|
|
32
|
+
/** When it is let go, or a key moved it. */
|
|
33
|
+
onChange?: (value: number) => void
|
|
34
|
+
}
|
package/src/ui/switch/README.md
CHANGED
|
@@ -112,3 +112,14 @@ Example:
|
|
|
112
112
|
```stx
|
|
113
113
|
<Switch checked className="!bg-green-500" />
|
|
114
114
|
```
|
|
115
|
+
|
|
116
|
+
## Mac look
|
|
117
|
+
|
|
118
|
+
`variant="mac"` draws the switch System Settings draws: a 36x20 capsule with a 22x16 pill for a knob, green when on (`--stx-mac-switch-on`, never the accent). `size="mini"` is the 26x15 one. Everything else is the same switch: `checked`, `v-model:checked`, `@change`, `name` and the hidden input, `disabled`, `label`.
|
|
119
|
+
|
|
120
|
+
```html
|
|
121
|
+
<Switch variant="mac" v-model:checked="tint" name="tint" />
|
|
122
|
+
<Switch variant="mac" size="mini" checked />
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
Colours and type come from the `--stx-mac-*` custom properties (`src/utils/mac-theme.ts`), light and dark, so an app re-themes it by setting a variable. A window that is not the key window (`data-stx-window-active="false"` on an ancestor, or Craft's `data-craft-window-active`) draws it without colour. The knob's shadow is `--stx-mac-switch-knob-shadow` and the inactive fill `--stx-mac-switch-inactive`.
|