gooee 0.52.0 → 1.0.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/README.md +10 -3
- package/package.json +6 -2
- package/scripts/add.js +181 -42
- package/src/base.css +3 -1
- package/src/components/Accordion/Accordion.module.css +7 -5
- package/src/components/Accordion/Accordion.tsx +13 -11
- package/src/components/Accordion/Accordion.vue +16 -15
- package/src/components/Accordion/AccordionItem.vue +8 -7
- package/src/components/Alert/Alert.module.css +9 -7
- package/src/components/Alert/Alert.tsx +25 -16
- package/src/components/Alert/Alert.vue +31 -27
- package/src/components/AlertDialog/AlertDialog.module.css +2 -0
- package/src/components/AlertDialog/AlertDialog.tsx +8 -7
- package/src/components/AlertDialog/AlertDialog.vue +25 -23
- package/src/components/AnimatedNumber/AnimatedNumber.module.css +5 -3
- package/src/components/AnimatedNumber/AnimatedNumber.tsx +6 -6
- package/src/components/AnimatedNumber/AnimatedNumber.vue +5 -5
- package/src/components/AspectRatio/AspectRatio.module.css +2 -0
- package/src/components/AspectRatio/AspectRatio.tsx +3 -3
- package/src/components/AspectRatio/AspectRatio.vue +5 -8
- package/src/components/Avatar/Avatar.module.css +10 -8
- package/src/components/Avatar/Avatar.tsx +4 -3
- package/src/components/Avatar/Avatar.vue +17 -19
- package/src/components/Avatar/index.ts +0 -2
- package/src/components/AvatarGroup/AvatarGroup.module.css +11 -9
- package/src/components/AvatarGroup/AvatarGroup.tsx +4 -4
- package/src/components/AvatarGroup/AvatarGroup.vue +13 -16
- package/src/components/Badge/Badge.module.css +6 -4
- package/src/components/Badge/Badge.tsx +3 -3
- package/src/components/Badge/Badge.vue +15 -14
- package/src/components/Breadcrumb/Breadcrumb.module.css +5 -3
- package/src/components/Breadcrumb/Breadcrumb.tsx +20 -12
- package/src/components/Breadcrumb/Breadcrumb.vue +33 -25
- package/src/components/Button/Button.module.css +16 -14
- package/src/components/Button/Button.tsx +6 -4
- package/src/components/Button/Button.vue +42 -33
- package/src/components/ButtonGroup/ButtonGroup.module.css +2 -0
- package/src/components/ButtonGroup/ButtonGroup.tsx +1 -1
- package/src/components/ButtonGroup/ButtonGroup.vue +9 -12
- package/src/components/Card/Card.module.css +6 -4
- package/src/components/Card/Card.tsx +6 -6
- package/src/components/Card/Card.vue +18 -21
- package/src/components/Center/Center.module.css +2 -0
- package/src/components/Center/Center.tsx +1 -1
- package/src/components/Center/Center.vue +18 -15
- package/src/components/Checkbox/Checkbox.module.css +10 -8
- package/src/components/Checkbox/Checkbox.tsx +7 -5
- package/src/components/Checkbox/Checkbox.vue +29 -31
- package/src/components/CheckboxGroup/CheckboxGroup.module.css +3 -1
- package/src/components/CheckboxGroup/CheckboxGroup.tsx +4 -4
- package/src/components/CheckboxGroup/CheckboxGroup.vue +33 -30
- package/src/components/Cluster/Cluster.module.css +2 -0
- package/src/components/Cluster/Cluster.tsx +1 -1
- package/src/components/Cluster/Cluster.vue +21 -17
- package/src/components/CodeBlock/CodeBlock.module.css +12 -10
- package/src/components/CodeBlock/CodeBlock.tsx +18 -10
- package/src/components/CodeBlock/CodeBlock.vue +30 -27
- package/src/components/CodeBlock/highlight.ts +1 -1
- package/src/components/Collapsible/Collapsible.module.css +7 -5
- package/src/components/Collapsible/Collapsible.tsx +7 -6
- package/src/components/Collapsible/Collapsible.vue +30 -26
- package/src/components/Container/Container.module.css +2 -0
- package/src/components/Container/Container.tsx +1 -1
- package/src/components/Container/Container.vue +13 -12
- package/src/components/CopyButton/CopyButton.module.css +20 -18
- package/src/components/CopyButton/CopyButton.tsx +21 -14
- package/src/components/CopyButton/CopyButton.vue +41 -31
- package/src/components/Dial/Dial.module.css +26 -11
- package/src/components/Dial/Dial.tsx +18 -18
- package/src/components/Dial/Dial.vue +57 -60
- package/src/components/Dialog/Dialog.module.css +4 -2
- package/src/components/Dialog/Dialog.tsx +22 -13
- package/src/components/Dialog/Dialog.vue +34 -30
- package/src/components/Divider/Divider.module.css +5 -3
- package/src/components/Divider/Divider.tsx +6 -4
- package/src/components/Divider/Divider.vue +13 -16
- package/src/components/DropdownMenu/DropdownMenu.module.css +8 -6
- package/src/components/DropdownMenu/DropdownMenu.tsx +11 -8
- package/src/components/DropdownMenu/DropdownMenu.vue +24 -27
- package/src/components/EmptyState/EmptyState.module.css +6 -4
- package/src/components/EmptyState/EmptyState.tsx +6 -6
- package/src/components/EmptyState/EmptyState.vue +14 -17
- package/src/components/Fab/Fab.module.css +19 -17
- package/src/components/Fab/Fab.tsx +11 -9
- package/src/components/Fab/Fab.vue +29 -26
- package/src/components/Fieldset/Fieldset.module.css +2 -0
- package/src/components/Fieldset/Fieldset.tsx +4 -3
- package/src/components/Fieldset/Fieldset.vue +4 -4
- package/src/components/FormField/FormField.module.css +5 -3
- package/src/components/FormField/FormField.tsx +7 -7
- package/src/components/FormField/FormField.vue +4 -4
- package/src/components/Grid/Grid.module.css +2 -0
- package/src/components/Grid/Grid.tsx +1 -1
- package/src/components/Grid/Grid.vue +25 -22
- package/src/components/HoldToConfirm/HoldToConfirm.module.css +13 -11
- package/src/components/HoldToConfirm/HoldToConfirm.tsx +11 -9
- package/src/components/HoldToConfirm/HoldToConfirm.vue +37 -32
- package/src/components/IconButton/IconButton.module.css +7 -5
- package/src/components/IconButton/IconButton.tsx +2 -1
- package/src/components/IconButton/IconButton.vue +15 -14
- package/src/components/Input/Input.module.css +12 -10
- package/src/components/Input/Input.tsx +9 -7
- package/src/components/Input/Input.vue +45 -35
- package/src/components/InputGroup/InputGroup.module.css +8 -6
- package/src/components/InputGroup/InputGroup.tsx +5 -4
- package/src/components/InputGroup/InputGroup.vue +41 -36
- package/src/components/Kbd/Kbd.module.css +9 -7
- package/src/components/Kbd/Kbd.tsx +1 -1
- package/src/components/Kbd/Kbd.vue +1 -1
- package/src/components/Link/Link.module.css +4 -2
- package/src/components/Link/Link.tsx +4 -3
- package/src/components/Link/Link.vue +13 -16
- package/src/components/LivePill/LivePill.module.css +39 -37
- package/src/components/LivePill/LivePill.tsx +11 -10
- package/src/components/LivePill/LivePill.vue +38 -40
- package/src/components/Meter/Meter.module.css +5 -3
- package/src/components/Meter/Meter.tsx +9 -8
- package/src/components/Meter/Meter.vue +52 -43
- package/src/components/MorphButton/MorphButton.module.css +11 -9
- package/src/components/MorphButton/MorphButton.tsx +20 -10
- package/src/components/MorphButton/MorphButton.vue +29 -25
- package/src/components/NumberInput/NumberInput.module.css +7 -5
- package/src/components/NumberInput/NumberInput.tsx +11 -8
- package/src/components/NumberInput/NumberInput.vue +69 -57
- package/src/components/Pagination/Pagination.module.css +147 -5
- package/src/components/Pagination/Pagination.tsx +216 -41
- package/src/components/Pagination/Pagination.vue +201 -36
- package/src/components/Pagination/labels.ts +38 -0
- package/src/components/PasswordInput/PasswordInput.module.css +10 -8
- package/src/components/PasswordInput/PasswordInput.tsx +15 -7
- package/src/components/PasswordInput/PasswordInput.vue +20 -16
- package/src/components/PasswordInput/index.ts +1 -1
- package/src/components/PickerWheel/DateWheel.vue +20 -12
- package/src/components/PickerWheel/PickerWheel.module.css +15 -6
- package/src/components/PickerWheel/PickerWheel.tsx +70 -44
- package/src/components/PickerWheel/PickerWheel.vue +39 -38
- package/src/components/PickerWheel/TimeWheel.vue +23 -21
- package/src/components/PickerWheel/WheelColumn.vue +7 -5
- package/src/components/Popover/Popover.module.css +5 -3
- package/src/components/Popover/Popover.tsx +17 -8
- package/src/components/Popover/Popover.vue +26 -25
- package/src/components/ProgressBar/ProgressBar.module.css +4 -2
- package/src/components/ProgressBar/ProgressBar.tsx +6 -5
- package/src/components/ProgressBar/ProgressBar.vue +28 -25
- package/src/components/Prose/Prose.module.css +5 -3
- package/src/components/Prose/Prose.tsx +1 -1
- package/src/components/Prose/Prose.vue +5 -8
- package/src/components/Radio/Radio.module.css +10 -8
- package/src/components/Radio/Radio.tsx +10 -8
- package/src/components/Radio/Radio.vue +8 -8
- package/src/components/Radio/RadioGroup.vue +33 -35
- package/src/components/Radio/radioContext.ts +12 -0
- package/src/components/Retime/Retime.vue +25 -22
- package/src/components/RulerScrubber/RulerScrubber.module.css +11 -2
- package/src/components/RulerScrubber/RulerScrubber.tsx +19 -18
- package/src/components/RulerScrubber/RulerScrubber.vue +50 -54
- package/src/components/ScrollArea/ScrollArea.module.css +17 -15
- package/src/components/ScrollArea/ScrollArea.tsx +5 -4
- package/src/components/ScrollArea/ScrollArea.vue +15 -17
- package/src/components/SearchInput/SearchInput.module.css +6 -4
- package/src/components/SearchInput/SearchInput.tsx +15 -8
- package/src/components/SearchInput/SearchInput.vue +20 -17
- package/src/components/SearchInput/index.ts +1 -1
- package/src/components/SegmentedControl/SegmentedControl.module.css +7 -5
- package/src/components/SegmentedControl/SegmentedControl.tsx +9 -5
- package/src/components/SegmentedControl/SegmentedControl.vue +25 -29
- package/src/components/Select/Select.module.css +19 -17
- package/src/components/Select/Select.tsx +30 -17
- package/src/components/Select/Select.vue +62 -57
- package/src/components/Sheet/Sheet.module.css +6 -4
- package/src/components/Sheet/Sheet.tsx +39 -29
- package/src/components/Sheet/Sheet.vue +46 -40
- package/src/components/Skeleton/Skeleton.module.css +4 -2
- package/src/components/Skeleton/Skeleton.tsx +3 -2
- package/src/components/Skeleton/Skeleton.vue +16 -18
- package/src/components/Slider/Slider.module.css +14 -12
- package/src/components/Slider/Slider.tsx +20 -9
- package/src/components/Slider/Slider.vue +47 -37
- package/src/components/Spinner/Spinner.module.css +2 -0
- package/src/components/Spinner/Spinner.tsx +3 -3
- package/src/components/Spinner/Spinner.vue +9 -12
- package/src/components/Split/Split.module.css +2 -0
- package/src/components/Split/Split.tsx +3 -3
- package/src/components/Split/Split.vue +19 -17
- package/src/components/SplitFlap/SplitFlap.module.css +9 -7
- package/src/components/SplitFlap/SplitFlap.tsx +2 -2
- package/src/components/SplitFlap/SplitFlap.vue +24 -21
- package/src/components/Stack/Stack.module.css +2 -0
- package/src/components/Stack/Stack.tsx +1 -1
- package/src/components/Stack/Stack.vue +13 -12
- package/src/components/SwipeDeck/SwipeDeck.module.css +13 -11
- package/src/components/SwipeDeck/SwipeDeck.tsx +23 -28
- package/src/components/SwipeDeck/SwipeDeck.vue +32 -38
- package/src/components/Switch/Switch.module.css +10 -8
- package/src/components/Switch/Switch.tsx +6 -5
- package/src/components/Switch/Switch.vue +22 -24
- package/src/components/Table/Table.module.css +24 -22
- package/src/components/Table/Table.tsx +27 -30
- package/src/components/Table/Table.vue +93 -79
- package/src/components/TableOfContents/TableOfContents.module.css +9 -7
- package/src/components/TableOfContents/TableOfContents.tsx +8 -8
- package/src/components/TableOfContents/TableOfContents.vue +20 -23
- package/src/components/Tabs/Tab.vue +3 -0
- package/src/components/Tabs/TabList.vue +2 -2
- package/src/components/Tabs/TabPanel.vue +2 -0
- package/src/components/Tabs/Tabs.module.css +4 -2
- package/src/components/Tabs/Tabs.tsx +10 -5
- package/src/components/Tabs/Tabs.vue +1 -1
- package/src/components/Tag/Tag.module.css +12 -10
- package/src/components/Tag/Tag.tsx +13 -15
- package/src/components/Tag/Tag.vue +12 -14
- package/src/components/Textarea/Textarea.module.css +8 -6
- package/src/components/Textarea/Textarea.tsx +4 -3
- package/src/components/Textarea/Textarea.vue +32 -34
- package/src/components/ThemeToggle/ThemeToggle.module.css +2 -0
- package/src/components/ThemeToggle/ThemeToggle.tsx +7 -7
- package/src/components/ThemeToggle/ThemeToggle.vue +24 -22
- package/src/components/Toast/Toast.module.css +17 -15
- package/src/components/Toast/Toast.tsx +51 -34
- package/src/components/Toast/Toast.vue +35 -24
- package/src/components/Toast/ToastItem.vue +17 -16
- package/src/components/Toggle/Toggle.module.css +11 -9
- package/src/components/Toggle/Toggle.tsx +3 -2
- package/src/components/Toggle/Toggle.vue +13 -15
- package/src/components/Tooltip/Tooltip.module.css +5 -3
- package/src/components/Tooltip/Tooltip.tsx +1 -0
- package/src/components/Tooltip/Tooltip.vue +13 -18
- package/src/components/VisuallyHidden/VisuallyHidden.module.css +2 -0
- package/src/components/VisuallyHidden/VisuallyHidden.tsx +1 -1
- package/src/components/VisuallyHidden/VisuallyHidden.vue +5 -8
- package/src/{internal → icons}/icons.module.css +4 -2
- package/src/{internal → icons}/icons.tsx +15 -16
- package/src/internal/FieldMessage.module.css +5 -3
- package/src/internal/FieldMessage.tsx +2 -2
- package/src/internal/FieldMessage.vue +2 -2
- package/src/internal/Roll.module.css +5 -3
- package/src/internal/feel.ts +12 -10
- package/src/internal/fling.ts +3 -3
- package/src/internal/liquid.ts +12 -10
- package/src/internal/liquidMatter.ts +1 -1
- package/src/internal/liquidMore.ts +7 -7
- package/src/internal/motion/checkbox.ts +4 -4
- package/src/internal/motion/fling.ts +19 -9
- package/src/internal/motion/holdToConfirm.ts +3 -3
- package/src/internal/motion/index.ts +8 -6
- package/src/internal/motion/liquid.ts +16 -4
- package/src/internal/motion/liquidMatter.ts +8 -6
- package/src/internal/motion/liquidMore.ts +44 -25
- package/src/internal/motion/livePill.ts +1 -1
- package/src/internal/motion/numberInput.ts +2 -2
- package/src/internal/motion/pickerWheel.ts +7 -4
- package/src/internal/motion/ruler.ts +1 -1
- package/src/internal/motion/scrollArea.ts +3 -3
- package/src/internal/motion/scrollFrame.ts +9 -7
- package/src/internal/motion/scrubber.ts +39 -20
- package/src/internal/motion/slider.ts +38 -4
- package/src/internal/motion/softPress.ts +10 -9
- package/src/internal/motion/splitFlap.ts +4 -4
- package/src/internal/motion/swipeDeck.ts +38 -7
- package/src/internal/motion/table.ts +3 -6
- package/src/internal/motion/themeIcon.ts +1 -1
- package/src/internal/motion/themeReveal.ts +1 -1
- package/src/internal/motion/toast.ts +3 -3
- package/src/internal/motion.ts +7 -8
- package/src/internal/scrollFrame.ts +3 -3
- package/src/internal/useScrub.ts +1 -15
- package/src/internal/vue/useScrub.ts +2 -6
- package/src/tokens.css +81 -421
- package/src/{internal/vueIcons.ts → icons/vue.ts} +5 -5
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
/* The script reads this token, so each is registered with its default: set it on :root to change it. */
|
|
2
|
+
@property --gooee-ruler-scrubber-tick-gap {
|
|
3
|
+
syntax: '<length>';
|
|
4
|
+
inherits: true;
|
|
5
|
+
initial-value: 12px;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
@layer gooee.components {
|
|
1
9
|
.root {
|
|
2
10
|
display: grid;
|
|
3
11
|
gap: var(--gooee-space-6);
|
|
@@ -31,9 +39,9 @@
|
|
|
31
39
|
}
|
|
32
40
|
|
|
33
41
|
.track {
|
|
34
|
-
--base: calc(var(--gooee-ruler-h) * 0.63);
|
|
42
|
+
--base: calc(var(--gooee-ruler-scrubber-h, 120px) * 0.63);
|
|
35
43
|
position: relative;
|
|
36
|
-
height: var(--gooee-ruler-h);
|
|
44
|
+
height: var(--gooee-ruler-scrubber-h, 120px);
|
|
37
45
|
border-radius: var(--gooee-radius-md);
|
|
38
46
|
cursor: grab;
|
|
39
47
|
outline: none;
|
|
@@ -144,3 +152,4 @@
|
|
|
144
152
|
.tag[data-measure] {
|
|
145
153
|
visibility: hidden;
|
|
146
154
|
}
|
|
155
|
+
}
|
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
import { useEffect, useId, useLayoutEffect, useRef, useState, type ComponentPropsWithRef, type ReactNode } from 'react'
|
|
4
4
|
import { cx } from '../../internal/cx'
|
|
5
5
|
import { clamp, follow, pull, roundTo, wheelSteps } from '../../internal/feel'
|
|
6
|
-
import { morphCurve,
|
|
6
|
+
import { morphCurve, motionMs } from '../../internal/motion'
|
|
7
7
|
import { measureRuler, rulerScale, rulerScrub, type RulerFit } from '../../internal/motion/ruler'
|
|
8
8
|
import { Roll } from '../../internal/Roll'
|
|
9
9
|
import { useControllable } from '../../internal/useControllable'
|
|
10
|
-
import { ink,
|
|
10
|
+
import { ink, useScrub } from '../../internal/useScrub'
|
|
11
11
|
import styles from './RulerScrubber.module.css'
|
|
12
12
|
|
|
13
13
|
export type RulerScrubberProps = Omit<ComponentPropsWithRef<'div'>, 'defaultValue' | 'onChange' | 'children'> & {
|
|
@@ -17,10 +17,10 @@ export type RulerScrubberProps = Omit<ComponentPropsWithRef<'div'>, 'defaultValu
|
|
|
17
17
|
value?: number
|
|
18
18
|
/** Starting value when you do not control it. Undefined starts at min. */
|
|
19
19
|
defaultValue?: number
|
|
20
|
-
/** Called
|
|
20
|
+
/** Called with each new value under the needle, while the ruler still moves. */
|
|
21
21
|
onValueChange?: (value: number) => void
|
|
22
|
-
/** Called
|
|
23
|
-
|
|
22
|
+
/** Called once the ruler comes to rest on a new value. */
|
|
23
|
+
onValueCommit?: (value: number) => void
|
|
24
24
|
/** Lowest value. */
|
|
25
25
|
min?: number
|
|
26
26
|
/** Highest value. */
|
|
@@ -48,7 +48,7 @@ export function RulerScrubber({
|
|
|
48
48
|
value: valueProp,
|
|
49
49
|
defaultValue,
|
|
50
50
|
onValueChange,
|
|
51
|
-
|
|
51
|
+
onValueCommit,
|
|
52
52
|
min = 0,
|
|
53
53
|
max = 100,
|
|
54
54
|
step = 1,
|
|
@@ -76,7 +76,7 @@ export function RulerScrubber({
|
|
|
76
76
|
const wheel = useRef(wheelSteps())
|
|
77
77
|
|
|
78
78
|
// The drag, keys, tap and wheel (motion/ruler.ts) on the shared scrubber.
|
|
79
|
-
const sc = useScrub({ value, ...rulerScrub(scale, fit, wheel.current),
|
|
79
|
+
const sc = useScrub({ value, ...rulerScrub(scale, fit, wheel.current), onMark: setValue, onSettle: (v) => onValueCommit?.(v), haptics })
|
|
80
80
|
|
|
81
81
|
useLayoutEffect(() => {
|
|
82
82
|
const el = sc.ref.current
|
|
@@ -91,24 +91,23 @@ export function RulerScrubber({
|
|
|
91
91
|
// The ticks lean and grow only while the ruler moves. The lean eases in as it starts and settles flat as it stops.
|
|
92
92
|
const [lean, setLean] = useState(0)
|
|
93
93
|
const leaning = useRef<ReturnType<typeof follow> | null>(null)
|
|
94
|
-
if (!leaning.current) leaning.current = follow({ time: () =>
|
|
94
|
+
if (!leaning.current) leaning.current = follow({ time: () => motionMs('morph-out'), curve: morphCurve(), onFrame: setLean })
|
|
95
95
|
useEffect(() => {
|
|
96
|
-
leaning.current?.set(sc.moving &&
|
|
96
|
+
leaning.current?.set(sc.moving && motionMs('morph-out') > 0 ? 1 : 0)
|
|
97
97
|
}, [sc.moving])
|
|
98
98
|
useEffect(() => () => leaning.current?.stop(), [])
|
|
99
99
|
|
|
100
100
|
const shown = land(sc.at)
|
|
101
|
-
useOnChange(shown, onScrub)
|
|
102
101
|
|
|
103
102
|
return (
|
|
104
|
-
<div className={cx(styles.root, className)} {...rest}>
|
|
103
|
+
<div className={cx(styles.root, className)} data-slot="ruler-scrubber" {...rest}>
|
|
105
104
|
<div className={styles.head}>
|
|
106
|
-
<span id={labelId} className={styles.label}>
|
|
105
|
+
<span id={labelId} className={styles.label} data-slot="field-label">
|
|
107
106
|
{label}
|
|
108
107
|
</span>
|
|
109
108
|
<Roll text={formatValue(shown)} className={styles.readout} />
|
|
110
109
|
{detail && (
|
|
111
|
-
<span id={detailId} className={styles.detail}>
|
|
110
|
+
<span id={detailId} className={styles.detail} data-slot="ruler-scrubber-detail">
|
|
112
111
|
{detail}
|
|
113
112
|
</span>
|
|
114
113
|
)}
|
|
@@ -116,6 +115,7 @@ export function RulerScrubber({
|
|
|
116
115
|
<div
|
|
117
116
|
ref={sc.ref}
|
|
118
117
|
className={styles.track}
|
|
118
|
+
data-slot="ruler-scrubber-track"
|
|
119
119
|
role="slider"
|
|
120
120
|
tabIndex={0}
|
|
121
121
|
aria-labelledby={labelId}
|
|
@@ -128,7 +128,7 @@ export function RulerScrubber({
|
|
|
128
128
|
data-leaning={lean > 0 || undefined}
|
|
129
129
|
{...sc.handlers}
|
|
130
130
|
>
|
|
131
|
-
<span className={styles.needle} aria-hidden />
|
|
131
|
+
<span className={styles.needle} data-slot="ruler-scrubber-needle" aria-hidden />
|
|
132
132
|
<div className={styles.clip} aria-hidden>
|
|
133
133
|
{all.map((v, i) => {
|
|
134
134
|
const d = (v - sc.at) / step
|
|
@@ -138,9 +138,10 @@ export function RulerScrubber({
|
|
|
138
138
|
const tilt = -Math.sign(d) * 14 * Math.sin(Math.PI * Math.min(1, Math.abs(d) / 6)) * (1 - on)
|
|
139
139
|
const tier = labelled.has(v) ? 'major' : i % 2 === 0 ? 'mid' : 'minor'
|
|
140
140
|
return (
|
|
141
|
-
<span key={v} className={styles.mark} style={{ transform: `translateX(calc(${d.toFixed(3)} * var(--gooee-ruler-tick-gap)))` }}>
|
|
141
|
+
<span key={v} className={styles.mark} style={{ transform: `translateX(calc(${d.toFixed(3)} * var(--gooee-ruler-scrubber-tick-gap)))` }}>
|
|
142
142
|
<i
|
|
143
143
|
className={styles.tick}
|
|
144
|
+
data-slot="ruler-scrubber-tick"
|
|
144
145
|
data-tier={tier}
|
|
145
146
|
style={{
|
|
146
147
|
background: ink(on, tier === 'major' ? 'var(--gooee-color-fg-muted)' : 'var(--gooee-color-border-strong)', 'var(--gooee-color-accent)'),
|
|
@@ -148,7 +149,7 @@ export function RulerScrubber({
|
|
|
148
149
|
}}
|
|
149
150
|
/>
|
|
150
151
|
{tier === 'major' && (
|
|
151
|
-
<span className={styles.num} style={{ color: ink(pull(d, 2)) }}>
|
|
152
|
+
<span className={styles.num} data-slot="ruler-scrubber-number" style={{ color: ink(pull(d, 2)) }}>
|
|
152
153
|
{markText(v)}
|
|
153
154
|
</span>
|
|
154
155
|
)}
|
|
@@ -159,7 +160,7 @@ export function RulerScrubber({
|
|
|
159
160
|
{strongLabel && (
|
|
160
161
|
<div className={styles.tags} aria-hidden>
|
|
161
162
|
{/* Measured once, so a tag near an end can stay whole inside the ruler. */}
|
|
162
|
-
<span ref={tagRef} className={styles.tag} data-measure>
|
|
163
|
+
<span ref={tagRef} className={styles.tag} data-slot="ruler-scrubber-tag" data-measure>
|
|
163
164
|
{strongLabel}
|
|
164
165
|
</span>
|
|
165
166
|
{[...strongSet].map((v) => {
|
|
@@ -167,7 +168,7 @@ export function RulerScrubber({
|
|
|
167
168
|
const room = (fit.width - fit.tag) / 2
|
|
168
169
|
if (!fit.gap || Math.abs(x) > fit.width / 2) return null
|
|
169
170
|
return (
|
|
170
|
-
<span key={v} className={styles.tag} style={{ transform: `translateX(calc(${clamp(x, -room, room).toFixed(1)}px - 50%))` }}>
|
|
171
|
+
<span key={v} className={styles.tag} data-slot="ruler-scrubber-tag" style={{ transform: `translateX(calc(${clamp(x, -room, room).toFixed(1)}px - 50%))` }}>
|
|
171
172
|
{strongLabel}
|
|
172
173
|
</span>
|
|
173
174
|
)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import { computed, onBeforeUnmount, onMounted, ref, useId, useSlots, watch } from 'vue'
|
|
3
3
|
import { clamp, follow, pull, roundTo, wheelSteps } from '../../internal/feel'
|
|
4
|
-
import { morphCurve,
|
|
4
|
+
import { morphCurve, motionMs } from '../../internal/motion'
|
|
5
5
|
import { measureRuler, rulerScale, rulerScrub, type RulerFit } from '../../internal/motion/ruler'
|
|
6
6
|
import { ink } from '../../internal/motion/scrubLook'
|
|
7
7
|
import Roll from '../../internal/Roll.vue'
|
|
@@ -10,41 +10,38 @@ import styles from './RulerScrubber.module.css'
|
|
|
10
10
|
|
|
11
11
|
// The Vue RulerScrubber: the same look (RulerScrubber.module.css), drag, lean and landing as the React one.
|
|
12
12
|
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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] }>()
|
|
13
|
+
const { defaultValue, min = 0, max = 100, step = 1, marks: marksProp, strong = [], strongLabel, formatValue = String, formatMark, detail, haptics = false } = defineProps<{
|
|
14
|
+
/** Visible name of the ruler, also read by screen readers. */
|
|
15
|
+
label: string
|
|
16
|
+
/** Starting value when there is no v-model. Undefined starts at min. */
|
|
17
|
+
defaultValue?: number
|
|
18
|
+
/** Lowest value. */
|
|
19
|
+
min?: number
|
|
20
|
+
/** Highest value. */
|
|
21
|
+
max?: number
|
|
22
|
+
/** Size of one step: one tick on the ruler, and a mark it is drawn onto. */
|
|
23
|
+
step?: number
|
|
24
|
+
/** Values with a long, numbered tick. Page Up and Page Down jump between them. Defaults to every 10 steps. */
|
|
25
|
+
marks?: number[]
|
|
26
|
+
/** Values drawn stronger, such as a limit or the usual choice. */
|
|
27
|
+
strong?: number[]
|
|
28
|
+
/** A tag under each strong mark, such as "Allowance". */
|
|
29
|
+
strongLabel?: string
|
|
30
|
+
/** Turns the value into the readout and what screen readers hear. */
|
|
31
|
+
formatValue?: (value: number) => string
|
|
32
|
+
/** Turns a mark into the number under its tick. Defaults to formatValue. */
|
|
33
|
+
formatMark?: (value: number) => string
|
|
34
|
+
/** A line under the readout, such as what the value means. The detail slot replaces it. */
|
|
35
|
+
detail?: string
|
|
36
|
+
/** A short buzz on each tick while it moves, on phones that can (Android). */
|
|
37
|
+
haptics?: boolean
|
|
38
|
+
}>()
|
|
39
|
+
const emit = defineEmits<{ /** The value the ruler came to rest on, once it rests. */ valueCommit: [value: number] }>()
|
|
43
40
|
const slots = useSlots()
|
|
44
41
|
|
|
45
|
-
/** The value, set
|
|
42
|
+
/** The value under the needle, set on each new one while the ruler moves. Use v-model, or leave it out and the ruler keeps its own value. */
|
|
46
43
|
const model = defineModel<number>()
|
|
47
|
-
const local = ref(
|
|
44
|
+
const local = ref(defaultValue ?? min)
|
|
48
45
|
const raw = computed({
|
|
49
46
|
get: () => model.value ?? local.value,
|
|
50
47
|
set: (next: number) => {
|
|
@@ -55,18 +52,18 @@ const raw = computed({
|
|
|
55
52
|
|
|
56
53
|
const labelId = useId()
|
|
57
54
|
const detailId = useId()
|
|
58
|
-
const scale = computed(() => ({ min
|
|
55
|
+
const scale = computed(() => ({ min, max, step, marks: marksProp }))
|
|
59
56
|
const ruler = computed(() => rulerScale(scale.value))
|
|
60
|
-
const value = computed(() => clamp(raw.value,
|
|
61
|
-
const strongSet = computed(() => new Set(
|
|
62
|
-
const markText = (v: number) => (
|
|
57
|
+
const value = computed(() => clamp(raw.value, min, ruler.value.top))
|
|
58
|
+
const strongSet = computed(() => new Set(strong.map((v) => roundTo(v, step, min))))
|
|
59
|
+
const markText = (v: number) => (formatMark ?? formatValue)(v)
|
|
63
60
|
// The px between two ticks (a token) and how many ticks fit either side of the needle.
|
|
64
61
|
const fit = ref<RulerFit>({ gap: 0, span: 24, width: 0, tag: 0 })
|
|
65
62
|
const tagEl = ref<HTMLElement | null>(null)
|
|
66
63
|
const wheel = wheelSteps()
|
|
67
64
|
|
|
68
65
|
// 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),
|
|
66
|
+
const sc = useScrub(() => ({ value: value.value, ...rulerScrub(scale.value, fit.value, wheel), onMark: (v: number) => (raw.value = v), onSettle: (v: number) => emit('valueCommit', v), haptics }))
|
|
70
67
|
const scrubEl = sc.el
|
|
71
68
|
|
|
72
69
|
const measure = () => scrubEl.value && (fit.value = measureRuler(scrubEl.value, tagEl.value))
|
|
@@ -76,24 +73,22 @@ onMounted(() => {
|
|
|
76
73
|
ro = new ResizeObserver(measure)
|
|
77
74
|
if (scrubEl.value) ro.observe(scrubEl.value)
|
|
78
75
|
})
|
|
79
|
-
watch(() =>
|
|
76
|
+
watch(() => strongLabel, measure, { flush: 'post' })
|
|
80
77
|
|
|
81
78
|
// The ticks lean and grow only while the ruler moves. The lean eases in as it starts and settles flat as it stops.
|
|
82
79
|
const lean = ref(0)
|
|
83
|
-
const leaning = follow({ time: () =>
|
|
84
|
-
watch(sc.moving, (m) => leaning.set(m &&
|
|
80
|
+
const leaning = follow({ time: () => motionMs('morph-out'), curve: morphCurve(), onFrame: (v) => (lean.value = v) })
|
|
81
|
+
watch(sc.moving, (m) => leaning.set(m && motionMs('morph-out') > 0 ? 1 : 0))
|
|
85
82
|
onBeforeUnmount(() => {
|
|
86
83
|
ro?.disconnect()
|
|
87
84
|
leaning.stop()
|
|
88
85
|
})
|
|
89
86
|
|
|
90
87
|
const shown = computed(() => ruler.value.land(sc.at.value))
|
|
91
|
-
|
|
92
|
-
const hasDetail = computed(() => !!(props.detail || slots.detail))
|
|
88
|
+
const hasDetail = computed(() => !!(detail || slots.detail))
|
|
93
89
|
|
|
94
90
|
const marks = computed(() => {
|
|
95
91
|
const at = sc.at.value
|
|
96
|
-
const { step } = props
|
|
97
92
|
return ruler.value.all.flatMap((v, i) => {
|
|
98
93
|
const d = (v - at) / step
|
|
99
94
|
if (Math.abs(d) > fit.value.span) return []
|
|
@@ -105,7 +100,7 @@ const marks = computed(() => {
|
|
|
105
100
|
{
|
|
106
101
|
v,
|
|
107
102
|
tier,
|
|
108
|
-
place: `translateX(calc(${d.toFixed(3)} * var(--gooee-ruler-tick-gap)))`,
|
|
103
|
+
place: `translateX(calc(${d.toFixed(3)} * var(--gooee-ruler-scrubber-tick-gap)))`,
|
|
109
104
|
tick: {
|
|
110
105
|
background: ink(on, tier === 'major' ? 'var(--gooee-color-fg-muted)' : 'var(--gooee-color-border-strong)', 'var(--gooee-color-accent)'),
|
|
111
106
|
transform: lean.value > 0 ? `rotate(${(tilt * lean.value).toFixed(2)}deg) scaleY(${(1 + near * 0.9 * lean.value).toFixed(3)})` : undefined,
|
|
@@ -120,7 +115,7 @@ const tags = computed(() => {
|
|
|
120
115
|
const { gap, width, tag } = fit.value
|
|
121
116
|
const room = (width - tag) / 2
|
|
122
117
|
return [...strongSet.value].flatMap((v) => {
|
|
123
|
-
const x = ((v - sc.at.value) /
|
|
118
|
+
const x = ((v - sc.at.value) / step) * gap
|
|
124
119
|
if (!gap || Math.abs(x) > width / 2) return []
|
|
125
120
|
return [{ v, x: clamp(x, -room, room).toFixed(1) }]
|
|
126
121
|
})
|
|
@@ -128,15 +123,16 @@ const tags = computed(() => {
|
|
|
128
123
|
</script>
|
|
129
124
|
|
|
130
125
|
<template>
|
|
131
|
-
<div :class="styles.root">
|
|
126
|
+
<div :class="styles.root" data-slot="ruler-scrubber">
|
|
132
127
|
<div :class="styles.head">
|
|
133
|
-
<span :id="labelId" :class="styles.label">{{ label }}</span>
|
|
128
|
+
<span :id="labelId" :class="styles.label" data-slot="field-label">{{ label }}</span>
|
|
134
129
|
<Roll :text="formatValue(shown)" :class="styles.readout" />
|
|
135
|
-
<span v-if="hasDetail" :id="detailId" :class="styles.detail"><slot name="detail">{{ detail }}</slot></span>
|
|
130
|
+
<span v-if="hasDetail" :id="detailId" :class="styles.detail" data-slot="ruler-scrubber-detail"><slot name="detail">{{ detail }}</slot></span>
|
|
136
131
|
</div>
|
|
137
132
|
<div
|
|
138
133
|
ref="scrubEl"
|
|
139
134
|
:class="styles.track"
|
|
135
|
+
data-slot="ruler-scrubber-track"
|
|
140
136
|
role="slider"
|
|
141
137
|
tabindex="0"
|
|
142
138
|
:aria-labelledby="labelId"
|
|
@@ -149,17 +145,17 @@ const tags = computed(() => {
|
|
|
149
145
|
:data-leaning="lean > 0 || undefined"
|
|
150
146
|
v-on="sc.handlers"
|
|
151
147
|
>
|
|
152
|
-
<span :class="styles.needle" aria-hidden="true" />
|
|
148
|
+
<span :class="styles.needle" data-slot="ruler-scrubber-needle" aria-hidden="true" />
|
|
153
149
|
<div :class="styles.clip" aria-hidden="true">
|
|
154
150
|
<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>
|
|
151
|
+
<i :class="styles.tick" data-slot="ruler-scrubber-tick" :data-tier="m.tier" :style="m.tick" />
|
|
152
|
+
<span v-if="m.tier === 'major'" :class="styles.num" data-slot="ruler-scrubber-number" :style="{ color: m.num }">{{ markText(m.v) }}</span>
|
|
157
153
|
</span>
|
|
158
154
|
</div>
|
|
159
155
|
<div v-if="strongLabel" :class="styles.tags" aria-hidden="true">
|
|
160
156
|
<!-- 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>
|
|
157
|
+
<span ref="tagEl" :class="styles.tag" data-slot="ruler-scrubber-tag" data-measure="true">{{ strongLabel }}</span>
|
|
158
|
+
<span v-for="t in tags" :key="t.v" :class="styles.tag" data-slot="ruler-scrubber-tag" :style="{ transform: `translateX(calc(${t.x}px - 50%))` }">{{ strongLabel }}</span>
|
|
163
159
|
</div>
|
|
164
160
|
</div>
|
|
165
161
|
</div>
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
@layer gooee.components {
|
|
1
2
|
.root {
|
|
2
3
|
position: relative;
|
|
3
4
|
min-width: 0;
|
|
@@ -16,7 +17,7 @@
|
|
|
16
17
|
}
|
|
17
18
|
|
|
18
19
|
.viewport::-webkit-scrollbar { display: none; }
|
|
19
|
-
.viewport:focus-visible { outline: none; box-shadow: inset 0 0 0 var(--gooee-
|
|
20
|
+
.viewport:focus-visible { outline: none; box-shadow: inset 0 0 0 var(--gooee-focus-width) var(--gooee-color-fg); }
|
|
20
21
|
|
|
21
22
|
.root[data-orientation="vertical"] .viewport { overflow-x: hidden; }
|
|
22
23
|
.root[data-orientation="horizontal"] .viewport { overflow-y: hidden; }
|
|
@@ -27,16 +28,16 @@
|
|
|
27
28
|
z-index: 1;
|
|
28
29
|
padding: var(--gooee-space-1);
|
|
29
30
|
opacity: 0;
|
|
30
|
-
transition: opacity var(--gooee-motion-slow) var(--gooee-ease-
|
|
31
|
+
transition: opacity var(--gooee-motion-slow) var(--gooee-ease-morph);
|
|
31
32
|
}
|
|
32
33
|
|
|
33
|
-
.track[data-
|
|
34
|
-
.track[data-
|
|
35
|
-
.root[data-orientation="both"] .track[data-
|
|
34
|
+
.track[data-orientation="vertical"] { top: 0; right: 0; bottom: 0; width: calc(var(--gooee-scroll-area-bar-w-active, 10px) + var(--gooee-space-1) * 2); }
|
|
35
|
+
.track[data-orientation="horizontal"] { left: 0; right: 0; bottom: 0; height: calc(var(--gooee-scroll-area-bar-w-active, 10px) + var(--gooee-space-1) * 2); }
|
|
36
|
+
.root[data-orientation="both"] .track[data-orientation="vertical"] { bottom: calc(var(--gooee-scroll-area-bar-w-active, 10px) + var(--gooee-space-1) * 2); }
|
|
36
37
|
|
|
37
38
|
.track[data-hidden] { display: none; }
|
|
38
39
|
|
|
39
|
-
.root[data-
|
|
40
|
+
.root[data-scrolling] .track,
|
|
40
41
|
.root[data-dragging] .track { opacity: 1; }
|
|
41
42
|
|
|
42
43
|
@media (hover: hover) {
|
|
@@ -52,21 +53,22 @@
|
|
|
52
53
|
cursor: grab;
|
|
53
54
|
touch-action: none;
|
|
54
55
|
transition:
|
|
55
|
-
width var(--gooee-motion-base) var(--gooee-ease-
|
|
56
|
-
height var(--gooee-motion-base) var(--gooee-ease-
|
|
57
|
-
background-color var(--gooee-motion-fast) var(--gooee-ease-
|
|
56
|
+
width var(--gooee-motion-base) var(--gooee-ease-morph),
|
|
57
|
+
height var(--gooee-motion-base) var(--gooee-ease-morph),
|
|
58
|
+
background-color var(--gooee-motion-fast) var(--gooee-ease-morph);
|
|
58
59
|
}
|
|
59
60
|
|
|
60
|
-
.track[data-
|
|
61
|
-
.track[data-
|
|
61
|
+
.track[data-orientation="vertical"] .thumb { width: var(--gooee-scroll-area-bar-w, 6px); left: auto; right: var(--gooee-space-1); }
|
|
62
|
+
.track[data-orientation="horizontal"] .thumb { height: var(--gooee-scroll-area-bar-w, 6px); top: auto; bottom: var(--gooee-space-1); }
|
|
62
63
|
|
|
63
|
-
.root[data-dragging] .track[data-
|
|
64
|
-
.root[data-dragging] .track[data-
|
|
64
|
+
.root[data-dragging] .track[data-orientation="vertical"] .thumb { width: var(--gooee-scroll-area-bar-w-active, 10px); }
|
|
65
|
+
.root[data-dragging] .track[data-orientation="horizontal"] .thumb { height: var(--gooee-scroll-area-bar-w-active, 10px); }
|
|
65
66
|
|
|
66
67
|
.root[data-dragging] .thumb { background: var(--gooee-color-fg-muted); cursor: grabbing; }
|
|
67
68
|
|
|
68
69
|
@media (hover: hover) {
|
|
69
|
-
.track[data-
|
|
70
|
-
.track[data-
|
|
70
|
+
.track[data-orientation="vertical"]:hover .thumb { width: var(--gooee-scroll-area-bar-w-active, 10px); }
|
|
71
|
+
.track[data-orientation="horizontal"]:hover .thumb { height: var(--gooee-scroll-area-bar-w-active, 10px); }
|
|
71
72
|
.thumb:hover { background: var(--gooee-color-fg-muted); cursor: grabbing; }
|
|
72
73
|
}
|
|
74
|
+
}
|
|
@@ -34,12 +34,13 @@ export function ScrollArea({ label, maxHeight, orientation = 'vertical', classNa
|
|
|
34
34
|
useEffect(() => a.destroy, [a])
|
|
35
35
|
|
|
36
36
|
const track = (axis: ScrollAxis) => (
|
|
37
|
-
<div className={styles.track} data-
|
|
37
|
+
<div className={styles.track} data-slot="scroll-area-scrollbar" data-orientation={axis === 'y' ? 'vertical' : 'horizontal'} aria-hidden="true" onPointerDown={(e) => a.trackDown(axis, e)}>
|
|
38
38
|
<div
|
|
39
39
|
ref={(el) => {
|
|
40
40
|
thumbs.current[axis] = el
|
|
41
41
|
}}
|
|
42
42
|
className={styles.thumb}
|
|
43
|
+
data-slot="scroll-area-thumb"
|
|
43
44
|
onPointerDown={(e) => a.thumbDown(axis, e)}
|
|
44
45
|
onPointerMove={a.thumbMove}
|
|
45
46
|
onPointerUp={a.thumbUp}
|
|
@@ -49,9 +50,9 @@ export function ScrollArea({ label, maxHeight, orientation = 'vertical', classNa
|
|
|
49
50
|
)
|
|
50
51
|
|
|
51
52
|
return (
|
|
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}>
|
|
54
|
-
<div className={styles.content}>{children}</div>
|
|
53
|
+
<div ref={rootRef} className={cx(styles.root, className)} data-slot="scroll-area" data-orientation={orientation} onPointerEnter={a.wake} onPointerMove={a.wake}>
|
|
54
|
+
<div ref={viewportRef} className={styles.viewport} data-slot="scroll-area-viewport" style={{ maxHeight }} role="region" aria-label={label} tabIndex={0} onScroll={a.onScroll}>
|
|
55
|
+
<div className={styles.content} data-slot="scroll-area-content">{children}</div>
|
|
55
56
|
</div>
|
|
56
57
|
{showY && track('y')}
|
|
57
58
|
{showX && track('x')}
|
|
@@ -5,25 +5,22 @@ import styles from './ScrollArea.module.css'
|
|
|
5
5
|
|
|
6
6
|
// The Vue ScrollArea: the same look (ScrollArea.module.css) and drawn scrollbar as the React one.
|
|
7
7
|
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}>(),
|
|
17
|
-
{ orientation: 'vertical' },
|
|
18
|
-
)
|
|
8
|
+
const { maxHeight, orientation = 'vertical' } = defineProps<{
|
|
9
|
+
/** Name of the scrollable region. Required, because the region takes keyboard focus. */
|
|
10
|
+
label: string
|
|
11
|
+
/** A number in pixels, or any CSS length such as "50vh". */
|
|
12
|
+
maxHeight?: number | string
|
|
13
|
+
/** Which ways the content can scroll, and which scrollbars show. */
|
|
14
|
+
orientation?: 'vertical' | 'horizontal' | 'both'
|
|
15
|
+
}>()
|
|
19
16
|
defineSlots<{ default?: () => unknown }>()
|
|
20
17
|
|
|
21
18
|
const root = ref<HTMLElement | null>(null)
|
|
22
19
|
const viewport = ref<HTMLElement | null>(null)
|
|
23
20
|
const thumbY = ref<HTMLElement | null>(null)
|
|
24
21
|
const thumbX = ref<HTMLElement | null>(null)
|
|
25
|
-
const axes = computed(() => [
|
|
26
|
-
const height = computed(() => (typeof
|
|
22
|
+
const axes = computed(() => [orientation !== 'horizontal' && ('y' as const), orientation !== 'vertical' && ('x' as const)].filter((a) => a !== false))
|
|
23
|
+
const height = computed(() => (typeof maxHeight === 'number' ? `${maxHeight}px` : maxHeight))
|
|
27
24
|
|
|
28
25
|
// The thumbs, their idle fade and drags (motion/scrollArea.ts): direct style writes, so scrolling never re-renders.
|
|
29
26
|
const area = createScrollArea({ root: () => root.value, viewport: () => viewport.value, thumb: (axis) => (axis === 'y' ? thumbY.value : thumbX.value) })
|
|
@@ -40,14 +37,15 @@ const setThumb = (axis: 'x' | 'y') => (el: unknown) => {
|
|
|
40
37
|
</script>
|
|
41
38
|
|
|
42
39
|
<template>
|
|
43
|
-
<div ref="root" :class="styles.root" :data-orientation="orientation" @pointerenter="area.wake" @pointermove="area.wake">
|
|
44
|
-
<div ref="viewport" :class="styles.viewport" :style="{ maxHeight: height }" role="region" :aria-label="label" tabindex="0" @scroll="area.onScroll">
|
|
45
|
-
<div :class="styles.content"><slot /></div>
|
|
40
|
+
<div ref="root" :class="styles.root" data-slot="scroll-area" :data-orientation="orientation" @pointerenter="area.wake" @pointermove="area.wake">
|
|
41
|
+
<div ref="viewport" :class="styles.viewport" data-slot="scroll-area-viewport" :style="{ maxHeight: height }" role="region" :aria-label="label" tabindex="0" @scroll="area.onScroll">
|
|
42
|
+
<div :class="styles.content" data-slot="scroll-area-content"><slot /></div>
|
|
46
43
|
</div>
|
|
47
|
-
<div v-for="axis in axes" :key="axis" :class="styles.track" :data-
|
|
44
|
+
<div v-for="axis in axes" :key="axis" :class="styles.track" data-slot="scroll-area-scrollbar" :data-orientation="axis === 'y' ? 'vertical' : 'horizontal'" aria-hidden="true" @pointerdown="area.trackDown(axis, $event)">
|
|
48
45
|
<div
|
|
49
46
|
:ref="setThumb(axis)"
|
|
50
47
|
:class="styles.thumb"
|
|
48
|
+
data-slot="scroll-area-thumb"
|
|
51
49
|
@pointerdown="area.thumbDown(axis, $event)"
|
|
52
50
|
@pointermove="area.thumbMove"
|
|
53
51
|
@pointerup="area.thumbUp"
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
@layer gooee.components {
|
|
1
2
|
/* Hide the browser's own clear button */
|
|
2
3
|
.root input::-webkit-search-cancel-button,
|
|
3
4
|
.root input::-webkit-search-decoration { -webkit-appearance: none; appearance: none; }
|
|
@@ -16,10 +17,10 @@
|
|
|
16
17
|
color: var(--gooee-color-fg);
|
|
17
18
|
font-size: var(--gooee-icon-sm);
|
|
18
19
|
cursor: pointer;
|
|
19
|
-
animation: popIn var(--gooee-motion-slow) var(--gooee-ease-
|
|
20
|
+
animation: popIn var(--gooee-motion-slow) var(--gooee-ease-morph);
|
|
20
21
|
transition:
|
|
21
|
-
background-color var(--gooee-motion-fast) var(--gooee-ease-
|
|
22
|
-
transform var(--gooee-motion-slow) var(--gooee-ease-
|
|
22
|
+
background-color var(--gooee-motion-fast) var(--gooee-ease-morph),
|
|
23
|
+
transform var(--gooee-motion-slow) var(--gooee-ease-morph);
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
.clear::after {
|
|
@@ -36,7 +37,7 @@
|
|
|
36
37
|
|
|
37
38
|
.hint {
|
|
38
39
|
display: inline-flex;
|
|
39
|
-
animation: fadeIn var(--gooee-motion-base) var(--gooee-ease-
|
|
40
|
+
animation: fadeIn var(--gooee-motion-base) var(--gooee-ease-morph);
|
|
40
41
|
}
|
|
41
42
|
|
|
42
43
|
/* Touch screens rarely have a keyboard; the shortcut still works */
|
|
@@ -51,3 +52,4 @@
|
|
|
51
52
|
@keyframes fadeIn {
|
|
52
53
|
from { opacity: 0; }
|
|
53
54
|
}
|
|
55
|
+
}
|
|
@@ -2,15 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
import { useEffect, useRef } from 'react'
|
|
4
4
|
import { cx } from '../../internal/cx'
|
|
5
|
-
import { SearchIcon, XIcon } from '../../
|
|
5
|
+
import { SearchIcon, XIcon } from '../../icons/icons'
|
|
6
6
|
import { mergeRefs } from '../../internal/mergeRefs'
|
|
7
7
|
import { shortcutFocus } from '../../internal/motion/keys'
|
|
8
8
|
import { useControllable } from '../../internal/useControllable'
|
|
9
|
-
import { Input, type InputProps } from '../Input'
|
|
9
|
+
import { Input, type InputLabels, type InputProps } from '../Input'
|
|
10
10
|
import { Kbd } from '../Kbd'
|
|
11
11
|
import styles from './SearchInput.module.css'
|
|
12
12
|
|
|
13
|
-
export type
|
|
13
|
+
export type SearchInputLabels = InputLabels & {
|
|
14
|
+
/** Screen reader name for the clear button. */
|
|
15
|
+
clear: string
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export type SearchInputProps = Omit<InputProps, 'type' | 'leading' | 'trailing' | 'value' | 'defaultValue' | 'onChange' | 'labels'> & {
|
|
14
19
|
/** Search text, when you control it. */
|
|
15
20
|
value?: string
|
|
16
21
|
/** Starting value when you do not control it. */
|
|
@@ -21,8 +26,8 @@ export type SearchInputProps = Omit<InputProps, 'type' | 'leading' | 'trailing'
|
|
|
21
26
|
onSearch?: (value: string) => void
|
|
22
27
|
/** A single key, such as "/". Pressing it anywhere on the page focuses the field. */
|
|
23
28
|
shortcut?: string
|
|
24
|
-
/**
|
|
25
|
-
|
|
29
|
+
/** Text for the label and the clear button, so you can translate it. Missing keys use the English defaults. */
|
|
30
|
+
labels?: Partial<SearchInputLabels>
|
|
26
31
|
}
|
|
27
32
|
|
|
28
33
|
export function SearchInput({
|
|
@@ -31,7 +36,7 @@ export function SearchInput({
|
|
|
31
36
|
onValueChange,
|
|
32
37
|
onSearch,
|
|
33
38
|
shortcut,
|
|
34
|
-
|
|
39
|
+
labels,
|
|
35
40
|
className,
|
|
36
41
|
ref,
|
|
37
42
|
onKeyDown,
|
|
@@ -48,6 +53,7 @@ export function SearchInput({
|
|
|
48
53
|
return (
|
|
49
54
|
<Input
|
|
50
55
|
{...rest}
|
|
56
|
+
labels={labels}
|
|
51
57
|
ref={mergeRefs(inputRef, ref)}
|
|
52
58
|
className={cx(styles.root, className)}
|
|
53
59
|
type="search"
|
|
@@ -72,7 +78,8 @@ export function SearchInput({
|
|
|
72
78
|
<button
|
|
73
79
|
type="button"
|
|
74
80
|
className={styles.clear}
|
|
75
|
-
|
|
81
|
+
data-slot="search-input-clear"
|
|
82
|
+
aria-label={labels?.clear ?? 'Clear search'}
|
|
76
83
|
onClick={() => {
|
|
77
84
|
setValue('')
|
|
78
85
|
inputRef.current?.focus()
|
|
@@ -81,7 +88,7 @@ export function SearchInput({
|
|
|
81
88
|
<XIcon />
|
|
82
89
|
</button>
|
|
83
90
|
) : shortcut ? (
|
|
84
|
-
<span className={styles.hint} aria-hidden="true">
|
|
91
|
+
<span className={styles.hint} data-slot="search-input-shortcut" aria-hidden="true">
|
|
85
92
|
<Kbd listen={shortcut}>{shortcut}</Kbd>
|
|
86
93
|
</span>
|
|
87
94
|
) : null
|