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
package/src/internal/focus.ts
CHANGED
|
@@ -1,40 +1,9 @@
|
|
|
1
1
|
import { useEffect, type RefObject } from 'react'
|
|
2
|
-
import {
|
|
2
|
+
import { trapFocus } from './motion/focus'
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
'a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"]), [contenteditable="true"]'
|
|
6
|
-
|
|
7
|
-
export function focusables(root: HTMLElement): HTMLElement[] {
|
|
8
|
-
return Array.from(root.querySelectorAll<HTMLElement>(FOCUSABLE)).filter(
|
|
9
|
-
(el) => !el.hasAttribute('inert') && el.getClientRects().length > 0,
|
|
10
|
-
)
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
// Safari, on iPhone and on Mac, does not focus a button when it is tapped or clicked. So the control
|
|
14
|
-
// that opened a layer is often not the focused element; remember the last one pressed instead.
|
|
15
|
-
// Watched from the moment this file loads, since a layer only mounts after the press that opens it.
|
|
16
|
-
let lastPressed: HTMLElement | null = null
|
|
17
|
-
if (typeof document !== 'undefined') {
|
|
18
|
-
document.addEventListener(
|
|
19
|
-
'pointerdown',
|
|
20
|
-
(e) => {
|
|
21
|
-
lastPressed = (e.target instanceof Element ? e.target.closest<HTMLElement>(FOCUSABLE) : null) ?? null
|
|
22
|
-
},
|
|
23
|
-
true,
|
|
24
|
-
)
|
|
25
|
-
// Focus moved from code stays above a phone keyboard.
|
|
26
|
-
watchKeyboard()
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// Where focus should go back to: the focused element, unless it is the page or a box around the
|
|
30
|
-
// control that was just pressed. Then that control.
|
|
31
|
-
export function returnTarget(): HTMLElement | null {
|
|
32
|
-
const active = document.activeElement as HTMLElement | null
|
|
33
|
-
const pressed = lastPressed && lastPressed.isConnected ? lastPressed : null
|
|
34
|
-
if (pressed && (!active || active === document.body || (active !== pressed && active.contains(pressed)))) return pressed
|
|
35
|
-
return active
|
|
36
|
-
}
|
|
4
|
+
export { focusables, returnTarget, trapFocus } from './motion/focus'
|
|
37
5
|
|
|
6
|
+
/** React's hold on trapFocus (motion/focus.ts): while `active`, Tab stays inside `ref`. */
|
|
38
7
|
export function useFocusTrap(
|
|
39
8
|
ref: RefObject<HTMLElement | null>,
|
|
40
9
|
active: boolean,
|
|
@@ -45,50 +14,6 @@ export function useFocusTrap(
|
|
|
45
14
|
if (!active) return
|
|
46
15
|
const root = ref.current
|
|
47
16
|
if (!root) return
|
|
48
|
-
|
|
49
|
-
// Close buttons opt out of first focus, so focus lands on the content or the safe action.
|
|
50
|
-
const list = focusables(root)
|
|
51
|
-
const first = initialFocus?.current ?? list.find((el) => !el.hasAttribute('data-skip-initial-focus')) ?? list[0] ?? root
|
|
52
|
-
first.focus({ preventScroll: true })
|
|
53
|
-
|
|
54
|
-
// Safari's plain Tab skips buttons, so it can jump from the middle of the layer to the page behind,
|
|
55
|
-
// or off the page. A Tab that lands outside goes back to the end it wrapped past.
|
|
56
|
-
let check = 0
|
|
57
|
-
const onKey = (e: KeyboardEvent) => {
|
|
58
|
-
if (e.key !== 'Tab') return
|
|
59
|
-
const items = focusables(root)
|
|
60
|
-
if (items.length === 0) {
|
|
61
|
-
e.preventDefault()
|
|
62
|
-
root.focus()
|
|
63
|
-
return
|
|
64
|
-
}
|
|
65
|
-
const firstEl = items[0]
|
|
66
|
-
const lastEl = items[items.length - 1]
|
|
67
|
-
const current = document.activeElement
|
|
68
|
-
if (e.shiftKey && (current === firstEl || current === root)) {
|
|
69
|
-
e.preventDefault()
|
|
70
|
-
lastEl.focus()
|
|
71
|
-
} else if (!e.shiftKey && current === lastEl) {
|
|
72
|
-
e.preventDefault()
|
|
73
|
-
firstEl.focus()
|
|
74
|
-
} else {
|
|
75
|
-
const back = e.shiftKey
|
|
76
|
-
clearTimeout(check)
|
|
77
|
-
check = window.setTimeout(() => {
|
|
78
|
-
if (root.contains(document.activeElement)) return
|
|
79
|
-
const now = focusables(root)
|
|
80
|
-
now[back ? now.length - 1 : 0]?.focus({ preventScroll: true })
|
|
81
|
-
})
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
root.addEventListener('keydown', onKey)
|
|
85
|
-
return () => {
|
|
86
|
-
clearTimeout(check)
|
|
87
|
-
root.removeEventListener('keydown', onKey)
|
|
88
|
-
// Give focus back only if it is still in the layer, so a click elsewhere keeps its own focus.
|
|
89
|
-
const now = document.activeElement
|
|
90
|
-
const stillInside = !now || now === document.body || root.contains(now)
|
|
91
|
-
if (restore && stillInside && previous && document.contains(previous)) previous.focus({ preventScroll: true })
|
|
92
|
-
}
|
|
17
|
+
return trapFocus(root, { initialFocus: initialFocus?.current, restore })
|
|
93
18
|
}, [active])
|
|
94
19
|
}
|
|
@@ -5,24 +5,37 @@
|
|
|
5
5
|
.icon[data-motion="swing"] { transform-origin: 50% 12%; }
|
|
6
6
|
.icon[data-motion="grow"] { transform-origin: 50% 86%; }
|
|
7
7
|
|
|
8
|
-
.icon[data-motion="nudge-r"] { --gooee-icon-play: gooee-icon-nudge-r; }
|
|
9
|
-
.icon[data-motion="nudge-l"] { --gooee-icon-play: gooee-icon-nudge-l; }
|
|
10
|
-
.icon[data-motion="nudge-u"] { --gooee-icon-play: gooee-icon-nudge-u; }
|
|
11
|
-
.icon[data-motion="nudge-d"] { --gooee-icon-play: gooee-icon-nudge-d; }
|
|
12
|
-
.icon[data-motion="nudge-ur"] { --gooee-icon-play: gooee-icon-nudge-ur; }
|
|
13
|
-
.icon[data-motion="swing"] { --gooee-icon-play: gooee-icon-swing; }
|
|
14
|
-
.icon[data-motion="turn"] { --gooee-icon-play: gooee-icon-turn; }
|
|
15
|
-
.icon[data-motion="pop"] { --gooee-icon-play: gooee-icon-pop; }
|
|
16
|
-
.icon[data-motion="blink"] { --gooee-icon-play: gooee-icon-blink; }
|
|
17
|
-
.icon[data-motion="wiggle"] { --gooee-icon-play: gooee-icon-wiggle; }
|
|
18
|
-
.icon[data-motion="bounce"] { --gooee-icon-play: gooee-icon-bounce; }
|
|
19
|
-
.icon[data-motion="grow"] { --gooee-icon-play: gooee-icon-grow; }
|
|
20
8
|
|
|
21
9
|
@media (prefers-reduced-motion: no-preference) {
|
|
22
10
|
:global(:is(a, button, label, summary, [role="button"], [role="menuitem"], [role="tab"], [role="option"], [role="link"])):is(:hover, :focus-visible) .icon,
|
|
23
11
|
.icon:hover {
|
|
24
|
-
animation: var(--gooee-
|
|
12
|
+
animation-duration: var(--gooee-motion-slow);
|
|
13
|
+
animation-timing-function: var(--gooee-ease-out);
|
|
25
14
|
}
|
|
15
|
+
:global(:is(a, button, label, summary, [role="button"], [role="menuitem"], [role="tab"], [role="option"], [role="link"])):is(:hover, :focus-visible) .icon[data-motion="nudge-r"],
|
|
16
|
+
.icon[data-motion="nudge-r"]:hover { animation-name: nudge-r; }
|
|
17
|
+
:global(:is(a, button, label, summary, [role="button"], [role="menuitem"], [role="tab"], [role="option"], [role="link"])):is(:hover, :focus-visible) .icon[data-motion="nudge-l"],
|
|
18
|
+
.icon[data-motion="nudge-l"]:hover { animation-name: nudge-l; }
|
|
19
|
+
:global(:is(a, button, label, summary, [role="button"], [role="menuitem"], [role="tab"], [role="option"], [role="link"])):is(:hover, :focus-visible) .icon[data-motion="nudge-u"],
|
|
20
|
+
.icon[data-motion="nudge-u"]:hover { animation-name: nudge-u; }
|
|
21
|
+
:global(:is(a, button, label, summary, [role="button"], [role="menuitem"], [role="tab"], [role="option"], [role="link"])):is(:hover, :focus-visible) .icon[data-motion="nudge-d"],
|
|
22
|
+
.icon[data-motion="nudge-d"]:hover { animation-name: nudge-d; }
|
|
23
|
+
:global(:is(a, button, label, summary, [role="button"], [role="menuitem"], [role="tab"], [role="option"], [role="link"])):is(:hover, :focus-visible) .icon[data-motion="nudge-ur"],
|
|
24
|
+
.icon[data-motion="nudge-ur"]:hover { animation-name: nudge-ur; }
|
|
25
|
+
:global(:is(a, button, label, summary, [role="button"], [role="menuitem"], [role="tab"], [role="option"], [role="link"])):is(:hover, :focus-visible) .icon[data-motion="swing"],
|
|
26
|
+
.icon[data-motion="swing"]:hover { animation-name: swing; }
|
|
27
|
+
:global(:is(a, button, label, summary, [role="button"], [role="menuitem"], [role="tab"], [role="option"], [role="link"])):is(:hover, :focus-visible) .icon[data-motion="turn"],
|
|
28
|
+
.icon[data-motion="turn"]:hover { animation-name: turn; }
|
|
29
|
+
:global(:is(a, button, label, summary, [role="button"], [role="menuitem"], [role="tab"], [role="option"], [role="link"])):is(:hover, :focus-visible) .icon[data-motion="pop"],
|
|
30
|
+
.icon[data-motion="pop"]:hover { animation-name: pop; }
|
|
31
|
+
:global(:is(a, button, label, summary, [role="button"], [role="menuitem"], [role="tab"], [role="option"], [role="link"])):is(:hover, :focus-visible) .icon[data-motion="blink"],
|
|
32
|
+
.icon[data-motion="blink"]:hover { animation-name: blink; }
|
|
33
|
+
:global(:is(a, button, label, summary, [role="button"], [role="menuitem"], [role="tab"], [role="option"], [role="link"])):is(:hover, :focus-visible) .icon[data-motion="wiggle"],
|
|
34
|
+
.icon[data-motion="wiggle"]:hover { animation-name: wiggle; }
|
|
35
|
+
:global(:is(a, button, label, summary, [role="button"], [role="menuitem"], [role="tab"], [role="option"], [role="link"])):is(:hover, :focus-visible) .icon[data-motion="bounce"],
|
|
36
|
+
.icon[data-motion="bounce"]:hover { animation-name: bounce; }
|
|
37
|
+
:global(:is(a, button, label, summary, [role="button"], [role="menuitem"], [role="tab"], [role="option"], [role="link"])):is(:hover, :focus-visible) .icon[data-motion="grow"],
|
|
38
|
+
.icon[data-motion="grow"]:hover { animation-name: grow; }
|
|
26
39
|
:global(:is(a, button, label, summary, [role="button"], [role="menuitem"], [role="tab"], [role="option"], [role="link"])):is(:hover, :focus-visible) .icon[data-motion="draw"] > *,
|
|
27
40
|
.icon[data-motion="draw"]:hover > * {
|
|
28
41
|
stroke-dasharray: 1;
|
|
@@ -30,33 +43,32 @@
|
|
|
30
43
|
}
|
|
31
44
|
}
|
|
32
45
|
|
|
33
|
-
@keyframes
|
|
34
|
-
@keyframes
|
|
35
|
-
@keyframes
|
|
36
|
-
@keyframes
|
|
37
|
-
@keyframes
|
|
38
|
-
@keyframes
|
|
46
|
+
@keyframes nudge-r { 40% { transform: translateX(0.12em); } }
|
|
47
|
+
@keyframes nudge-l { 40% { transform: translateX(-0.12em); } }
|
|
48
|
+
@keyframes nudge-u { 40% { transform: translateY(-0.12em); } }
|
|
49
|
+
@keyframes nudge-d { 40% { transform: translateY(0.12em); } }
|
|
50
|
+
@keyframes nudge-ur { 40% { transform: translate(0.1em, -0.1em); } }
|
|
51
|
+
@keyframes swing {
|
|
39
52
|
25% { transform: rotate(14deg); }
|
|
40
53
|
50% { transform: rotate(-10deg); }
|
|
41
54
|
75% { transform: rotate(5deg); }
|
|
42
55
|
}
|
|
43
|
-
@keyframes
|
|
44
|
-
@keyframes
|
|
45
|
-
@keyframes
|
|
46
|
-
@keyframes
|
|
56
|
+
@keyframes turn { to { transform: rotate(1turn); } }
|
|
57
|
+
@keyframes pop { 40% { transform: scale(1.18); } }
|
|
58
|
+
@keyframes blink { 45% { transform: scaleY(0.12); } }
|
|
59
|
+
@keyframes wiggle {
|
|
47
60
|
20% { transform: rotate(-10deg); }
|
|
48
61
|
40% { transform: rotate(9deg); }
|
|
49
62
|
60% { transform: rotate(-6deg); }
|
|
50
63
|
80% { transform: rotate(3deg); }
|
|
51
64
|
}
|
|
52
|
-
@keyframes
|
|
65
|
+
@keyframes grow {
|
|
53
66
|
40% { transform: scale(0.94, 1.14); }
|
|
54
67
|
70% { transform: scale(1.02, 0.97); }
|
|
55
68
|
}
|
|
56
|
-
@keyframes
|
|
69
|
+
@keyframes bounce {
|
|
57
70
|
35% { transform: translateY(-0.14em); }
|
|
58
71
|
65% { transform: translateY(0.03em); }
|
|
59
72
|
}
|
|
60
|
-
/*
|
|
61
|
-
name travels in --gooee-icon-play, which CSS modules do not rename. */
|
|
73
|
+
/* Every name is local to this file, so a bundler's CSS modules (Turbopack too) rename them in step. */
|
|
62
74
|
@keyframes draw { from { stroke-dashoffset: 1; } to { stroke-dashoffset: 0; } }
|
package/src/internal/layers.ts
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import { useEffect, useRef, type RefObject } from 'react'
|
|
2
|
+
import { dismissable, lockScroll, type DismissOptions } from './motion/layers'
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
const stack: Array<{ id: symbol; hint: boolean }> = []
|
|
4
|
+
export { dismissable, lockScroll, type DismissOptions } from './motion/layers'
|
|
5
5
|
|
|
6
|
+
/** React's hold on dismissable (motion/layers.ts): while `active`, Esc and a press outside `refs` call `onDismiss`. */
|
|
6
7
|
export function useDismiss(
|
|
7
8
|
active: boolean,
|
|
8
9
|
refs: Array<RefObject<HTMLElement | null>>,
|
|
9
10
|
onDismiss: (reason: 'escape' | 'outside', event: Event) => void,
|
|
10
|
-
|
|
11
|
-
outside it, while no layer is open above it, counts as outside too. */
|
|
12
|
-
options: { outside?: boolean; hint?: boolean; focusOut?: boolean } = {},
|
|
11
|
+
options: DismissOptions = {},
|
|
13
12
|
) {
|
|
14
13
|
const { outside = true, hint = false, focusOut = false } = options
|
|
15
14
|
const cb = useRef(onDismiss)
|
|
@@ -19,67 +18,14 @@ export function useDismiss(
|
|
|
19
18
|
|
|
20
19
|
useEffect(() => {
|
|
21
20
|
if (!active) return
|
|
22
|
-
|
|
23
|
-
stack.push({ id, hint })
|
|
24
|
-
const isTop = () => stack[stack.length - 1]?.id === id
|
|
25
|
-
const isTopForPointer = () => stack.filter((l) => !l.hint).pop()?.id === id
|
|
26
|
-
|
|
27
|
-
const onKey = (e: KeyboardEvent) => {
|
|
28
|
-
if (e.key === 'Escape' && isTop()) {
|
|
29
|
-
e.stopPropagation()
|
|
30
|
-
cb.current('escape', e)
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
const onPointer = (e: PointerEvent) => {
|
|
34
|
-
if (!outside || !isTopForPointer()) return
|
|
35
|
-
const target = e.target as Node
|
|
36
|
-
if (refsRef.current.some((r) => r.current?.contains(target))) return
|
|
37
|
-
// Things like the toast stack sit above every layer and never count as outside.
|
|
38
|
-
if (target instanceof Element && target.closest('[data-gooee-layer-ignore]')) return
|
|
39
|
-
cb.current('outside', e)
|
|
40
|
-
}
|
|
41
|
-
const onFocus = (e: FocusEvent) => {
|
|
42
|
-
if (!focusOut || !isTopForPointer()) return
|
|
43
|
-
const target = e.target as Node
|
|
44
|
-
if (refsRef.current.some((r) => r.current?.contains(target))) return
|
|
45
|
-
cb.current('outside', e)
|
|
46
|
-
}
|
|
47
|
-
document.addEventListener('keydown', onKey)
|
|
48
|
-
document.addEventListener('pointerdown', onPointer)
|
|
49
|
-
document.addEventListener('focusin', onFocus)
|
|
50
|
-
return () => {
|
|
51
|
-
document.removeEventListener('keydown', onKey)
|
|
52
|
-
document.removeEventListener('pointerdown', onPointer)
|
|
53
|
-
document.removeEventListener('focusin', onFocus)
|
|
54
|
-
const i = stack.findIndex((l) => l.id === id)
|
|
55
|
-
if (i >= 0) stack.splice(i, 1)
|
|
56
|
-
}
|
|
21
|
+
return dismissable(() => refsRef.current.map((r) => r.current), (reason, e) => cb.current(reason, e), { outside, hint, focusOut })
|
|
57
22
|
}, [active, outside, hint, focusOut])
|
|
58
23
|
}
|
|
59
24
|
|
|
60
|
-
|
|
61
|
-
let saved = ''
|
|
62
|
-
let savedPadding = ''
|
|
63
|
-
|
|
25
|
+
/** React's hold on lockScroll (motion/layers.ts). */
|
|
64
26
|
export function useScrollLock(active: boolean) {
|
|
65
27
|
useEffect(() => {
|
|
66
28
|
if (!active) return
|
|
67
|
-
|
|
68
|
-
const body = document.body
|
|
69
|
-
// Fills the space the scrollbar leaves, so the page does not shift sideways.
|
|
70
|
-
const bar = window.innerWidth - document.documentElement.clientWidth
|
|
71
|
-
saved = body.style.overflow
|
|
72
|
-
savedPadding = body.style.paddingRight
|
|
73
|
-
if (bar > 0) body.style.paddingRight = `calc(${getComputedStyle(body).paddingRight} + ${bar}px)`
|
|
74
|
-
body.style.overflow = 'hidden'
|
|
75
|
-
}
|
|
76
|
-
lockCount++
|
|
77
|
-
return () => {
|
|
78
|
-
lockCount--
|
|
79
|
-
if (lockCount === 0) {
|
|
80
|
-
document.body.style.overflow = saved
|
|
81
|
-
document.body.style.paddingRight = savedPadding
|
|
82
|
-
}
|
|
83
|
-
}
|
|
29
|
+
return lockScroll()
|
|
84
30
|
}, [active])
|
|
85
31
|
}
|
package/src/internal/liquid.ts
CHANGED
|
@@ -1,212 +1,45 @@
|
|
|
1
1
|
import { useLayoutEffect, useRef, type RefObject } from 'react'
|
|
2
|
-
import {
|
|
3
|
-
import { bezier } from './feel'
|
|
4
|
-
import { easing, morphCurve, motionMs, prefersReducedMotion } from './motion'
|
|
2
|
+
import { createDialogMorph, createLiquid, createStretch, type LiquidOrigin as Origin, type StretchBox } from './motion/liquid'
|
|
5
3
|
|
|
6
|
-
|
|
7
|
-
// corners) at the panel's edge nearest the opener, then fills out to the whole panel; on close it
|
|
8
|
-
// folds back. Only a clip changes, so nothing inside the panel is stretched and text stays sharp.
|
|
9
|
-
// Both ways play the morph curve forward, so a close moves from its first frame, and a move caught
|
|
10
|
-
// half way starts from the shape on screen.
|
|
11
|
-
// Where the browser cannot clip or animate this way, or with reduced motion, the part's own CSS fade
|
|
12
|
-
// runs instead.
|
|
4
|
+
export { startShape, stretch, type StretchBox } from './motion/liquid'
|
|
13
5
|
|
|
14
|
-
/** What the panel grows from: the opener
|
|
6
|
+
/** What the panel grows from: the opener's ref, or a function that finds the opener or a rectangle at open time. */
|
|
15
7
|
export type LiquidOrigin = RefObject<HTMLElement | null> | (() => HTMLElement | DOMRect | null)
|
|
16
8
|
|
|
17
|
-
|
|
18
|
-
typeof CSS !== 'undefined' &&
|
|
19
|
-
CSS.supports('clip-path', 'inset(0px round 1px)') &&
|
|
20
|
-
typeof Element !== 'undefined' &&
|
|
21
|
-
typeof Element.prototype.animate === 'function'
|
|
22
|
-
|
|
23
|
-
const clamp = (v: number, max: number) => Math.max(0, Math.min(max, v))
|
|
24
|
-
|
|
25
|
-
// How far the panel's shadow reaches past its box, so the clip can end there and the shadow grows in
|
|
26
|
-
// with the panel instead of appearing all at once when the clip is removed.
|
|
27
|
-
function shadowReach(el: HTMLElement) {
|
|
28
|
-
let reach = 0
|
|
29
|
-
for (const shadow of getComputedStyle(el).boxShadow.split(/,(?![^(]*\))/)) {
|
|
30
|
-
if (shadow.includes('inset')) continue
|
|
31
|
-
const [x = 0, y = 0, blur = 0, spread = 0] = (shadow.replace(/rgba?\([^)]*\)|#[\da-f]+/gi, '').match(/-?[\d.]+px/g) ?? []).map(parseFloat)
|
|
32
|
-
reach = Math.max(reach, Math.abs(x) + blur + spread, Math.abs(y) + blur + spread)
|
|
33
|
-
}
|
|
34
|
-
return Math.ceil(reach)
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// The opener's footprint on the panel, as an inset from each edge. An opener above or below the panel
|
|
38
|
-
// lands as a strip on the nearest edge; one beside it, on the nearest side; one inside it (a click
|
|
39
|
-
// point), where it is.
|
|
40
|
-
export function startShape(panel: DOMRect, from: DOMRect, radius: string) {
|
|
41
|
-
const w = panel.width
|
|
42
|
-
const h = panel.height
|
|
43
|
-
let top = clamp(from.top - panel.top, h)
|
|
44
|
-
let bottom = clamp(panel.bottom - from.bottom, h)
|
|
45
|
-
let left = clamp(from.left - panel.left, w)
|
|
46
|
-
let right = clamp(panel.right - from.right, w)
|
|
47
|
-
const fh = Math.min(from.height, h)
|
|
48
|
-
const fw = Math.min(from.width, w)
|
|
49
|
-
if (from.bottom <= panel.top + 1) [top, bottom] = [0, h - fh]
|
|
50
|
-
else if (from.top >= panel.bottom - 1) [top, bottom] = [h - fh, 0]
|
|
51
|
-
else if (from.right <= panel.left + 1) [left, right] = [0, w - fw]
|
|
52
|
-
else if (from.left >= panel.right - 1) [left, right] = [w - fw, 0]
|
|
53
|
-
// Never less than a sliver, so the shape always has somewhere to grow from.
|
|
54
|
-
if (w - left - right < 2) right = Math.max(0, w - left - 2)
|
|
55
|
-
if (h - top - bottom < 2) bottom = Math.max(0, h - top - 2)
|
|
56
|
-
return `inset(${top}px ${right}px ${bottom}px ${left}px round ${radius})`
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// The phone layout of Dialog and AlertDialog, as their CSS sets it.
|
|
60
|
-
const SHEET = '(max-width: 520px)'
|
|
61
|
-
|
|
62
|
-
const live = (run: Animation | null) => run?.playState === 'running' || run?.playState === 'paused'
|
|
63
|
-
|
|
64
|
-
// Grows the panel out of `found` (or folds it back) from wherever the last run left it.
|
|
65
|
-
function clipMorph(p: HTMLElement, found: HTMLElement | DOMRect, state: 'open' | 'closed', last: Animation | null) {
|
|
66
|
-
const opener = found instanceof HTMLElement ? found : null
|
|
67
|
-
const from = found instanceof HTMLElement ? found.getBoundingClientRect() : found
|
|
68
|
-
const now = live(last) ? getComputedStyle(p).clipPath : null
|
|
69
|
-
last?.cancel()
|
|
70
|
-
// Set before measuring, so the part's CSS enter animation is not caught mid-scale.
|
|
71
|
-
p.dataset.liquid = ''
|
|
72
|
-
// Never rounder than half the opener's height: a pill's 999px corner would keep a tall panel a
|
|
73
|
-
// capsule for most of the growth.
|
|
74
|
-
const cap = Math.min(from.width, from.height) / 2
|
|
75
|
-
const radius = `${Math.min(cap, opener ? parseFloat(getComputedStyle(opener).borderRadius) || 0 : cap)}px`
|
|
76
|
-
const start = startShape(p.getBoundingClientRect(), from, radius)
|
|
77
|
-
const room = shadowReach(p)
|
|
78
|
-
const corner = getComputedStyle(p).borderRadius || '0px'
|
|
79
|
-
const end = `inset(${-room}px round calc(${corner} + ${room}px))`
|
|
80
|
-
// data-liquid stays set while the panel is open: taking it off would restart the part's CSS enter animation.
|
|
81
|
-
if (state === 'open') return p.animate({ clipPath: [now ?? start, end] }, { duration: motionMs('morph'), easing: easing('morph') })
|
|
82
|
-
// A close starts at the panel's own edge, not out past its shadow, so the edge moves on the first frame.
|
|
83
|
-
// It also fades by 65% of the fold: when the opener sits outside the panel, the shrinking clip would
|
|
84
|
-
// otherwise leave a strip of the panel on its near edge until the very end.
|
|
85
|
-
return p.animate(
|
|
86
|
-
[
|
|
87
|
-
{ clipPath: now ?? `inset(0px round ${corner})`, opacity: 1 },
|
|
88
|
-
{ opacity: 1, offset: 0.2 },
|
|
89
|
-
{ opacity: 0, offset: 0.65 },
|
|
90
|
-
{ clipPath: start, opacity: 0 },
|
|
91
|
-
],
|
|
92
|
-
{ duration: motionMs('morph-out'), easing: easing('morph'), fill: 'forwards' },
|
|
93
|
-
)
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Plays the growth when `state` turns open (once `ready`, that is, once the panel is in its place) and
|
|
98
|
-
* the fold when it turns closed. Marks the panel with data-liquid while it runs, so the part's CSS can
|
|
99
|
-
* stand its own enter and exit animation down. The part's usePresence exit is 'morph-out', so the
|
|
100
|
-
* fold lands as the panel unmounts.
|
|
101
|
-
*/
|
|
9
|
+
/** React's hold on createLiquid (motion/liquid.ts): grows when `state` turns open (once `ready`), folds when it turns closed. */
|
|
102
10
|
export function useLiquid(panel: RefObject<HTMLElement | null>, origin: LiquidOrigin, state: 'open' | 'closed', ready: boolean) {
|
|
103
|
-
const
|
|
11
|
+
const from = useRef(origin)
|
|
12
|
+
from.current = origin
|
|
13
|
+
const liquid = useRef<ReturnType<typeof createLiquid>>(null)
|
|
14
|
+
liquid.current ??= createLiquid(() => panel.current, (() => {
|
|
15
|
+
const o = from.current
|
|
16
|
+
return typeof o === 'function' ? o() : o.current
|
|
17
|
+
}) satisfies Origin)
|
|
104
18
|
useLayoutEffect(() => {
|
|
105
|
-
|
|
106
|
-
if (!p || !ready || prefersReducedMotion() || !able()) return
|
|
107
|
-
const found = typeof origin === 'function' ? origin() : origin.current
|
|
108
|
-
if (!found) return
|
|
109
|
-
run.current = clipMorph(p, found, state, run.current)
|
|
19
|
+
if (ready) liquid.current!.play(state)
|
|
110
20
|
// Plays once per open and once per close; the origin is read fresh each time.
|
|
111
21
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
112
22
|
}, [state, ready])
|
|
113
|
-
useLayoutEffect(() => () =>
|
|
23
|
+
useLayoutEffect(() => () => liquid.current!.destroy(), [])
|
|
114
24
|
}
|
|
115
25
|
|
|
116
|
-
/**
|
|
117
|
-
* A centred dialog grows out of the control that opened it (the one focus goes back to) and folds back
|
|
118
|
-
* into it. Opened from code with no such control, it grows from the middle of the screen. On a phone
|
|
119
|
-
* the dialog is a bottom sheet: it grows out of a control it covers, as one in the thumb zone is, and
|
|
120
|
-
* otherwise rises from the bottom edge. A sheet the hand drags away (data-fluid) is carried by the drag.
|
|
121
|
-
*/
|
|
26
|
+
/** React's hold on createDialogMorph (motion/liquid.ts). */
|
|
122
27
|
export function useDialogMorph(panel: RefObject<HTMLElement | null>, open: boolean, mounted: boolean, state: 'open' | 'closed') {
|
|
123
|
-
const opener = useRef<HTMLElement | null>(null)
|
|
124
28
|
const wasOpen = useRef(false)
|
|
125
|
-
const
|
|
126
|
-
|
|
29
|
+
const morph = useRef<ReturnType<typeof createDialogMorph>>(null)
|
|
30
|
+
morph.current ??= createDialogMorph(() => panel.current)
|
|
127
31
|
// Runs before the focus trap moves focus into the dialog.
|
|
128
32
|
useLayoutEffect(() => {
|
|
129
|
-
if (open && !wasOpen.current)
|
|
33
|
+
if (open && !wasOpen.current) morph.current!.opening()
|
|
130
34
|
wasOpen.current = open
|
|
131
35
|
}, [open])
|
|
132
36
|
useLayoutEffect(() => {
|
|
133
|
-
|
|
134
|
-
if (!p || !mounted || prefersReducedMotion() || !able()) return
|
|
135
|
-
const el = opener.current
|
|
136
|
-
const box = el && el !== document.body && el.isConnected ? el.getBoundingClientRect() : null
|
|
137
|
-
const found = el && box && box.width > 0 && box.height > 0 ? el : null
|
|
138
|
-
if (state === 'open' && !live(run.current)) {
|
|
139
|
-
const r = p.getBoundingClientRect()
|
|
140
|
-
rise.current = window.matchMedia(SHEET).matches && !(found && box && box.top >= r.top && box.bottom <= r.bottom + 1)
|
|
141
|
-
}
|
|
142
|
-
if (state === 'closed' && 'fluid' in p.dataset) return
|
|
143
|
-
if (!rise.current) {
|
|
144
|
-
run.current = clipMorph(p, found ?? new DOMRect(window.innerWidth / 2 - 1, window.innerHeight / 2 - 1, 2, 2), state, run.current)
|
|
145
|
-
return
|
|
146
|
-
}
|
|
147
|
-
const now = live(run.current) ? getComputedStyle(p).transform : null
|
|
148
|
-
run.current?.cancel()
|
|
149
|
-
p.dataset.liquid = ''
|
|
150
|
-
const down = 'translateY(100%)'
|
|
151
|
-
run.current =
|
|
152
|
-
state === 'open'
|
|
153
|
-
? p.animate({ transform: [now ?? down, 'none'] }, { duration: motionMs('morph'), easing: easing('morph') })
|
|
154
|
-
: p.animate({ transform: [now ?? 'none', down] }, { duration: motionMs('morph-out'), easing: easing('morph'), fill: 'forwards' })
|
|
37
|
+
if (mounted) morph.current!.play(state)
|
|
155
38
|
}, [state, mounted, panel])
|
|
156
|
-
useLayoutEffect(() => () =>
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
/** A highlight's place in its row: its start edge (left, or top on the y axis), its length, and (for rows that wrap) its top. */
|
|
160
|
-
export type StretchBox = { x: number; w: number; y?: number }
|
|
161
|
-
|
|
162
|
-
// The leading edge moves over this share of the time; the trailing edge starts the rest of the way in.
|
|
163
|
-
const LEAD = 0.75
|
|
164
|
-
const runs = new WeakMap<HTMLElement, Animation>()
|
|
165
|
-
|
|
166
|
-
// Where a stretch caught half way has the highlight now.
|
|
167
|
-
function placeNow(node: HTMLElement, axis: 'x' | 'y'): StretchBox {
|
|
168
|
-
const s = getComputedStyle(node)
|
|
169
|
-
const m = new DOMMatrixReadOnly(s.transform === 'none' ? undefined : s.transform)
|
|
170
|
-
return axis === 'x' ? { x: m.m41, w: parseFloat(s.width), y: m.m42 } : { x: m.m42, w: parseFloat(s.height) }
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
/**
|
|
174
|
-
* Moves a highlight with two edges: the one nearest the new place leaves first and the far one
|
|
175
|
-
* catches up, both on the morph curve, so it stretches toward the choice and settles there. A move
|
|
176
|
-
* caught half way turns from where it is. `place` turns a box into the highlight's transform.
|
|
177
|
-
*/
|
|
178
|
-
export function stretch(node: HTMLElement, from: StretchBox, to: StretchBox, place: (b: StretchBox) => string, axis: 'x' | 'y' = 'x') {
|
|
179
|
-
const last = runs.get(node) ?? null
|
|
180
|
-
const start = live(last) ? placeNow(node, axis) : from
|
|
181
|
-
last?.cancel()
|
|
182
|
-
const ms = motionMs('base')
|
|
183
|
-
if (!ms || prefersReducedMotion() || !able()) return
|
|
184
|
-
const size = axis === 'x' ? 'width' : 'height'
|
|
185
|
-
const ease = bezier(morphCurve())
|
|
186
|
-
const ahead = to.x + to.w / 2 >= start.x + start.w / 2
|
|
187
|
-
const frames: Keyframe[] = []
|
|
188
|
-
for (let i = 0; i <= 12; i++) {
|
|
189
|
-
const t = i / 12
|
|
190
|
-
const lead = ease(Math.min(1, t / LEAD))
|
|
191
|
-
const trail = ease(Math.max(0, (t - 1 + LEAD) / LEAD))
|
|
192
|
-
const a = start.x + (to.x - start.x) * (ahead ? trail : lead)
|
|
193
|
-
const b = start.x + start.w + (to.x + to.w - start.x - start.w) * (ahead ? lead : trail)
|
|
194
|
-
frames.push({ transform: place({ x: a, w: b - a, y: to.y }), [size]: `${b - a}px` })
|
|
195
|
-
}
|
|
196
|
-
node.dataset.liquid = ''
|
|
197
|
-
const run = node.animate(frames, { duration: ms })
|
|
198
|
-
runs.set(node, run)
|
|
199
|
-
// Only the latest stretch takes the mark off: a cancelled one settles later, mid-way through the next.
|
|
200
|
-
const done = () => {
|
|
201
|
-
if (runs.get(node) === run) delete node.dataset.liquid
|
|
202
|
-
}
|
|
203
|
-
run.finished.then(done, done)
|
|
39
|
+
useLayoutEffect(() => () => morph.current!.destroy(), [])
|
|
204
40
|
}
|
|
205
41
|
|
|
206
|
-
/**
|
|
207
|
-
* Liquid highlight: when the choice changes, the highlight stretches toward it (see stretch). Runs
|
|
208
|
-
* only on a change of choice; a resize simply follows. Along one row, or one column with axis 'y'.
|
|
209
|
-
*/
|
|
42
|
+
/** React's hold on createStretch (motion/liquid.ts): the highlight stretches when the choice changes. */
|
|
210
43
|
export function useStretch(
|
|
211
44
|
el: RefObject<HTMLElement | null>,
|
|
212
45
|
box: StretchBox | null,
|
|
@@ -215,34 +48,14 @@ export function useStretch(
|
|
|
215
48
|
place: (b: StretchBox) => string,
|
|
216
49
|
axis: 'x' | 'y' = 'x',
|
|
217
50
|
) {
|
|
218
|
-
const
|
|
219
|
-
|
|
51
|
+
const fmt = useRef(place)
|
|
52
|
+
fmt.current = place
|
|
53
|
+
const run = useRef<ReturnType<typeof createStretch>>(null)
|
|
54
|
+
run.current ??= createStretch(() => el.current, (b) => fmt.current(b), axis)
|
|
220
55
|
useLayoutEffect(() => {
|
|
221
|
-
|
|
222
|
-
const prev = last.current
|
|
223
|
-
// A part often renders the new choice before it has measured its new place, so only a moved box
|
|
224
|
-
// counts; it then stretches if the choice behind it changed, and simply follows a resize.
|
|
225
|
-
// No highlight (nothing chosen): forget the old place, so the next one appears rather than stretching from it.
|
|
226
|
-
if (!box) {
|
|
227
|
-
last.current = null
|
|
228
|
-
return
|
|
229
|
-
}
|
|
230
|
-
if (prev && prev.box.x === box.x && prev.box.w === box.w && prev.box.y === box.y) return
|
|
231
|
-
last.current = { box, choice }
|
|
232
|
-
if (!node || !prev || !ready) return
|
|
233
|
-
if (prev.choice === choice || (prev.box.y ?? 0) !== (box.y ?? 0)) {
|
|
234
|
-
runs.get(node)?.cancel()
|
|
235
|
-
return
|
|
236
|
-
}
|
|
237
|
-
moved.current = node
|
|
238
|
-
stretch(node, prev.box, box, place, axis)
|
|
56
|
+
run.current!.update(box, choice, ready)
|
|
239
57
|
// Keyed on the choice and the box; `place` is a pure formatter.
|
|
240
58
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
241
59
|
}, [choice, box?.x, box?.w, box?.y, ready])
|
|
242
|
-
useLayoutEffect(
|
|
243
|
-
() => () => {
|
|
244
|
-
if (moved.current) runs.get(moved.current)?.cancel()
|
|
245
|
-
},
|
|
246
|
-
[],
|
|
247
|
-
)
|
|
60
|
+
useLayoutEffect(() => () => run.current!.destroy(), [])
|
|
248
61
|
}
|