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,249 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed, onBeforeUnmount, onMounted, 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 { createDetentSheet, DETENT_NAME, detentHeights, detentOrder, type SheetDetent } from '../../internal/motion/sheetDetents'
|
|
7
|
+
import { usePresence } from '../../internal/vue/usePresence'
|
|
8
|
+
import { XIcon } from '../../internal/vueIcons'
|
|
9
|
+
import styles from './Sheet.module.css'
|
|
10
|
+
|
|
11
|
+
// The Vue Sheet: the same look (Sheet.module.css), drag, heights and focus as the React one.
|
|
12
|
+
// With detents, the grabber becomes a control for the height, and the sheet is modal only at its highest.
|
|
13
|
+
// Other attributes, such as class, go to the panel.
|
|
14
|
+
defineOptions({ inheritAttrs: false })
|
|
15
|
+
|
|
16
|
+
const props = withDefaults(
|
|
17
|
+
defineProps<{
|
|
18
|
+
/** Visible heading, also the dialog's accessible name. The title slot replaces it. */
|
|
19
|
+
title?: string
|
|
20
|
+
/** Text under the title, also read as the dialog's description. The description slot replaces it. */
|
|
21
|
+
description?: string
|
|
22
|
+
/** Screen reader name for the close button. */
|
|
23
|
+
closeLabel?: string
|
|
24
|
+
/** Element to focus first. Defaults to the first focusable element in the content. */
|
|
25
|
+
initialFocus?: HTMLElement | null
|
|
26
|
+
/** Heights the sheet rests at, such as ['peek', 'half', 'full']. Below the highest one it is not modal: the page behind stays usable. */
|
|
27
|
+
detents?: SheetDetent[]
|
|
28
|
+
/** The height it rests at. Use v-model:detent to control it. */
|
|
29
|
+
detent?: SheetDetent
|
|
30
|
+
/** The height it opens at when you do not control it. Defaults to the lowest. */
|
|
31
|
+
defaultDetent?: SheetDetent
|
|
32
|
+
/** Screen reader name for the grabber, which sets the height. */
|
|
33
|
+
heightLabel?: string
|
|
34
|
+
}>(),
|
|
35
|
+
{ closeLabel: 'Close', heightLabel: 'Sheet height' },
|
|
36
|
+
)
|
|
37
|
+
/** Whether the sheet is open. Use v-model:open; Esc, an outside tap, a drag or the close button set it false. */
|
|
38
|
+
const open = defineModel<boolean>('open', { required: true })
|
|
39
|
+
const emit = defineEmits<{ 'update:detent': [detent: SheetDetent] }>()
|
|
40
|
+
const slots = defineSlots<{ default?: () => unknown; title?: () => unknown; description?: () => unknown; footer?: () => unknown }>()
|
|
41
|
+
|
|
42
|
+
const id = useId()
|
|
43
|
+
const panel = ref<HTMLElement | null>(null)
|
|
44
|
+
const overlay = ref<HTMLElement | null>(null)
|
|
45
|
+
const grabber = ref<HTMLElement | null>(null)
|
|
46
|
+
const body = ref<HTMLElement | null>(null)
|
|
47
|
+
const hasDescription = computed(() => !!(props.description || slots.description))
|
|
48
|
+
const close = () => (open.value = false)
|
|
49
|
+
const { mounted, state } = usePresence(open, 'morph-out')
|
|
50
|
+
const withDetents = computed(() => !!props.detents?.length)
|
|
51
|
+
|
|
52
|
+
// On the server (Nuxt) there is no page to hold, so the watchers wait for the browser.
|
|
53
|
+
const server = typeof window === 'undefined'
|
|
54
|
+
const releases: Record<string, () => void> = {}
|
|
55
|
+
const hold = (key: string, make: (() => () => void) | false) => {
|
|
56
|
+
releases[key]?.()
|
|
57
|
+
releases[key] = make && !server ? make() : () => {}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Without detents: the hand pulls it down to close.
|
|
61
|
+
const drag = createDragClose(() => panel.value, { onClose: close, isOpen: () => open.value })
|
|
62
|
+
watch(open, (now) => {
|
|
63
|
+
if (withDetents.value) return
|
|
64
|
+
if (now) drag.fling.opened()
|
|
65
|
+
else drag.fling.closed()
|
|
66
|
+
})
|
|
67
|
+
watch(open, (now) => hold('lock', !withDetents.value && now && lockScroll), { immediate: true })
|
|
68
|
+
watch(open, (now) => hold('dismiss', !withDetents.value && now && (() => dismissable(() => [panel.value], close))), { immediate: true })
|
|
69
|
+
watch(
|
|
70
|
+
() => !withDetents.value && open.value && mounted.value,
|
|
71
|
+
(on) => hold('trap', on && !!panel.value && (() => trapFocus(panel.value!, { initialFocus: props.initialFocus }))),
|
|
72
|
+
{ flush: 'post', immediate: true },
|
|
73
|
+
)
|
|
74
|
+
const onAnimationEnd = (e: AnimationEvent) => {
|
|
75
|
+
if (e.target === panel.value && state.value === 'open') (e.target as HTMLElement).style.transform = ''
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// With detents: drag, flick, the grabber's keys and where focus goes (motion/sheetDetents.ts).
|
|
79
|
+
const order = computed(() => detentOrder(props.detents ?? []))
|
|
80
|
+
const top = computed(() => order.value.length - 1)
|
|
81
|
+
const inner = ref<SheetDetent>(props.defaultDetent ?? order.value[0])
|
|
82
|
+
const index = computed(() => Math.max(0, order.value.indexOf(props.detent ?? inner.value)))
|
|
83
|
+
const atTop = computed(() => index.value === top.value)
|
|
84
|
+
const vh = ref(server ? 0 : window.innerHeight)
|
|
85
|
+
const heights = computed(() => detentHeights(order.value, vh.value))
|
|
86
|
+
const dragging = ref(false)
|
|
87
|
+
const target = ref(index.value)
|
|
88
|
+
const said = ref('')
|
|
89
|
+
const shown = computed(() => order.value[dragging.value ? target.value : index.value])
|
|
90
|
+
|
|
91
|
+
const sheet = createDetentSheet({
|
|
92
|
+
panel: () => panel.value,
|
|
93
|
+
overlay: () => overlay.value,
|
|
94
|
+
grabber: () => grabber.value,
|
|
95
|
+
body: () => body.value,
|
|
96
|
+
order: () => order.value,
|
|
97
|
+
heights: () => heights.value,
|
|
98
|
+
index: () => index.value,
|
|
99
|
+
open: () => open.value,
|
|
100
|
+
change: (i) => {
|
|
101
|
+
if (props.detent === undefined) inner.value = order.value[i]
|
|
102
|
+
emit('update:detent', order.value[i])
|
|
103
|
+
},
|
|
104
|
+
close,
|
|
105
|
+
target: (i) => (target.value = i),
|
|
106
|
+
dragging: (on) => (dragging.value = on),
|
|
107
|
+
say: (text) => (said.value = text),
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
const onResize = () => (vh.value = window.innerHeight)
|
|
111
|
+
onMounted(() => window.addEventListener('resize', onResize))
|
|
112
|
+
|
|
113
|
+
// Before the new state renders, so the opener is read while it still has focus.
|
|
114
|
+
watch(open, (now) => withDetents.value && now && !server && sheet.opening(), { flush: 'pre', immediate: true })
|
|
115
|
+
watch(
|
|
116
|
+
[open, mounted, index, vh],
|
|
117
|
+
() => {
|
|
118
|
+
if (withDetents.value && open.value && mounted.value && !server) sheet.sync(props.initialFocus)
|
|
119
|
+
},
|
|
120
|
+
{ flush: 'post', immediate: true },
|
|
121
|
+
)
|
|
122
|
+
// Closed, it gives focus back to its opener, and opens next time at the default height.
|
|
123
|
+
watch(
|
|
124
|
+
open,
|
|
125
|
+
(now) => {
|
|
126
|
+
if (!withDetents.value || now) return
|
|
127
|
+
inner.value = props.defaultDetent ?? order.value[0]
|
|
128
|
+
sheet.closed()
|
|
129
|
+
},
|
|
130
|
+
{ flush: 'post' },
|
|
131
|
+
)
|
|
132
|
+
// At the top it is modal: focus stays where it is in the sheet, or starts on initialFocus.
|
|
133
|
+
watch(
|
|
134
|
+
() => withDetents.value && open.value && mounted.value && atTop.value,
|
|
135
|
+
(on) =>
|
|
136
|
+
hold(
|
|
137
|
+
'detentTrap',
|
|
138
|
+
on &&
|
|
139
|
+
!!panel.value &&
|
|
140
|
+
(() => {
|
|
141
|
+
const el = panel.value!
|
|
142
|
+
const active = document.activeElement as HTMLElement | null
|
|
143
|
+
return trapFocus(el, { initialFocus: active && el.contains(active) ? active : (props.initialFocus ?? null), restore: false })
|
|
144
|
+
}),
|
|
145
|
+
),
|
|
146
|
+
{ flush: 'post', immediate: true },
|
|
147
|
+
)
|
|
148
|
+
watch(
|
|
149
|
+
() => withDetents.value && open.value && atTop.value,
|
|
150
|
+
(on) => hold('detentLock', on && lockScroll),
|
|
151
|
+
{ immediate: true },
|
|
152
|
+
)
|
|
153
|
+
watch([open, atTop], () => hold('detentDismiss', withDetents.value && open.value && (() => dismissable(() => [panel.value], sheet.stepDown, { outside: atTop.value }))), { immediate: true })
|
|
154
|
+
watch(mounted, () => hold('touch', withDetents.value && !!body.value && (() => sheet.holdTouch(body.value!))), { flush: 'post', immediate: true })
|
|
155
|
+
|
|
156
|
+
onBeforeUnmount(() => {
|
|
157
|
+
Object.values(releases).forEach((r) => r())
|
|
158
|
+
drag.fling.stop()
|
|
159
|
+
sheet.destroy()
|
|
160
|
+
if (!server) window.removeEventListener('resize', onResize)
|
|
161
|
+
})
|
|
162
|
+
</script>
|
|
163
|
+
|
|
164
|
+
<template>
|
|
165
|
+
<Teleport v-if="mounted" to="body">
|
|
166
|
+
<template v-if="!withDetents">
|
|
167
|
+
<div :class="styles.overlay" :data-state="state" aria-hidden="true" />
|
|
168
|
+
<div
|
|
169
|
+
v-bind="$attrs"
|
|
170
|
+
ref="panel"
|
|
171
|
+
role="dialog"
|
|
172
|
+
aria-modal="true"
|
|
173
|
+
:aria-labelledby="`${id}-title`"
|
|
174
|
+
:aria-describedby="hasDescription ? `${id}-desc` : undefined"
|
|
175
|
+
tabindex="-1"
|
|
176
|
+
:class="styles.sheet"
|
|
177
|
+
:data-state="state"
|
|
178
|
+
@animationend="onAnimationEnd"
|
|
179
|
+
>
|
|
180
|
+
<div :class="styles.grab" @pointerdown="drag.down" @pointermove="drag.move" @pointerup="drag.up" @pointercancel="drag.up">
|
|
181
|
+
<span :class="styles.handle" aria-hidden="true" />
|
|
182
|
+
<header :class="styles.header">
|
|
183
|
+
<div :class="styles.titles">
|
|
184
|
+
<h2 :id="`${id}-title`" :class="styles.title"><slot name="title">{{ title }}</slot></h2>
|
|
185
|
+
<p v-if="hasDescription" :id="`${id}-desc`" :class="styles.description"><slot name="description">{{ description }}</slot></p>
|
|
186
|
+
</div>
|
|
187
|
+
<button type="button" :class="styles.close" :aria-label="closeLabel" data-skip-initial-focus="true" @click="close">
|
|
188
|
+
<XIcon />
|
|
189
|
+
</button>
|
|
190
|
+
</header>
|
|
191
|
+
</div>
|
|
192
|
+
<div v-if="slots.default" :class="styles.body"><slot /></div>
|
|
193
|
+
<footer v-if="slots.footer" :class="styles.footer"><slot name="footer" /></footer>
|
|
194
|
+
</div>
|
|
195
|
+
</template>
|
|
196
|
+
<template v-else>
|
|
197
|
+
<div ref="overlay" :class="styles.overlay" :data-state="state" data-detents="true" :data-top="atTop || undefined" aria-hidden="true" />
|
|
198
|
+
<div
|
|
199
|
+
v-bind="$attrs"
|
|
200
|
+
:id="`${id}-sheet`"
|
|
201
|
+
ref="panel"
|
|
202
|
+
role="dialog"
|
|
203
|
+
:aria-modal="atTop || undefined"
|
|
204
|
+
:aria-labelledby="`${id}-title`"
|
|
205
|
+
:aria-describedby="hasDescription ? `${id}-desc` : undefined"
|
|
206
|
+
tabindex="-1"
|
|
207
|
+
:class="styles.sheet"
|
|
208
|
+
:data-state="state"
|
|
209
|
+
data-detents="true"
|
|
210
|
+
:data-top="atTop || undefined"
|
|
211
|
+
:data-dragging="dragging || undefined"
|
|
212
|
+
:style="{ height: `${heights[top]}px` }"
|
|
213
|
+
@pointerdown="sheet.down"
|
|
214
|
+
@focusin="sheet.focusIn($event.target)"
|
|
215
|
+
>
|
|
216
|
+
<div
|
|
217
|
+
ref="grabber"
|
|
218
|
+
:class="styles.grabber"
|
|
219
|
+
role="slider"
|
|
220
|
+
tabindex="0"
|
|
221
|
+
:aria-label="heightLabel"
|
|
222
|
+
aria-orientation="vertical"
|
|
223
|
+
aria-valuemin="0"
|
|
224
|
+
:aria-valuemax="top"
|
|
225
|
+
:aria-valuenow="index"
|
|
226
|
+
:aria-valuetext="DETENT_NAME[order[index]]"
|
|
227
|
+
:aria-controls="`${id}-sheet`"
|
|
228
|
+
:data-detent="shown"
|
|
229
|
+
@keydown="sheet.grabKey"
|
|
230
|
+
@click="sheet.grabClick"
|
|
231
|
+
>
|
|
232
|
+
<span :class="styles.pill" />
|
|
233
|
+
</div>
|
|
234
|
+
<header :class="styles.header">
|
|
235
|
+
<div :class="styles.titles">
|
|
236
|
+
<h2 :id="`${id}-title`" :class="styles.title"><slot name="title">{{ title }}</slot></h2>
|
|
237
|
+
<p v-if="hasDescription" :id="`${id}-desc`" :class="styles.description"><slot name="description">{{ description }}</slot></p>
|
|
238
|
+
</div>
|
|
239
|
+
<button type="button" :class="styles.close" :aria-label="closeLabel" data-skip-initial-focus="true" @click="close">
|
|
240
|
+
<XIcon />
|
|
241
|
+
</button>
|
|
242
|
+
</header>
|
|
243
|
+
<div v-if="slots.default" ref="body" :class="styles.body"><slot /></div>
|
|
244
|
+
<footer v-if="slots.footer" :class="styles.footer"><slot name="footer" /></footer>
|
|
245
|
+
<p :class="styles.srOnly" aria-live="polite">{{ said }}</p>
|
|
246
|
+
</div>
|
|
247
|
+
</template>
|
|
248
|
+
</Teleport>
|
|
249
|
+
</template>
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed } from 'vue'
|
|
3
|
+
import styles from './Skeleton.module.css'
|
|
4
|
+
|
|
5
|
+
// The Vue Skeleton: the same shapes (Skeleton.module.css) as the React one.
|
|
6
|
+
// Decorative only. Mark the loading container with aria-busy and a label instead.
|
|
7
|
+
const props = withDefaults(
|
|
8
|
+
defineProps<{
|
|
9
|
+
/** Text draws lines, rect a box, circle a round shape such as an avatar. */
|
|
10
|
+
shape?: 'text' | 'rect' | 'circle'
|
|
11
|
+
/** Any CSS width, such as 120 or "50%". */
|
|
12
|
+
width?: number | string
|
|
13
|
+
/** Any CSS height. Ignored for text, where lines set the height. */
|
|
14
|
+
height?: number | string
|
|
15
|
+
/** For text: number of lines. The last one is shorter, like real text. */
|
|
16
|
+
lines?: number
|
|
17
|
+
/** Solid grey shapes, or a sketch: the same shapes as dashed outlines, like a pencil layout. */
|
|
18
|
+
variant?: 'solid' | 'sketch'
|
|
19
|
+
}>(),
|
|
20
|
+
{ shape: 'rect', lines: 1, variant: 'solid' },
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
// A number is pixels, as in React.
|
|
24
|
+
const px = (v: number | string | undefined) => (typeof v === 'number' ? `${v}px` : v)
|
|
25
|
+
const look = computed(() => props.variant === 'sketch' && styles.sketch)
|
|
26
|
+
</script>
|
|
27
|
+
|
|
28
|
+
<template>
|
|
29
|
+
<span v-if="shape === 'text'" :class="styles.lines" :style="{ width: px(width) }" aria-hidden="true">
|
|
30
|
+
<span
|
|
31
|
+
v-for="i in lines"
|
|
32
|
+
:key="i - 1"
|
|
33
|
+
:class="[styles.bone, styles.text, look]"
|
|
34
|
+
:style="{ width: lines > 1 && i === lines ? '62%' : '100%', '--i': i - 1 }"
|
|
35
|
+
/>
|
|
36
|
+
</span>
|
|
37
|
+
<span v-else :class="[styles.bone, styles[shape], look]" :style="{ width: px(width), height: px(height) }" aria-hidden="true" />
|
|
38
|
+
</template>
|
|
@@ -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>
|