gooee 0.48.0 → 0.51.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/package.json +4 -2
- package/scripts/add.js +28 -6
- package/src/components/Accordion/Accordion.vue +62 -0
- package/src/components/Accordion/AccordionItem.vue +45 -0
- package/src/components/Accordion/accordionContext.ts +6 -0
- package/src/components/Alert/Alert.tsx +7 -27
- package/src/components/Alert/Alert.vue +59 -0
- package/src/components/AlertDialog/AlertDialog.vue +126 -0
- package/src/components/AnimatedNumber/AnimatedNumber.vue +36 -0
- package/src/components/AspectRatio/AspectRatio.vue +17 -0
- package/src/components/Avatar/Avatar.vue +56 -0
- package/src/components/AvatarGroup/AvatarGroup.vue +42 -0
- package/src/components/Badge/Badge.vue +32 -0
- package/src/components/Breadcrumb/Breadcrumb.vue +58 -0
- package/src/components/Button/Button.vue +130 -0
- package/src/components/ButtonGroup/ButtonGroup.tsx +4 -21
- package/src/components/ButtonGroup/ButtonGroup.vue +33 -0
- package/src/components/Card/Card.vue +34 -0
- package/src/components/Center/Center.vue +32 -0
- package/src/components/Checkbox/Checkbox.tsx +8 -25
- package/src/components/Checkbox/Checkbox.vue +108 -0
- package/src/components/CheckboxGroup/CheckboxGroup.vue +76 -0
- package/src/components/Cluster/Cluster.vue +34 -0
- package/src/components/CodeBlock/CodeBlock.vue +45 -0
- package/src/components/Collapsible/Collapsible.vue +59 -0
- package/src/components/Container/Container.vue +22 -0
- package/src/components/CopyButton/CopyButton.tsx +3 -49
- package/src/components/CopyButton/CopyButton.vue +116 -0
- package/src/components/Dial/Dial.tsx +12 -120
- package/src/components/Dial/Dial.vue +228 -0
- package/src/components/Dialog/Dialog.vue +139 -0
- package/src/components/Divider/Divider.vue +27 -0
- package/src/components/DropdownMenu/DropdownMenu.tsx +11 -46
- package/src/components/DropdownMenu/DropdownMenu.vue +185 -0
- package/src/components/EmptyState/EmptyState.vue +33 -0
- package/src/components/Fab/Fab.tsx +4 -14
- package/src/components/Fab/Fab.vue +115 -0
- package/src/components/Fieldset/Fieldset.vue +42 -0
- package/src/components/FormField/FormField.tsx +2 -17
- package/src/components/FormField/FormField.vue +64 -0
- package/src/components/Grid/Grid.vue +43 -0
- package/src/components/HoldToConfirm/HoldToConfirm.tsx +13 -142
- package/src/components/HoldToConfirm/HoldToConfirm.vue +281 -0
- package/src/components/IconButton/IconButton.vue +25 -0
- package/src/components/Input/Input.vue +112 -0
- package/src/components/InputGroup/InputGroup.vue +102 -0
- package/src/components/Kbd/Kbd.tsx +2 -12
- package/src/components/Kbd/Kbd.vue +21 -0
- package/src/components/Link/Link.vue +38 -0
- package/src/components/LivePill/LivePill.tsx +12 -40
- package/src/components/LivePill/LivePill.vue +152 -0
- package/src/components/Meter/Meter.vue +88 -0
- package/src/components/MorphButton/MorphButton.tsx +11 -67
- package/src/components/MorphButton/MorphButton.vue +120 -0
- package/src/components/NumberInput/NumberInput.tsx +11 -48
- package/src/components/NumberInput/NumberInput.vue +184 -0
- package/src/components/Pagination/Pagination.tsx +2 -15
- package/src/components/Pagination/Pagination.vue +87 -0
- package/src/components/Pagination/range.ts +15 -0
- package/src/components/PasswordInput/PasswordInput.vue +53 -0
- package/src/components/PickerWheel/DateWheel.vue +48 -0
- package/src/components/PickerWheel/PickerWheel.tsx +15 -129
- package/src/components/PickerWheel/PickerWheel.vue +77 -0
- package/src/components/PickerWheel/TimeWheel.vue +50 -0
- package/src/components/PickerWheel/WheelColumn.vue +70 -0
- package/src/components/Popover/Popover.vue +108 -0
- package/src/components/ProgressBar/ProgressBar.vue +48 -0
- package/src/components/Prose/Prose.vue +18 -0
- package/src/components/Radio/Radio.vue +49 -0
- package/src/components/Radio/RadioGroup.vue +69 -0
- package/src/components/Retime/Retime.tsx +7 -40
- package/src/components/Retime/Retime.vue +64 -0
- package/src/components/RulerScrubber/RulerScrubber.tsx +9 -38
- package/src/components/RulerScrubber/RulerScrubber.vue +166 -0
- package/src/components/ScrollArea/ScrollArea.tsx +17 -129
- package/src/components/ScrollArea/ScrollArea.vue +58 -0
- package/src/components/SearchInput/SearchInput.tsx +2 -15
- package/src/components/SearchInput/SearchInput.vue +70 -0
- package/src/components/SegmentedControl/SegmentedControl.tsx +7 -51
- package/src/components/SegmentedControl/SegmentedControl.vue +111 -0
- package/src/components/Select/Select.tsx +16 -47
- package/src/components/Select/Select.vue +236 -0
- package/src/components/Sheet/Sheet.tsx +52 -231
- package/src/components/Sheet/Sheet.vue +249 -0
- package/src/components/Skeleton/Skeleton.vue +38 -0
- package/src/components/Slider/Slider.tsx +25 -84
- package/src/components/Slider/Slider.vue +113 -0
- package/src/components/Spinner/Spinner.vue +30 -0
- package/src/components/Split/Split.vue +34 -0
- package/src/components/SplitFlap/SplitFlap.tsx +11 -175
- package/src/components/SplitFlap/SplitFlap.vue +52 -0
- package/src/components/Stack/Stack.vue +22 -0
- package/src/components/SwipeDeck/SwipeDeck.tsx +30 -194
- package/src/components/SwipeDeck/SwipeDeck.vue +168 -0
- package/src/components/Switch/Switch.tsx +6 -75
- package/src/components/Switch/Switch.vue +66 -0
- package/src/components/Table/Table.module.css +12 -3
- package/src/components/Table/Table.tsx +8 -59
- package/src/components/Table/Table.vue +274 -0
- package/src/components/TableOfContents/TableOfContents.vue +90 -0
- package/src/components/Tabs/Tab.vue +37 -0
- package/src/components/Tabs/TabList.vue +47 -0
- package/src/components/Tabs/TabPanel.vue +26 -0
- package/src/components/Tabs/Tabs.module.css +2 -2
- package/src/components/Tabs/Tabs.tsx +11 -84
- package/src/components/Tabs/Tabs.vue +33 -0
- package/src/components/Tabs/tabsContext.ts +15 -0
- package/src/components/Tag/Tag.tsx +6 -26
- package/src/components/Tag/Tag.vue +63 -0
- package/src/components/Textarea/Textarea.tsx +2 -22
- package/src/components/Textarea/Textarea.vue +120 -0
- package/src/components/ThemeToggle/ThemeToggle.tsx +10 -84
- package/src/components/ThemeToggle/ThemeToggle.vue +90 -0
- package/src/components/Toast/Toast.tsx +34 -264
- package/src/components/Toast/Toast.vue +138 -0
- package/src/components/Toast/ToastItem.vue +108 -0
- package/src/components/Toggle/Toggle.vue +52 -0
- package/src/components/Tooltip/Tooltip.tsx +17 -48
- package/src/components/Tooltip/Tooltip.vue +95 -0
- package/src/components/VisuallyHidden/VisuallyHidden.vue +17 -0
- package/src/internal/FieldMessage.vue +41 -0
- package/src/internal/Roll.vue +20 -0
- package/src/internal/fling.ts +29 -106
- package/src/internal/focus.ts +4 -79
- package/src/internal/icons.module.css +39 -27
- package/src/internal/layers.ts +7 -61
- package/src/internal/liquid.ts +26 -213
- package/src/internal/liquidMatter.ts +9 -181
- package/src/internal/liquidMore.ts +6 -669
- package/src/internal/motion/alert.ts +17 -0
- package/src/internal/motion/buttonGroup.ts +21 -0
- package/src/internal/motion/checkbox.ts +39 -0
- package/src/internal/motion/collapseOut.ts +26 -0
- package/src/internal/motion/copyButton.ts +48 -0
- package/src/internal/motion/dial.ts +137 -0
- package/src/internal/motion/fab.ts +14 -0
- package/src/internal/motion/fling.ts +147 -0
- package/src/internal/motion/floating.ts +58 -0
- package/src/internal/motion/focus.ts +88 -0
- package/src/internal/motion/formField.ts +19 -0
- package/src/internal/motion/holdToConfirm.ts +147 -0
- package/src/internal/motion/index.ts +20 -0
- package/src/internal/motion/keys.ts +42 -0
- package/src/internal/motion/layers.ts +78 -0
- package/src/internal/motion/liquid.ts +241 -0
- package/src/internal/motion/liquidMatter.ts +198 -0
- package/src/internal/motion/liquidMore.ts +676 -0
- package/src/internal/motion/listbox.ts +69 -0
- package/src/internal/motion/livePill.ts +71 -0
- package/src/internal/motion/menuKeys.ts +58 -0
- package/src/internal/motion/morphButton.ts +71 -0
- package/src/internal/motion/numberInput.ts +57 -0
- package/src/internal/motion/pickerWheel.ts +166 -0
- package/src/internal/motion/retime.ts +45 -0
- package/src/internal/motion/ruler.ts +57 -0
- package/src/internal/motion/scrollArea.ts +133 -0
- package/src/internal/motion/scrollFrame.ts +152 -0
- package/src/internal/motion/scrubLook.ts +15 -0
- package/src/internal/motion/scrubber.ts +154 -0
- package/src/internal/motion/segmented.ts +63 -0
- package/src/internal/motion/sheetDetents.ts +271 -0
- package/src/internal/motion/slider.ts +108 -0
- package/src/internal/motion/softPress.ts +334 -0
- package/src/internal/motion/splitFlap.ts +205 -0
- package/src/internal/motion/swipeDeck.ts +236 -0
- package/src/internal/motion/switchThumb.ts +83 -0
- package/src/internal/motion/table.ts +77 -0
- package/src/internal/motion/tabs.ts +105 -0
- package/src/internal/motion/textarea.ts +22 -0
- package/src/internal/motion/themeIcon.ts +91 -0
- package/src/internal/motion/themeReveal.ts +71 -0
- package/src/internal/motion/toast.ts +291 -0
- package/src/internal/motion/tooltip.ts +58 -0
- package/src/internal/scrollFrame.ts +4 -145
- package/src/internal/softPress.ts +27 -289
- package/src/internal/themeReveal.ts +3 -61
- package/src/internal/useFloating.ts +9 -49
- package/src/internal/useScrub.ts +15 -120
- package/src/internal/vue/trigger.ts +18 -0
- package/src/internal/vue/useFloating.ts +38 -0
- package/src/internal/vue/usePresence.ts +21 -0
- package/src/internal/vue/useScrub.ts +40 -0
- package/src/internal/vueIcons.ts +134 -0
- package/src/tokens.css +5 -0
- package/src/internal/relativeTime.ts +0 -26
|
@@ -2,8 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { useEffect, useId, useRef, useState, type ComponentPropsWithRef, type KeyboardEvent, type PointerEvent } from 'react'
|
|
4
4
|
import { cx } from '../../internal/cx'
|
|
5
|
-
import {
|
|
6
|
-
import { morphCurve, motionMs, prefersReducedMotion } from '../../internal/motion'
|
|
5
|
+
import { createSlider } from '../../internal/motion/slider'
|
|
7
6
|
import { useControllable } from '../../internal/useControllable'
|
|
8
7
|
import styles from './Slider.module.css'
|
|
9
8
|
|
|
@@ -57,65 +56,25 @@ export function Slider({
|
|
|
57
56
|
const [value, setValue] = useControllable(valueProp, defaultValue ?? min, onValueChange)
|
|
58
57
|
// Where the thumb is drawn while it glides to a click or settles on a mark; the value is set already.
|
|
59
58
|
const [shown, setShown] = useState<number | null>(null)
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
59
|
+
const latest = useRef({ value, min, max, step, marks })
|
|
60
|
+
latest.current = { value, min, max, step, marks }
|
|
61
|
+
const set = useRef(setValue)
|
|
62
|
+
set.current = setValue
|
|
63
|
+
// The glide, the grab and the landing on marks (motion/slider.ts).
|
|
64
|
+
const slider = useRef<ReturnType<typeof createSlider>>(null)
|
|
65
|
+
slider.current ??= createSlider(
|
|
66
|
+
() => latest.current,
|
|
67
|
+
(v) => {
|
|
68
|
+
latest.current = { ...latest.current, value: v }
|
|
69
|
+
set.current(v)
|
|
70
|
+
},
|
|
71
|
+
setShown,
|
|
72
|
+
)
|
|
65
73
|
const at = shown ?? value
|
|
66
74
|
const pct = max === min ? 0 : ((at - min) / (max - min)) * 100
|
|
67
75
|
const text = formatValue(value)
|
|
68
|
-
// A let-go within half of this (3% of the track) of a mark lands on it.
|
|
69
|
-
const reach = (max - min) * 0.06
|
|
70
|
-
const decimals = (String(step).split('.')[1] ?? '').length
|
|
71
|
-
const toStep = (v: number) => Math.min(max, Math.max(min, Number((Math.round((v - min) / step) * step + min).toFixed(decimals))))
|
|
72
|
-
|
|
73
|
-
useEffect(() => () => cancelAnimationFrame(glide.current), [])
|
|
74
|
-
|
|
75
|
-
// The thumb travels from where it is drawn to `to` on the morph curve. A click and a landing both use it.
|
|
76
|
-
function glideTo(from: number, to: number) {
|
|
77
|
-
cancelAnimationFrame(glide.current)
|
|
78
|
-
const ms = motionMs('morph-out')
|
|
79
|
-
if (!ms || from === to || prefersReducedMotion()) return setShown(null)
|
|
80
|
-
const ease = bezier(morphCurve())
|
|
81
|
-
const t0 = performance.now()
|
|
82
|
-
const tick = (now: number) => {
|
|
83
|
-
const p = Math.min(1, (now - t0) / ms)
|
|
84
|
-
setShown(p < 1 ? from + (to - from) * ease(p) : null)
|
|
85
|
-
if (p < 1) glide.current = requestAnimationFrame(tick)
|
|
86
|
-
}
|
|
87
|
-
glide.current = requestAnimationFrame(tick)
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// The value under the pointer, before any step, from the input's own geometry: the thumb's centre
|
|
91
|
-
// runs from half a thumb in at each end.
|
|
92
|
-
function track(input: HTMLInputElement) {
|
|
93
|
-
const r = input.getBoundingClientRect()
|
|
94
|
-
const thumb = parseFloat(getComputedStyle(input).getPropertyValue('--thumb')) || 0
|
|
95
|
-
return { left: r.left + thumb / 2, width: Math.max(1, r.width - thumb), thumb }
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
function fromPointer(input: HTMLInputElement, x: number) {
|
|
99
|
-
const t = track(input)
|
|
100
|
-
return min + Math.min(1, Math.max(0, (x - t.left) / t.width)) * (max - min)
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
function change(input: HTMLInputElement, native: number) {
|
|
104
|
-
const p = press.current
|
|
105
|
-
const next = p && marks?.length ? toStep(fromPointer(input, p.lastX - p.grab)) : native
|
|
106
|
-
// A press that has not moved is a click: the value jumps, the thumb glides there. Once it moves, the hand leads.
|
|
107
|
-
if (p && !p.moved) glideTo(at, next)
|
|
108
|
-
else if (shown !== null) {
|
|
109
|
-
cancelAnimationFrame(glide.current)
|
|
110
|
-
setShown(null)
|
|
111
|
-
}
|
|
112
|
-
latest.current = next
|
|
113
|
-
setValue(next)
|
|
114
|
-
}
|
|
115
76
|
|
|
116
|
-
|
|
117
|
-
press.current = null
|
|
118
|
-
}
|
|
77
|
+
useEffect(() => () => slider.current!.destroy(), [])
|
|
119
78
|
|
|
120
79
|
return (
|
|
121
80
|
<div className={cx(styles.root, className)} data-disabled={disabled || undefined}>
|
|
@@ -136,50 +95,32 @@ export function Slider({
|
|
|
136
95
|
aria-valuenow={value}
|
|
137
96
|
aria-valuetext={formatValue === String ? undefined : text}
|
|
138
97
|
// Only "input": the browser's "change" on release carries the thumb's mid-glide place, not the value.
|
|
139
|
-
onChange={(e) => e.nativeEvent.type === 'input' &&
|
|
98
|
+
onChange={(e) => e.nativeEvent.type === 'input' && slider.current!.input(e.currentTarget, Number(e.target.value))}
|
|
140
99
|
onPointerDown={(e: PointerEvent<HTMLInputElement>) => {
|
|
141
|
-
|
|
142
|
-
const centre = t.left + ((value - min) / (max - min || 1)) * t.width
|
|
143
|
-
const grab = marks?.length && Math.abs(e.clientX - centre) <= t.thumb / 2 ? e.clientX - centre : 0
|
|
144
|
-
press.current = { x: e.clientX, lastX: e.clientX, moved: false, grab }
|
|
100
|
+
slider.current!.down(e.currentTarget, e.clientX)
|
|
145
101
|
onPointerDown?.(e)
|
|
146
102
|
}}
|
|
147
103
|
onPointerMove={(e: PointerEvent<HTMLInputElement>) => {
|
|
148
|
-
|
|
149
|
-
if (p) {
|
|
150
|
-
p.lastX = e.clientX
|
|
151
|
-
if (Math.abs(e.clientX - p.x) > 3) p.moved = true
|
|
152
|
-
}
|
|
104
|
+
slider.current!.move(e.clientX)
|
|
153
105
|
onPointerMove?.(e)
|
|
154
106
|
}}
|
|
155
107
|
onPointerUp={(e: PointerEvent<HTMLInputElement>) => {
|
|
156
|
-
|
|
157
|
-
// Let go near a mark: it lands on the mark.
|
|
158
|
-
const now = latest.current
|
|
159
|
-
const mark = marks?.length ? nearestMark(now, marks) : null
|
|
160
|
-
if (mark !== null && mark !== now && Math.abs(mark - now) < reach / 2) {
|
|
161
|
-
glideTo(at, mark)
|
|
162
|
-
setValue(mark)
|
|
163
|
-
}
|
|
108
|
+
slider.current!.up()
|
|
164
109
|
onPointerUp?.(e)
|
|
165
110
|
}}
|
|
166
111
|
onPointerCancel={(e: PointerEvent<HTMLInputElement>) => {
|
|
167
|
-
|
|
112
|
+
slider.current!.end()
|
|
168
113
|
onPointerCancel?.(e)
|
|
169
114
|
}}
|
|
170
|
-
onLostPointerCapture={
|
|
115
|
+
onLostPointerCapture={slider.current.end}
|
|
171
116
|
onBlur={(e) => {
|
|
172
|
-
|
|
117
|
+
slider.current!.end()
|
|
173
118
|
onBlur?.(e)
|
|
174
119
|
}}
|
|
175
120
|
onKeyDown={(e: KeyboardEvent<HTMLInputElement>) => {
|
|
176
|
-
|
|
121
|
+
slider.current!.end()
|
|
177
122
|
onKeyDown?.(e)
|
|
178
|
-
if (e.defaultPrevented
|
|
179
|
-
const sorted = [...marks].sort((a, b) => a - b)
|
|
180
|
-
const next = e.key === 'PageUp' ? (sorted.find((m) => m > value) ?? max) : ([...sorted].reverse().find((m) => m < value) ?? min)
|
|
181
|
-
e.preventDefault()
|
|
182
|
-
setValue(next)
|
|
123
|
+
if (!e.defaultPrevented && slider.current!.key(e.key)) e.preventDefault()
|
|
183
124
|
}}
|
|
184
125
|
{...rest}
|
|
185
126
|
/>
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed, onBeforeUnmount, ref, useAttrs, useId } from 'vue'
|
|
3
|
+
import { createSlider } from '../../internal/motion/slider'
|
|
4
|
+
import styles from './Slider.module.css'
|
|
5
|
+
|
|
6
|
+
// The Vue Slider: the same look (Slider.module.css), glide and marks as the React one.
|
|
7
|
+
// Other attributes, such as name or a listener, go to the input. A class goes to the root, as in React.
|
|
8
|
+
defineOptions({ inheritAttrs: false })
|
|
9
|
+
|
|
10
|
+
const props = withDefaults(
|
|
11
|
+
defineProps<{
|
|
12
|
+
/** Visible name of the slider, also read by screen readers. */
|
|
13
|
+
label: string
|
|
14
|
+
/** Starting value when there is no v-model. Undefined starts at min. */
|
|
15
|
+
defaultValue?: number
|
|
16
|
+
/** Lowest value on the track. */
|
|
17
|
+
min?: number
|
|
18
|
+
/** Highest value on the track. */
|
|
19
|
+
max?: number
|
|
20
|
+
/** Size of each move, by drag or arrow key. */
|
|
21
|
+
step?: number
|
|
22
|
+
/** Shows the value next to the label and in a bubble while dragging. */
|
|
23
|
+
showValue?: boolean
|
|
24
|
+
/** Turns the number into the text shown and read by screen readers. */
|
|
25
|
+
formatValue?: (value: number) => string
|
|
26
|
+
/** Values the thumb is drawn to as it passes, shown as dots on the track. Let go near one and it lands on it; Page Up and Page Down jump between them. */
|
|
27
|
+
marks?: number[]
|
|
28
|
+
disabled?: boolean
|
|
29
|
+
id?: string
|
|
30
|
+
}>(),
|
|
31
|
+
{ min: 0, max: 100, step: 1, showValue: true, formatValue: String },
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
/** The value. Use v-model, or leave it out and the slider keeps its own value. */
|
|
35
|
+
const model = defineModel<number>()
|
|
36
|
+
const local = ref(props.defaultValue ?? props.min)
|
|
37
|
+
const value = computed({
|
|
38
|
+
get: () => model.value ?? local.value,
|
|
39
|
+
set: (next: number) => {
|
|
40
|
+
local.value = next
|
|
41
|
+
model.value = next
|
|
42
|
+
},
|
|
43
|
+
})
|
|
44
|
+
const attrs = useAttrs()
|
|
45
|
+
const inputAttrs = computed(() => {
|
|
46
|
+
const { class: _, ...rest } = attrs
|
|
47
|
+
return rest
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
const auto = useId()
|
|
51
|
+
const inputId = computed(() => props.id ?? auto)
|
|
52
|
+
// Where the thumb is drawn while it glides to a click or settles on a mark; the value is set already.
|
|
53
|
+
const shown = ref<number | null>(null)
|
|
54
|
+
const at = computed(() => shown.value ?? value.value)
|
|
55
|
+
const pct = computed(() => (props.max === props.min ? 0 : ((at.value - props.min) / (props.max - props.min)) * 100))
|
|
56
|
+
const text = computed(() => props.formatValue(value.value))
|
|
57
|
+
|
|
58
|
+
// The glide, the grab and the landing on marks (motion/slider.ts).
|
|
59
|
+
const slider = createSlider(
|
|
60
|
+
() => ({ value: value.value, min: props.min, max: props.max, step: props.step, marks: props.marks }),
|
|
61
|
+
(v) => (value.value = v),
|
|
62
|
+
(v) => (shown.value = v),
|
|
63
|
+
)
|
|
64
|
+
onBeforeUnmount(slider.destroy)
|
|
65
|
+
|
|
66
|
+
const onInput = (e: Event) => {
|
|
67
|
+
const input = e.target as HTMLInputElement
|
|
68
|
+
slider.input(input, Number(input.value))
|
|
69
|
+
// A v-model that holds its value keeps the thumb where it was.
|
|
70
|
+
input.value = String(at.value)
|
|
71
|
+
}
|
|
72
|
+
const onKeydown = (e: KeyboardEvent) => {
|
|
73
|
+
slider.end()
|
|
74
|
+
if (!e.defaultPrevented && slider.key(e.key)) e.preventDefault()
|
|
75
|
+
}
|
|
76
|
+
</script>
|
|
77
|
+
|
|
78
|
+
<template>
|
|
79
|
+
<div :class="[styles.root, attrs.class]" :data-disabled="disabled || undefined">
|
|
80
|
+
<div :class="styles.head">
|
|
81
|
+
<label :for="inputId" :class="styles.label">{{ label }}</label>
|
|
82
|
+
<output v-if="showValue" :for="inputId" :class="styles.value" aria-hidden="true">{{ text }}</output>
|
|
83
|
+
</div>
|
|
84
|
+
<div :class="styles.trackWrap" :data-gliding="shown !== null || undefined" :style="{ '--pct': `${pct}%`, '--p': pct / 100 }">
|
|
85
|
+
<input
|
|
86
|
+
v-bind="inputAttrs"
|
|
87
|
+
:id="inputId"
|
|
88
|
+
type="range"
|
|
89
|
+
:class="styles.input"
|
|
90
|
+
:min="min"
|
|
91
|
+
:max="max"
|
|
92
|
+
:step="shown === null ? step : 'any'"
|
|
93
|
+
:value="at"
|
|
94
|
+
:disabled="disabled"
|
|
95
|
+
:aria-valuenow="value"
|
|
96
|
+
:aria-valuetext="formatValue === String ? undefined : text"
|
|
97
|
+
@input="onInput"
|
|
98
|
+
@pointerdown="slider.down($event.currentTarget as HTMLInputElement, $event.clientX)"
|
|
99
|
+
@pointermove="slider.move($event.clientX)"
|
|
100
|
+
@pointerup="slider.up()"
|
|
101
|
+
@pointercancel="slider.end()"
|
|
102
|
+
@lostpointercapture="slider.end()"
|
|
103
|
+
@blur="slider.end()"
|
|
104
|
+
@keydown="onKeydown"
|
|
105
|
+
/>
|
|
106
|
+
<span v-if="showValue" :class="styles.bubble" aria-hidden="true">{{ text }}</span>
|
|
107
|
+
<!-- After the bubble, which CSS shows from the input just before it. -->
|
|
108
|
+
<span v-if="marks?.length" :class="styles.marks" aria-hidden="true">
|
|
109
|
+
<span v-for="m in marks" :key="m" :class="styles.mark" :data-on="m === value || undefined" :style="{ '--m': (m - min) / (max - min || 1) }" />
|
|
110
|
+
</span>
|
|
111
|
+
</div>
|
|
112
|
+
</div>
|
|
113
|
+
</template>
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { onMounted, ref } from 'vue'
|
|
3
|
+
import styles from './Spinner.module.css'
|
|
4
|
+
|
|
5
|
+
// The Vue Spinner: the same look (Spinner.module.css) as the React one.
|
|
6
|
+
|
|
7
|
+
withDefaults(
|
|
8
|
+
defineProps<{
|
|
9
|
+
/** Diameter of the spinner. */
|
|
10
|
+
size?: 'sm' | 'md' | 'lg'
|
|
11
|
+
/** Spoken to screen readers. Pass null when a parent already announces the busy state. */
|
|
12
|
+
label?: string | null
|
|
13
|
+
}>(),
|
|
14
|
+
{ size: 'md', label: 'Loading' },
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
// The label lands after the empty live region is mounted, so screen readers hear it.
|
|
18
|
+
const mounted = ref(false)
|
|
19
|
+
onMounted(() => (mounted.value = true))
|
|
20
|
+
</script>
|
|
21
|
+
|
|
22
|
+
<template>
|
|
23
|
+
<span :class="[styles.root, styles[size]]" :role="label ? 'status' : undefined">
|
|
24
|
+
<svg :class="styles.svg" viewBox="0 0 24 24" aria-hidden="true" focusable="false">
|
|
25
|
+
<circle :class="styles.track" cx="12" cy="12" r="9.5" />
|
|
26
|
+
<circle :class="styles.arc" cx="12" cy="12" r="9.5" pathLength="100" />
|
|
27
|
+
</svg>
|
|
28
|
+
<span v-if="label" :class="styles.srOnly">{{ mounted ? label : null }}</span>
|
|
29
|
+
</span>
|
|
30
|
+
</template>
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed } from 'vue'
|
|
3
|
+
import { space, type Space } from '../../internal/space'
|
|
4
|
+
import styles from './Split.module.css'
|
|
5
|
+
|
|
6
|
+
// The Vue Split: the same look (Split.module.css) as the React one. The sidebar slot is the narrow column;
|
|
7
|
+
// leave it out for one column. Other attributes go to the outer box.
|
|
8
|
+
const props = withDefaults(
|
|
9
|
+
defineProps<{
|
|
10
|
+
/** Which side the sidebar sits on. It also comes first ("start") or last ("end") when the columns stack. */
|
|
11
|
+
side?: 'start' | 'end'
|
|
12
|
+
/** Width of the sidebar, from the --gooee-split-side-* tokens. */
|
|
13
|
+
sidebarWidth?: 'sm' | 'md' | 'lg'
|
|
14
|
+
/** Space between the columns, and between them once stacked, as a step of the space scale. */
|
|
15
|
+
gap?: Space
|
|
16
|
+
/** What shows once the columns stack: both, only main, or only the sidebar. */
|
|
17
|
+
stacked?: 'both' | 'main' | 'sidebar'
|
|
18
|
+
}>(),
|
|
19
|
+
{ side: 'start', sidebarWidth: 'md', gap: 7, stacked: 'both' },
|
|
20
|
+
)
|
|
21
|
+
const slots = defineSlots<{ default?: () => unknown; sidebar?: () => unknown }>()
|
|
22
|
+
const hasSide = computed(() => !!slots.sidebar)
|
|
23
|
+
</script>
|
|
24
|
+
|
|
25
|
+
<!-- The outer box is the query container: an element cannot query its own width. -->
|
|
26
|
+
<template>
|
|
27
|
+
<div :class="styles.root" :style="{ '--split-gap': space(gap), '--split-side': `var(--gooee-split-side-${sidebarWidth})` }">
|
|
28
|
+
<div :class="[styles.inner, hasSide ? styles[side] : styles.solo]" :data-stacked="stacked">
|
|
29
|
+
<div v-if="hasSide && side === 'start'" :class="styles.side"><slot name="sidebar" /></div>
|
|
30
|
+
<div :class="styles.main"><slot /></div>
|
|
31
|
+
<div v-if="hasSide && side === 'end'" :class="styles.side"><slot name="sidebar" /></div>
|
|
32
|
+
</div>
|
|
33
|
+
</div>
|
|
34
|
+
</template>
|
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
import { useEffect, useRef, useState, type ComponentPropsWithRef } from 'react'
|
|
4
4
|
import { cx } from '../../internal/cx'
|
|
5
|
-
import {
|
|
5
|
+
import { createSplitFlap, flapCellsHtml, SPLIT_FLAP_CHARS, type FlapLook } from '../../internal/motion/splitFlap'
|
|
6
6
|
import styles from './SplitFlap.module.css'
|
|
7
7
|
|
|
8
|
+
export { SPLIT_FLAP_CHARS }
|
|
9
|
+
|
|
8
10
|
export type SplitFlapProps = Omit<ComponentPropsWithRef<'span'>, 'children'> & {
|
|
9
11
|
/** The text the board shows. A change flips each cell forward through the drum to its new letter. */
|
|
10
12
|
value: string
|
|
@@ -20,199 +22,33 @@ export type SplitFlapProps = Omit<ComponentPropsWithRef<'span'>, 'children'> & {
|
|
|
20
22
|
onSettle?: (value: string) => void
|
|
21
23
|
}
|
|
22
24
|
|
|
23
|
-
|
|
24
|
-
export const SPLIT_FLAP_CHARS = ' ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789:.,-+%/'
|
|
25
|
-
|
|
26
|
-
// A fold of about 90ms, fast steps of 40ms, and the last three slow down. A cell passes 8 letters at
|
|
27
|
-
// most, and the cells start one after another within 350ms, so a whole change ends inside a second.
|
|
28
|
-
const FOLD = 90
|
|
29
|
-
const FAST = 40
|
|
30
|
-
const TAIL = [70, 100, 140]
|
|
31
|
-
const MAX_STEPS = 8
|
|
32
|
-
const STAGGER = 35
|
|
33
|
-
const CASCADE_CAP = 350
|
|
34
|
-
// The fast motion token at its base, so Retime scales the board with everything else.
|
|
35
|
-
const FAST_TOKEN = 140
|
|
36
|
-
|
|
37
|
-
type Cell = { root: HTMLSpanElement; top: HTMLSpanElement; bottom: HTMLSpanElement; shown: string }
|
|
38
|
-
|
|
39
|
-
/** The letters a cell passes on its way from `from` to `to`, at most MAX_STEPS, ending on `to`. */
|
|
40
|
-
function route(from: string, to: string, drum: string) {
|
|
41
|
-
const a = drum.indexOf(from)
|
|
42
|
-
const b = drum.indexOf(to)
|
|
43
|
-
if (a < 0 || b < 0) return from === to ? [] : [to]
|
|
44
|
-
const n = Math.min((b - a + drum.length) % drum.length, MAX_STEPS)
|
|
45
|
-
return Array.from({ length: n }, (_, i) => drum[(b - n + 1 + i + drum.length) % drum.length])
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/** The wait before each step: fast in the middle, slow for the last three. */
|
|
49
|
-
const gaps = (n: number) => Array.from({ length: n }, (_, i) => (n - 1 - i < TAIL.length ? TAIL[TAIL.length - n + i] : FAST))
|
|
50
|
-
|
|
51
|
-
const NBSP = ' '
|
|
52
|
-
const shownChar = (ch: string) => (ch === ' ' ? NBSP : ch)
|
|
53
|
-
const escape = (ch: string) => ({ '&': '&', '<': '<', '>': '>' })[ch] ?? ch
|
|
54
|
-
|
|
55
|
-
const halfHtml = (cls: string, ch: string) => `<span class="${cls}"><span class="${styles.glyph}">${escape(shownChar(ch))}</span></span>`
|
|
56
|
-
const cellHtml = (ch: string) => `<span class="${styles.cell}">${halfHtml(styles.top, ch)}${halfHtml(styles.bottom, ch)}</span>`
|
|
57
|
-
|
|
58
|
-
const fromHtml = (html: string) => {
|
|
59
|
-
const t = document.createElement('template')
|
|
60
|
-
t.innerHTML = html
|
|
61
|
-
return t.content.firstElementChild as HTMLSpanElement
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const makeCell = (ch: string): Cell => {
|
|
65
|
-
const root = fromHtml(cellHtml(ch))
|
|
66
|
-
return { root, top: root.children[0] as HTMLSpanElement, bottom: root.children[1] as HTMLSpanElement, shown: ch }
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
const setHalf = (h: Element, ch: string) => {
|
|
70
|
-
;(h.firstElementChild as HTMLElement).textContent = shownChar(ch)
|
|
71
|
-
}
|
|
25
|
+
const LOOK: FlapLook = { cell: styles.cell, top: styles.top, bottom: styles.bottom, glyph: styles.glyph, flap: styles.flap, front: styles.front, back: styles.back }
|
|
72
26
|
|
|
73
27
|
export function SplitFlap({ value, length = 0, size = 'md', chars = SPLIT_FLAP_CHARS, announce = true, onSettle, className, ...rest }: SplitFlapProps) {
|
|
74
28
|
const target = value.padEnd(length, ' ')
|
|
75
29
|
// The first cells come with the markup, so a server page shows the board before any script runs.
|
|
76
|
-
const [first] = useState(() => ({ __html:
|
|
30
|
+
const [first] = useState(() => ({ __html: flapCellsHtml(LOOK, target) }))
|
|
77
31
|
const [said, setSaid] = useState(value)
|
|
78
32
|
const board = useRef<HTMLSpanElement>(null)
|
|
79
|
-
const
|
|
80
|
-
const timers = useRef<number[]>([])
|
|
81
|
-
const anims = useRef(new Set<Animation>())
|
|
82
|
-
const run = useRef(0)
|
|
83
|
-
const shrinkEnd = useRef<(() => void) | null>(null)
|
|
33
|
+
const flap = useRef<ReturnType<typeof createSplitFlap> | null>(null)
|
|
84
34
|
const settle = useRef(onSettle)
|
|
85
35
|
settle.current = onSettle
|
|
86
36
|
|
|
87
|
-
|
|
88
|
-
timers.current.forEach(clearTimeout)
|
|
89
|
-
timers.current = []
|
|
90
|
-
anims.current.forEach((a) => a.finish())
|
|
91
|
-
anims.current.clear()
|
|
92
|
-
shrinkEnd.current?.()
|
|
93
|
-
// Caught mid-run, each cell carries on from the letter it was showing.
|
|
94
|
-
for (const c of cells.current ?? []) setHalf(c.bottom, c.shown)
|
|
95
|
-
}
|
|
96
|
-
|
|
37
|
+
// The board runs in motion/splitFlap.ts. The first cells came with the markup.
|
|
97
38
|
useEffect(() => {
|
|
98
39
|
const b = board.current
|
|
99
40
|
if (!b) return
|
|
100
|
-
if (!
|
|
101
|
-
|
|
41
|
+
if (!flap.current) {
|
|
42
|
+
flap.current = createSplitFlap(b, LOOK, target)
|
|
102
43
|
return
|
|
103
44
|
}
|
|
104
|
-
|
|
105
|
-
const live = () => id === run.current
|
|
106
|
-
const running = timers.current.length > 0 || anims.current.size > 0
|
|
107
|
-
stopAll()
|
|
108
|
-
const done = () => {
|
|
109
|
-
if (!live()) return
|
|
110
|
-
timers.current = []
|
|
45
|
+
flap.current.show(target, chars, () => {
|
|
111
46
|
setSaid(value)
|
|
112
47
|
settle.current?.(value)
|
|
113
|
-
}
|
|
114
|
-
const list = cells.current
|
|
115
|
-
if (list.map((c) => c.shown).join('') === target) {
|
|
116
|
-
if (running) done()
|
|
117
|
-
return
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
const scale = readMotionMs('fast') / FAST_TOKEN
|
|
121
|
-
// Reduced motion: the new text at once, with no flips and no morph.
|
|
122
|
-
if (!scale) {
|
|
123
|
-
cells.current = [...target].map(makeCell)
|
|
124
|
-
b.replaceChildren(...cells.current.map((c) => c.root))
|
|
125
|
-
done()
|
|
126
|
-
return
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
const n0 = list.length
|
|
130
|
-
const n1 = target.length
|
|
131
|
-
const radius = getComputedStyle(b).borderRadius || '0px'
|
|
132
|
-
const grow = { duration: readMotionMs('morph'), easing: easing('morph') }
|
|
133
|
-
const shrink = { duration: readMotionMs('morph-out'), easing: easing('morph') }
|
|
134
|
-
let left = 0
|
|
135
|
-
const landed = () => {
|
|
136
|
-
if (--left === 0) done()
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
// Longer: the new cells are laid out at once, and the board's edge grows over them.
|
|
140
|
-
if (n1 > n0) {
|
|
141
|
-
const before = b.offsetWidth
|
|
142
|
-
for (let i = n0; i < n1; i++) {
|
|
143
|
-
const c = makeCell(' ')
|
|
144
|
-
list.push(c)
|
|
145
|
-
b.append(c.root)
|
|
146
|
-
}
|
|
147
|
-
const wider = b.offsetWidth - before
|
|
148
|
-
const a = b.animate({ clipPath: [`inset(0 ${wider}px 0 0 round ${radius})`, `inset(0 0 0 0 round ${radius})`] }, grow)
|
|
149
|
-
anims.current.add(a)
|
|
150
|
-
a.finished.then(() => anims.current.delete(a), () => {})
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
// Shorter: the board's edge folds over the extra cells while the rest flip, then they go.
|
|
154
|
-
if (n1 < n0) {
|
|
155
|
-
const keep = list.slice(0, n1)
|
|
156
|
-
const box = b.getBoundingClientRect()
|
|
157
|
-
const edge = keep.length ? keep[keep.length - 1].root.getBoundingClientRect().right : box.left
|
|
158
|
-
const a = b.animate({ clipPath: [`inset(0 0 0 0 round ${radius})`, `inset(0 ${box.right - edge}px 0 0 round ${radius})`] }, { ...shrink, fill: 'forwards' })
|
|
159
|
-
left++
|
|
160
|
-
const end = () => {
|
|
161
|
-
shrinkEnd.current = null
|
|
162
|
-
list.slice(n1).forEach((c) => c.root.remove())
|
|
163
|
-
cells.current = keep
|
|
164
|
-
a.cancel()
|
|
165
|
-
if (live()) landed()
|
|
166
|
-
}
|
|
167
|
-
shrinkEnd.current = end
|
|
168
|
-
a.finished.then(() => shrinkEnd.current === end && end(), () => {})
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
const goal = [...target]
|
|
172
|
-
const changed = goal.map((ch, i) => (list[i].shown !== ch ? i : -1)).filter((i) => i >= 0)
|
|
173
|
-
const stagger = Math.min(STAGGER, CASCADE_CAP / Math.max(1, changed.length))
|
|
174
|
-
left += changed.length
|
|
175
|
-
if (!left) return done()
|
|
176
|
-
|
|
177
|
-
const flip = (cell: Cell, next: string, last: boolean, fold: number) => {
|
|
178
|
-
const prev = cell.shown
|
|
179
|
-
cell.shown = next
|
|
180
|
-
setHalf(cell.top, next)
|
|
181
|
-
// The falling flap: the old letter's top half in front, the new letter's bottom half behind.
|
|
182
|
-
const flap = fromHtml(`<span class="${styles.flap}">${halfHtml(styles.front, prev)}${halfHtml(styles.back, next)}</span>`)
|
|
183
|
-
cell.root.append(flap)
|
|
184
|
-
const a = flap.animate([{ transform: 'rotateX(0deg)' }, { transform: 'rotateX(-180deg)' }], { duration: fold, easing: easing('morph') })
|
|
185
|
-
anims.current.add(a)
|
|
186
|
-
const end = () => {
|
|
187
|
-
anims.current.delete(a)
|
|
188
|
-
setHalf(cell.bottom, next)
|
|
189
|
-
flap.remove()
|
|
190
|
-
if (last && live()) landed()
|
|
191
|
-
}
|
|
192
|
-
a.finished.then(end, end)
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
changed.forEach((i, order) => {
|
|
196
|
-
const cell = list[i]
|
|
197
|
-
const path = route(cell.shown, goal[i], chars)
|
|
198
|
-
const wait = gaps(path.length)
|
|
199
|
-
let t = order * stagger
|
|
200
|
-
path.forEach((next, k) => {
|
|
201
|
-
timers.current.push(window.setTimeout(() => flip(cell, next, k === path.length - 1, Math.max(FOLD, wait[k]) * scale), t * scale))
|
|
202
|
-
t += wait[k]
|
|
203
|
-
})
|
|
204
48
|
})
|
|
205
49
|
}, [target])
|
|
206
50
|
|
|
207
|
-
useEffect(
|
|
208
|
-
() => () => {
|
|
209
|
-
// Gone: the run is over, so a cancelled flip ends without calling onSettle.
|
|
210
|
-
run.current++
|
|
211
|
-
timers.current.forEach(clearTimeout)
|
|
212
|
-
anims.current.forEach((a) => a.cancel())
|
|
213
|
-
},
|
|
214
|
-
[],
|
|
215
|
-
)
|
|
51
|
+
useEffect(() => () => flap.current?.destroy(), [])
|
|
216
52
|
|
|
217
53
|
return (
|
|
218
54
|
<span className={cx(styles.root, className)} data-size={size} {...rest}>
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue'
|
|
3
|
+
import { createSplitFlap, flapCellsHtml, SPLIT_FLAP_CHARS, type FlapLook } from '../../internal/motion/splitFlap'
|
|
4
|
+
import styles from './SplitFlap.module.css'
|
|
5
|
+
|
|
6
|
+
// The Vue SplitFlap: the same look (SplitFlap.module.css) and flips (motion/splitFlap.ts) as the React one.
|
|
7
|
+
// Other attributes go to the root.
|
|
8
|
+
const props = withDefaults(
|
|
9
|
+
defineProps<{
|
|
10
|
+
/** The text the board shows. A change flips each cell forward through the drum to its new letter. */
|
|
11
|
+
value: string
|
|
12
|
+
/** At least this many cells: shorter text is padded with blank ones, so a column keeps its width. */
|
|
13
|
+
length?: number
|
|
14
|
+
/** Text size of the cells. */
|
|
15
|
+
size?: 'sm' | 'md' | 'lg'
|
|
16
|
+
/** The drum's letters, in the order a cell passes them. A letter that is not on it flips straight in. */
|
|
17
|
+
chars?: string
|
|
18
|
+
/** Says the new text to screen readers once, when the board has landed. Turn off when one message covers several boards. */
|
|
19
|
+
announce?: boolean
|
|
20
|
+
}>(),
|
|
21
|
+
{ length: 0, size: 'md', chars: SPLIT_FLAP_CHARS, announce: true },
|
|
22
|
+
)
|
|
23
|
+
/** settle: fires once with the text when every cell has landed. */
|
|
24
|
+
const emit = defineEmits<{ settle: [value: string] }>()
|
|
25
|
+
|
|
26
|
+
const LOOK: FlapLook = { cell: styles.cell, top: styles.top, bottom: styles.bottom, glyph: styles.glyph, flap: styles.flap, front: styles.front, back: styles.back }
|
|
27
|
+
const target = computed(() => props.value.padEnd(props.length, ' '))
|
|
28
|
+
// The first cells come with the markup, so a server page shows the board before any script runs.
|
|
29
|
+
const first = flapCellsHtml(LOOK, target.value)
|
|
30
|
+
const said = ref(props.value)
|
|
31
|
+
const board = ref<HTMLSpanElement | null>(null)
|
|
32
|
+
let flap: ReturnType<typeof createSplitFlap> | null = null
|
|
33
|
+
|
|
34
|
+
onMounted(() => {
|
|
35
|
+
if (board.value) flap = createSplitFlap(board.value, LOOK, target.value)
|
|
36
|
+
})
|
|
37
|
+
watch(target, (t) => {
|
|
38
|
+
const value = props.value
|
|
39
|
+
flap?.show(t, props.chars, () => {
|
|
40
|
+
said.value = value
|
|
41
|
+
emit('settle', value)
|
|
42
|
+
})
|
|
43
|
+
})
|
|
44
|
+
onBeforeUnmount(() => flap?.destroy())
|
|
45
|
+
</script>
|
|
46
|
+
|
|
47
|
+
<template>
|
|
48
|
+
<span :class="styles.root" :data-size="size">
|
|
49
|
+
<span :class="styles.sr" :aria-live="announce ? 'polite' : undefined" aria-atomic="true">{{ said }}</span>
|
|
50
|
+
<span ref="board" :class="styles.board" aria-hidden="true" v-html="first" />
|
|
51
|
+
</span>
|
|
52
|
+
</template>
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { space, type Space } from '../../internal/space'
|
|
3
|
+
import styles from './Stack.module.css'
|
|
4
|
+
|
|
5
|
+
// The Vue Stack: the same look (Stack.module.css) as the React one. Other attributes go to the element.
|
|
6
|
+
withDefaults(
|
|
7
|
+
defineProps<{
|
|
8
|
+
/** Space between items, as a step of the space scale (0 to 12, read as --gooee-space-N). */
|
|
9
|
+
gap?: Space
|
|
10
|
+
/** Lines items up across the stack. "stretch" makes each item full width. */
|
|
11
|
+
align?: 'stretch' | 'start' | 'center' | 'end'
|
|
12
|
+
/** Element to render, so the stack can be a list, a section or a form. */
|
|
13
|
+
as?: 'div' | 'section' | 'article' | 'aside' | 'nav' | 'header' | 'footer' | 'main' | 'form' | 'fieldset' | 'ul' | 'ol'
|
|
14
|
+
}>(),
|
|
15
|
+
{ gap: 5, align: 'stretch', as: 'div' },
|
|
16
|
+
)
|
|
17
|
+
defineSlots<{ default?: () => unknown }>()
|
|
18
|
+
</script>
|
|
19
|
+
|
|
20
|
+
<template>
|
|
21
|
+
<component :is="as" :class="[styles.root, styles[align]]" :style="{ '--stack-gap': space(gap) }"><slot /></component>
|
|
22
|
+
</template>
|