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,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)
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed, onBeforeUnmount, onMounted, ref, useId, useSlots, watch } from 'vue'
|
|
3
|
+
import { clamp, follow, pull, roundTo, wheelSteps } from '../../internal/feel'
|
|
4
|
+
import { morphCurve, readMotionMs } from '../../internal/motion'
|
|
5
|
+
import { measureRuler, rulerScale, rulerScrub, type RulerFit } from '../../internal/motion/ruler'
|
|
6
|
+
import { ink } from '../../internal/motion/scrubLook'
|
|
7
|
+
import Roll from '../../internal/Roll.vue'
|
|
8
|
+
import { useScrub } from '../../internal/vue/useScrub'
|
|
9
|
+
import styles from './RulerScrubber.module.css'
|
|
10
|
+
|
|
11
|
+
// The Vue RulerScrubber: the same look (RulerScrubber.module.css), drag, lean and landing as the React one.
|
|
12
|
+
|
|
13
|
+
const props = withDefaults(
|
|
14
|
+
defineProps<{
|
|
15
|
+
/** Visible name of the ruler, also read by screen readers. */
|
|
16
|
+
label: string
|
|
17
|
+
/** Starting value when there is no v-model. Undefined starts at min. */
|
|
18
|
+
defaultValue?: number
|
|
19
|
+
/** Lowest value. */
|
|
20
|
+
min?: number
|
|
21
|
+
/** Highest value. */
|
|
22
|
+
max?: number
|
|
23
|
+
/** Size of one step: one tick on the ruler, and a mark it is drawn onto. */
|
|
24
|
+
step?: number
|
|
25
|
+
/** Values with a long, numbered tick. Page Up and Page Down jump between them. Defaults to every 10 steps. */
|
|
26
|
+
marks?: number[]
|
|
27
|
+
/** Values drawn stronger, such as a limit or the usual choice. */
|
|
28
|
+
strong?: number[]
|
|
29
|
+
/** A tag under each strong mark, such as "Allowance". */
|
|
30
|
+
strongLabel?: string
|
|
31
|
+
/** Turns the value into the readout and what screen readers hear. */
|
|
32
|
+
formatValue?: (value: number) => string
|
|
33
|
+
/** Turns a mark into the number under its tick. Defaults to formatValue. */
|
|
34
|
+
formatMark?: (value: number) => string
|
|
35
|
+
/** A line under the readout, such as what the value means. The detail slot replaces it. */
|
|
36
|
+
detail?: string
|
|
37
|
+
/** A short buzz on each tick while it moves, on phones that can (Android). */
|
|
38
|
+
haptics?: boolean
|
|
39
|
+
}>(),
|
|
40
|
+
{ min: 0, max: 100, step: 1, strong: () => [], formatValue: String, haptics: false },
|
|
41
|
+
)
|
|
42
|
+
const emit = defineEmits<{ /** The value under the needle while the ruler still moves. */ scrub: [value: number] }>()
|
|
43
|
+
const slots = useSlots()
|
|
44
|
+
|
|
45
|
+
/** The value, set once the ruler comes to rest. Use v-model, or leave it out and the ruler keeps its own value. */
|
|
46
|
+
const model = defineModel<number>()
|
|
47
|
+
const local = ref(props.defaultValue ?? props.min)
|
|
48
|
+
const raw = computed({
|
|
49
|
+
get: () => model.value ?? local.value,
|
|
50
|
+
set: (next: number) => {
|
|
51
|
+
local.value = next
|
|
52
|
+
model.value = next
|
|
53
|
+
},
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
const labelId = useId()
|
|
57
|
+
const detailId = useId()
|
|
58
|
+
const scale = computed(() => ({ min: props.min, max: props.max, step: props.step, marks: props.marks }))
|
|
59
|
+
const ruler = computed(() => rulerScale(scale.value))
|
|
60
|
+
const value = computed(() => clamp(raw.value, props.min, ruler.value.top))
|
|
61
|
+
const strongSet = computed(() => new Set(props.strong.map((v) => roundTo(v, props.step, props.min))))
|
|
62
|
+
const markText = (v: number) => (props.formatMark ?? props.formatValue)(v)
|
|
63
|
+
// The px between two ticks (a token) and how many ticks fit either side of the needle.
|
|
64
|
+
const fit = ref<RulerFit>({ gap: 0, span: 24, width: 0, tag: 0 })
|
|
65
|
+
const tagEl = ref<HTMLElement | null>(null)
|
|
66
|
+
const wheel = wheelSteps()
|
|
67
|
+
|
|
68
|
+
// The drag, keys, tap and wheel (motion/ruler.ts) on the shared scrubber.
|
|
69
|
+
const sc = useScrub(() => ({ value: value.value, ...rulerScrub(scale.value, fit.value, wheel), onSettle: (v: number) => (raw.value = v), haptics: props.haptics }))
|
|
70
|
+
const scrubEl = sc.el
|
|
71
|
+
|
|
72
|
+
const measure = () => scrubEl.value && (fit.value = measureRuler(scrubEl.value, tagEl.value))
|
|
73
|
+
let ro: ResizeObserver | null = null
|
|
74
|
+
onMounted(() => {
|
|
75
|
+
measure()
|
|
76
|
+
ro = new ResizeObserver(measure)
|
|
77
|
+
if (scrubEl.value) ro.observe(scrubEl.value)
|
|
78
|
+
})
|
|
79
|
+
watch(() => props.strongLabel, measure, { flush: 'post' })
|
|
80
|
+
|
|
81
|
+
// The ticks lean and grow only while the ruler moves. The lean eases in as it starts and settles flat as it stops.
|
|
82
|
+
const lean = ref(0)
|
|
83
|
+
const leaning = follow({ time: () => readMotionMs('morph-out'), curve: morphCurve(), onFrame: (v) => (lean.value = v) })
|
|
84
|
+
watch(sc.moving, (m) => leaning.set(m && readMotionMs('morph-out') > 0 ? 1 : 0))
|
|
85
|
+
onBeforeUnmount(() => {
|
|
86
|
+
ro?.disconnect()
|
|
87
|
+
leaning.stop()
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
const shown = computed(() => ruler.value.land(sc.at.value))
|
|
91
|
+
watch(shown, (v) => emit('scrub', v))
|
|
92
|
+
const hasDetail = computed(() => !!(props.detail || slots.detail))
|
|
93
|
+
|
|
94
|
+
const marks = computed(() => {
|
|
95
|
+
const at = sc.at.value
|
|
96
|
+
const { step } = props
|
|
97
|
+
return ruler.value.all.flatMap((v, i) => {
|
|
98
|
+
const d = (v - at) / step
|
|
99
|
+
if (Math.abs(d) > fit.value.span) return []
|
|
100
|
+
const on = pull(d, 1)
|
|
101
|
+
const near = pull(d, 5)
|
|
102
|
+
const tilt = -Math.sign(d) * 14 * Math.sin(Math.PI * Math.min(1, Math.abs(d) / 6)) * (1 - on)
|
|
103
|
+
const tier = ruler.value.labelled.has(v) ? 'major' : i % 2 === 0 ? 'mid' : 'minor'
|
|
104
|
+
return [
|
|
105
|
+
{
|
|
106
|
+
v,
|
|
107
|
+
tier,
|
|
108
|
+
place: `translateX(calc(${d.toFixed(3)} * var(--gooee-ruler-tick-gap)))`,
|
|
109
|
+
tick: {
|
|
110
|
+
background: ink(on, tier === 'major' ? 'var(--gooee-color-fg-muted)' : 'var(--gooee-color-border-strong)', 'var(--gooee-color-accent)'),
|
|
111
|
+
transform: lean.value > 0 ? `rotate(${(tilt * lean.value).toFixed(2)}deg) scaleY(${(1 + near * 0.9 * lean.value).toFixed(3)})` : undefined,
|
|
112
|
+
},
|
|
113
|
+
num: ink(pull(d, 2)),
|
|
114
|
+
},
|
|
115
|
+
]
|
|
116
|
+
})
|
|
117
|
+
})
|
|
118
|
+
|
|
119
|
+
const tags = computed(() => {
|
|
120
|
+
const { gap, width, tag } = fit.value
|
|
121
|
+
const room = (width - tag) / 2
|
|
122
|
+
return [...strongSet.value].flatMap((v) => {
|
|
123
|
+
const x = ((v - sc.at.value) / props.step) * gap
|
|
124
|
+
if (!gap || Math.abs(x) > width / 2) return []
|
|
125
|
+
return [{ v, x: clamp(x, -room, room).toFixed(1) }]
|
|
126
|
+
})
|
|
127
|
+
})
|
|
128
|
+
</script>
|
|
129
|
+
|
|
130
|
+
<template>
|
|
131
|
+
<div :class="styles.root">
|
|
132
|
+
<div :class="styles.head">
|
|
133
|
+
<span :id="labelId" :class="styles.label">{{ label }}</span>
|
|
134
|
+
<Roll :text="formatValue(shown)" :class="styles.readout" />
|
|
135
|
+
<span v-if="hasDetail" :id="detailId" :class="styles.detail"><slot name="detail">{{ detail }}</slot></span>
|
|
136
|
+
</div>
|
|
137
|
+
<div
|
|
138
|
+
ref="scrubEl"
|
|
139
|
+
:class="styles.track"
|
|
140
|
+
role="slider"
|
|
141
|
+
tabindex="0"
|
|
142
|
+
:aria-labelledby="labelId"
|
|
143
|
+
:aria-describedby="hasDetail ? detailId : undefined"
|
|
144
|
+
:aria-valuemin="min"
|
|
145
|
+
:aria-valuemax="ruler.top"
|
|
146
|
+
:aria-valuenow="value"
|
|
147
|
+
:aria-valuetext="formatValue(value)"
|
|
148
|
+
:data-moving="sc.moving.value || undefined"
|
|
149
|
+
:data-leaning="lean > 0 || undefined"
|
|
150
|
+
v-on="sc.handlers"
|
|
151
|
+
>
|
|
152
|
+
<span :class="styles.needle" aria-hidden="true" />
|
|
153
|
+
<div :class="styles.clip" aria-hidden="true">
|
|
154
|
+
<span v-for="m in marks" :key="m.v" :class="styles.mark" :style="{ transform: m.place }">
|
|
155
|
+
<i :class="styles.tick" :data-tier="m.tier" :style="m.tick" />
|
|
156
|
+
<span v-if="m.tier === 'major'" :class="styles.num" :style="{ color: m.num }">{{ markText(m.v) }}</span>
|
|
157
|
+
</span>
|
|
158
|
+
</div>
|
|
159
|
+
<div v-if="strongLabel" :class="styles.tags" aria-hidden="true">
|
|
160
|
+
<!-- Measured once, so a tag near an end can stay whole inside the ruler. -->
|
|
161
|
+
<span ref="tagEl" :class="styles.tag" data-measure="true">{{ strongLabel }}</span>
|
|
162
|
+
<span v-for="t in tags" :key="t.v" :class="styles.tag" :style="{ transform: `translateX(calc(${t.x}px - 50%))` }">{{ strongLabel }}</span>
|
|
163
|
+
</div>
|
|
164
|
+
</div>
|
|
165
|
+
</div>
|
|
166
|
+
</template>
|