gooee 0.48.0 → 0.51.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +4 -2
- package/scripts/add.js +28 -6
- package/src/components/Accordion/Accordion.vue +62 -0
- package/src/components/Accordion/AccordionItem.vue +45 -0
- package/src/components/Accordion/accordionContext.ts +6 -0
- package/src/components/Alert/Alert.tsx +7 -27
- package/src/components/Alert/Alert.vue +59 -0
- package/src/components/AlertDialog/AlertDialog.vue +126 -0
- package/src/components/AnimatedNumber/AnimatedNumber.vue +36 -0
- package/src/components/AspectRatio/AspectRatio.vue +17 -0
- package/src/components/Avatar/Avatar.vue +56 -0
- package/src/components/AvatarGroup/AvatarGroup.vue +42 -0
- package/src/components/Badge/Badge.vue +32 -0
- package/src/components/Breadcrumb/Breadcrumb.vue +58 -0
- package/src/components/Button/Button.vue +130 -0
- package/src/components/ButtonGroup/ButtonGroup.tsx +4 -21
- package/src/components/ButtonGroup/ButtonGroup.vue +33 -0
- package/src/components/Card/Card.vue +34 -0
- package/src/components/Center/Center.vue +32 -0
- package/src/components/Checkbox/Checkbox.tsx +8 -25
- package/src/components/Checkbox/Checkbox.vue +108 -0
- package/src/components/CheckboxGroup/CheckboxGroup.vue +76 -0
- package/src/components/Cluster/Cluster.vue +34 -0
- package/src/components/CodeBlock/CodeBlock.vue +45 -0
- package/src/components/Collapsible/Collapsible.vue +59 -0
- package/src/components/Container/Container.vue +22 -0
- package/src/components/CopyButton/CopyButton.tsx +3 -49
- package/src/components/CopyButton/CopyButton.vue +116 -0
- package/src/components/Dial/Dial.tsx +12 -120
- package/src/components/Dial/Dial.vue +228 -0
- package/src/components/Dialog/Dialog.vue +139 -0
- package/src/components/Divider/Divider.vue +27 -0
- package/src/components/DropdownMenu/DropdownMenu.tsx +11 -46
- package/src/components/DropdownMenu/DropdownMenu.vue +185 -0
- package/src/components/EmptyState/EmptyState.vue +33 -0
- package/src/components/Fab/Fab.tsx +4 -14
- package/src/components/Fab/Fab.vue +115 -0
- package/src/components/Fieldset/Fieldset.vue +42 -0
- package/src/components/FormField/FormField.tsx +2 -17
- package/src/components/FormField/FormField.vue +64 -0
- package/src/components/Grid/Grid.vue +43 -0
- package/src/components/HoldToConfirm/HoldToConfirm.tsx +13 -142
- package/src/components/HoldToConfirm/HoldToConfirm.vue +281 -0
- package/src/components/IconButton/IconButton.vue +25 -0
- package/src/components/Input/Input.vue +112 -0
- package/src/components/InputGroup/InputGroup.vue +102 -0
- package/src/components/Kbd/Kbd.tsx +2 -12
- package/src/components/Kbd/Kbd.vue +21 -0
- package/src/components/Link/Link.vue +38 -0
- package/src/components/LivePill/LivePill.tsx +12 -40
- package/src/components/LivePill/LivePill.vue +152 -0
- package/src/components/Meter/Meter.vue +88 -0
- package/src/components/MorphButton/MorphButton.tsx +11 -67
- package/src/components/MorphButton/MorphButton.vue +120 -0
- package/src/components/NumberInput/NumberInput.tsx +11 -48
- package/src/components/NumberInput/NumberInput.vue +184 -0
- package/src/components/Pagination/Pagination.tsx +2 -15
- package/src/components/Pagination/Pagination.vue +87 -0
- package/src/components/Pagination/range.ts +15 -0
- package/src/components/PasswordInput/PasswordInput.vue +53 -0
- package/src/components/PickerWheel/DateWheel.vue +48 -0
- package/src/components/PickerWheel/PickerWheel.tsx +15 -129
- package/src/components/PickerWheel/PickerWheel.vue +77 -0
- package/src/components/PickerWheel/TimeWheel.vue +50 -0
- package/src/components/PickerWheel/WheelColumn.vue +70 -0
- package/src/components/Popover/Popover.vue +108 -0
- package/src/components/ProgressBar/ProgressBar.vue +48 -0
- package/src/components/Prose/Prose.vue +18 -0
- package/src/components/Radio/Radio.vue +49 -0
- package/src/components/Radio/RadioGroup.vue +69 -0
- package/src/components/Retime/Retime.tsx +7 -40
- package/src/components/Retime/Retime.vue +64 -0
- package/src/components/RulerScrubber/RulerScrubber.tsx +9 -38
- package/src/components/RulerScrubber/RulerScrubber.vue +166 -0
- package/src/components/ScrollArea/ScrollArea.tsx +17 -129
- package/src/components/ScrollArea/ScrollArea.vue +58 -0
- package/src/components/SearchInput/SearchInput.tsx +2 -15
- package/src/components/SearchInput/SearchInput.vue +70 -0
- package/src/components/SegmentedControl/SegmentedControl.tsx +7 -51
- package/src/components/SegmentedControl/SegmentedControl.vue +111 -0
- package/src/components/Select/Select.tsx +16 -47
- package/src/components/Select/Select.vue +236 -0
- package/src/components/Sheet/Sheet.tsx +52 -231
- package/src/components/Sheet/Sheet.vue +249 -0
- package/src/components/Skeleton/Skeleton.vue +38 -0
- package/src/components/Slider/Slider.tsx +25 -84
- package/src/components/Slider/Slider.vue +113 -0
- package/src/components/Spinner/Spinner.vue +30 -0
- package/src/components/Split/Split.vue +34 -0
- package/src/components/SplitFlap/SplitFlap.tsx +11 -175
- package/src/components/SplitFlap/SplitFlap.vue +52 -0
- package/src/components/Stack/Stack.vue +22 -0
- package/src/components/SwipeDeck/SwipeDeck.tsx +30 -194
- package/src/components/SwipeDeck/SwipeDeck.vue +168 -0
- package/src/components/Switch/Switch.tsx +6 -75
- package/src/components/Switch/Switch.vue +66 -0
- package/src/components/Table/Table.module.css +12 -3
- package/src/components/Table/Table.tsx +8 -59
- package/src/components/Table/Table.vue +274 -0
- package/src/components/TableOfContents/TableOfContents.vue +90 -0
- package/src/components/Tabs/Tab.vue +37 -0
- package/src/components/Tabs/TabList.vue +47 -0
- package/src/components/Tabs/TabPanel.vue +26 -0
- package/src/components/Tabs/Tabs.module.css +2 -2
- package/src/components/Tabs/Tabs.tsx +11 -84
- package/src/components/Tabs/Tabs.vue +33 -0
- package/src/components/Tabs/tabsContext.ts +15 -0
- package/src/components/Tag/Tag.tsx +6 -26
- package/src/components/Tag/Tag.vue +63 -0
- package/src/components/Textarea/Textarea.tsx +2 -22
- package/src/components/Textarea/Textarea.vue +120 -0
- package/src/components/ThemeToggle/ThemeToggle.tsx +10 -84
- package/src/components/ThemeToggle/ThemeToggle.vue +90 -0
- package/src/components/Toast/Toast.tsx +34 -264
- package/src/components/Toast/Toast.vue +138 -0
- package/src/components/Toast/ToastItem.vue +108 -0
- package/src/components/Toggle/Toggle.vue +52 -0
- package/src/components/Tooltip/Tooltip.tsx +17 -48
- package/src/components/Tooltip/Tooltip.vue +95 -0
- package/src/components/VisuallyHidden/VisuallyHidden.vue +17 -0
- package/src/internal/FieldMessage.vue +41 -0
- package/src/internal/Roll.vue +20 -0
- package/src/internal/fling.ts +29 -106
- package/src/internal/focus.ts +4 -79
- package/src/internal/icons.module.css +39 -27
- package/src/internal/layers.ts +7 -61
- package/src/internal/liquid.ts +26 -213
- package/src/internal/liquidMatter.ts +9 -181
- package/src/internal/liquidMore.ts +6 -669
- package/src/internal/motion/alert.ts +17 -0
- package/src/internal/motion/buttonGroup.ts +21 -0
- package/src/internal/motion/checkbox.ts +39 -0
- package/src/internal/motion/collapseOut.ts +26 -0
- package/src/internal/motion/copyButton.ts +48 -0
- package/src/internal/motion/dial.ts +137 -0
- package/src/internal/motion/fab.ts +14 -0
- package/src/internal/motion/fling.ts +147 -0
- package/src/internal/motion/floating.ts +58 -0
- package/src/internal/motion/focus.ts +88 -0
- package/src/internal/motion/formField.ts +19 -0
- package/src/internal/motion/holdToConfirm.ts +147 -0
- package/src/internal/motion/index.ts +20 -0
- package/src/internal/motion/keys.ts +42 -0
- package/src/internal/motion/layers.ts +78 -0
- package/src/internal/motion/liquid.ts +241 -0
- package/src/internal/motion/liquidMatter.ts +198 -0
- package/src/internal/motion/liquidMore.ts +676 -0
- package/src/internal/motion/listbox.ts +69 -0
- package/src/internal/motion/livePill.ts +71 -0
- package/src/internal/motion/menuKeys.ts +58 -0
- package/src/internal/motion/morphButton.ts +71 -0
- package/src/internal/motion/numberInput.ts +57 -0
- package/src/internal/motion/pickerWheel.ts +166 -0
- package/src/internal/motion/retime.ts +45 -0
- package/src/internal/motion/ruler.ts +57 -0
- package/src/internal/motion/scrollArea.ts +133 -0
- package/src/internal/motion/scrollFrame.ts +152 -0
- package/src/internal/motion/scrubLook.ts +15 -0
- package/src/internal/motion/scrubber.ts +154 -0
- package/src/internal/motion/segmented.ts +63 -0
- package/src/internal/motion/sheetDetents.ts +271 -0
- package/src/internal/motion/slider.ts +108 -0
- package/src/internal/motion/softPress.ts +334 -0
- package/src/internal/motion/splitFlap.ts +205 -0
- package/src/internal/motion/swipeDeck.ts +236 -0
- package/src/internal/motion/switchThumb.ts +83 -0
- package/src/internal/motion/table.ts +77 -0
- package/src/internal/motion/tabs.ts +105 -0
- package/src/internal/motion/textarea.ts +22 -0
- package/src/internal/motion/themeIcon.ts +91 -0
- package/src/internal/motion/themeReveal.ts +71 -0
- package/src/internal/motion/toast.ts +291 -0
- package/src/internal/motion/tooltip.ts +58 -0
- package/src/internal/scrollFrame.ts +4 -145
- package/src/internal/softPress.ts +27 -289
- package/src/internal/themeReveal.ts +3 -61
- package/src/internal/useFloating.ts +9 -49
- package/src/internal/useScrub.ts +15 -120
- package/src/internal/vue/trigger.ts +18 -0
- package/src/internal/vue/useFloating.ts +38 -0
- package/src/internal/vue/usePresence.ts +21 -0
- package/src/internal/vue/useScrub.ts +40 -0
- package/src/internal/vueIcons.ts +134 -0
- package/src/tokens.css +5 -0
- package/src/internal/relativeTime.ts +0 -26
|
@@ -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>
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed, useId } from 'vue'
|
|
3
|
+
import styles from './ProgressBar.module.css'
|
|
4
|
+
|
|
5
|
+
// The Vue ProgressBar: the same look (ProgressBar.module.css) as the React one.
|
|
6
|
+
const props = withDefaults(
|
|
7
|
+
defineProps<{
|
|
8
|
+
/** Says what is in progress. Shown above the bar and read by screen readers. */
|
|
9
|
+
label: string
|
|
10
|
+
/** 0 to max. Leave it out for an indeterminate bar. */
|
|
11
|
+
value?: number
|
|
12
|
+
/** The value that means done. */
|
|
13
|
+
max?: number
|
|
14
|
+
/** Shows the percentage next to the label. */
|
|
15
|
+
showValue?: boolean
|
|
16
|
+
/** Hides the label visually but keeps it for screen readers. */
|
|
17
|
+
hideLabel?: boolean
|
|
18
|
+
/** Thickness of the bar. */
|
|
19
|
+
size?: 'sm' | 'md'
|
|
20
|
+
}>(),
|
|
21
|
+
{ max: 100, showValue: true, size: 'md' },
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
const id = useId()
|
|
25
|
+
const determinate = computed(() => props.value !== undefined)
|
|
26
|
+
const ratio = computed(() => (props.value !== undefined ? Math.min(Math.max(props.value / props.max, 0), 1) : 0))
|
|
27
|
+
const now = computed(() => (props.value !== undefined ? Math.min(Math.max(props.value, 0), props.max) : undefined))
|
|
28
|
+
</script>
|
|
29
|
+
|
|
30
|
+
<template>
|
|
31
|
+
<div :class="styles.root">
|
|
32
|
+
<div :class="[styles.head, hideLabel && styles.srOnly]">
|
|
33
|
+
<span :id="id" :class="styles.label">{{ label }}</span>
|
|
34
|
+
<span v-if="determinate && showValue" :class="styles.value" aria-hidden="true">{{ Math.round(ratio * 100) }}%</span>
|
|
35
|
+
</div>
|
|
36
|
+
<div
|
|
37
|
+
role="progressbar"
|
|
38
|
+
:aria-labelledby="id"
|
|
39
|
+
:aria-valuemin="determinate ? 0 : undefined"
|
|
40
|
+
:aria-valuemax="determinate ? max : undefined"
|
|
41
|
+
:aria-valuenow="now"
|
|
42
|
+
:class="[styles.track, styles[size]]"
|
|
43
|
+
:data-indeterminate="!determinate || undefined"
|
|
44
|
+
>
|
|
45
|
+
<span :class="styles.fill" :style="determinate ? { transform: `scaleX(${ratio})` } : undefined" />
|
|
46
|
+
</div>
|
|
47
|
+
</div>
|
|
48
|
+
</template>
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import styles from './Prose.module.css'
|
|
3
|
+
|
|
4
|
+
// The Vue Prose: the same look (Prose.module.css) as the React one. It styles the plain HTML inside it,
|
|
5
|
+
// so Markdown or CMS HTML can go in with v-html, or as the default slot.
|
|
6
|
+
withDefaults(
|
|
7
|
+
defineProps<{
|
|
8
|
+
/** The element to render, such as article. */
|
|
9
|
+
as?: string
|
|
10
|
+
}>(),
|
|
11
|
+
{ as: 'div' },
|
|
12
|
+
)
|
|
13
|
+
defineSlots<{ default?: () => unknown }>()
|
|
14
|
+
</script>
|
|
15
|
+
|
|
16
|
+
<template>
|
|
17
|
+
<component :is="as" :class="styles.root"><slot /></component>
|
|
18
|
+
</template>
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed, inject, useId } from 'vue'
|
|
3
|
+
import { radioKey } from './RadioGroup.vue'
|
|
4
|
+
import styles from './Radio.module.css'
|
|
5
|
+
|
|
6
|
+
// The Vue Radio: one choice inside a RadioGroup, the same look (Radio.module.css) as the React one.
|
|
7
|
+
|
|
8
|
+
const props = defineProps<{
|
|
9
|
+
/** The group value this radio stands for. */
|
|
10
|
+
value: string
|
|
11
|
+
/** Visible text next to the circle. Clicking it picks the radio. */
|
|
12
|
+
label: string
|
|
13
|
+
/** Extra text under the label, also read by screen readers. */
|
|
14
|
+
description?: string
|
|
15
|
+
/** Turns off only this radio. */
|
|
16
|
+
disabled?: boolean
|
|
17
|
+
}>()
|
|
18
|
+
|
|
19
|
+
const ctx = inject(radioKey)
|
|
20
|
+
if (!ctx) throw new Error('Radio must be inside RadioGroup')
|
|
21
|
+
const id = useId()
|
|
22
|
+
const isOn = computed(() => ctx.value.value === props.value)
|
|
23
|
+
</script>
|
|
24
|
+
|
|
25
|
+
<template>
|
|
26
|
+
<div :class="styles.root" :data-disabled="disabled || ctx.disabled.value || undefined">
|
|
27
|
+
<span :class="styles.circleWrap">
|
|
28
|
+
<input
|
|
29
|
+
:id="id"
|
|
30
|
+
type="radio"
|
|
31
|
+
:class="styles.input"
|
|
32
|
+
:name="ctx.name.value"
|
|
33
|
+
:value="value"
|
|
34
|
+
:checked="isOn"
|
|
35
|
+
:disabled="disabled"
|
|
36
|
+
:aria-invalid="ctx.invalid.value || undefined"
|
|
37
|
+
:aria-describedby="description ? `${id}-desc` : undefined"
|
|
38
|
+
@change="ctx.set(value)"
|
|
39
|
+
/>
|
|
40
|
+
<span :class="styles.circle" :data-on="isOn || undefined" aria-hidden="true">
|
|
41
|
+
<span :class="styles.dot" />
|
|
42
|
+
</span>
|
|
43
|
+
</span>
|
|
44
|
+
<span :class="styles.text">
|
|
45
|
+
<label :for="id" :class="styles.label">{{ label }}</label>
|
|
46
|
+
<span v-if="description" :id="`${id}-desc`" :class="styles.description">{{ description }}</span>
|
|
47
|
+
</span>
|
|
48
|
+
</div>
|
|
49
|
+
</template>
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { InjectionKey, Ref } from 'vue'
|
|
3
|
+
|
|
4
|
+
export type RadioContext = { name: Ref<string>; value: Ref<string | null>; set: (v: string) => void; disabled: Ref<boolean | undefined>; invalid: Ref<boolean> }
|
|
5
|
+
export const radioKey: InjectionKey<RadioContext> = Symbol('radio')
|
|
6
|
+
</script>
|
|
7
|
+
|
|
8
|
+
<script setup lang="ts">
|
|
9
|
+
import { computed, provide, ref, useId } from 'vue'
|
|
10
|
+
import FieldMessage from '../../internal/FieldMessage.vue'
|
|
11
|
+
import styles from './Radio.module.css'
|
|
12
|
+
|
|
13
|
+
// The Vue RadioGroup: the same look (Radio.module.css) as the React one. Put Radio parts in its slot.
|
|
14
|
+
|
|
15
|
+
const props = withDefaults(
|
|
16
|
+
defineProps<{
|
|
17
|
+
/** Visible group label (rendered as the fieldset legend). */
|
|
18
|
+
label: string
|
|
19
|
+
/** Extra text under the group label. */
|
|
20
|
+
description?: string
|
|
21
|
+
/** Error under the radios. Marks the group invalid and is read with it. */
|
|
22
|
+
error?: string
|
|
23
|
+
/** Starting value when there is no v-model. */
|
|
24
|
+
defaultValue?: string | null
|
|
25
|
+
/** Form field name shared by every radio. Undefined makes a unique one. */
|
|
26
|
+
name?: string
|
|
27
|
+
/** Turns off every radio in the group. */
|
|
28
|
+
disabled?: boolean
|
|
29
|
+
/** Stacks the radios or puts them in a row. */
|
|
30
|
+
orientation?: 'vertical' | 'horizontal'
|
|
31
|
+
}>(),
|
|
32
|
+
{ defaultValue: null, disabled: undefined, orientation: 'vertical' },
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
/** The selected value. Null means nothing is picked. Use v-model, or leave it out and the group keeps its own state. */
|
|
36
|
+
const model = defineModel<string | null>()
|
|
37
|
+
const local = ref(props.defaultValue)
|
|
38
|
+
const value = computed({
|
|
39
|
+
get: () => (model.value === undefined ? local.value : model.value),
|
|
40
|
+
set: (next: string | null) => {
|
|
41
|
+
local.value = next
|
|
42
|
+
model.value = next
|
|
43
|
+
},
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
const auto = useId()
|
|
47
|
+
const descId = `${auto}-desc`
|
|
48
|
+
const errorId = `${auto}-error`
|
|
49
|
+
const describedBy = computed(() => [props.description ? descId : null, props.error ? errorId : null].filter(Boolean).join(' ') || undefined)
|
|
50
|
+
|
|
51
|
+
provide(radioKey, {
|
|
52
|
+
name: computed(() => props.name ?? auto),
|
|
53
|
+
value,
|
|
54
|
+
set: (v) => (value.value = v),
|
|
55
|
+
disabled: computed(() => props.disabled),
|
|
56
|
+
invalid: computed(() => !!props.error),
|
|
57
|
+
})
|
|
58
|
+
</script>
|
|
59
|
+
|
|
60
|
+
<template>
|
|
61
|
+
<fieldset role="radiogroup" :class="styles.group" :disabled="disabled" :aria-invalid="error ? true : undefined" :aria-describedby="describedBy" :data-invalid="error ? true : undefined">
|
|
62
|
+
<legend :class="styles.legend">{{ label }}</legend>
|
|
63
|
+
<p v-if="description" :id="descId" :class="styles.groupDescription">{{ description }}</p>
|
|
64
|
+
<div :class="[styles.items, styles[orientation]]">
|
|
65
|
+
<slot />
|
|
66
|
+
</div>
|
|
67
|
+
<FieldMessage :help-id="`${auto}-help`" :error-id="errorId" :error="error" />
|
|
68
|
+
</fieldset>
|
|
69
|
+
</template>
|
|
@@ -3,35 +3,9 @@
|
|
|
3
3
|
import { useEffect, useRef } from 'react'
|
|
4
4
|
import { useControllable } from '../../internal/useControllable'
|
|
5
5
|
import { SegmentedControl } from '../SegmentedControl'
|
|
6
|
+
import { applyRetime, commitSpeed, defaultRetimeLabels, RETIME_EVENT, retimeSpeeds, savedSpeed, type RetimeLabels, type RetimeSpeed } from '../../internal/motion/retime'
|
|
6
7
|
|
|
7
|
-
export
|
|
8
|
-
|
|
9
|
-
export type RetimeLabels = Record<RetimeSpeed, string>
|
|
10
|
-
|
|
11
|
-
const defaultLabels: RetimeLabels = { off: 'Off', slower: 'Slower', normal: 'Normal', faster: 'Faster' }
|
|
12
|
-
|
|
13
|
-
// How long motion takes compared with normal. Off is 0, so nothing moves at all.
|
|
14
|
-
const SCALE: Record<RetimeSpeed, number> = { off: 0, slower: 1.5, normal: 1, faster: 0.6 }
|
|
15
|
-
|
|
16
|
-
const STORAGE_KEY = 'gooee-motion-speed'
|
|
17
|
-
const CHANGE_EVENT = 'gooee-retime'
|
|
18
|
-
|
|
19
|
-
/** Retimes every animation in the library at once. Reduced motion in the system still wins. */
|
|
20
|
-
export function applyRetime(speed: RetimeSpeed) {
|
|
21
|
-
if (typeof document === 'undefined') return
|
|
22
|
-
document.documentElement.style.setProperty('--gooee-motion-scale', String(SCALE[speed]))
|
|
23
|
-
// Other Retime controls on the page (a header and a menu, say) follow the same choice.
|
|
24
|
-
window.dispatchEvent(new CustomEvent<RetimeSpeed>(CHANGE_EVENT, { detail: speed }))
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function savedSpeed(): RetimeSpeed | null {
|
|
28
|
-
try {
|
|
29
|
-
const v = localStorage.getItem(STORAGE_KEY)
|
|
30
|
-
return v && v in SCALE ? (v as RetimeSpeed) : null
|
|
31
|
-
} catch {
|
|
32
|
-
return null
|
|
33
|
-
}
|
|
34
|
-
}
|
|
8
|
+
export { applyRetime, type RetimeLabels, type RetimeSpeed }
|
|
35
9
|
|
|
36
10
|
export type RetimeProps = {
|
|
37
11
|
/** Visible label. */
|
|
@@ -65,7 +39,7 @@ export function Retime({
|
|
|
65
39
|
fullWidth,
|
|
66
40
|
className,
|
|
67
41
|
}: RetimeProps) {
|
|
68
|
-
const labels = { ...
|
|
42
|
+
const labels = { ...defaultRetimeLabels, ...labelsProp }
|
|
69
43
|
const [speed, setSpeed] = useControllable(value, defaultValue, onValueChange)
|
|
70
44
|
|
|
71
45
|
// A speed saved on an earlier visit comes back after the first render, so server and client agree.
|
|
@@ -85,21 +59,14 @@ export function Retime({
|
|
|
85
59
|
useEffect(() => {
|
|
86
60
|
if (value !== undefined) return
|
|
87
61
|
const follow = (e: Event) => setSpeed((e as CustomEvent<RetimeSpeed>).detail)
|
|
88
|
-
window.addEventListener(
|
|
89
|
-
return () => window.removeEventListener(
|
|
62
|
+
window.addEventListener(RETIME_EVENT, follow)
|
|
63
|
+
return () => window.removeEventListener(RETIME_EVENT, follow)
|
|
90
64
|
}, [value, setSpeed])
|
|
91
65
|
|
|
92
66
|
useEffect(() => {
|
|
93
67
|
if (pending.current && pending.current !== speed) return
|
|
94
68
|
pending.current = null
|
|
95
|
-
|
|
96
|
-
applyRetime(speed)
|
|
97
|
-
if (!remember) return
|
|
98
|
-
try {
|
|
99
|
-
localStorage.setItem(STORAGE_KEY, speed)
|
|
100
|
-
} catch {
|
|
101
|
-
// Not saved; the speed still holds for this visit.
|
|
102
|
-
}
|
|
69
|
+
commitSpeed(speed, remember)
|
|
103
70
|
}, [speed, remember])
|
|
104
71
|
|
|
105
72
|
return (
|
|
@@ -108,7 +75,7 @@ export function Retime({
|
|
|
108
75
|
size={size}
|
|
109
76
|
value={speed}
|
|
110
77
|
onValueChange={(v) => setSpeed(v as RetimeSpeed)}
|
|
111
|
-
options={
|
|
78
|
+
options={retimeSpeeds.map((s) => ({ value: s, label: labels[s] }))}
|
|
112
79
|
fullWidth={fullWidth}
|
|
113
80
|
className={className}
|
|
114
81
|
/>
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
export { applyRetime, type RetimeLabels, type RetimeSpeed } from '../../internal/motion/retime'
|
|
3
|
+
</script>
|
|
4
|
+
|
|
5
|
+
<script setup lang="ts">
|
|
6
|
+
import { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue'
|
|
7
|
+
import { commitSpeed, defaultRetimeLabels, RETIME_EVENT, retimeSpeeds, savedSpeed, type RetimeLabels, type RetimeSpeed } from '../../internal/motion/retime'
|
|
8
|
+
import SegmentedControl from '../SegmentedControl/SegmentedControl.vue'
|
|
9
|
+
|
|
10
|
+
// The Vue Retime: the same control and speed (motion/retime.ts) as the React one.
|
|
11
|
+
|
|
12
|
+
const props = withDefaults(
|
|
13
|
+
defineProps<{
|
|
14
|
+
/** Visible label. */
|
|
15
|
+
label?: string
|
|
16
|
+
/** Starting speed when there is no v-model. A speed saved on this device wins over it. */
|
|
17
|
+
defaultValue?: RetimeSpeed
|
|
18
|
+
/** Saves the choice on this device, so it lasts across visits. */
|
|
19
|
+
remember?: boolean
|
|
20
|
+
/** Height of the control. */
|
|
21
|
+
size?: 'sm' | 'md'
|
|
22
|
+
/** Text for each speed, so you can translate it. */
|
|
23
|
+
labels?: Partial<RetimeLabels>
|
|
24
|
+
/** Fills the row, with the speeds sharing it evenly, as in a settings panel. */
|
|
25
|
+
fullWidth?: boolean
|
|
26
|
+
}>(),
|
|
27
|
+
{ label: 'Motion', defaultValue: 'normal', remember: true, size: 'md' },
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
/** The chosen speed. Use v-model, or leave it out and the part keeps its own. */
|
|
31
|
+
const model = defineModel<RetimeSpeed>()
|
|
32
|
+
const local = ref<RetimeSpeed>(props.defaultValue)
|
|
33
|
+
const speed = computed({
|
|
34
|
+
get: () => model.value ?? local.value,
|
|
35
|
+
set: (next: RetimeSpeed) => {
|
|
36
|
+
local.value = next
|
|
37
|
+
model.value = next
|
|
38
|
+
},
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
const options = computed(() => {
|
|
42
|
+
const labels = { ...defaultRetimeLabels, ...props.labels }
|
|
43
|
+
return retimeSpeeds.map((s) => ({ value: s, label: labels[s] }))
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
// A speed saved on an earlier visit comes back after mount, so server and client agree.
|
|
47
|
+
const follow = (e: Event) => {
|
|
48
|
+
if (model.value === undefined) speed.value = (e as CustomEvent<RetimeSpeed>).detail
|
|
49
|
+
}
|
|
50
|
+
onMounted(() => {
|
|
51
|
+
if (props.remember && model.value === undefined) {
|
|
52
|
+
const saved = savedSpeed()
|
|
53
|
+
if (saved) local.value = saved
|
|
54
|
+
}
|
|
55
|
+
window.addEventListener(RETIME_EVENT, follow)
|
|
56
|
+
commitSpeed(speed.value, props.remember)
|
|
57
|
+
watch([speed, () => props.remember], () => commitSpeed(speed.value, props.remember))
|
|
58
|
+
})
|
|
59
|
+
onBeforeUnmount(() => window.removeEventListener(RETIME_EVENT, follow))
|
|
60
|
+
</script>
|
|
61
|
+
|
|
62
|
+
<template>
|
|
63
|
+
<SegmentedControl :label="label" :size="size" :model-value="speed" :options="options" :full-width="fullWidth" @update:model-value="speed = $event as RetimeSpeed" />
|
|
64
|
+
</template>
|
|
@@ -2,11 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
import { useEffect, useId, useLayoutEffect, useRef, useState, type ComponentPropsWithRef, type ReactNode } from 'react'
|
|
4
4
|
import { cx } from '../../internal/cx'
|
|
5
|
-
import { clamp, follow,
|
|
5
|
+
import { clamp, follow, pull, roundTo, wheelSteps } from '../../internal/feel'
|
|
6
6
|
import { morphCurve, readMotionMs } from '../../internal/motion'
|
|
7
|
+
import { measureRuler, rulerScale, rulerScrub, type RulerFit } from '../../internal/motion/ruler'
|
|
7
8
|
import { Roll } from '../../internal/Roll'
|
|
8
9
|
import { useControllable } from '../../internal/useControllable'
|
|
9
|
-
import { ink,
|
|
10
|
+
import { ink, useOnChange, useScrub } from '../../internal/useScrub'
|
|
10
11
|
import styles from './RulerScrubber.module.css'
|
|
11
12
|
|
|
12
13
|
export type RulerScrubberProps = Omit<ComponentPropsWithRef<'div'>, 'defaultValue' | 'onChange' | 'children'> & {
|
|
@@ -63,54 +64,24 @@ export function RulerScrubber({
|
|
|
63
64
|
}: RulerScrubberProps) {
|
|
64
65
|
const labelId = useId()
|
|
65
66
|
const detailId = useId()
|
|
66
|
-
const
|
|
67
|
+
const scale = { min, max, step, marks }
|
|
68
|
+
const { top, all, labelled, land } = rulerScale(scale)
|
|
67
69
|
const [raw, setValue] = useControllable(valueProp, defaultValue ?? min, onValueChange)
|
|
68
70
|
const value = clamp(raw, min, top)
|
|
69
|
-
const all = steps(min, max, step)
|
|
70
|
-
const labelled = new Set((marks ?? all.filter((_, i) => i % 10 === 0)).map((v) => roundTo(v, step, min)))
|
|
71
71
|
const strongSet = new Set(strong.map((v) => roundTo(v, step, min)))
|
|
72
|
-
const land = (p: number) => clamp(roundTo(p, step, min), min, top)
|
|
73
72
|
const markText = formatMark ?? formatValue
|
|
74
73
|
// The px between two ticks (a token) and how many ticks fit either side of the needle.
|
|
75
|
-
const [fit, setFit] = useState({ gap: 0, span: 24, width: 0, tag: 0 })
|
|
74
|
+
const [fit, setFit] = useState<RulerFit>({ gap: 0, span: 24, width: 0, tag: 0 })
|
|
76
75
|
const tagRef = useRef<HTMLSpanElement>(null)
|
|
77
76
|
const wheel = useRef(wheelSteps())
|
|
78
77
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
min,
|
|
82
|
-
max: top,
|
|
83
|
-
edge: step,
|
|
84
|
-
land,
|
|
85
|
-
// The hand at 4000px a second at most, so a hard throw still stops in reach.
|
|
86
|
-
maxSpeed: fit.gap ? (4000 / fit.gap) * step : undefined,
|
|
87
|
-
// Dragging left brings higher values in, like pulling a tape.
|
|
88
|
-
move: (e, last) => (-(e.clientX - last.x) / (fit.gap || 1)) * step * (e.shiftKey ? 0.25 : 1),
|
|
89
|
-
key: (k, t) => stepKey(k, t, { min, max, step, marks: [...labelled] }),
|
|
90
|
-
// A tap without a drag goes to the tick under it, so the ruler works with one plain press.
|
|
91
|
-
tap: (e, at) => {
|
|
92
|
-
if (!fit.gap) return null
|
|
93
|
-
const r = e.currentTarget.getBoundingClientRect()
|
|
94
|
-
return land(at + ((e.clientX - (r.left + r.width / 2)) / fit.gap) * step)
|
|
95
|
-
},
|
|
96
|
-
wheel: (e, t) => {
|
|
97
|
-
const dx = sideways(e)
|
|
98
|
-
if (dx === null || !fit.gap) return null
|
|
99
|
-
const n = wheel.current(dx, fit.gap, e.timeStamp)
|
|
100
|
-
const to = clamp(roundTo(t + n * step, step, min), min, top)
|
|
101
|
-
return to === t && (t === min || t === top) ? null : to
|
|
102
|
-
},
|
|
103
|
-
onSettle: setValue,
|
|
104
|
-
haptics,
|
|
105
|
-
})
|
|
78
|
+
// The drag, keys, tap and wheel (motion/ruler.ts) on the shared scrubber.
|
|
79
|
+
const sc = useScrub({ value, ...rulerScrub(scale, fit, wheel.current), onSettle: setValue, haptics })
|
|
106
80
|
|
|
107
81
|
useLayoutEffect(() => {
|
|
108
82
|
const el = sc.ref.current
|
|
109
83
|
if (!el) return
|
|
110
|
-
const measure = () =>
|
|
111
|
-
const gap = tokenNumber(el, '--gooee-ruler-tick-gap')
|
|
112
|
-
setFit({ gap, span: gap ? Math.ceil(el.clientWidth / 2 / gap) + 1 : 24, width: el.clientWidth, tag: tagRef.current?.offsetWidth ?? 0 })
|
|
113
|
-
}
|
|
84
|
+
const measure = () => setFit(measureRuler(el, tagRef.current))
|
|
114
85
|
measure()
|
|
115
86
|
const ro = new ResizeObserver(measure)
|
|
116
87
|
ro.observe(el)
|