gooee 0.48.0 → 0.51.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +4 -2
- package/scripts/add.js +28 -6
- package/src/components/Accordion/Accordion.vue +62 -0
- package/src/components/Accordion/AccordionItem.vue +45 -0
- package/src/components/Accordion/accordionContext.ts +6 -0
- package/src/components/Alert/Alert.tsx +7 -27
- package/src/components/Alert/Alert.vue +59 -0
- package/src/components/AlertDialog/AlertDialog.vue +126 -0
- package/src/components/AnimatedNumber/AnimatedNumber.vue +36 -0
- package/src/components/AspectRatio/AspectRatio.vue +17 -0
- package/src/components/Avatar/Avatar.vue +56 -0
- package/src/components/AvatarGroup/AvatarGroup.vue +42 -0
- package/src/components/Badge/Badge.vue +32 -0
- package/src/components/Breadcrumb/Breadcrumb.vue +58 -0
- package/src/components/Button/Button.vue +130 -0
- package/src/components/ButtonGroup/ButtonGroup.tsx +4 -21
- package/src/components/ButtonGroup/ButtonGroup.vue +33 -0
- package/src/components/Card/Card.vue +34 -0
- package/src/components/Center/Center.vue +32 -0
- package/src/components/Checkbox/Checkbox.tsx +8 -25
- package/src/components/Checkbox/Checkbox.vue +108 -0
- package/src/components/CheckboxGroup/CheckboxGroup.vue +76 -0
- package/src/components/Cluster/Cluster.vue +34 -0
- package/src/components/CodeBlock/CodeBlock.vue +45 -0
- package/src/components/Collapsible/Collapsible.vue +59 -0
- package/src/components/Container/Container.vue +22 -0
- package/src/components/CopyButton/CopyButton.tsx +3 -49
- package/src/components/CopyButton/CopyButton.vue +116 -0
- package/src/components/Dial/Dial.tsx +12 -120
- package/src/components/Dial/Dial.vue +228 -0
- package/src/components/Dialog/Dialog.vue +139 -0
- package/src/components/Divider/Divider.vue +27 -0
- package/src/components/DropdownMenu/DropdownMenu.tsx +11 -46
- package/src/components/DropdownMenu/DropdownMenu.vue +185 -0
- package/src/components/EmptyState/EmptyState.vue +33 -0
- package/src/components/Fab/Fab.tsx +4 -14
- package/src/components/Fab/Fab.vue +115 -0
- package/src/components/Fieldset/Fieldset.vue +42 -0
- package/src/components/FormField/FormField.tsx +2 -17
- package/src/components/FormField/FormField.vue +64 -0
- package/src/components/Grid/Grid.vue +43 -0
- package/src/components/HoldToConfirm/HoldToConfirm.tsx +13 -142
- package/src/components/HoldToConfirm/HoldToConfirm.vue +281 -0
- package/src/components/IconButton/IconButton.vue +25 -0
- package/src/components/Input/Input.vue +112 -0
- package/src/components/InputGroup/InputGroup.vue +102 -0
- package/src/components/Kbd/Kbd.tsx +2 -12
- package/src/components/Kbd/Kbd.vue +21 -0
- package/src/components/Link/Link.vue +38 -0
- package/src/components/LivePill/LivePill.tsx +12 -40
- package/src/components/LivePill/LivePill.vue +152 -0
- package/src/components/Meter/Meter.vue +88 -0
- package/src/components/MorphButton/MorphButton.tsx +11 -67
- package/src/components/MorphButton/MorphButton.vue +120 -0
- package/src/components/NumberInput/NumberInput.tsx +11 -48
- package/src/components/NumberInput/NumberInput.vue +184 -0
- package/src/components/Pagination/Pagination.tsx +2 -15
- package/src/components/Pagination/Pagination.vue +87 -0
- package/src/components/Pagination/range.ts +15 -0
- package/src/components/PasswordInput/PasswordInput.vue +53 -0
- package/src/components/PickerWheel/DateWheel.vue +48 -0
- package/src/components/PickerWheel/PickerWheel.tsx +15 -129
- package/src/components/PickerWheel/PickerWheel.vue +77 -0
- package/src/components/PickerWheel/TimeWheel.vue +50 -0
- package/src/components/PickerWheel/WheelColumn.vue +70 -0
- package/src/components/Popover/Popover.vue +108 -0
- package/src/components/ProgressBar/ProgressBar.vue +48 -0
- package/src/components/Prose/Prose.vue +18 -0
- package/src/components/Radio/Radio.vue +49 -0
- package/src/components/Radio/RadioGroup.vue +69 -0
- package/src/components/Retime/Retime.tsx +7 -40
- package/src/components/Retime/Retime.vue +64 -0
- package/src/components/RulerScrubber/RulerScrubber.tsx +9 -38
- package/src/components/RulerScrubber/RulerScrubber.vue +166 -0
- package/src/components/ScrollArea/ScrollArea.tsx +17 -129
- package/src/components/ScrollArea/ScrollArea.vue +58 -0
- package/src/components/SearchInput/SearchInput.tsx +2 -15
- package/src/components/SearchInput/SearchInput.vue +70 -0
- package/src/components/SegmentedControl/SegmentedControl.tsx +7 -51
- package/src/components/SegmentedControl/SegmentedControl.vue +111 -0
- package/src/components/Select/Select.tsx +16 -47
- package/src/components/Select/Select.vue +236 -0
- package/src/components/Sheet/Sheet.tsx +52 -231
- package/src/components/Sheet/Sheet.vue +249 -0
- package/src/components/Skeleton/Skeleton.vue +38 -0
- package/src/components/Slider/Slider.tsx +25 -84
- package/src/components/Slider/Slider.vue +113 -0
- package/src/components/Spinner/Spinner.vue +30 -0
- package/src/components/Split/Split.vue +34 -0
- package/src/components/SplitFlap/SplitFlap.tsx +11 -175
- package/src/components/SplitFlap/SplitFlap.vue +52 -0
- package/src/components/Stack/Stack.vue +22 -0
- package/src/components/SwipeDeck/SwipeDeck.tsx +30 -194
- package/src/components/SwipeDeck/SwipeDeck.vue +168 -0
- package/src/components/Switch/Switch.tsx +6 -75
- package/src/components/Switch/Switch.vue +66 -0
- package/src/components/Table/Table.module.css +12 -3
- package/src/components/Table/Table.tsx +8 -59
- package/src/components/Table/Table.vue +274 -0
- package/src/components/TableOfContents/TableOfContents.vue +90 -0
- package/src/components/Tabs/Tab.vue +37 -0
- package/src/components/Tabs/TabList.vue +47 -0
- package/src/components/Tabs/TabPanel.vue +26 -0
- package/src/components/Tabs/Tabs.module.css +2 -2
- package/src/components/Tabs/Tabs.tsx +11 -84
- package/src/components/Tabs/Tabs.vue +33 -0
- package/src/components/Tabs/tabsContext.ts +15 -0
- package/src/components/Tag/Tag.tsx +6 -26
- package/src/components/Tag/Tag.vue +63 -0
- package/src/components/Textarea/Textarea.tsx +2 -22
- package/src/components/Textarea/Textarea.vue +120 -0
- package/src/components/ThemeToggle/ThemeToggle.tsx +10 -84
- package/src/components/ThemeToggle/ThemeToggle.vue +90 -0
- package/src/components/Toast/Toast.tsx +34 -264
- package/src/components/Toast/Toast.vue +138 -0
- package/src/components/Toast/ToastItem.vue +108 -0
- package/src/components/Toggle/Toggle.vue +52 -0
- package/src/components/Tooltip/Tooltip.tsx +17 -48
- package/src/components/Tooltip/Tooltip.vue +95 -0
- package/src/components/VisuallyHidden/VisuallyHidden.vue +17 -0
- package/src/internal/FieldMessage.vue +41 -0
- package/src/internal/Roll.vue +20 -0
- package/src/internal/fling.ts +29 -106
- package/src/internal/focus.ts +4 -79
- package/src/internal/icons.module.css +39 -27
- package/src/internal/layers.ts +7 -61
- package/src/internal/liquid.ts +26 -213
- package/src/internal/liquidMatter.ts +9 -181
- package/src/internal/liquidMore.ts +6 -669
- package/src/internal/motion/alert.ts +17 -0
- package/src/internal/motion/buttonGroup.ts +21 -0
- package/src/internal/motion/checkbox.ts +39 -0
- package/src/internal/motion/collapseOut.ts +26 -0
- package/src/internal/motion/copyButton.ts +48 -0
- package/src/internal/motion/dial.ts +137 -0
- package/src/internal/motion/fab.ts +14 -0
- package/src/internal/motion/fling.ts +147 -0
- package/src/internal/motion/floating.ts +58 -0
- package/src/internal/motion/focus.ts +88 -0
- package/src/internal/motion/formField.ts +19 -0
- package/src/internal/motion/holdToConfirm.ts +147 -0
- package/src/internal/motion/index.ts +20 -0
- package/src/internal/motion/keys.ts +42 -0
- package/src/internal/motion/layers.ts +78 -0
- package/src/internal/motion/liquid.ts +241 -0
- package/src/internal/motion/liquidMatter.ts +198 -0
- package/src/internal/motion/liquidMore.ts +676 -0
- package/src/internal/motion/listbox.ts +69 -0
- package/src/internal/motion/livePill.ts +71 -0
- package/src/internal/motion/menuKeys.ts +58 -0
- package/src/internal/motion/morphButton.ts +71 -0
- package/src/internal/motion/numberInput.ts +57 -0
- package/src/internal/motion/pickerWheel.ts +166 -0
- package/src/internal/motion/retime.ts +45 -0
- package/src/internal/motion/ruler.ts +57 -0
- package/src/internal/motion/scrollArea.ts +133 -0
- package/src/internal/motion/scrollFrame.ts +152 -0
- package/src/internal/motion/scrubLook.ts +15 -0
- package/src/internal/motion/scrubber.ts +154 -0
- package/src/internal/motion/segmented.ts +63 -0
- package/src/internal/motion/sheetDetents.ts +271 -0
- package/src/internal/motion/slider.ts +108 -0
- package/src/internal/motion/softPress.ts +334 -0
- package/src/internal/motion/splitFlap.ts +205 -0
- package/src/internal/motion/swipeDeck.ts +236 -0
- package/src/internal/motion/switchThumb.ts +83 -0
- package/src/internal/motion/table.ts +77 -0
- package/src/internal/motion/tabs.ts +105 -0
- package/src/internal/motion/textarea.ts +22 -0
- package/src/internal/motion/themeIcon.ts +91 -0
- package/src/internal/motion/themeReveal.ts +71 -0
- package/src/internal/motion/toast.ts +291 -0
- package/src/internal/motion/tooltip.ts +58 -0
- package/src/internal/scrollFrame.ts +4 -145
- package/src/internal/softPress.ts +27 -289
- package/src/internal/themeReveal.ts +3 -61
- package/src/internal/useFloating.ts +9 -49
- package/src/internal/useScrub.ts +15 -120
- package/src/internal/vue/trigger.ts +18 -0
- package/src/internal/vue/useFloating.ts +38 -0
- package/src/internal/vue/usePresence.ts +21 -0
- package/src/internal/vue/useScrub.ts +40 -0
- package/src/internal/vueIcons.ts +134 -0
- package/src/tokens.css +5 -0
- package/src/internal/relativeTime.ts +0 -26
|
@@ -0,0 +1,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')}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed, onBeforeUnmount, onMounted, ref } from 'vue'
|
|
3
|
+
import { createScrollArea } from '../../internal/motion/scrollArea'
|
|
4
|
+
import styles from './ScrollArea.module.css'
|
|
5
|
+
|
|
6
|
+
// The Vue ScrollArea: the same look (ScrollArea.module.css) and drawn scrollbar as the React one.
|
|
7
|
+
|
|
8
|
+
const props = withDefaults(
|
|
9
|
+
defineProps<{
|
|
10
|
+
/** Name of the scrollable region. Required, because the region takes keyboard focus. */
|
|
11
|
+
label: string
|
|
12
|
+
/** A number in pixels, or any CSS length such as "50vh". */
|
|
13
|
+
maxHeight?: number | string
|
|
14
|
+
/** Which ways the content can scroll, and which scrollbars show. */
|
|
15
|
+
orientation?: 'vertical' | 'horizontal' | 'both'
|
|
16
|
+
}>(),
|
|
17
|
+
{ orientation: 'vertical' },
|
|
18
|
+
)
|
|
19
|
+
defineSlots<{ default?: () => unknown }>()
|
|
20
|
+
|
|
21
|
+
const root = ref<HTMLElement | null>(null)
|
|
22
|
+
const viewport = ref<HTMLElement | null>(null)
|
|
23
|
+
const thumbY = ref<HTMLElement | null>(null)
|
|
24
|
+
const thumbX = ref<HTMLElement | null>(null)
|
|
25
|
+
const axes = computed(() => [props.orientation !== 'horizontal' && ('y' as const), props.orientation !== 'vertical' && ('x' as const)].filter((a) => a !== false))
|
|
26
|
+
const height = computed(() => (typeof props.maxHeight === 'number' ? `${props.maxHeight}px` : props.maxHeight))
|
|
27
|
+
|
|
28
|
+
// The thumbs, their idle fade and drags (motion/scrollArea.ts): direct style writes, so scrolling never re-renders.
|
|
29
|
+
const area = createScrollArea({ root: () => root.value, viewport: () => viewport.value, thumb: (axis) => (axis === 'y' ? thumbY.value : thumbX.value) })
|
|
30
|
+
let stop = () => {}
|
|
31
|
+
onMounted(() => (stop = area.observe()))
|
|
32
|
+
onBeforeUnmount(() => {
|
|
33
|
+
stop()
|
|
34
|
+
area.destroy()
|
|
35
|
+
})
|
|
36
|
+
const setThumb = (axis: 'x' | 'y') => (el: unknown) => {
|
|
37
|
+
if (axis === 'y') thumbY.value = el as HTMLElement | null
|
|
38
|
+
else thumbX.value = el as HTMLElement | null
|
|
39
|
+
}
|
|
40
|
+
</script>
|
|
41
|
+
|
|
42
|
+
<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>
|
|
46
|
+
</div>
|
|
47
|
+
<div v-for="axis in axes" :key="axis" :class="styles.track" :data-axis="axis" aria-hidden="true" @pointerdown="area.trackDown(axis, $event)">
|
|
48
|
+
<div
|
|
49
|
+
:ref="setThumb(axis)"
|
|
50
|
+
:class="styles.thumb"
|
|
51
|
+
@pointerdown="area.thumbDown(axis, $event)"
|
|
52
|
+
@pointermove="area.thumbMove"
|
|
53
|
+
@pointerup="area.thumbUp"
|
|
54
|
+
@pointercancel="area.thumbUp"
|
|
55
|
+
/>
|
|
56
|
+
</div>
|
|
57
|
+
</div>
|
|
58
|
+
</template>
|
|
@@ -4,6 +4,7 @@ import { useEffect, useRef } from 'react'
|
|
|
4
4
|
import { cx } from '../../internal/cx'
|
|
5
5
|
import { SearchIcon, XIcon } from '../../internal/icons'
|
|
6
6
|
import { mergeRefs } from '../../internal/mergeRefs'
|
|
7
|
+
import { shortcutFocus } from '../../internal/motion/keys'
|
|
7
8
|
import { useControllable } from '../../internal/useControllable'
|
|
8
9
|
import { Input, type InputProps } from '../Input'
|
|
9
10
|
import { Kbd } from '../Kbd'
|
|
@@ -24,9 +25,6 @@ export type SearchInputProps = Omit<InputProps, 'type' | 'leading' | 'trailing'
|
|
|
24
25
|
clearLabel?: string
|
|
25
26
|
}
|
|
26
27
|
|
|
27
|
-
const isTyping = (el: Element | null) =>
|
|
28
|
-
!!el && (el instanceof HTMLInputElement || el instanceof HTMLTextAreaElement || el instanceof HTMLSelectElement || (el as HTMLElement).isContentEditable)
|
|
29
|
-
|
|
30
28
|
export function SearchInput({
|
|
31
29
|
value: valueProp,
|
|
32
30
|
defaultValue = '',
|
|
@@ -42,20 +40,9 @@ export function SearchInput({
|
|
|
42
40
|
const [value, setValue] = useControllable(valueProp, defaultValue, onValueChange)
|
|
43
41
|
const inputRef = useRef<HTMLInputElement>(null)
|
|
44
42
|
|
|
45
|
-
// Ignored while another field has focus, so it never steals typed text, and while a modal
|
|
46
|
-
// this field is not in is open, so focus never leaves the modal.
|
|
47
43
|
useEffect(() => {
|
|
48
44
|
if (!shortcut) return
|
|
49
|
-
|
|
50
|
-
if (e.key !== shortcut || e.metaKey || e.ctrlKey || e.altKey || isTyping(document.activeElement)) return
|
|
51
|
-
const modals = document.querySelectorAll('[aria-modal="true"]')
|
|
52
|
-
if (modals.length && !modals[modals.length - 1].contains(inputRef.current)) return
|
|
53
|
-
e.preventDefault()
|
|
54
|
-
inputRef.current?.focus()
|
|
55
|
-
inputRef.current?.select()
|
|
56
|
-
}
|
|
57
|
-
window.addEventListener('keydown', onKey)
|
|
58
|
-
return () => window.removeEventListener('keydown', onKey)
|
|
45
|
+
return shortcutFocus(shortcut, () => inputRef.current)
|
|
59
46
|
}, [shortcut])
|
|
60
47
|
|
|
61
48
|
return (
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { onBeforeUnmount, onMounted, ref, watch } from 'vue'
|
|
3
|
+
import { SearchIcon, XIcon } from '../../internal/vueIcons'
|
|
4
|
+
import { shortcutFocus } from '../../internal/motion/keys'
|
|
5
|
+
import Input from '../Input/Input.vue'
|
|
6
|
+
import Kbd from '../Kbd/Kbd.vue'
|
|
7
|
+
import styles from './SearchInput.module.css'
|
|
8
|
+
|
|
9
|
+
// The Vue SearchInput: Input with a search icon, a clear button and an optional key shortcut, like the React one.
|
|
10
|
+
// Other attributes, such as label, size or placeholder, go to the Input.
|
|
11
|
+
const props = withDefaults(
|
|
12
|
+
defineProps<{
|
|
13
|
+
/** Always required. A placeholder is only an example, never the label. */
|
|
14
|
+
label: string
|
|
15
|
+
/** A single key, such as "/". Pressing it anywhere on the page focuses the field. */
|
|
16
|
+
shortcut?: string
|
|
17
|
+
/** Screen reader name for the clear button. */
|
|
18
|
+
clearLabel?: string
|
|
19
|
+
}>(),
|
|
20
|
+
{ clearLabel: 'Clear search' },
|
|
21
|
+
)
|
|
22
|
+
/** The search text. Use v-model, or leave it out and the field keeps its own text. Also changes on clear. */
|
|
23
|
+
const model = defineModel<string>({ default: '' })
|
|
24
|
+
const emit = defineEmits<{ search: [value: string] }>()
|
|
25
|
+
|
|
26
|
+
const root = ref<InstanceType<typeof Input> | null>(null)
|
|
27
|
+
const field = () => root.value?.input ?? null
|
|
28
|
+
|
|
29
|
+
let stop = () => {}
|
|
30
|
+
onMounted(() =>
|
|
31
|
+
watch(
|
|
32
|
+
() => props.shortcut,
|
|
33
|
+
(key) => {
|
|
34
|
+
stop()
|
|
35
|
+
stop = key ? shortcutFocus(key, field) : () => {}
|
|
36
|
+
},
|
|
37
|
+
{ immediate: true },
|
|
38
|
+
),
|
|
39
|
+
)
|
|
40
|
+
onBeforeUnmount(() => stop())
|
|
41
|
+
|
|
42
|
+
const onKeydown = (e: KeyboardEvent) => {
|
|
43
|
+
// Enter during IME composition picks a word, not a search
|
|
44
|
+
if (e.isComposing || e.keyCode === 229) return
|
|
45
|
+
if (e.key === 'Enter') emit('search', model.value)
|
|
46
|
+
else if (e.key === 'Escape' && model.value) {
|
|
47
|
+
e.preventDefault()
|
|
48
|
+
e.stopPropagation()
|
|
49
|
+
model.value = ''
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
const clear = () => {
|
|
53
|
+
model.value = ''
|
|
54
|
+
field()?.focus()
|
|
55
|
+
}
|
|
56
|
+
</script>
|
|
57
|
+
|
|
58
|
+
<template>
|
|
59
|
+
<Input ref="root" v-model="model" :label="label" :class="styles.root" type="search" enterkeyhint="search" :aria-keyshortcuts="shortcut" @keydown="onKeydown">
|
|
60
|
+
<template #leading><SearchIcon /></template>
|
|
61
|
+
<template v-if="model" #trailing>
|
|
62
|
+
<button type="button" :class="styles.clear" :aria-label="clearLabel" @click="clear"><XIcon /></button>
|
|
63
|
+
</template>
|
|
64
|
+
<template v-else-if="shortcut" #trailing>
|
|
65
|
+
<span :class="styles.hint" aria-hidden="true">
|
|
66
|
+
<Kbd :listen="shortcut">{{ shortcut }}</Kbd>
|
|
67
|
+
</span>
|
|
68
|
+
</template>
|
|
69
|
+
</Input>
|
|
70
|
+
</template>
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import { useLayoutEffect, useRef, useState, type KeyboardEvent, type ReactNode } from 'react'
|
|
4
4
|
import { cx } from '../../internal/cx'
|
|
5
5
|
import { useFlow } from '../../internal/liquidMatter'
|
|
6
|
+
import { measureSegments, segmentInk, segmentKey } from '../../internal/motion/segmented'
|
|
6
7
|
import { useControllable } from '../../internal/useControllable'
|
|
7
8
|
import styles from './SegmentedControl.module.css'
|
|
8
9
|
|
|
@@ -49,14 +50,8 @@ export function SegmentedControl({
|
|
|
49
50
|
|
|
50
51
|
useLayoutEffect(() => {
|
|
51
52
|
const measure = () => {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
if (root) {
|
|
55
|
-
root.removeAttribute('data-tight')
|
|
56
|
-
if (root.scrollWidth > root.clientWidth) root.setAttribute('data-tight', '')
|
|
57
|
-
}
|
|
58
|
-
const el = refs.current[index]
|
|
59
|
-
if (el) setPill({ x: el.offsetLeft, w: el.offsetWidth })
|
|
53
|
+
const place = measureSegments(rootRef.current, refs.current[index])
|
|
54
|
+
if (place) setPill(place)
|
|
60
55
|
}
|
|
61
56
|
measure()
|
|
62
57
|
const ro = new ResizeObserver(measure)
|
|
@@ -73,51 +68,12 @@ export function SegmentedControl({
|
|
|
73
68
|
|
|
74
69
|
// The pill flows to the new choice. The labels stay put; under the liquid they take the chosen
|
|
75
70
|
// colour, from a copy of the row clipped to the same outline.
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
if (!outline || !root) {
|
|
80
|
-
inkRef.current?.remove()
|
|
81
|
-
inkRef.current = null
|
|
82
|
-
return
|
|
83
|
-
}
|
|
84
|
-
if (!inkRef.current) {
|
|
85
|
-
const layer = document.createElement('div')
|
|
86
|
-
layer.className = styles.ink
|
|
87
|
-
layer.setAttribute('aria-hidden', 'true')
|
|
88
|
-
layer.inert = true
|
|
89
|
-
for (const el of refs.current) {
|
|
90
|
-
if (!el) continue
|
|
91
|
-
const copy = el.cloneNode(true) as HTMLElement
|
|
92
|
-
copy.removeAttribute('id')
|
|
93
|
-
copy.style.left = `${el.offsetLeft}px`
|
|
94
|
-
copy.style.top = `${el.offsetTop}px`
|
|
95
|
-
copy.style.width = `${el.offsetWidth}px`
|
|
96
|
-
copy.style.height = `${el.offsetHeight}px`
|
|
97
|
-
layer.append(copy)
|
|
98
|
-
}
|
|
99
|
-
root.append(layer)
|
|
100
|
-
inkRef.current = layer
|
|
101
|
-
}
|
|
102
|
-
inkRef.current.style.clipPath = `path('${outline}')`
|
|
103
|
-
}
|
|
104
|
-
useFlow(rootRef, pillRef, pill, index, ready, styles.liquid, false, ink)
|
|
105
|
-
|
|
106
|
-
const move = (from: number, dir: 1 | -1) => {
|
|
107
|
-
let i = from
|
|
108
|
-
for (let n = 0; n < options.length; n++) {
|
|
109
|
-
i = (i + dir + options.length) % options.length
|
|
110
|
-
if (!options[i].disabled) return i
|
|
111
|
-
}
|
|
112
|
-
return from
|
|
113
|
-
}
|
|
71
|
+
const ink = useRef<ReturnType<typeof segmentInk>>(null)
|
|
72
|
+
ink.current ??= segmentInk(() => rootRef.current, () => refs.current, styles.ink)
|
|
73
|
+
useFlow(rootRef, pillRef, pill, index, ready, styles.liquid, false, ink.current)
|
|
114
74
|
|
|
115
75
|
const onKeyDown = (e: KeyboardEvent) => {
|
|
116
|
-
|
|
117
|
-
if (e.key === 'ArrowRight' || e.key === 'ArrowDown') next = move(tabStop, 1)
|
|
118
|
-
else if (e.key === 'ArrowLeft' || e.key === 'ArrowUp') next = move(tabStop, -1)
|
|
119
|
-
else if (e.key === 'Home') next = move(-1, 1)
|
|
120
|
-
else if (e.key === 'End') next = move(options.length, -1)
|
|
76
|
+
const next = segmentKey(e.key, tabStop, options.map((o) => !!o.disabled))
|
|
121
77
|
if (next < 0) return
|
|
122
78
|
e.preventDefault()
|
|
123
79
|
setValue(options[next].value)
|