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,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>
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { useEffect, useLayoutEffect, useRef, type CSSProperties, type ReactNode } from 'react'
|
|
4
4
|
import { cx } from '../../internal/cx'
|
|
5
|
-
import {
|
|
5
|
+
import { createScrollArea, type ScrollAxis } from '../../internal/motion/scrollArea'
|
|
6
6
|
import styles from './ScrollArea.module.css'
|
|
7
7
|
|
|
8
8
|
export type ScrollAreaProps = {
|
|
@@ -18,151 +18,39 @@ export type ScrollAreaProps = {
|
|
|
18
18
|
children: ReactNode
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
type Axis = 'y' | 'x'
|
|
22
|
-
const IDLE_MS = 900
|
|
23
|
-
|
|
24
21
|
export function ScrollArea({ label, maxHeight, orientation = 'vertical', className, children }: ScrollAreaProps) {
|
|
25
22
|
const rootRef = useRef<HTMLDivElement>(null)
|
|
26
23
|
const viewportRef = useRef<HTMLDivElement>(null)
|
|
27
|
-
const thumbs = useRef<Record<
|
|
28
|
-
const idle = useRef<number | undefined>(undefined)
|
|
29
|
-
const drag = useRef<{ axis: Axis; start: number; scroll: number; ratio: number; pointer: number } | null>(null)
|
|
24
|
+
const thumbs = useRef<Record<ScrollAxis, HTMLDivElement | null>>({ x: null, y: null })
|
|
30
25
|
const showY = orientation !== 'horizontal'
|
|
31
26
|
const showX = orientation !== 'vertical'
|
|
32
27
|
|
|
33
|
-
//
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
if (!vp || !root) return
|
|
38
|
-
const place = (axis: Axis) => {
|
|
39
|
-
const thumb = thumbs.current[axis]
|
|
40
|
-
if (!thumb) return
|
|
41
|
-
const track = thumb.parentElement as HTMLElement
|
|
42
|
-
const size = axis === 'y' ? vp.clientHeight : vp.clientWidth
|
|
43
|
-
const full = axis === 'y' ? vp.scrollHeight : vp.scrollWidth
|
|
44
|
-
const pos = axis === 'y' ? vp.scrollTop : vp.scrollLeft
|
|
45
|
-
const overflow = full > size + 1
|
|
46
|
-
track.toggleAttribute('data-hidden', !overflow)
|
|
47
|
-
if (!overflow) return
|
|
48
|
-
const pad = parseFloat(getComputedStyle(track).paddingTop) || 0
|
|
49
|
-
const trackLen = (axis === 'y' ? track.clientHeight : track.clientWidth) - pad * 2
|
|
50
|
-
const minThumb = parseFloat(getComputedStyle(root).getPropertyValue('--gooee-scrollbar-min')) || 24
|
|
51
|
-
const len = Math.max(minThumb, (size / full) * trackLen)
|
|
52
|
-
const offset = (pos / (full - size)) * (trackLen - len)
|
|
53
|
-
if (axis === 'y') {
|
|
54
|
-
thumb.style.height = `${len}px`
|
|
55
|
-
thumb.style.transform = `translateY(${offset}px)`
|
|
56
|
-
} else {
|
|
57
|
-
thumb.style.width = `${len}px`
|
|
58
|
-
thumb.style.transform = `translateX(${offset}px)`
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
place('y')
|
|
62
|
-
place('x')
|
|
63
|
-
}, [])
|
|
64
|
-
|
|
65
|
-
const wake = () => {
|
|
66
|
-
const root = rootRef.current
|
|
67
|
-
if (!root) return
|
|
68
|
-
root.setAttribute('data-active', '')
|
|
69
|
-
window.clearTimeout(idle.current)
|
|
70
|
-
idle.current = window.setTimeout(() => {
|
|
71
|
-
if (!drag.current) root.removeAttribute('data-active')
|
|
72
|
-
}, IDLE_MS)
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
useLayoutEffect(() => {
|
|
76
|
-
update()
|
|
77
|
-
const vp = viewportRef.current
|
|
78
|
-
if (!vp) return
|
|
79
|
-
const ro = new ResizeObserver(update)
|
|
80
|
-
ro.observe(vp)
|
|
81
|
-
if (vp.firstElementChild) ro.observe(vp.firstElementChild)
|
|
82
|
-
return () => ro.disconnect()
|
|
83
|
-
}, [update])
|
|
84
|
-
|
|
85
|
-
useEffect(() => () => window.clearTimeout(idle.current), [])
|
|
86
|
-
|
|
87
|
-
const onThumbDown = (axis: Axis) => (e: PointerEvent<HTMLDivElement>) => {
|
|
88
|
-
const vp = viewportRef.current
|
|
89
|
-
if (!vp || (e.pointerType === 'mouse' && e.button !== 0)) return
|
|
90
|
-
e.preventDefault()
|
|
91
|
-
e.stopPropagation()
|
|
92
|
-
const track = e.currentTarget.parentElement as HTMLElement
|
|
93
|
-
const size = axis === 'y' ? vp.clientHeight : vp.clientWidth
|
|
94
|
-
const full = axis === 'y' ? vp.scrollHeight : vp.scrollWidth
|
|
95
|
-
const pad = parseFloat(getComputedStyle(track).paddingTop) || 0
|
|
96
|
-
const trackLen = (axis === 'y' ? track.clientHeight : track.clientWidth) - pad * 2
|
|
97
|
-
const thumbLen = axis === 'y' ? e.currentTarget.offsetHeight : e.currentTarget.offsetWidth
|
|
98
|
-
// The thumb travels the track minus its own length, which is all the scroll there is.
|
|
99
|
-
drag.current = {
|
|
100
|
-
axis,
|
|
101
|
-
start: axis === 'y' ? e.clientY : e.clientX,
|
|
102
|
-
scroll: axis === 'y' ? vp.scrollTop : vp.scrollLeft,
|
|
103
|
-
ratio: (full - size) / Math.max(1, trackLen - thumbLen),
|
|
104
|
-
pointer: e.pointerId,
|
|
105
|
-
}
|
|
106
|
-
e.currentTarget.setPointerCapture(e.pointerId)
|
|
107
|
-
rootRef.current?.setAttribute('data-dragging', '')
|
|
108
|
-
}
|
|
28
|
+
// The thumbs, their idle fade and drags (motion/scrollArea.ts): direct style writes, so scrolling never re-renders React.
|
|
29
|
+
const area = useRef<ReturnType<typeof createScrollArea>>(null)
|
|
30
|
+
area.current ??= createScrollArea({ root: () => rootRef.current, viewport: () => viewportRef.current, thumb: (axis) => thumbs.current[axis] })
|
|
31
|
+
const a = area.current
|
|
109
32
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
const vp = viewportRef.current
|
|
113
|
-
if (!d || !vp || d.pointer !== e.pointerId) return
|
|
114
|
-
const delta = (d.axis === 'y' ? e.clientY : e.clientX) - d.start
|
|
115
|
-
if (d.axis === 'y') vp.scrollTop = d.scroll + delta * d.ratio
|
|
116
|
-
else vp.scrollLeft = d.scroll + delta * d.ratio
|
|
117
|
-
}
|
|
33
|
+
useLayoutEffect(() => a.observe(), [a])
|
|
34
|
+
useEffect(() => a.destroy, [a])
|
|
118
35
|
|
|
119
|
-
const
|
|
120
|
-
|
|
121
|
-
e.currentTarget.releasePointerCapture(drag.current.pointer)
|
|
122
|
-
drag.current = null
|
|
123
|
-
rootRef.current?.removeAttribute('data-dragging')
|
|
124
|
-
wake()
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
const onTrackDown = (axis: Axis) => (e: PointerEvent<HTMLDivElement>) => {
|
|
128
|
-
const vp = viewportRef.current
|
|
129
|
-
const thumb = thumbs.current[axis]
|
|
130
|
-
if (!vp || !thumb) return
|
|
131
|
-
const r = thumb.getBoundingClientRect()
|
|
132
|
-
const before = axis === 'y' ? e.clientY < r.top : e.clientX < r.left
|
|
133
|
-
const page = (axis === 'y' ? vp.clientHeight : vp.clientWidth) * 0.9
|
|
134
|
-
vp.scrollBy({ [axis === 'y' ? 'top' : 'left']: before ? -page : page, behavior: prefersReducedMotion() ? 'auto' : 'smooth' })
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
const track = (axis: Axis) => (
|
|
138
|
-
<div className={styles.track} data-axis={axis} aria-hidden="true" onPointerDown={onTrackDown(axis)}>
|
|
36
|
+
const track = (axis: ScrollAxis) => (
|
|
37
|
+
<div className={styles.track} data-axis={axis} aria-hidden="true" onPointerDown={(e) => a.trackDown(axis, e)}>
|
|
139
38
|
<div
|
|
140
39
|
ref={(el) => {
|
|
141
40
|
thumbs.current[axis] = el
|
|
142
41
|
}}
|
|
143
42
|
className={styles.thumb}
|
|
144
|
-
onPointerDown={
|
|
145
|
-
onPointerMove={
|
|
146
|
-
onPointerUp={
|
|
147
|
-
onPointerCancel={
|
|
43
|
+
onPointerDown={(e) => a.thumbDown(axis, e)}
|
|
44
|
+
onPointerMove={a.thumbMove}
|
|
45
|
+
onPointerUp={a.thumbUp}
|
|
46
|
+
onPointerCancel={a.thumbUp}
|
|
148
47
|
/>
|
|
149
48
|
</div>
|
|
150
49
|
)
|
|
151
50
|
|
|
152
51
|
return (
|
|
153
|
-
<div ref={rootRef} className={cx(styles.root, className)} data-orientation={orientation} onPointerEnter={wake} onPointerMove={wake}>
|
|
154
|
-
<div
|
|
155
|
-
ref={viewportRef}
|
|
156
|
-
className={styles.viewport}
|
|
157
|
-
style={{ maxHeight }}
|
|
158
|
-
role="region"
|
|
159
|
-
aria-label={label}
|
|
160
|
-
tabIndex={0}
|
|
161
|
-
onScroll={() => {
|
|
162
|
-
update()
|
|
163
|
-
wake()
|
|
164
|
-
}}
|
|
165
|
-
>
|
|
52
|
+
<div ref={rootRef} className={cx(styles.root, className)} data-orientation={orientation} onPointerEnter={a.wake} onPointerMove={a.wake}>
|
|
53
|
+
<div ref={viewportRef} className={styles.viewport} style={{ maxHeight }} role="region" aria-label={label} tabIndex={0} onScroll={a.onScroll}>
|
|
166
54
|
<div className={styles.content}>{children}</div>
|
|
167
55
|
</div>
|
|
168
56
|
{showY && track('y')}
|