gooee 0.50.0 → 0.51.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -4
- package/package.json +5 -3
- 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 -143
- 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 +11 -39
- 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/focus.ts +4 -47
- package/src/internal/icons.module.css +39 -27
- package/src/internal/layers.ts +7 -61
- 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/floating.ts +58 -0
- package/src/internal/motion/focus.ts +53 -0
- package/src/internal/motion/formField.ts +19 -0
- package/src/internal/motion/holdToConfirm.ts +147 -0
- package/src/internal/motion/keys.ts +42 -0
- package/src/internal/motion/layers.ts +78 -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/scrubLook.ts +15 -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/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/themeReveal.ts +3 -61
- package/src/internal/useFloating.ts +9 -49
- package/src/internal/useScrub.ts +1 -13
- 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
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed, onBeforeUnmount, onMounted, ref, useId, useSlots, watch } from 'vue'
|
|
3
|
+
import { clamp, pull, roundTo, wheelSteps } from '../../internal/feel'
|
|
4
|
+
import { arcTouch, CX, CY, DOT, dialScale, dialScrub, H, KNOB, polar, SWEEP, W, type Rim } from '../../internal/motion/dial'
|
|
5
|
+
import { ink, tokenNumber } from '../../internal/motion/scrubLook'
|
|
6
|
+
import Roll from '../../internal/Roll.vue'
|
|
7
|
+
import { useScrub } from '../../internal/vue/useScrub'
|
|
8
|
+
import styles from './Dial.module.css'
|
|
9
|
+
|
|
10
|
+
// The Vue Dial: the same look (Dial.module.css), turn and landing as the React one.
|
|
11
|
+
|
|
12
|
+
const props = withDefaults(
|
|
13
|
+
defineProps<{
|
|
14
|
+
/** Visible name of the dial, also read by screen readers. */
|
|
15
|
+
label: string
|
|
16
|
+
/** Starting value when there is no v-model. Undefined starts at min. */
|
|
17
|
+
defaultValue?: number
|
|
18
|
+
/** Lowest value. */
|
|
19
|
+
min?: number
|
|
20
|
+
/** Highest value. */
|
|
21
|
+
max?: number
|
|
22
|
+
/** Size of one step. Every step is a mark the dial is drawn onto. */
|
|
23
|
+
step?: number
|
|
24
|
+
/** Values with a printed label. Page Up and Page Down jump between them. Defaults to min and max. */
|
|
25
|
+
marks?: number[]
|
|
26
|
+
/** Values drawn stronger, such as the usual setting. */
|
|
27
|
+
strong?: number[]
|
|
28
|
+
/** "printed": the scale is printed on the knob and turns under a fixed index. "mercury": a solid knob with a few named levels. "arc": the rim of a large dial, swiped sideways. */
|
|
29
|
+
variant?: 'printed' | 'mercury' | 'arc'
|
|
30
|
+
/** Turns the value into the readout and what screen readers hear. */
|
|
31
|
+
formatValue?: (value: number) => string
|
|
32
|
+
/** Turns a mark into its printed label. Defaults to formatValue. */
|
|
33
|
+
formatMark?: (value: number) => string
|
|
34
|
+
/** A line under the readout, such as what the value means. The detail slot replaces it. */
|
|
35
|
+
detail?: string
|
|
36
|
+
/** A double click goes back to this value. */
|
|
37
|
+
resetValue?: number
|
|
38
|
+
/** A short buzz on each step while it turns, on phones that can (Android). */
|
|
39
|
+
haptics?: boolean
|
|
40
|
+
}>(),
|
|
41
|
+
{ min: 0, max: 100, step: 1, strong: () => [], variant: 'printed', formatValue: String, haptics: false },
|
|
42
|
+
)
|
|
43
|
+
const emit = defineEmits<{ /** The value under the index while the dial still turns. */ scrub: [value: number] }>()
|
|
44
|
+
const slots = useSlots()
|
|
45
|
+
|
|
46
|
+
/** The value, set once the dial comes to rest. Use v-model, or leave it out and the dial keeps its own value. */
|
|
47
|
+
const model = defineModel<number>()
|
|
48
|
+
const local = ref(props.defaultValue ?? props.min)
|
|
49
|
+
const raw = computed({
|
|
50
|
+
get: () => model.value ?? local.value,
|
|
51
|
+
set: (next: number) => {
|
|
52
|
+
local.value = next
|
|
53
|
+
model.value = next
|
|
54
|
+
},
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
const labelId = useId()
|
|
58
|
+
const detailId = useId()
|
|
59
|
+
const goo = useId().replace(/:/g, '')
|
|
60
|
+
const scale = computed(() => ({ min: props.min, max: props.max, step: props.step, marks: props.marks, variant: props.variant }))
|
|
61
|
+
const dial = computed(() => dialScale(scale.value))
|
|
62
|
+
const value = computed(() => clamp(raw.value, props.min, dial.value.top))
|
|
63
|
+
const strongSet = computed(() => new Set(props.strong.map((v) => roundTo(v, props.step, props.min))))
|
|
64
|
+
const markText = (v: number) => (props.formatMark ?? props.formatValue)(v)
|
|
65
|
+
// The arc's rim: its radius and the length of one step along it, both tokens.
|
|
66
|
+
const rim = ref<Rim | null>(null)
|
|
67
|
+
const wheel = wheelSteps()
|
|
68
|
+
|
|
69
|
+
// The drag, keys, tap and wheel (motion/dial.ts) on the shared scrubber.
|
|
70
|
+
const sc = useScrub(() => ({ value: value.value, ...dialScrub(scale.value, rim.value, wheel), onSettle: (v: number) => (raw.value = v), haptics: props.haptics }))
|
|
71
|
+
const scrubEl = sc.el
|
|
72
|
+
|
|
73
|
+
// The arc takes only sideways touches, so the page still scrolls under a finger on it (motion/dial.ts).
|
|
74
|
+
let stopTouch = () => {}
|
|
75
|
+
const measureRim = () => {
|
|
76
|
+
stopTouch()
|
|
77
|
+
stopTouch = () => {}
|
|
78
|
+
if (props.variant !== 'arc' || !scrubEl.value) return
|
|
79
|
+
rim.value = { r: tokenNumber(scrubEl.value, '--gooee-dial-arc-radius'), gap: tokenNumber(scrubEl.value, '--gooee-dial-arc-gap') }
|
|
80
|
+
stopTouch = arcTouch(scrubEl.value)
|
|
81
|
+
}
|
|
82
|
+
onMounted(measureRim)
|
|
83
|
+
watch(() => props.variant, measureRim, { flush: 'post' })
|
|
84
|
+
onBeforeUnmount(() => stopTouch())
|
|
85
|
+
|
|
86
|
+
const shown = computed(() => dial.value.land(sc.at.value))
|
|
87
|
+
watch(shown, (v) => emit('scrub', v))
|
|
88
|
+
|
|
89
|
+
const hasDetail = computed(() => !!(props.detail || slots.detail))
|
|
90
|
+
const index = computed(() => dial.value.all.indexOf(value.value))
|
|
91
|
+
const sliderAttrs = computed(() => ({
|
|
92
|
+
role: 'slider',
|
|
93
|
+
tabindex: 0,
|
|
94
|
+
'aria-labelledby': labelId,
|
|
95
|
+
'aria-describedby': hasDetail.value ? detailId : undefined,
|
|
96
|
+
'aria-valuemin': props.min,
|
|
97
|
+
'aria-valuemax': dial.value.top,
|
|
98
|
+
'aria-valuenow': value.value,
|
|
99
|
+
'aria-valuetext': props.variant === 'mercury' && index.value >= 0 ? `${props.formatValue(value.value)}, ${index.value + 1} of ${dial.value.all.length}` : props.formatValue(value.value),
|
|
100
|
+
'data-moving': sc.moving.value || undefined,
|
|
101
|
+
}))
|
|
102
|
+
const onDblclick = () => props.resetValue !== undefined && sc.go(dial.value.land(props.resetValue))
|
|
103
|
+
|
|
104
|
+
// Mercury: the bump on the knob and each level's dot and drop.
|
|
105
|
+
const mercury = computed(() => {
|
|
106
|
+
const { all, stepDeg } = dial.value
|
|
107
|
+
const at = sc.at.value
|
|
108
|
+
const [bx, by] = polar(-135 + ((at - props.min) / props.step) * stepDeg, KNOB)
|
|
109
|
+
const levels = all.map((v, i) => {
|
|
110
|
+
const a = -135 + i * stepDeg
|
|
111
|
+
const [x, y] = polar(a, DOT)
|
|
112
|
+
const [lx, ly] = polar(a, DOT + 22)
|
|
113
|
+
const p = pull(at - v, props.step)
|
|
114
|
+
const [dx, dy] = polar(a, DOT - 12 * p)
|
|
115
|
+
return { v, x, y, lx, ly, anchor: Math.abs(a) < 1 ? 'middle' : a < 0 ? 'end' : 'start', on: v === shown.value, dx, dy, dr: p * 9 }
|
|
116
|
+
})
|
|
117
|
+
return { bx, by, levels }
|
|
118
|
+
})
|
|
119
|
+
|
|
120
|
+
// Arc: the marks near the index, each leaning in by its pull.
|
|
121
|
+
const arcMarks = computed(() => {
|
|
122
|
+
const r = rim.value
|
|
123
|
+
const degPerStep = r && r.r ? (r.gap / r.r) * (180 / Math.PI) : 0
|
|
124
|
+
if (degPerStep <= 0) return []
|
|
125
|
+
const at = sc.at.value
|
|
126
|
+
return dial.value.all.flatMap((v, i) => {
|
|
127
|
+
const a = ((v - at) / props.step) * degPerStep
|
|
128
|
+
if (Math.abs(a) > 22) return []
|
|
129
|
+
const p = pull(at - v, props.step * 1.2)
|
|
130
|
+
const tier = dial.value.labelled.includes(v) ? 'major' : i % 2 === 0 ? 'mid' : 'minor'
|
|
131
|
+
return [{ v, a, p, tier }]
|
|
132
|
+
})
|
|
133
|
+
})
|
|
134
|
+
|
|
135
|
+
// Printed: the face turns under the index.
|
|
136
|
+
const printed = computed(() => {
|
|
137
|
+
const { min, max, step, marks } = props
|
|
138
|
+
const { all, labelled, top } = dial.value
|
|
139
|
+
const turned = ((sc.at.value - min) / (max - min || 1)) * SWEEP
|
|
140
|
+
// The face prints min, the middle and max unless marks say otherwise; the keys still jump by marks.
|
|
141
|
+
const nums = marks ? labelled : [...new Set([min, roundTo((min + max) / 2, step, min), top])]
|
|
142
|
+
// A longer tick every ten steps on a long scale, so the amount can be counted at a glance.
|
|
143
|
+
const tenth = all.length > 20 ? step * 10 : 0
|
|
144
|
+
const isMajor = (v: number) => nums.includes(v) || (tenth > 0 && Math.abs((v - min) / tenth - Math.round((v - min) / tenth)) < 1e-6)
|
|
145
|
+
// Every step gets a tick while they fit round the knob (thinner past 49); past that only the long ones.
|
|
146
|
+
const dense = all.length > 49
|
|
147
|
+
const ticks = (all.length <= 121 ? all : all.filter((v) => isMajor(v) || strongSet.value.has(v))).map((v) => {
|
|
148
|
+
const at = (-(v - min) / (max - min || 1)) * SWEEP
|
|
149
|
+
const major = isMajor(v)
|
|
150
|
+
return { v, at, p: pull(sc.at.value - v, step), major, fine: dense && !major, num: nums.includes(v) }
|
|
151
|
+
})
|
|
152
|
+
return { turned, ticks }
|
|
153
|
+
})
|
|
154
|
+
</script>
|
|
155
|
+
|
|
156
|
+
<template>
|
|
157
|
+
<div :class="[styles.root, styles[variant]]">
|
|
158
|
+
<div :class="styles.head">
|
|
159
|
+
<span :id="labelId" :class="styles.label">{{ label }}</span>
|
|
160
|
+
<Roll :text="formatValue(shown)" :class="styles.readout" :still="sc.moving.value" />
|
|
161
|
+
<span v-if="hasDetail" :id="detailId" :class="styles.detail"><slot name="detail">{{ detail }}</slot></span>
|
|
162
|
+
</div>
|
|
163
|
+
<div v-if="variant === 'mercury'" ref="scrubEl" :class="styles.mercuryHit" v-bind="sliderAttrs" v-on="sc.handlers" @dblclick="onDblclick">
|
|
164
|
+
<svg :viewBox="`0 0 ${W} ${H}`" :class="styles.mercurySvg" aria-hidden="true">
|
|
165
|
+
<defs>
|
|
166
|
+
<filter :id="goo" x="-20%" y="-20%" width="140%" height="140%">
|
|
167
|
+
<feGaussianBlur in="SourceGraphic" stdDeviation="5" result="blur" />
|
|
168
|
+
<feColorMatrix in="blur" mode="matrix" values="1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 22 -9" result="goo" />
|
|
169
|
+
<feComposite in="SourceGraphic" in2="goo" operator="atop" />
|
|
170
|
+
</filter>
|
|
171
|
+
</defs>
|
|
172
|
+
<g v-for="l in mercury.levels" :key="l.v">
|
|
173
|
+
<circle :cx="l.x" :cy="l.y" :r="3.5" :class="styles.dot" :data-on="l.on || undefined" />
|
|
174
|
+
<text :x="l.lx" :y="l.ly" :text-anchor="l.anchor" dominant-baseline="middle" :class="styles.level" :data-on="l.on || undefined">{{ markText(l.v) }}</text>
|
|
175
|
+
</g>
|
|
176
|
+
<g :filter="`url(#${goo})`" :class="styles.metal">
|
|
177
|
+
<circle :cx="CX" :cy="CY" :r="KNOB" />
|
|
178
|
+
<circle :cx="mercury.bx" :cy="mercury.by" :r="10" />
|
|
179
|
+
<circle v-for="l in mercury.levels" :key="l.v" :cx="l.dx" :cy="l.dy" :r="l.dr" />
|
|
180
|
+
</g>
|
|
181
|
+
<circle :cx="CX" :cy="CY" :r="KNOB - 14" :class="styles.groove" />
|
|
182
|
+
</svg>
|
|
183
|
+
</div>
|
|
184
|
+
<div v-else-if="variant === 'arc'" ref="scrubEl" :class="styles.arcStage" v-bind="sliderAttrs" v-on="sc.handlers" @dblclick="onDblclick">
|
|
185
|
+
<span :class="styles.arcIndex" aria-hidden="true" />
|
|
186
|
+
<div :class="styles.arcClip" aria-hidden="true">
|
|
187
|
+
<div :class="styles.hub">
|
|
188
|
+
<span :class="styles.disc" />
|
|
189
|
+
<span v-for="m in arcMarks" :key="m.v" :class="styles.arcMark" :style="{ transform: `rotate(${m.a}deg) translateY(calc(var(--gooee-dial-arc-radius) * -1))` }">
|
|
190
|
+
<i :class="styles.arcTick" :data-tier="m.tier" :style="{ background: ink(m.p, 'var(--gooee-color-border-strong)', 'var(--gooee-color-accent)'), transform: `scaleY(${1 + m.p * 0.7})` }" />
|
|
191
|
+
<span v-if="m.tier === 'major'" :class="styles.arcNum" :style="{ color: ink(m.p), transform: `translateX(-50%) scale(${1 + m.p * 0.3})` }">{{ markText(m.v) }}</span>
|
|
192
|
+
<span v-if="strongSet.has(m.v)" :class="styles.arcStrong" />
|
|
193
|
+
</span>
|
|
194
|
+
</div>
|
|
195
|
+
</div>
|
|
196
|
+
</div>
|
|
197
|
+
<div v-else :class="styles.bezel">
|
|
198
|
+
<span :class="styles.index" aria-hidden="true" />
|
|
199
|
+
<!-- How much: the ring fills from min (where the face has turned it) up to the index. -->
|
|
200
|
+
<svg :class="styles.fill" aria-hidden="true">
|
|
201
|
+
<!-- A negative dash length is invalid and draws the whole ring, so the arc is clamped and left out at min. -->
|
|
202
|
+
<circle v-if="printed.turned > 0.5" :pathLength="360" :stroke-dasharray="`${Math.min(printed.turned, 360)} 360`" />
|
|
203
|
+
</svg>
|
|
204
|
+
<div ref="scrubEl" :class="styles.knob" v-bind="sliderAttrs" v-on="sc.handlers" @dblclick="onDblclick">
|
|
205
|
+
<div :class="styles.face" :style="{ transform: `rotate(${printed.turned}deg)` }" aria-hidden="true">
|
|
206
|
+
<span v-for="t in printed.ticks" :key="t.v" :class="styles.spoke" :style="{ transform: `rotate(${t.at}deg)` }">
|
|
207
|
+
<i
|
|
208
|
+
:class="styles.tick"
|
|
209
|
+
:data-major="t.major || undefined"
|
|
210
|
+
:data-fine="t.fine || undefined"
|
|
211
|
+
:data-strong="strongSet.has(t.v) || undefined"
|
|
212
|
+
:data-current="t.v === shown || undefined"
|
|
213
|
+
:style="{ background: ink(t.p, 'var(--gooee-color-border-strong)', 'var(--gooee-color-accent)'), transform: `scaleY(${1 + t.p * 0.5})` }"
|
|
214
|
+
/>
|
|
215
|
+
<span v-if="t.num" :class="styles.numAt" :style="{ transform: `translateY(var(--num-r)) rotate(${-(t.at + printed.turned)}deg)` }">
|
|
216
|
+
<span :class="styles.num" :style="{ color: ink(t.p), transform: `translate(-50%, -50%) scale(${1 + t.p * 0.45})`, fontWeight: `calc(var(--gooee-weight-medium) + (var(--gooee-weight-semibold) - var(--gooee-weight-medium)) * ${t.p.toFixed(3)})` }">{{
|
|
217
|
+
markText(t.v)
|
|
218
|
+
}}</span>
|
|
219
|
+
</span>
|
|
220
|
+
</span>
|
|
221
|
+
<span :class="styles.cap" />
|
|
222
|
+
</div>
|
|
223
|
+
<!-- The grip: an indent on the cap that points at the value under the index, so it reads as a knob to turn. -->
|
|
224
|
+
<span :class="styles.grip" aria-hidden="true" />
|
|
225
|
+
</div>
|
|
226
|
+
</div>
|
|
227
|
+
</div>
|
|
228
|
+
</template>
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed, nextTick, onBeforeUnmount, ref, useId, watch } from 'vue'
|
|
3
|
+
import { createDragClose } from '../../internal/motion/fling'
|
|
4
|
+
import { trapFocus } from '../../internal/motion/focus'
|
|
5
|
+
import { dismissable, lockScroll } from '../../internal/motion/layers'
|
|
6
|
+
import { createDialogMorph } from '../../internal/motion/liquid'
|
|
7
|
+
import { motionMs } from '../../internal/motion'
|
|
8
|
+
import styles from './Dialog.module.css'
|
|
9
|
+
|
|
10
|
+
// The Vue Dialog: the same look (Dialog.module.css), morph, focus and drag to close as the React one.
|
|
11
|
+
|
|
12
|
+
const props = withDefaults(
|
|
13
|
+
defineProps<{
|
|
14
|
+
/** Heading of the dialog. Also its accessible name. The title slot replaces it. */
|
|
15
|
+
title?: string
|
|
16
|
+
/** Short text under the title, read out when the dialog opens. The description slot replaces it. */
|
|
17
|
+
description?: string
|
|
18
|
+
/** Maximum width of the panel. */
|
|
19
|
+
size?: 'sm' | 'md' | 'lg'
|
|
20
|
+
/** Set false for dialogs that must not close by a stray tap, like unsaved work. */
|
|
21
|
+
dismissOnOverlay?: boolean
|
|
22
|
+
/** Screen reader name for the close button. */
|
|
23
|
+
closeLabel?: string
|
|
24
|
+
/** Element to focus first. Defaults to the first focusable element. */
|
|
25
|
+
initialFocus?: HTMLElement | null
|
|
26
|
+
}>(),
|
|
27
|
+
{ size: 'md', dismissOnOverlay: true, closeLabel: 'Close' },
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
/** Shows the dialog. Use v-model:open; the close button, Esc, an outside tap or a pull down set it false. */
|
|
31
|
+
const open = defineModel<boolean>('open', { required: true })
|
|
32
|
+
const slots = defineSlots<{ default?: () => unknown; title?: () => unknown; description?: () => unknown; footer?: () => unknown }>()
|
|
33
|
+
|
|
34
|
+
const id = useId()
|
|
35
|
+
const panel = ref<HTMLElement | null>(null)
|
|
36
|
+
const hasDescription = computed(() => !!(props.description || slots.description))
|
|
37
|
+
const close = () => (open.value = false)
|
|
38
|
+
|
|
39
|
+
// Stays in the page through the fold, then leaves.
|
|
40
|
+
const mounted = ref(open.value)
|
|
41
|
+
const state = computed(() => (open.value ? 'open' : 'closed'))
|
|
42
|
+
let leaving = 0
|
|
43
|
+
|
|
44
|
+
// The panel grows out of the control that opened it and folds back into it (motion/liquid.ts).
|
|
45
|
+
const morph = createDialogMorph(() => panel.value)
|
|
46
|
+
// On a phone the dialog is a bottom sheet, and the hand can pull it down to close.
|
|
47
|
+
const drag = createDragClose(() => panel.value, {
|
|
48
|
+
onClose: close,
|
|
49
|
+
isOpen: () => open.value,
|
|
50
|
+
can: (e) => window.matchMedia('(max-width: 520px)').matches && !!(e.target as HTMLElement).closest(`.${styles.handle}, .${styles.header}`),
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
let release: Array<() => void> = []
|
|
54
|
+
const stop = () => {
|
|
55
|
+
release.forEach((r) => r())
|
|
56
|
+
release = []
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// On the server (Nuxt) there is no page to move or hold, so both watchers wait for the browser.
|
|
60
|
+
const server = typeof window === 'undefined'
|
|
61
|
+
|
|
62
|
+
// Before the new state renders, so the opener is read while it still has focus.
|
|
63
|
+
watch(
|
|
64
|
+
open,
|
|
65
|
+
(now, was) => {
|
|
66
|
+
if (server) return
|
|
67
|
+
clearTimeout(leaving)
|
|
68
|
+
if (now && !was) morph.opening()
|
|
69
|
+
if (now) {
|
|
70
|
+
mounted.value = true
|
|
71
|
+
drag.fling.opened()
|
|
72
|
+
} else {
|
|
73
|
+
drag.fling.closed()
|
|
74
|
+
leaving = window.setTimeout(() => (mounted.value = false), motionMs('morph-out'))
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
{ immediate: true, flush: 'pre' },
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
// Once the panel is in the page: play the morph, and hold the scroll, the layer and focus while open.
|
|
81
|
+
watch(
|
|
82
|
+
[state, mounted],
|
|
83
|
+
async () => {
|
|
84
|
+
if (server || !mounted.value) return
|
|
85
|
+
await nextTick()
|
|
86
|
+
morph.play(state.value)
|
|
87
|
+
stop()
|
|
88
|
+
if (!open.value || !panel.value) return
|
|
89
|
+
const el = panel.value
|
|
90
|
+
release.push(lockScroll(), dismissable(() => [el], close, { outside: props.dismissOnOverlay }), trapFocus(el, { initialFocus: props.initialFocus }))
|
|
91
|
+
},
|
|
92
|
+
{ immediate: true, flush: 'post' },
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
onBeforeUnmount(() => {
|
|
96
|
+
clearTimeout(leaving)
|
|
97
|
+
stop()
|
|
98
|
+
morph.destroy()
|
|
99
|
+
drag.fling.stop()
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
const grab = computed(() =>
|
|
103
|
+
props.dismissOnOverlay ? { onPointerdown: drag.down, onPointermove: drag.move, onPointerup: drag.up, onPointercancel: drag.up } : {},
|
|
104
|
+
)
|
|
105
|
+
</script>
|
|
106
|
+
|
|
107
|
+
<template>
|
|
108
|
+
<Teleport v-if="mounted" to="body">
|
|
109
|
+
<div :class="styles.overlay" :data-state="state" aria-hidden="true" />
|
|
110
|
+
<div :class="styles.positioner">
|
|
111
|
+
<div
|
|
112
|
+
ref="panel"
|
|
113
|
+
role="dialog"
|
|
114
|
+
aria-modal="true"
|
|
115
|
+
:aria-labelledby="`${id}-title`"
|
|
116
|
+
:aria-describedby="hasDescription ? `${id}-desc` : undefined"
|
|
117
|
+
tabindex="-1"
|
|
118
|
+
:class="[styles.panel, styles[size]]"
|
|
119
|
+
:data-state="state"
|
|
120
|
+
v-bind="grab"
|
|
121
|
+
>
|
|
122
|
+
<span v-if="dismissOnOverlay" :class="styles.handle" aria-hidden="true" />
|
|
123
|
+
<header :class="styles.header">
|
|
124
|
+
<div :class="styles.titles">
|
|
125
|
+
<h2 :id="`${id}-title`" :class="styles.title"><slot name="title">{{ title }}</slot></h2>
|
|
126
|
+
<p v-if="hasDescription" :id="`${id}-desc`" :class="styles.description"><slot name="description">{{ description }}</slot></p>
|
|
127
|
+
</div>
|
|
128
|
+
<button type="button" :class="styles.close" :aria-label="closeLabel" data-skip-initial-focus="true" @click="close">
|
|
129
|
+
<svg width="1em" height="1em" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false">
|
|
130
|
+
<path d="M6 6l12 12M18 6L6 18" />
|
|
131
|
+
</svg>
|
|
132
|
+
</button>
|
|
133
|
+
</header>
|
|
134
|
+
<div v-if="slots.default" :class="styles.body"><slot /></div>
|
|
135
|
+
<footer v-if="slots.footer" :class="styles.footer"><slot name="footer" /></footer>
|
|
136
|
+
</div>
|
|
137
|
+
</div>
|
|
138
|
+
</Teleport>
|
|
139
|
+
</template>
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import styles from './Divider.module.css'
|
|
3
|
+
|
|
4
|
+
// The Vue Divider: the same look (Divider.module.css) as the React one.
|
|
5
|
+
withDefaults(
|
|
6
|
+
defineProps<{
|
|
7
|
+
/** Direction of the line. A vertical line stretches to the height of its flex row. */
|
|
8
|
+
orientation?: 'horizontal' | 'vertical'
|
|
9
|
+
/** Text in the middle of a horizontal line, such as "or". The label slot replaces it. */
|
|
10
|
+
label?: string
|
|
11
|
+
/** Draws the line in from the centre when it mounts. */
|
|
12
|
+
animated?: boolean
|
|
13
|
+
}>(),
|
|
14
|
+
{ orientation: 'horizontal', animated: true },
|
|
15
|
+
)
|
|
16
|
+
const slots = defineSlots<{ label?: () => unknown }>()
|
|
17
|
+
</script>
|
|
18
|
+
|
|
19
|
+
<template>
|
|
20
|
+
<!-- A separator hides its children, so the role sits on the lines and the label is still read. -->
|
|
21
|
+
<div v-if="(label || slots.label) && orientation === 'horizontal'" :class="[styles.labelled, animated && styles.animated]">
|
|
22
|
+
<span :class="styles.line" role="separator" aria-orientation="horizontal" />
|
|
23
|
+
<span :class="styles.text"><slot name="label">{{ label }}</slot></span>
|
|
24
|
+
<span :class="styles.line" role="separator" aria-orientation="horizontal" />
|
|
25
|
+
</div>
|
|
26
|
+
<div v-else role="separator" :aria-orientation="orientation" :class="[styles.root, styles[orientation], animated && styles.animated]" />
|
|
27
|
+
</template>
|
|
@@ -17,6 +17,7 @@ import { useDismiss } from '../../internal/layers'
|
|
|
17
17
|
import { useLiquid } from '../../internal/liquid'
|
|
18
18
|
import { useBead } from '../../internal/liquidMore'
|
|
19
19
|
import { mergeRefs } from '../../internal/mergeRefs'
|
|
20
|
+
import { createMenuKeys, itemKey, menuButtonKey, menuItems } from '../../internal/motion/menuKeys'
|
|
20
21
|
import { Portal } from '../../internal/Portal'
|
|
21
22
|
import { useFloating, type Align } from '../../internal/useFloating'
|
|
22
23
|
import { usePresence } from '../../internal/usePresence'
|
|
@@ -62,7 +63,6 @@ export function DropdownMenu({ trigger, items, label, align = 'start' }: Dropdow
|
|
|
62
63
|
const [focusAt, setFocusAt] = useState<'first' | 'last'>('first')
|
|
63
64
|
const anchorRef = useRef<HTMLElement>(null)
|
|
64
65
|
const menuRef = useRef<HTMLDivElement>(null)
|
|
65
|
-
const typeahead = useRef({ text: '', at: 0 })
|
|
66
66
|
const { mounted, state } = usePresence(open, 'morph-out')
|
|
67
67
|
const floating = useFloating(anchorRef, menuRef, { open: mounted, side: 'bottom', align, offset: 6 })
|
|
68
68
|
// The menu grows out of its button and folds back into it.
|
|
@@ -76,12 +76,9 @@ export function DropdownMenu({ trigger, items, label, align = 'start' }: Dropdow
|
|
|
76
76
|
}
|
|
77
77
|
useDismiss(open, [anchorRef, menuRef], (reason) => close(reason === 'escape'))
|
|
78
78
|
|
|
79
|
-
const menuItems = () =>
|
|
80
|
-
Array.from(menuRef.current?.querySelectorAll<HTMLElement>('[role="menuitem"]:not([aria-disabled="true"])') ?? [])
|
|
81
|
-
|
|
82
79
|
useEffect(() => {
|
|
83
80
|
if (!open) return
|
|
84
|
-
const list = menuItems()
|
|
81
|
+
const list = menuItems(menuRef.current)
|
|
85
82
|
;(focusAt === 'first' ? list[0] : list[list.length - 1])?.focus({ preventScroll: true })
|
|
86
83
|
}, [open, focusAt])
|
|
87
84
|
|
|
@@ -90,33 +87,11 @@ export function DropdownMenu({ trigger, items, label, align = 'start' }: Dropdow
|
|
|
90
87
|
setOpen(true)
|
|
91
88
|
}
|
|
92
89
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
list[(n + list.length) % list.length]?.focus()
|
|
99
|
-
}
|
|
100
|
-
if (e.key === 'ArrowDown') go(i + 1)
|
|
101
|
-
else if (e.key === 'ArrowUp') go(i - 1)
|
|
102
|
-
else if (e.key === 'Home') go(0)
|
|
103
|
-
else if (e.key === 'End') go(list.length - 1)
|
|
104
|
-
// The menu is portalled, so focus goes back to the trigger and Tab carries on from there.
|
|
105
|
-
else if (e.key === 'Tab') close()
|
|
106
|
-
else if (e.key.length === 1 && /\S/.test(e.key)) {
|
|
107
|
-
const now = Date.now()
|
|
108
|
-
const t = typeahead.current
|
|
109
|
-
t.text = now - t.at > 600 ? e.key.toLowerCase() : t.text + e.key.toLowerCase()
|
|
110
|
-
t.at = now
|
|
111
|
-
for (let n = 1; n <= list.length; n++) {
|
|
112
|
-
const el = list[(i + n) % list.length]
|
|
113
|
-
if (el.textContent?.trim().toLowerCase().startsWith(t.text)) {
|
|
114
|
-
el.focus()
|
|
115
|
-
break
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
}
|
|
90
|
+
// Arrows, Home, End, type-ahead and Tab (motion/menuKeys.ts).
|
|
91
|
+
const closeRef = useRef(close)
|
|
92
|
+
closeRef.current = close
|
|
93
|
+
const keys = useRef<ReturnType<typeof createMenuKeys>>(null)
|
|
94
|
+
keys.current ??= createMenuKeys(() => menuRef.current, () => closeRef.current())
|
|
120
95
|
|
|
121
96
|
if (!isValidElement(trigger)) return null
|
|
122
97
|
const tp = trigger.props
|
|
@@ -139,13 +114,8 @@ export function DropdownMenu({ trigger, items, label, align = 'start' }: Dropdow
|
|
|
139
114
|
},
|
|
140
115
|
onKeyDown: (e: KeyboardEvent<HTMLElement>) => {
|
|
141
116
|
tp.onKeyDown?.(e)
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
openMenu('first')
|
|
145
|
-
} else if (e.key === 'ArrowUp') {
|
|
146
|
-
e.preventDefault()
|
|
147
|
-
openMenu('last')
|
|
148
|
-
}
|
|
117
|
+
const at = menuButtonKey(e)
|
|
118
|
+
if (at) openMenu(at)
|
|
149
119
|
},
|
|
150
120
|
} as TriggerProps)}
|
|
151
121
|
{mounted && (
|
|
@@ -160,7 +130,7 @@ export function DropdownMenu({ trigger, items, label, align = 'start' }: Dropdow
|
|
|
160
130
|
data-state={state}
|
|
161
131
|
data-side={floating.side}
|
|
162
132
|
style={floating.style}
|
|
163
|
-
onKeyDown={
|
|
133
|
+
onKeyDown={keys.current}
|
|
164
134
|
>
|
|
165
135
|
{items.map((item, i) => {
|
|
166
136
|
if (item.type === 'separator') return <div key={i} role="separator" className={styles.separator} />
|
|
@@ -187,12 +157,7 @@ export function DropdownMenu({ trigger, items, label, align = 'start' }: Dropdow
|
|
|
187
157
|
close()
|
|
188
158
|
item.onSelect?.()
|
|
189
159
|
}}
|
|
190
|
-
onKeyDown={
|
|
191
|
-
if (e.key === 'Enter' || e.key === ' ') {
|
|
192
|
-
e.preventDefault()
|
|
193
|
-
e.currentTarget.click()
|
|
194
|
-
}
|
|
195
|
-
}}
|
|
160
|
+
onKeyDown={itemKey}
|
|
196
161
|
>
|
|
197
162
|
{item.icon && <span className={styles.icon}>{item.icon}</span>}
|
|
198
163
|
<span className={styles.label}>
|