gooee 0.50.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 -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,53 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed, ref } from 'vue'
|
|
3
|
+
import Input from '../Input/Input.vue'
|
|
4
|
+
import styles from './PasswordInput.module.css'
|
|
5
|
+
|
|
6
|
+
// The Vue PasswordInput: an Input with a show and hide toggle, the same look (PasswordInput.module.css) as the React one.
|
|
7
|
+
// Every Input prop and attribute passes through; autocomplete defaults to current-password.
|
|
8
|
+
const props = withDefaults(
|
|
9
|
+
defineProps<{
|
|
10
|
+
/** Always required. A placeholder is only an example, never the label. */
|
|
11
|
+
label: string
|
|
12
|
+
/** Start with the password shown, when there is no v-model:visible. */
|
|
13
|
+
defaultVisible?: boolean
|
|
14
|
+
/** Name of the toggle. It stays the same; aria-pressed says whether it is on. */
|
|
15
|
+
toggleLabel?: string
|
|
16
|
+
disabled?: boolean
|
|
17
|
+
}>(),
|
|
18
|
+
{ defaultVisible: false, toggleLabel: 'Show password' },
|
|
19
|
+
)
|
|
20
|
+
/** The text, passed to the Input. */
|
|
21
|
+
const model = defineModel<string>()
|
|
22
|
+
/** Whether the password shows as plain text. Use v-model:visible, or leave it out and the field keeps its own state. */
|
|
23
|
+
const visibleModel = defineModel<boolean | undefined>('visible', { default: undefined })
|
|
24
|
+
const inner = ref(props.defaultVisible)
|
|
25
|
+
const visible = computed(() => visibleModel.value ?? inner.value)
|
|
26
|
+
const toggle = () => {
|
|
27
|
+
inner.value = !visible.value
|
|
28
|
+
visibleModel.value = !visible.value
|
|
29
|
+
}
|
|
30
|
+
</script>
|
|
31
|
+
|
|
32
|
+
<template>
|
|
33
|
+
<Input
|
|
34
|
+
v-model="model"
|
|
35
|
+
:label="label"
|
|
36
|
+
:class="styles.root"
|
|
37
|
+
:type="visible ? 'text' : 'password'"
|
|
38
|
+
autocomplete="current-password"
|
|
39
|
+
spellcheck="false"
|
|
40
|
+
autocapitalize="off"
|
|
41
|
+
:disabled="disabled"
|
|
42
|
+
>
|
|
43
|
+
<template #trailing>
|
|
44
|
+
<button type="button" :class="styles.toggle" :aria-label="toggleLabel" :aria-pressed="visible" :disabled="disabled" @click="toggle">
|
|
45
|
+
<svg viewBox="0 0 24 24" :class="styles.eye" :data-open="visible || undefined" aria-hidden="true" focusable="false">
|
|
46
|
+
<path :class="styles.lid" d="M2.5 12s3.5-6.5 9.5-6.5 9.5 6.5 9.5 6.5-3.5 6.5-9.5 6.5S2.5 12 2.5 12z" />
|
|
47
|
+
<circle :class="styles.pupil" cx="12" cy="12" r="2.75" />
|
|
48
|
+
<path :class="styles.slash" d="M4 4l16 16" pathLength="1" />
|
|
49
|
+
</svg>
|
|
50
|
+
</button>
|
|
51
|
+
</template>
|
|
52
|
+
</Input>
|
|
53
|
+
</template>
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed, ref } from 'vue'
|
|
3
|
+
import { dateWheel, today } from '../../internal/motion/pickerWheel'
|
|
4
|
+
import PickerWheel from './PickerWheel.vue'
|
|
5
|
+
|
|
6
|
+
// PickerWheel set up for a date: day, month and year, with each month's real length (the Vue DateWheel).
|
|
7
|
+
// Other props (detail, haptics) go to the PickerWheel.
|
|
8
|
+
|
|
9
|
+
const props = defineProps<{
|
|
10
|
+
/** Visible name of the whole wheel, read by screen readers as the group's name. */
|
|
11
|
+
label: string
|
|
12
|
+
/** Starting date when there is no v-model. Undefined starts today. */
|
|
13
|
+
defaultValue?: string
|
|
14
|
+
/** The first year on the wheel. Undefined is 100 years ago. */
|
|
15
|
+
fromYear?: number
|
|
16
|
+
/** The last year on the wheel. Undefined is 10 years from now. */
|
|
17
|
+
toYear?: number
|
|
18
|
+
/** Dates, as "YYYY-MM-DD", drawn stronger. Undefined is today. */
|
|
19
|
+
strong?: string[]
|
|
20
|
+
}>()
|
|
21
|
+
const emit = defineEmits<{ /** The date in the band while the wheel still turns, as "YYYY-MM-DD". */ scrub: [value: string] }>()
|
|
22
|
+
|
|
23
|
+
const now = today()
|
|
24
|
+
/** The date as "YYYY-MM-DD", set once the wheel comes to rest. Use v-model, or leave it out and the wheel keeps its own date. */
|
|
25
|
+
const model = defineModel<string>()
|
|
26
|
+
const local = ref(props.defaultValue ?? now)
|
|
27
|
+
const value = computed({
|
|
28
|
+
get: () => model.value ?? local.value,
|
|
29
|
+
set: (next: string) => {
|
|
30
|
+
local.value = next
|
|
31
|
+
model.value = next
|
|
32
|
+
},
|
|
33
|
+
})
|
|
34
|
+
const wheel = computed(() => dateWheel(value.value, now, props.fromYear, props.toYear, props.strong))
|
|
35
|
+
</script>
|
|
36
|
+
|
|
37
|
+
<template>
|
|
38
|
+
<PickerWheel
|
|
39
|
+
:label="label"
|
|
40
|
+
:columns="wheel.columns"
|
|
41
|
+
:model-value="wheel.rows"
|
|
42
|
+
:format-value="wheel.show"
|
|
43
|
+
@update:model-value="(rows) => rows && (value = wheel.toDate(rows))"
|
|
44
|
+
@scrub="emit('scrub', wheel.toDate($event))"
|
|
45
|
+
>
|
|
46
|
+
<template v-for="(_, name) in $slots" #[name]><slot :name="name" /></template>
|
|
47
|
+
</PickerWheel>
|
|
48
|
+
</template>
|
|
@@ -3,22 +3,12 @@
|
|
|
3
3
|
import { useEffect, useId, useLayoutEffect, useRef, useState, type ComponentPropsWithRef, type ReactNode } from 'react'
|
|
4
4
|
import { cx } from '../../internal/cx'
|
|
5
5
|
import { clamp, pull, wheelSteps, wrap } from '../../internal/feel'
|
|
6
|
+
import { columnScrub, columnState, dateWheel, drumRows, timeWheel, today, type ColumnState, type WheelColumn } from '../../internal/motion/pickerWheel'
|
|
6
7
|
import { useControllable } from '../../internal/useControllable'
|
|
7
8
|
import { ink, tokenNumber, useOnChange, useScrub } from '../../internal/useScrub'
|
|
8
9
|
import styles from './PickerWheel.module.css'
|
|
9
10
|
|
|
10
|
-
export type PickerWheelColumn =
|
|
11
|
-
/** Name screen readers hear for this column, such as "Hour". */
|
|
12
|
-
label: string
|
|
13
|
-
/** The rows, top to bottom. */
|
|
14
|
-
options: string[]
|
|
15
|
-
/** The last row runs on into the first, as hours do. */
|
|
16
|
-
loop?: boolean
|
|
17
|
-
/** Rows, by index, drawn stronger, such as :00 and :30, or today. Page Up and Page Down jump between them. */
|
|
18
|
-
strong?: number[]
|
|
19
|
-
/** Twice as wide, for words such as month names. */
|
|
20
|
-
wide?: boolean
|
|
21
|
-
}
|
|
11
|
+
export type PickerWheelColumn = WheelColumn
|
|
22
12
|
|
|
23
13
|
export type PickerWheelProps = Omit<ComponentPropsWithRef<'div'>, 'defaultValue' | 'onChange' | 'children'> & {
|
|
24
14
|
/** Visible name of the whole wheel, read by screen readers as the group's name. */
|
|
@@ -41,9 +31,6 @@ export type PickerWheelProps = Omit<ComponentPropsWithRef<'div'>, 'defaultValue'
|
|
|
41
31
|
haptics?: boolean
|
|
42
32
|
}
|
|
43
33
|
|
|
44
|
-
// Rows drawn either side of the band. At the tilt token's 18 degrees a row this far round is nearly edge on.
|
|
45
|
-
const SPAN = 4
|
|
46
|
-
|
|
47
34
|
type ColumnProps = {
|
|
48
35
|
column: PickerWheelColumn
|
|
49
36
|
index: number
|
|
@@ -57,71 +44,23 @@ function Column({ column, index, onChange, onShown, haptics }: ColumnProps) {
|
|
|
57
44
|
const { options, loop = false } = column
|
|
58
45
|
const n = options.length
|
|
59
46
|
const strong = new Set(column.strong ?? [])
|
|
60
|
-
const
|
|
61
|
-
|
|
47
|
+
const state = useRef<ColumnState>(null)
|
|
48
|
+
state.current ??= columnState(index)
|
|
49
|
+
const st = state.current
|
|
62
50
|
const wheel = useRef(wheelSteps())
|
|
63
|
-
// In a loop the position runs on past the last row; the row shown is the position folded into the list.
|
|
64
|
-
const nearest = (t: number, i: number) => (loop ? Math.round(t) + ((((i - wrap(Math.round(t), n)) % n) + n + Math.floor(n / 2)) % n) - Math.floor(n / 2) : i)
|
|
65
|
-
const fit = (v: number) => (loop ? v : clamp(v, 0, n - 1))
|
|
66
|
-
const rested = useRef(index)
|
|
67
|
-
const strongFrom = (t: number, dir: 1 | -1) => {
|
|
68
|
-
const i = wrap(Math.round(t), n)
|
|
69
|
-
for (let d = 1; d < n; d++) if (strong.has(wrap(i + dir * d, n)) && (loop || (i + dir * d >= 0 && i + dir * d < n))) return fit(Math.round(t) + dir * d)
|
|
70
|
-
return fit(Math.round(t) + dir * 5)
|
|
71
|
-
}
|
|
72
51
|
|
|
52
|
+
// The keys, tap and wheel of one column (motion/pickerWheel.ts) on the shared scrubber.
|
|
73
53
|
const sc = useScrub({
|
|
74
|
-
|
|
75
|
-
min: loop ? undefined : 0,
|
|
76
|
-
max: loop ? undefined : n - 1,
|
|
77
|
-
edge: 0.6,
|
|
78
|
-
land: (p) => fit(Math.round(p)),
|
|
79
|
-
maxSpeed: 40,
|
|
80
|
-
move: (e, last) => -(e.clientY - last.y) / (row.current || 1),
|
|
81
|
-
// The APG spinbutton keys: Up is the next, higher value and Down the one before.
|
|
82
|
-
key: (k, t) => {
|
|
83
|
-
if (k === 'ArrowUp') return fit(Math.round(t) + 1)
|
|
84
|
-
if (k === 'ArrowDown') return fit(Math.round(t) - 1)
|
|
85
|
-
if (k === 'PageUp') return strongFrom(t, 1)
|
|
86
|
-
if (k === 'PageDown') return strongFrom(t, -1)
|
|
87
|
-
if (k === 'Home') return nearest(t, 0)
|
|
88
|
-
if (k === 'End') return nearest(t, n - 1)
|
|
89
|
-
if (k.length === 1 && /\S/.test(k)) {
|
|
90
|
-
const now = performance.now()
|
|
91
|
-
typed.current = { text: (now - typed.current.at < 800 ? typed.current.text : '') + k.toLowerCase(), at: now }
|
|
92
|
-
const q = typed.current.text
|
|
93
|
-
// A padded number answers to its plain digits, so "5" finds "05" before "50".
|
|
94
|
-
const said = (o: string) => (/^\d+$/.test(o) ? String(Number(o)) : o.toLowerCase())
|
|
95
|
-
const exact = options.findIndex((o) => o.toLowerCase() === q || said(o) === q)
|
|
96
|
-
const hit = exact >= 0 ? exact : options.findIndex((o) => o.toLowerCase().startsWith(q))
|
|
97
|
-
return hit >= 0 ? nearest(t, hit) : null
|
|
98
|
-
}
|
|
99
|
-
return null
|
|
100
|
-
},
|
|
101
|
-
tap: (e, at) => {
|
|
102
|
-
const r = e.currentTarget.getBoundingClientRect()
|
|
103
|
-
const tilt = (tokenNumber(e.currentTarget, '--gooee-wheel-tilt') * Math.PI) / 180
|
|
104
|
-
const radius = row.current / 2 / Math.tan(tilt / 2)
|
|
105
|
-
const dy = e.clientY - (r.top + r.height / 2)
|
|
106
|
-
if (!tilt || !radius) return null
|
|
107
|
-
return fit(Math.round(at + Math.asin(clamp(dy / radius, -1, 1)) / tilt))
|
|
108
|
-
},
|
|
109
|
-
// Only a focused column takes the wheel, and at an end it lets the page scroll on.
|
|
110
|
-
wheel: (e, t, focused) => {
|
|
111
|
-
if (!focused || !e.deltaY) return null
|
|
112
|
-
const dir = Math.sign(e.deltaY)
|
|
113
|
-
if (!loop && ((dir > 0 && t >= n - 1) || (dir < 0 && t <= 0))) return null
|
|
114
|
-
return fit(t + wheel.current(e.deltaY * (e.deltaMode === 1 ? 40 : 1)))
|
|
115
|
-
},
|
|
54
|
+
...columnScrub(column, index, st, wheel.current),
|
|
116
55
|
onSettle: (to) => {
|
|
117
|
-
rested
|
|
56
|
+
st.rested = to
|
|
118
57
|
onChange(wrap(to, n))
|
|
119
58
|
},
|
|
120
59
|
haptics,
|
|
121
60
|
})
|
|
122
61
|
|
|
123
62
|
useLayoutEffect(() => {
|
|
124
|
-
row
|
|
63
|
+
st.row = tokenNumber(sc.ref.current, '--gooee-hit-min')
|
|
125
64
|
}, [sc.ref])
|
|
126
65
|
|
|
127
66
|
// The list got shorter (31 days to 30): stay on the last row instead of jumping.
|
|
@@ -130,22 +69,18 @@ function Column({ column, index, onChange, onShown, haptics }: ColumnProps) {
|
|
|
130
69
|
if (lastN.current === n) return
|
|
131
70
|
const i = Math.min(wrap(Math.round(sc.target()), lastN.current), n - 1)
|
|
132
71
|
lastN.current = n
|
|
133
|
-
rested
|
|
72
|
+
st.rested = i
|
|
134
73
|
sc.place(i)
|
|
135
74
|
}, [n, sc])
|
|
136
75
|
|
|
137
|
-
const settled = wrap(Math.round(rested
|
|
76
|
+
const settled = wrap(Math.round(st.rested), n)
|
|
138
77
|
const shown = wrap(Math.round(sc.at), n)
|
|
139
78
|
const told = useRef(onShown)
|
|
140
79
|
told.current = onShown
|
|
141
80
|
useEffect(() => told.current(shown), [shown])
|
|
142
81
|
|
|
143
82
|
const grip = pull(sc.at - Math.round(sc.at), 0.5)
|
|
144
|
-
const rows
|
|
145
|
-
for (let k = Math.floor(sc.at) - SPAN; k <= Math.ceil(sc.at) + SPAN; k++) {
|
|
146
|
-
if (!loop && (k < 0 || k > n - 1)) continue
|
|
147
|
-
rows.push({ k, d: k - sc.at, i: wrap(k, n) })
|
|
148
|
-
}
|
|
83
|
+
const rows = drumRows(sc.at, n, loop)
|
|
149
84
|
|
|
150
85
|
return (
|
|
151
86
|
<div
|
|
@@ -218,8 +153,6 @@ export function PickerWheel({ label, columns, value: valueProp, defaultValue, on
|
|
|
218
153
|
)
|
|
219
154
|
}
|
|
220
155
|
|
|
221
|
-
const pad = (v: number) => String(v).padStart(2, '0')
|
|
222
|
-
|
|
223
156
|
export type TimeWheelProps = Omit<PickerWheelProps, 'columns' | 'value' | 'defaultValue' | 'onValueChange' | 'onScrub' | 'formatValue'> & {
|
|
224
157
|
/** The time as "HH:mm" in 24 hours, when you control it. */
|
|
225
158
|
value?: string
|
|
@@ -240,38 +173,10 @@ export type TimeWheelProps = Omit<PickerWheelProps, 'columns' | 'value' | 'defau
|
|
|
240
173
|
/** PickerWheel set up for a time: hour, minute and, on a 12 hour clock, AM or PM. */
|
|
241
174
|
export function TimeWheel({ value: valueProp, defaultValue = '09:00', onValueChange, onScrub, hourCycle = 12, minuteStep = 1, strong = [0, 30], ...rest }: TimeWheelProps) {
|
|
242
175
|
const [value, setValue] = useControllable(valueProp, defaultValue, onValueChange)
|
|
243
|
-
const
|
|
244
|
-
const minutes = Array.from({ length: Math.ceil(60 / minuteStep) }, (_, i) => i * minuteStep)
|
|
245
|
-
const columns: PickerWheelColumn[] = [
|
|
246
|
-
{ label: 'Hour', options: twelve ? Array.from({ length: 12 }, (_, i) => String(i + 1)) : Array.from({ length: 24 }, (_, i) => pad(i)), loop: true },
|
|
247
|
-
{ label: 'Minute', options: minutes.map(pad), loop: true, strong: strong.map((m) => minutes.indexOf(m)).filter((i) => i >= 0) },
|
|
248
|
-
...(twelve ? [{ label: 'AM or PM', options: ['AM', 'PM'] }] : []),
|
|
249
|
-
]
|
|
250
|
-
const toRows = (hhmm: string) => {
|
|
251
|
-
const [h = 0, m = 0] = hhmm.split(':').map(Number)
|
|
252
|
-
const mi = clamp(Math.round(m / minuteStep), 0, minutes.length - 1)
|
|
253
|
-
return twelve ? [(h % 12 || 12) - 1, mi, h >= 12 ? 1 : 0] : [h, mi]
|
|
254
|
-
}
|
|
255
|
-
const toTime = (rows: number[]) => {
|
|
256
|
-
const h = twelve ? ((rows[0] + 1) % 12) + (rows[2] ? 12 : 0) : rows[0]
|
|
257
|
-
return `${pad(h)}:${pad(minutes[rows[1]])}`
|
|
258
|
-
}
|
|
259
|
-
const show = (rows: number[]) => (twelve ? `${rows[0] + 1}:${pad(minutes[rows[1]])} ${rows[2] ? 'PM' : 'AM'}` : `${pad(rows[0])}:${pad(minutes[rows[1]])}`)
|
|
176
|
+
const { columns, toRows, toTime, show } = timeWheel(hourCycle, minuteStep, strong)
|
|
260
177
|
return <PickerWheel {...rest} columns={columns} value={toRows(value)} onValueChange={(rows) => setValue(toTime(rows))} onScrub={onScrub && ((rows) => onScrub(toTime(rows)))} formatValue={show} />
|
|
261
178
|
}
|
|
262
179
|
|
|
263
|
-
const MONTHS = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
|
|
264
|
-
const daysIn = (month: number, year: number) => new Date(year, month + 1, 0).getDate()
|
|
265
|
-
const iso = (y: number, m: number, d: number) => `${y}-${pad(m + 1)}-${pad(d)}`
|
|
266
|
-
const parse = (s: string) => {
|
|
267
|
-
const [y, m, d] = s.split('-').map(Number)
|
|
268
|
-
return { y, m: m - 1, d }
|
|
269
|
-
}
|
|
270
|
-
const today = () => {
|
|
271
|
-
const t = new Date()
|
|
272
|
-
return iso(t.getFullYear(), t.getMonth(), t.getDate())
|
|
273
|
-
}
|
|
274
|
-
|
|
275
180
|
export type DateWheelProps = Omit<PickerWheelProps, 'columns' | 'value' | 'defaultValue' | 'onValueChange' | 'onScrub' | 'formatValue'> & {
|
|
276
181
|
/** The date as "YYYY-MM-DD", when you control it. */
|
|
277
182
|
value?: string
|
|
@@ -293,31 +198,12 @@ export type DateWheelProps = Omit<PickerWheelProps, 'columns' | 'value' | 'defau
|
|
|
293
198
|
export function DateWheel({ value: valueProp, defaultValue, onValueChange, onScrub, fromYear, toYear, strong, ...rest }: DateWheelProps) {
|
|
294
199
|
const now = today()
|
|
295
200
|
const [value, setValue] = useControllable(valueProp, defaultValue ?? now, onValueChange)
|
|
296
|
-
const
|
|
297
|
-
const last = toYear ?? parse(now).y + 10
|
|
298
|
-
const years = Array.from({ length: Math.max(1, last - first + 1) }, (_, i) => first + i)
|
|
299
|
-
const at = parse(value)
|
|
300
|
-
const y = clamp(at.y, first, last)
|
|
301
|
-
const count = daysIn(at.m, y)
|
|
302
|
-
const marks = (strong ?? [now]).map(parse)
|
|
303
|
-
const columns: PickerWheelColumn[] = [
|
|
304
|
-
{ label: 'Day', options: Array.from({ length: count }, (_, i) => String(i + 1)), loop: true, strong: marks.filter((s) => s.y === y && s.m === at.m).map((s) => s.d - 1) },
|
|
305
|
-
{ label: 'Month', options: MONTHS, loop: true, wide: true, strong: marks.filter((s) => s.y === y).map((s) => s.m) },
|
|
306
|
-
{ label: 'Year', options: years.map(String), strong: marks.map((s) => years.indexOf(s.y)).filter((i) => i >= 0) },
|
|
307
|
-
]
|
|
308
|
-
const toDate = (rows: number[]) => {
|
|
309
|
-
const yy = years[rows[2]]
|
|
310
|
-
return iso(yy, rows[1], Math.min(rows[0] + 1, daysIn(rows[1], yy)))
|
|
311
|
-
}
|
|
312
|
-
const show = (rows: number[]) => {
|
|
313
|
-
const p = parse(toDate(rows))
|
|
314
|
-
return new Date(p.y, p.m, p.d).toLocaleDateString('en-GB', { weekday: 'short', day: 'numeric', month: 'short', year: 'numeric' })
|
|
315
|
-
}
|
|
201
|
+
const { columns, rows, toDate, show } = dateWheel(value, now, fromYear, toYear, strong)
|
|
316
202
|
return (
|
|
317
203
|
<PickerWheel
|
|
318
204
|
{...rest}
|
|
319
205
|
columns={columns}
|
|
320
|
-
value={
|
|
206
|
+
value={rows}
|
|
321
207
|
onValueChange={(rows) => setValue(toDate(rows))}
|
|
322
208
|
onScrub={onScrub && ((rows) => onScrub(toDate(rows)))}
|
|
323
209
|
formatValue={show}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed, ref, useId, useSlots, watch } from 'vue'
|
|
3
|
+
import { clamp } from '../../internal/feel'
|
|
4
|
+
import type { WheelColumn as PickerWheelColumn } from '../../internal/motion/pickerWheel'
|
|
5
|
+
import WheelColumn from './WheelColumn.vue'
|
|
6
|
+
import styles from './PickerWheel.module.css'
|
|
7
|
+
|
|
8
|
+
// The Vue PickerWheel: the same look (PickerWheel.module.css), drag, coast and landing as the React one.
|
|
9
|
+
|
|
10
|
+
export type { PickerWheelColumn }
|
|
11
|
+
|
|
12
|
+
const props = withDefaults(
|
|
13
|
+
defineProps<{
|
|
14
|
+
/** Visible name of the whole wheel, read by screen readers as the group's name. */
|
|
15
|
+
label: string
|
|
16
|
+
/** The columns, left to right. */
|
|
17
|
+
columns: PickerWheelColumn[]
|
|
18
|
+
/** Starting rows when there is no v-model. Undefined starts on the first row of each. */
|
|
19
|
+
defaultValue?: number[]
|
|
20
|
+
/** Turns the rows into a large readout above the wheel. No readout when left out. */
|
|
21
|
+
formatValue?: (value: number[]) => string
|
|
22
|
+
/** A line under the label and readout, such as what the choice means. The detail slot replaces it. */
|
|
23
|
+
detail?: string
|
|
24
|
+
/** A short buzz on each row while it turns, on phones that can (Android). */
|
|
25
|
+
haptics?: boolean
|
|
26
|
+
}>(),
|
|
27
|
+
{ haptics: false },
|
|
28
|
+
)
|
|
29
|
+
const emit = defineEmits<{ /** The rows in the band while the wheel still turns. */ scrub: [value: number[]] }>()
|
|
30
|
+
const slots = useSlots()
|
|
31
|
+
|
|
32
|
+
/** The chosen row of each column, set once a column comes to rest. Use v-model, or leave it out and the wheel keeps its own rows. */
|
|
33
|
+
const model = defineModel<number[]>()
|
|
34
|
+
const local = ref(props.defaultValue ?? props.columns.map(() => 0))
|
|
35
|
+
const raw = computed({
|
|
36
|
+
get: () => model.value ?? local.value,
|
|
37
|
+
set: (next: number[]) => {
|
|
38
|
+
local.value = next
|
|
39
|
+
model.value = next
|
|
40
|
+
},
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
const labelId = useId()
|
|
44
|
+
const detailId = useId()
|
|
45
|
+
const value = computed(() => props.columns.map((c, i) => clamp(raw.value[i] ?? 0, 0, c.options.length - 1)))
|
|
46
|
+
// The rows as last set, so two columns that settle at once both count.
|
|
47
|
+
let latest = value.value
|
|
48
|
+
watch(value, (v) => (latest = v), { flush: 'sync' })
|
|
49
|
+
const onChange = (i: number, row: number) => {
|
|
50
|
+
if (latest[i] === row) return
|
|
51
|
+
const next = latest.map((v, j) => (j === i ? row : v))
|
|
52
|
+
latest = next
|
|
53
|
+
raw.value = next
|
|
54
|
+
}
|
|
55
|
+
const live = ref(value.value)
|
|
56
|
+
const onShown = (i: number, row: number) => {
|
|
57
|
+
if (live.value[i] !== row) live.value = live.value.map((v, j) => (j === i ? row : v))
|
|
58
|
+
}
|
|
59
|
+
watch(
|
|
60
|
+
() => live.value.join(','),
|
|
61
|
+
() => emit('scrub', live.value),
|
|
62
|
+
)
|
|
63
|
+
const hasDetail = computed(() => !!(props.detail || slots.detail))
|
|
64
|
+
</script>
|
|
65
|
+
|
|
66
|
+
<template>
|
|
67
|
+
<div :class="styles.root">
|
|
68
|
+
<div :class="styles.head">
|
|
69
|
+
<span :id="labelId" :class="styles.label">{{ label }}</span>
|
|
70
|
+
<span v-if="formatValue" :class="styles.readout">{{ formatValue(live) }}</span>
|
|
71
|
+
<span v-if="hasDetail" :id="detailId" :class="styles.detail"><slot name="detail">{{ detail }}</slot></span>
|
|
72
|
+
</div>
|
|
73
|
+
<div :class="styles.wheel" role="group" :aria-labelledby="labelId" :aria-describedby="hasDetail ? detailId : undefined">
|
|
74
|
+
<WheelColumn v-for="(c, i) in columns" :key="i" :column="c" :index="value[i]" :haptics="haptics" @change="onChange(i, $event)" @shown="onShown(i, $event)" />
|
|
75
|
+
</div>
|
|
76
|
+
</div>
|
|
77
|
+
</template>
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed, ref } from 'vue'
|
|
3
|
+
import { timeWheel } from '../../internal/motion/pickerWheel'
|
|
4
|
+
import PickerWheel from './PickerWheel.vue'
|
|
5
|
+
|
|
6
|
+
// PickerWheel set up for a time: hour, minute and, on a 12 hour clock, AM or PM (the Vue TimeWheel).
|
|
7
|
+
// Other props (detail, haptics) go to the PickerWheel.
|
|
8
|
+
|
|
9
|
+
const props = withDefaults(
|
|
10
|
+
defineProps<{
|
|
11
|
+
/** Visible name of the whole wheel, read by screen readers as the group's name. */
|
|
12
|
+
label: string
|
|
13
|
+
/** Starting time when there is no v-model. */
|
|
14
|
+
defaultValue?: string
|
|
15
|
+
/** 12 shows AM and PM; 24 shows hours 00 to 23. */
|
|
16
|
+
hourCycle?: 12 | 24
|
|
17
|
+
/** Minutes between two rows. */
|
|
18
|
+
minuteStep?: number
|
|
19
|
+
/** Minutes drawn stronger. Page Up and Page Down jump between them. */
|
|
20
|
+
strong?: number[]
|
|
21
|
+
}>(),
|
|
22
|
+
{ defaultValue: '09:00', hourCycle: 12, minuteStep: 1, strong: () => [0, 30] },
|
|
23
|
+
)
|
|
24
|
+
const emit = defineEmits<{ /** The time in the band while the wheel still turns, as "HH:mm". */ scrub: [value: string] }>()
|
|
25
|
+
|
|
26
|
+
/** The time as "HH:mm" in 24 hours, set once the wheel comes to rest. Use v-model, or leave it out and the wheel keeps its own time. */
|
|
27
|
+
const model = defineModel<string>()
|
|
28
|
+
const local = ref(props.defaultValue)
|
|
29
|
+
const value = computed({
|
|
30
|
+
get: () => model.value ?? local.value,
|
|
31
|
+
set: (next: string) => {
|
|
32
|
+
local.value = next
|
|
33
|
+
model.value = next
|
|
34
|
+
},
|
|
35
|
+
})
|
|
36
|
+
const wheel = computed(() => timeWheel(props.hourCycle, props.minuteStep, props.strong))
|
|
37
|
+
</script>
|
|
38
|
+
|
|
39
|
+
<template>
|
|
40
|
+
<PickerWheel
|
|
41
|
+
:label="label"
|
|
42
|
+
:columns="wheel.columns"
|
|
43
|
+
:model-value="wheel.toRows(value)"
|
|
44
|
+
:format-value="wheel.show"
|
|
45
|
+
@update:model-value="(rows) => rows && (value = wheel.toTime(rows))"
|
|
46
|
+
@scrub="emit('scrub', wheel.toTime($event))"
|
|
47
|
+
>
|
|
48
|
+
<template v-for="(_, name) in $slots" #[name]><slot :name="name" /></template>
|
|
49
|
+
</PickerWheel>
|
|
50
|
+
</template>
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed, onMounted, reactive, watch } from 'vue'
|
|
3
|
+
import { pull, wheelSteps, wrap } from '../../internal/feel'
|
|
4
|
+
import { columnScrub, columnState, drumRows, type WheelColumn } from '../../internal/motion/pickerWheel'
|
|
5
|
+
import { ink, tokenNumber } from '../../internal/motion/scrubLook'
|
|
6
|
+
import { useScrub } from '../../internal/vue/useScrub'
|
|
7
|
+
import styles from './PickerWheel.module.css'
|
|
8
|
+
|
|
9
|
+
// One column of the Vue PickerWheel: its rows are the marks. A drag follows the hand; a let-go lands on a row.
|
|
10
|
+
|
|
11
|
+
const props = defineProps<{ column: WheelColumn; index: number; haptics: boolean }>()
|
|
12
|
+
const emit = defineEmits<{ change: [index: number]; shown: [index: number] }>()
|
|
13
|
+
|
|
14
|
+
const n = computed(() => props.column.options.length)
|
|
15
|
+
const strong = computed(() => new Set(props.column.strong ?? []))
|
|
16
|
+
const st = reactive(columnState(props.index))
|
|
17
|
+
const wheel = wheelSteps()
|
|
18
|
+
|
|
19
|
+
// The keys, tap and wheel of one column (motion/pickerWheel.ts) on the shared scrubber.
|
|
20
|
+
const sc = useScrub(() => ({
|
|
21
|
+
...columnScrub(props.column, props.index, st, wheel),
|
|
22
|
+
onSettle: (to: number) => {
|
|
23
|
+
st.rested = to
|
|
24
|
+
emit('change', wrap(to, n.value))
|
|
25
|
+
},
|
|
26
|
+
haptics: props.haptics,
|
|
27
|
+
}))
|
|
28
|
+
const scrubEl = sc.el
|
|
29
|
+
onMounted(() => (st.row = tokenNumber(scrubEl.value, '--gooee-hit-min')))
|
|
30
|
+
|
|
31
|
+
// The list got shorter (31 days to 30): stay on the last row instead of jumping.
|
|
32
|
+
watch(
|
|
33
|
+
n,
|
|
34
|
+
(now, was) => {
|
|
35
|
+
const i = Math.min(wrap(Math.round(sc.target()), was), now - 1)
|
|
36
|
+
st.rested = i
|
|
37
|
+
sc.place(i)
|
|
38
|
+
},
|
|
39
|
+
{ flush: 'post' },
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
const settled = computed(() => wrap(Math.round(st.rested), n.value))
|
|
43
|
+
const shown = computed(() => wrap(Math.round(sc.at.value), n.value))
|
|
44
|
+
watch(shown, (i) => emit('shown', i), { immediate: true })
|
|
45
|
+
|
|
46
|
+
const grip = computed(() => pull(sc.at.value - Math.round(sc.at.value), 0.5))
|
|
47
|
+
const rows = computed(() => drumRows(sc.at.value, n.value, !!props.column.loop))
|
|
48
|
+
</script>
|
|
49
|
+
|
|
50
|
+
<template>
|
|
51
|
+
<div
|
|
52
|
+
ref="scrubEl"
|
|
53
|
+
:class="styles.column"
|
|
54
|
+
role="spinbutton"
|
|
55
|
+
tabindex="0"
|
|
56
|
+
:aria-label="column.label"
|
|
57
|
+
:aria-valuenow="settled"
|
|
58
|
+
:aria-valuetext="column.options[settled]"
|
|
59
|
+
:aria-valuemin="0"
|
|
60
|
+
:aria-valuemax="n - 1"
|
|
61
|
+
:data-wide="column.wide || undefined"
|
|
62
|
+
:data-moving="sc.moving.value || undefined"
|
|
63
|
+
v-on="sc.handlers"
|
|
64
|
+
>
|
|
65
|
+
<span :class="styles.band" :style="{ '--grip': grip.toFixed(3) }" aria-hidden="true" />
|
|
66
|
+
<div :class="styles.drum" aria-hidden="true">
|
|
67
|
+
<span v-for="r in rows" :key="r.k" :class="styles.row" :data-strong="strong.has(r.i) || undefined" :style="{ '--d': r.d.toFixed(3), color: ink(pull(r.d, 1)) }">{{ column.options[r.i] }}</span>
|
|
68
|
+
</div>
|
|
69
|
+
</div>
|
|
70
|
+
</template>
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { onBeforeUnmount, ref, shallowRef, useId, watch, type VNode } from 'vue'
|
|
3
|
+
import type { Align, Side } from '../../internal/motion/floating'
|
|
4
|
+
import { trapFocus } from '../../internal/motion/focus'
|
|
5
|
+
import { dismissable } from '../../internal/motion/layers'
|
|
6
|
+
import { createLiquid } from '../../internal/motion/liquid'
|
|
7
|
+
import { useFloating } from '../../internal/vue/useFloating'
|
|
8
|
+
import { usePresence } from '../../internal/vue/usePresence'
|
|
9
|
+
import { cloneTrigger, elementRef, firstNode } from '../../internal/vue/trigger'
|
|
10
|
+
import { XIcon } from '../../internal/vueIcons'
|
|
11
|
+
import styles from './Popover.module.css'
|
|
12
|
+
|
|
13
|
+
// The Vue Popover: the same look (Popover.module.css), growth, dismiss and focus as the React one.
|
|
14
|
+
// The trigger slot is one element, such as a Button, that opens and closes it on click.
|
|
15
|
+
// Other attributes, such as class, go to the panel.
|
|
16
|
+
defineOptions({ inheritAttrs: false })
|
|
17
|
+
|
|
18
|
+
const props = withDefaults(
|
|
19
|
+
defineProps<{
|
|
20
|
+
/** Visible heading, also the dialog's accessible name. The title slot replaces it. */
|
|
21
|
+
title?: string
|
|
22
|
+
/** Preferred side of the trigger. It flips when there is no room. */
|
|
23
|
+
side?: Side
|
|
24
|
+
/** How the panel lines up with the trigger along that side. */
|
|
25
|
+
align?: Align
|
|
26
|
+
/** Label for the close button. */
|
|
27
|
+
closeLabel?: string
|
|
28
|
+
}>(),
|
|
29
|
+
{ side: 'bottom', align: 'start', closeLabel: 'Close' },
|
|
30
|
+
)
|
|
31
|
+
/** Whether the panel is open. Use v-model:open to control it; without it the popover keeps its own state. */
|
|
32
|
+
const open = defineModel<boolean>('open', { default: false })
|
|
33
|
+
const slots = defineSlots<{ trigger?: () => VNode[]; default?: () => unknown; title?: () => unknown }>()
|
|
34
|
+
|
|
35
|
+
const id = useId()
|
|
36
|
+
const anchor = shallowRef<HTMLElement | null>(null)
|
|
37
|
+
const setAnchor = elementRef(anchor)
|
|
38
|
+
const panel = ref<HTMLElement | null>(null)
|
|
39
|
+
const close = () => (open.value = false)
|
|
40
|
+
const { mounted, state } = usePresence(open, 'morph-out')
|
|
41
|
+
const { style, side: placed, ready } = useFloating(anchor, panel, mounted, () => ({ side: props.side, align: props.align, offset: 8 }))
|
|
42
|
+
// Vue sets a bare number as no length at all, so the place gets its unit here.
|
|
43
|
+
// The panel grows out of its trigger and folds back into it.
|
|
44
|
+
const liquid = createLiquid(
|
|
45
|
+
() => panel.value,
|
|
46
|
+
() => anchor.value,
|
|
47
|
+
)
|
|
48
|
+
watch([state, () => mounted.value && ready.value], ([s, on]) => on && liquid.play(s), { flush: 'post' })
|
|
49
|
+
|
|
50
|
+
let releaseDismiss = () => {}
|
|
51
|
+
watch(open, (now) => {
|
|
52
|
+
releaseDismiss()
|
|
53
|
+
releaseDismiss = now ? dismissable(() => [anchor.value, panel.value], close) : () => {}
|
|
54
|
+
})
|
|
55
|
+
// Focus moves in while it is open, and goes back when it closes.
|
|
56
|
+
let releaseTrap = () => {}
|
|
57
|
+
watch(
|
|
58
|
+
() => open.value && mounted.value,
|
|
59
|
+
(on) => {
|
|
60
|
+
releaseTrap()
|
|
61
|
+
releaseTrap = on && panel.value ? trapFocus(panel.value) : () => {}
|
|
62
|
+
},
|
|
63
|
+
{ flush: 'post' },
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
onBeforeUnmount(() => {
|
|
67
|
+
releaseDismiss()
|
|
68
|
+
releaseTrap()
|
|
69
|
+
liquid.destroy()
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
// The trigger is the slot's own element, given the popover's ARIA and click, like React's cloneElement.
|
|
73
|
+
const trigger = () => {
|
|
74
|
+
const node = firstNode(slots.trigger?.())
|
|
75
|
+
return cloneTrigger(node, setAnchor, {
|
|
76
|
+
onClick: () => (open.value = !open.value),
|
|
77
|
+
'aria-haspopup': 'dialog',
|
|
78
|
+
'aria-expanded': open.value,
|
|
79
|
+
'aria-controls': open.value ? id : undefined,
|
|
80
|
+
})
|
|
81
|
+
}
|
|
82
|
+
</script>
|
|
83
|
+
|
|
84
|
+
<template>
|
|
85
|
+
<component :is="trigger()" />
|
|
86
|
+
<Teleport v-if="mounted" to="body">
|
|
87
|
+
<div
|
|
88
|
+
v-bind="$attrs"
|
|
89
|
+
:id="id"
|
|
90
|
+
ref="panel"
|
|
91
|
+
role="dialog"
|
|
92
|
+
:aria-labelledby="`${id}-title`"
|
|
93
|
+
tabindex="-1"
|
|
94
|
+
:class="styles.panel"
|
|
95
|
+
:data-state="state"
|
|
96
|
+
:data-side="placed"
|
|
97
|
+
:style="style"
|
|
98
|
+
>
|
|
99
|
+
<div :class="styles.head">
|
|
100
|
+
<h2 :id="`${id}-title`" :class="styles.title"><slot name="title">{{ title }}</slot></h2>
|
|
101
|
+
<button type="button" :class="styles.close" :aria-label="closeLabel" data-skip-initial-focus="true" @click="close">
|
|
102
|
+
<XIcon />
|
|
103
|
+
</button>
|
|
104
|
+
</div>
|
|
105
|
+
<div :class="styles.body"><slot /></div>
|
|
106
|
+
</div>
|
|
107
|
+
</Teleport>
|
|
108
|
+
</template>
|