gooee 0.50.0 → 0.51.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +4 -2
- package/scripts/add.js +28 -6
- package/src/components/Accordion/Accordion.vue +62 -0
- package/src/components/Accordion/AccordionItem.vue +45 -0
- package/src/components/Accordion/accordionContext.ts +6 -0
- package/src/components/Alert/Alert.tsx +7 -27
- package/src/components/Alert/Alert.vue +59 -0
- package/src/components/AlertDialog/AlertDialog.vue +126 -0
- package/src/components/AnimatedNumber/AnimatedNumber.vue +36 -0
- package/src/components/AspectRatio/AspectRatio.vue +17 -0
- package/src/components/Avatar/Avatar.vue +56 -0
- package/src/components/AvatarGroup/AvatarGroup.vue +42 -0
- package/src/components/Badge/Badge.vue +32 -0
- package/src/components/Breadcrumb/Breadcrumb.vue +58 -0
- package/src/components/Button/Button.vue +130 -0
- package/src/components/ButtonGroup/ButtonGroup.tsx +4 -21
- package/src/components/ButtonGroup/ButtonGroup.vue +33 -0
- package/src/components/Card/Card.vue +34 -0
- package/src/components/Center/Center.vue +32 -0
- package/src/components/Checkbox/Checkbox.tsx +8 -25
- package/src/components/Checkbox/Checkbox.vue +108 -0
- package/src/components/CheckboxGroup/CheckboxGroup.vue +76 -0
- package/src/components/Cluster/Cluster.vue +34 -0
- package/src/components/CodeBlock/CodeBlock.vue +45 -0
- package/src/components/Collapsible/Collapsible.vue +59 -0
- package/src/components/Container/Container.vue +22 -0
- package/src/components/CopyButton/CopyButton.tsx +3 -49
- package/src/components/CopyButton/CopyButton.vue +116 -0
- package/src/components/Dial/Dial.tsx +12 -120
- package/src/components/Dial/Dial.vue +228 -0
- package/src/components/Dialog/Dialog.vue +139 -0
- package/src/components/Divider/Divider.vue +27 -0
- package/src/components/DropdownMenu/DropdownMenu.tsx +11 -46
- package/src/components/DropdownMenu/DropdownMenu.vue +185 -0
- package/src/components/EmptyState/EmptyState.vue +33 -0
- package/src/components/Fab/Fab.tsx +4 -14
- package/src/components/Fab/Fab.vue +115 -0
- package/src/components/Fieldset/Fieldset.vue +42 -0
- package/src/components/FormField/FormField.tsx +2 -17
- package/src/components/FormField/FormField.vue +64 -0
- package/src/components/Grid/Grid.vue +43 -0
- package/src/components/HoldToConfirm/HoldToConfirm.tsx +13 -143
- package/src/components/HoldToConfirm/HoldToConfirm.vue +281 -0
- package/src/components/IconButton/IconButton.vue +25 -0
- package/src/components/Input/Input.vue +112 -0
- package/src/components/InputGroup/InputGroup.vue +102 -0
- package/src/components/Kbd/Kbd.tsx +2 -12
- package/src/components/Kbd/Kbd.vue +21 -0
- package/src/components/Link/Link.vue +38 -0
- package/src/components/LivePill/LivePill.tsx +11 -39
- package/src/components/LivePill/LivePill.vue +152 -0
- package/src/components/Meter/Meter.vue +88 -0
- package/src/components/MorphButton/MorphButton.tsx +11 -67
- package/src/components/MorphButton/MorphButton.vue +120 -0
- package/src/components/NumberInput/NumberInput.tsx +11 -48
- package/src/components/NumberInput/NumberInput.vue +184 -0
- package/src/components/Pagination/Pagination.tsx +2 -15
- package/src/components/Pagination/Pagination.vue +87 -0
- package/src/components/Pagination/range.ts +15 -0
- package/src/components/PasswordInput/PasswordInput.vue +53 -0
- package/src/components/PickerWheel/DateWheel.vue +48 -0
- package/src/components/PickerWheel/PickerWheel.tsx +15 -129
- package/src/components/PickerWheel/PickerWheel.vue +77 -0
- package/src/components/PickerWheel/TimeWheel.vue +50 -0
- package/src/components/PickerWheel/WheelColumn.vue +70 -0
- package/src/components/Popover/Popover.vue +108 -0
- package/src/components/ProgressBar/ProgressBar.vue +48 -0
- package/src/components/Prose/Prose.vue +18 -0
- package/src/components/Radio/Radio.vue +49 -0
- package/src/components/Radio/RadioGroup.vue +69 -0
- package/src/components/Retime/Retime.tsx +7 -40
- package/src/components/Retime/Retime.vue +64 -0
- package/src/components/RulerScrubber/RulerScrubber.tsx +9 -38
- package/src/components/RulerScrubber/RulerScrubber.vue +166 -0
- package/src/components/ScrollArea/ScrollArea.tsx +17 -129
- package/src/components/ScrollArea/ScrollArea.vue +58 -0
- package/src/components/SearchInput/SearchInput.tsx +2 -15
- package/src/components/SearchInput/SearchInput.vue +70 -0
- package/src/components/SegmentedControl/SegmentedControl.tsx +7 -51
- package/src/components/SegmentedControl/SegmentedControl.vue +111 -0
- package/src/components/Select/Select.tsx +16 -47
- package/src/components/Select/Select.vue +236 -0
- package/src/components/Sheet/Sheet.tsx +52 -231
- package/src/components/Sheet/Sheet.vue +249 -0
- package/src/components/Skeleton/Skeleton.vue +38 -0
- package/src/components/Slider/Slider.tsx +25 -84
- package/src/components/Slider/Slider.vue +113 -0
- package/src/components/Spinner/Spinner.vue +30 -0
- package/src/components/Split/Split.vue +34 -0
- package/src/components/SplitFlap/SplitFlap.tsx +11 -175
- package/src/components/SplitFlap/SplitFlap.vue +52 -0
- package/src/components/Stack/Stack.vue +22 -0
- package/src/components/SwipeDeck/SwipeDeck.tsx +30 -194
- package/src/components/SwipeDeck/SwipeDeck.vue +168 -0
- package/src/components/Switch/Switch.tsx +6 -75
- package/src/components/Switch/Switch.vue +66 -0
- package/src/components/Table/Table.module.css +12 -3
- package/src/components/Table/Table.tsx +8 -59
- package/src/components/Table/Table.vue +274 -0
- package/src/components/TableOfContents/TableOfContents.vue +90 -0
- package/src/components/Tabs/Tab.vue +37 -0
- package/src/components/Tabs/TabList.vue +47 -0
- package/src/components/Tabs/TabPanel.vue +26 -0
- package/src/components/Tabs/Tabs.module.css +2 -2
- package/src/components/Tabs/Tabs.tsx +11 -84
- package/src/components/Tabs/Tabs.vue +33 -0
- package/src/components/Tabs/tabsContext.ts +15 -0
- package/src/components/Tag/Tag.tsx +6 -26
- package/src/components/Tag/Tag.vue +63 -0
- package/src/components/Textarea/Textarea.tsx +2 -22
- package/src/components/Textarea/Textarea.vue +120 -0
- package/src/components/ThemeToggle/ThemeToggle.tsx +10 -84
- package/src/components/ThemeToggle/ThemeToggle.vue +90 -0
- package/src/components/Toast/Toast.tsx +34 -264
- package/src/components/Toast/Toast.vue +138 -0
- package/src/components/Toast/ToastItem.vue +108 -0
- package/src/components/Toggle/Toggle.vue +52 -0
- package/src/components/Tooltip/Tooltip.tsx +17 -48
- package/src/components/Tooltip/Tooltip.vue +95 -0
- package/src/components/VisuallyHidden/VisuallyHidden.vue +17 -0
- package/src/internal/FieldMessage.vue +41 -0
- package/src/internal/Roll.vue +20 -0
- package/src/internal/focus.ts +4 -47
- package/src/internal/icons.module.css +39 -27
- package/src/internal/layers.ts +7 -61
- package/src/internal/motion/alert.ts +17 -0
- package/src/internal/motion/buttonGroup.ts +21 -0
- package/src/internal/motion/checkbox.ts +39 -0
- package/src/internal/motion/collapseOut.ts +26 -0
- package/src/internal/motion/copyButton.ts +48 -0
- package/src/internal/motion/dial.ts +137 -0
- package/src/internal/motion/fab.ts +14 -0
- package/src/internal/motion/floating.ts +58 -0
- package/src/internal/motion/focus.ts +53 -0
- package/src/internal/motion/formField.ts +19 -0
- package/src/internal/motion/holdToConfirm.ts +147 -0
- package/src/internal/motion/keys.ts +42 -0
- package/src/internal/motion/layers.ts +78 -0
- package/src/internal/motion/listbox.ts +69 -0
- package/src/internal/motion/livePill.ts +71 -0
- package/src/internal/motion/menuKeys.ts +58 -0
- package/src/internal/motion/morphButton.ts +71 -0
- package/src/internal/motion/numberInput.ts +57 -0
- package/src/internal/motion/pickerWheel.ts +166 -0
- package/src/internal/motion/retime.ts +45 -0
- package/src/internal/motion/ruler.ts +57 -0
- package/src/internal/motion/scrollArea.ts +133 -0
- package/src/internal/motion/scrubLook.ts +15 -0
- package/src/internal/motion/segmented.ts +63 -0
- package/src/internal/motion/sheetDetents.ts +271 -0
- package/src/internal/motion/slider.ts +108 -0
- package/src/internal/motion/splitFlap.ts +205 -0
- package/src/internal/motion/swipeDeck.ts +236 -0
- package/src/internal/motion/switchThumb.ts +83 -0
- package/src/internal/motion/table.ts +77 -0
- package/src/internal/motion/tabs.ts +105 -0
- package/src/internal/motion/textarea.ts +22 -0
- package/src/internal/motion/themeIcon.ts +91 -0
- package/src/internal/motion/themeReveal.ts +71 -0
- package/src/internal/motion/toast.ts +291 -0
- package/src/internal/motion/tooltip.ts +58 -0
- package/src/internal/themeReveal.ts +3 -61
- package/src/internal/useFloating.ts +9 -49
- package/src/internal/useScrub.ts +1 -13
- package/src/internal/vue/trigger.ts +18 -0
- package/src/internal/vue/useFloating.ts +38 -0
- package/src/internal/vue/usePresence.ts +21 -0
- package/src/internal/vue/useScrub.ts +40 -0
- package/src/internal/vueIcons.ts +134 -0
- package/src/tokens.css +5 -0
- package/src/internal/relativeTime.ts +0 -26
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed, ref, useAttrs, useSlots } from 'vue'
|
|
3
|
+
import styles from './Toggle.module.css'
|
|
4
|
+
|
|
5
|
+
// The Vue Toggle: the same look (Toggle.module.css) as the React one. The icon goes in the icon slot;
|
|
6
|
+
// other attributes and listeners go to the button.
|
|
7
|
+
defineOptions({ inheritAttrs: false })
|
|
8
|
+
|
|
9
|
+
const props = withDefaults(
|
|
10
|
+
defineProps<{
|
|
11
|
+
/** Starting pressed state when there is no v-model. */
|
|
12
|
+
defaultPressed?: boolean
|
|
13
|
+
/** Height and text size, the same as Button. */
|
|
14
|
+
size?: 'sm' | 'md' | 'lg'
|
|
15
|
+
type?: 'button' | 'submit' | 'reset'
|
|
16
|
+
}>(),
|
|
17
|
+
{ defaultPressed: false, size: 'md', type: 'button' },
|
|
18
|
+
)
|
|
19
|
+
/** Pressed state. Use v-model:pressed, or leave it out and the toggle keeps its own state. */
|
|
20
|
+
const model = defineModel<boolean | undefined>('pressed', { type: Boolean, default: undefined })
|
|
21
|
+
const slots = useSlots() as { default?: () => unknown; icon?: () => unknown }
|
|
22
|
+
const attrs = useAttrs()
|
|
23
|
+
|
|
24
|
+
const own = ref(props.defaultPressed)
|
|
25
|
+
const pressed = computed(() => model.value ?? own.value)
|
|
26
|
+
const rest = computed(() => {
|
|
27
|
+
const { onClick: _onClick, ...others } = attrs
|
|
28
|
+
return others
|
|
29
|
+
})
|
|
30
|
+
// The caller's click runs first, and can stop the change with preventDefault.
|
|
31
|
+
const onClick = (e: MouseEvent) => {
|
|
32
|
+
const listener = attrs.onClick as ((e: MouseEvent) => void) | Array<(e: MouseEvent) => void> | undefined
|
|
33
|
+
;(Array.isArray(listener) ? listener : listener ? [listener] : []).forEach((f) => f(e))
|
|
34
|
+
if (e.defaultPrevented) return
|
|
35
|
+
own.value = !pressed.value
|
|
36
|
+
model.value = own.value
|
|
37
|
+
}
|
|
38
|
+
</script>
|
|
39
|
+
|
|
40
|
+
<template>
|
|
41
|
+
<button
|
|
42
|
+
v-bind="rest"
|
|
43
|
+
:type="type"
|
|
44
|
+
:aria-pressed="pressed"
|
|
45
|
+
:class="[styles.root, styles[size], !slots.default && styles.iconOnly]"
|
|
46
|
+
:data-on="pressed || undefined"
|
|
47
|
+
@click="onClick"
|
|
48
|
+
>
|
|
49
|
+
<span v-if="slots.icon" :class="styles.icon"><slot name="icon" /></span>
|
|
50
|
+
<slot />
|
|
51
|
+
</button>
|
|
52
|
+
</template>
|
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
import { useDismiss } from '../../internal/layers'
|
|
17
17
|
import { useLiquid } from '../../internal/liquid'
|
|
18
18
|
import { mergeRefs } from '../../internal/mergeRefs'
|
|
19
|
-
import {
|
|
19
|
+
import { createTipTimer, tipEdge } from '../../internal/motion/tooltip'
|
|
20
20
|
import { Portal } from '../../internal/Portal'
|
|
21
21
|
import { useFloating, type Side } from '../../internal/useFloating'
|
|
22
22
|
import { usePresence } from '../../internal/usePresence'
|
|
@@ -33,8 +33,6 @@ type TriggerProps = {
|
|
|
33
33
|
onPointerUp?: (e: PointerEvent<HTMLElement>) => void
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
// How long a tip stays after a tap on a touch screen, so it can be read.
|
|
37
|
-
const TOUCH_SHOW_MS = 1500
|
|
38
36
|
export type TooltipProps = {
|
|
39
37
|
/** Short text shown on hover and focus. It also describes the trigger to screen readers. */
|
|
40
38
|
content: ReactNode
|
|
@@ -46,86 +44,57 @@ export type TooltipProps = {
|
|
|
46
44
|
delay?: number
|
|
47
45
|
}
|
|
48
46
|
|
|
49
|
-
let lastClosedAt = 0
|
|
50
|
-
|
|
51
47
|
export function Tooltip({ content, side = 'top', children, delay }: TooltipProps) {
|
|
52
48
|
const id = useId()
|
|
53
49
|
const [open, setOpen] = useState(false)
|
|
54
50
|
const anchorRef = useRef<HTMLElement>(null)
|
|
55
51
|
const tipRef = useRef<HTMLDivElement>(null)
|
|
56
|
-
const timer = useRef<number | undefined>(undefined)
|
|
57
52
|
const { mounted, state } = usePresence(open, 'morph-out')
|
|
58
53
|
const floating = useFloating(anchorRef, tipRef, { open: mounted, side, offset: 8 })
|
|
59
54
|
// The tip grows out of the edge of the target it points to, a sliver as wide as the target, and folds back into it.
|
|
60
|
-
useLiquid(
|
|
61
|
-
tipRef,
|
|
62
|
-
() => {
|
|
63
|
-
const r = anchorRef.current?.getBoundingClientRect()
|
|
64
|
-
if (!r) return null
|
|
65
|
-
if (floating.side === 'top') return new DOMRect(r.left, r.top, r.width, 2)
|
|
66
|
-
if (floating.side === 'bottom') return new DOMRect(r.left, r.bottom - 2, r.width, 2)
|
|
67
|
-
if (floating.side === 'left') return new DOMRect(r.left, r.top, 2, r.height)
|
|
68
|
-
return new DOMRect(r.right - 2, r.top, 2, r.height)
|
|
69
|
-
},
|
|
70
|
-
state,
|
|
71
|
-
mounted && floating.ready,
|
|
72
|
-
)
|
|
55
|
+
useLiquid(tipRef, () => tipEdge(anchorRef.current, floating.side), state, mounted && floating.ready)
|
|
73
56
|
|
|
74
|
-
const
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
const
|
|
80
|
-
clear()
|
|
81
|
-
timer.current = window.setTimeout(() => {
|
|
82
|
-
setOpen(false)
|
|
83
|
-
lastClosedAt = Date.now()
|
|
84
|
-
}, wait)
|
|
85
|
-
}
|
|
57
|
+
const delayRef = useRef(delay)
|
|
58
|
+
delayRef.current = delay
|
|
59
|
+
// When it shows and hides (motion/tooltip.ts).
|
|
60
|
+
const timing = useRef<ReturnType<typeof createTipTimer>>(null)
|
|
61
|
+
timing.current ??= createTipTimer(setOpen, () => delayRef.current)
|
|
62
|
+
const tip = timing.current
|
|
86
63
|
|
|
87
64
|
// Esc hides it without moving focus (WCAG 1.4.13), and only it, not a dialog behind it.
|
|
88
65
|
useDismiss(open, [], () => setOpen(false), { outside: false, hint: true })
|
|
89
66
|
|
|
90
|
-
useEffect(() => clear, [])
|
|
67
|
+
useEffect(() => tip.clear, [tip])
|
|
91
68
|
|
|
92
69
|
if (!isValidElement(children)) return children
|
|
93
70
|
const props = children.props
|
|
94
71
|
|
|
95
|
-
// Right after one closes, the next shows at once
|
|
96
|
-
const hoverDelay = () => (Date.now() - lastClosedAt < 400 ? 0 : (delay ?? motionMs('delay-tooltip')))
|
|
97
|
-
|
|
98
72
|
const trigger = cloneElement(children, {
|
|
99
73
|
ref: mergeRefs(anchorRef, props.ref),
|
|
100
74
|
'aria-describedby': [props['aria-describedby'], open ? id : null].filter(Boolean).join(' ') || undefined,
|
|
101
75
|
onPointerEnter: (e: PointerEvent<HTMLElement>) => {
|
|
102
76
|
props.onPointerEnter?.(e)
|
|
103
|
-
|
|
77
|
+
tip.enter(e)
|
|
104
78
|
},
|
|
105
79
|
onPointerLeave: (e: PointerEvent<HTMLElement>) => {
|
|
106
80
|
props.onPointerLeave?.(e)
|
|
107
|
-
|
|
81
|
+
tip.leave(e)
|
|
108
82
|
},
|
|
109
|
-
// Touch has no hover: a tap shows the tip at once, and it fades a moment after the finger lifts.
|
|
110
83
|
onPointerDown: (e: PointerEvent<HTMLElement>) => {
|
|
111
84
|
props.onPointerDown?.(e)
|
|
112
|
-
|
|
113
|
-
if (e.pointerType === 'touch') {
|
|
114
|
-
clear()
|
|
115
|
-
setOpen(true)
|
|
116
|
-
}
|
|
85
|
+
tip.down(e)
|
|
117
86
|
},
|
|
118
87
|
onPointerUp: (e: PointerEvent<HTMLElement>) => {
|
|
119
88
|
props.onPointerUp?.(e)
|
|
120
|
-
|
|
89
|
+
tip.up(e)
|
|
121
90
|
},
|
|
122
91
|
onFocus: (e: FocusEvent<HTMLElement>) => {
|
|
123
92
|
props.onFocus?.(e)
|
|
124
|
-
|
|
93
|
+
tip.focus(e)
|
|
125
94
|
},
|
|
126
95
|
onBlur: (e: FocusEvent<HTMLElement>) => {
|
|
127
96
|
props.onBlur?.(e)
|
|
128
|
-
|
|
97
|
+
tip.blur()
|
|
129
98
|
},
|
|
130
99
|
})
|
|
131
100
|
|
|
@@ -142,8 +111,8 @@ export function Tooltip({ content, side = 'top', children, delay }: TooltipProps
|
|
|
142
111
|
data-state={state}
|
|
143
112
|
data-side={floating.side}
|
|
144
113
|
style={floating.style}
|
|
145
|
-
onPointerEnter={clear}
|
|
146
|
-
onPointerLeave={() => hide()}
|
|
114
|
+
onPointerEnter={tip.clear}
|
|
115
|
+
onPointerLeave={() => tip.hide()}
|
|
147
116
|
>
|
|
148
117
|
{content}
|
|
149
118
|
</div>
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { onBeforeUnmount, ref, shallowRef, useId, watch, type VNode } from 'vue'
|
|
3
|
+
import type { Side } from '../../internal/motion/floating'
|
|
4
|
+
import { dismissable } from '../../internal/motion/layers'
|
|
5
|
+
import { createLiquid } from '../../internal/motion/liquid'
|
|
6
|
+
import { createTipTimer, tipEdge } from '../../internal/motion/tooltip'
|
|
7
|
+
import { useFloating } from '../../internal/vue/useFloating'
|
|
8
|
+
import { usePresence } from '../../internal/vue/usePresence'
|
|
9
|
+
import { cloneTrigger, elementRef, firstNode } from '../../internal/vue/trigger'
|
|
10
|
+
import styles from './Tooltip.module.css'
|
|
11
|
+
|
|
12
|
+
// The Vue Tooltip: the same look (Tooltip.module.css), timing and growth as the React one.
|
|
13
|
+
// The default slot is the trigger: one focusable element, such as a Button.
|
|
14
|
+
|
|
15
|
+
const props = withDefaults(
|
|
16
|
+
defineProps<{
|
|
17
|
+
/** Short text shown on hover and focus. It also describes the trigger to screen readers. The content slot replaces it. */
|
|
18
|
+
content?: string
|
|
19
|
+
/** Preferred side of the trigger. It flips when there is no room. */
|
|
20
|
+
side?: Side
|
|
21
|
+
/** Delay before showing on hover. Defaults to the tooltip delay token. */
|
|
22
|
+
delay?: number
|
|
23
|
+
}>(),
|
|
24
|
+
{ side: 'top' },
|
|
25
|
+
)
|
|
26
|
+
const slots = defineSlots<{ default?: () => VNode[]; content?: () => unknown }>()
|
|
27
|
+
|
|
28
|
+
const id = useId()
|
|
29
|
+
const open = ref(false)
|
|
30
|
+
const anchor = shallowRef<HTMLElement | null>(null)
|
|
31
|
+
const setAnchor = elementRef(anchor)
|
|
32
|
+
const tip = ref<HTMLElement | null>(null)
|
|
33
|
+
const { mounted, state } = usePresence(open, 'morph-out')
|
|
34
|
+
const { style, side: placed, ready } = useFloating(anchor, tip, mounted, () => ({ side: props.side, offset: 8 }))
|
|
35
|
+
// Vue sets a bare number as no length at all, so the place gets its unit here.
|
|
36
|
+
// The tip grows out of the edge of the target it points to, a sliver as wide as the target, and folds back into it.
|
|
37
|
+
const liquid = createLiquid(
|
|
38
|
+
() => tip.value,
|
|
39
|
+
() => tipEdge(anchor.value, placed.value),
|
|
40
|
+
)
|
|
41
|
+
watch([state, () => mounted.value && ready.value], ([s, on]) => on && liquid.play(s), { flush: 'post' })
|
|
42
|
+
|
|
43
|
+
// When it shows and hides (motion/tooltip.ts).
|
|
44
|
+
const timer = createTipTimer(
|
|
45
|
+
(v) => (open.value = v),
|
|
46
|
+
() => props.delay,
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
// Esc hides it without moving focus (WCAG 1.4.13), and only it, not a dialog behind it.
|
|
50
|
+
let release = () => {}
|
|
51
|
+
watch(open, (now) => {
|
|
52
|
+
release()
|
|
53
|
+
release = now ? dismissable(() => [], () => (open.value = false), { outside: false, hint: true }) : () => {}
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
onBeforeUnmount(() => {
|
|
57
|
+
timer.clear()
|
|
58
|
+
release()
|
|
59
|
+
liquid.destroy()
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
// The trigger is the slot's own element, given the tip's ARIA and events, like React's cloneElement.
|
|
63
|
+
const trigger = () => {
|
|
64
|
+
const node = firstNode(slots.default?.())
|
|
65
|
+
if (!node) return null
|
|
66
|
+
return cloneTrigger(node, setAnchor, {
|
|
67
|
+
'aria-describedby': [node.props?.['aria-describedby'], open.value ? id : null].filter(Boolean).join(' ') || undefined,
|
|
68
|
+
onPointerenter: timer.enter,
|
|
69
|
+
onPointerleave: timer.leave,
|
|
70
|
+
onPointerdown: timer.down,
|
|
71
|
+
onPointerup: timer.up,
|
|
72
|
+
onFocus: timer.focus,
|
|
73
|
+
onBlur: timer.blur,
|
|
74
|
+
})
|
|
75
|
+
}
|
|
76
|
+
</script>
|
|
77
|
+
|
|
78
|
+
<template>
|
|
79
|
+
<component :is="trigger()" />
|
|
80
|
+
<Teleport v-if="mounted" to="body">
|
|
81
|
+
<div
|
|
82
|
+
:id="id"
|
|
83
|
+
ref="tip"
|
|
84
|
+
role="tooltip"
|
|
85
|
+
:class="styles.tip"
|
|
86
|
+
:data-state="state"
|
|
87
|
+
:data-side="placed"
|
|
88
|
+
:style="style"
|
|
89
|
+
@pointerenter="timer.clear"
|
|
90
|
+
@pointerleave="timer.hide()"
|
|
91
|
+
>
|
|
92
|
+
<slot name="content">{{ content }}</slot>
|
|
93
|
+
</div>
|
|
94
|
+
</Teleport>
|
|
95
|
+
</template>
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import styles from './VisuallyHidden.module.css'
|
|
3
|
+
|
|
4
|
+
// The Vue VisuallyHidden: the same look (VisuallyHidden.module.css) as the React one.
|
|
5
|
+
withDefaults(
|
|
6
|
+
defineProps<{
|
|
7
|
+
/** Shows the content while something inside it has keyboard focus, such as a skip link. */
|
|
8
|
+
focusable?: boolean
|
|
9
|
+
}>(),
|
|
10
|
+
{ focusable: false },
|
|
11
|
+
)
|
|
12
|
+
defineSlots<{ default?: () => unknown }>()
|
|
13
|
+
</script>
|
|
14
|
+
|
|
15
|
+
<template>
|
|
16
|
+
<span :class="focusable ? styles.focusable : styles.root"><slot /></span>
|
|
17
|
+
</template>
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed, ref, watch } from 'vue'
|
|
3
|
+
import { motionMs } from './motion'
|
|
4
|
+
import styles from './FieldMessage.module.css'
|
|
5
|
+
|
|
6
|
+
// The Vue field message: the same look (FieldMessage.module.css) as the React one.
|
|
7
|
+
const props = defineProps<{ helpId: string; errorId: string; help?: string; error?: string }>()
|
|
8
|
+
|
|
9
|
+
const hasError = computed(() => !!props.error)
|
|
10
|
+
// The last error stays visible while it animates out.
|
|
11
|
+
const lastError = ref(props.error)
|
|
12
|
+
let leaving = 0
|
|
13
|
+
watch(
|
|
14
|
+
() => props.error,
|
|
15
|
+
(now) => {
|
|
16
|
+
clearTimeout(leaving)
|
|
17
|
+
if (now) lastError.value = now
|
|
18
|
+
else leaving = window.setTimeout(() => (lastError.value = undefined), motionMs('base'))
|
|
19
|
+
},
|
|
20
|
+
)
|
|
21
|
+
const shown = computed(() => (hasError.value ? props.error : lastError.value))
|
|
22
|
+
</script>
|
|
23
|
+
|
|
24
|
+
<template>
|
|
25
|
+
<div v-if="help" :class="[styles.collapse, !hasError && styles.open]">
|
|
26
|
+
<div :class="styles.inner">
|
|
27
|
+
<p :id="helpId" :class="styles.help">{{ help }}</p>
|
|
28
|
+
</div>
|
|
29
|
+
</div>
|
|
30
|
+
<div :class="[styles.collapse, hasError && styles.open]" aria-live="polite">
|
|
31
|
+
<div :class="styles.inner">
|
|
32
|
+
<!-- Hidden from screen readers while it closes, so only the live error is read. -->
|
|
33
|
+
<p v-if="shown" :id="hasError ? errorId : undefined" :class="styles.error" :aria-hidden="hasError ? undefined : true">
|
|
34
|
+
<svg viewBox="0 0 16 16" aria-hidden="true" :class="styles.mark">
|
|
35
|
+
<circle cx="8" cy="8" r="7" />
|
|
36
|
+
<path d="M8 4.5v4.25M8 11v.01" />
|
|
37
|
+
</svg>{{ shown }}
|
|
38
|
+
</p>
|
|
39
|
+
</div>
|
|
40
|
+
</div>
|
|
41
|
+
</template>
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { ref, watch } from 'vue'
|
|
3
|
+
import styles from './Roll.module.css'
|
|
4
|
+
|
|
5
|
+
// Text that rolls in from the side it moved toward (the Vue twin of Roll.tsx). With reduced motion it just
|
|
6
|
+
// changes. `still` swaps the text in place, for values that change on every frame of a drag.
|
|
7
|
+
const props = defineProps<{ text: string; class?: string; still?: boolean }>()
|
|
8
|
+
const dir = ref<'up' | 'down'>('up')
|
|
9
|
+
watch(
|
|
10
|
+
() => props.text,
|
|
11
|
+
(now, was) => (dir.value = now.localeCompare(was, undefined, { numeric: true }) > 0 ? 'up' : 'down'),
|
|
12
|
+
{ flush: 'sync' },
|
|
13
|
+
)
|
|
14
|
+
</script>
|
|
15
|
+
|
|
16
|
+
<template>
|
|
17
|
+
<span :class="props.class ? `${styles.roll} ${props.class}` : styles.roll">
|
|
18
|
+
<span :key="still ? 'still' : text" :class="still ? undefined : styles.in" :data-dir="dir">{{ text }}</span>
|
|
19
|
+
</span>
|
|
20
|
+
</template>
|
package/src/internal/focus.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { useEffect, type RefObject } from 'react'
|
|
2
|
-
import {
|
|
2
|
+
import { trapFocus } from './motion/focus'
|
|
3
3
|
|
|
4
|
-
export { focusables, returnTarget } from './motion/focus'
|
|
4
|
+
export { focusables, returnTarget, trapFocus } from './motion/focus'
|
|
5
5
|
|
|
6
|
+
/** React's hold on trapFocus (motion/focus.ts): while `active`, Tab stays inside `ref`. */
|
|
6
7
|
export function useFocusTrap(
|
|
7
8
|
ref: RefObject<HTMLElement | null>,
|
|
8
9
|
active: boolean,
|
|
@@ -13,50 +14,6 @@ export function useFocusTrap(
|
|
|
13
14
|
if (!active) return
|
|
14
15
|
const root = ref.current
|
|
15
16
|
if (!root) return
|
|
16
|
-
|
|
17
|
-
// Close buttons opt out of first focus, so focus lands on the content or the safe action.
|
|
18
|
-
const list = focusables(root)
|
|
19
|
-
const first = initialFocus?.current ?? list.find((el) => !el.hasAttribute('data-skip-initial-focus')) ?? list[0] ?? root
|
|
20
|
-
first.focus({ preventScroll: true })
|
|
21
|
-
|
|
22
|
-
// Safari's plain Tab skips buttons, so it can jump from the middle of the layer to the page behind,
|
|
23
|
-
// or off the page. A Tab that lands outside goes back to the end it wrapped past.
|
|
24
|
-
let check = 0
|
|
25
|
-
const onKey = (e: KeyboardEvent) => {
|
|
26
|
-
if (e.key !== 'Tab') return
|
|
27
|
-
const items = focusables(root)
|
|
28
|
-
if (items.length === 0) {
|
|
29
|
-
e.preventDefault()
|
|
30
|
-
root.focus()
|
|
31
|
-
return
|
|
32
|
-
}
|
|
33
|
-
const firstEl = items[0]
|
|
34
|
-
const lastEl = items[items.length - 1]
|
|
35
|
-
const current = document.activeElement
|
|
36
|
-
if (e.shiftKey && (current === firstEl || current === root)) {
|
|
37
|
-
e.preventDefault()
|
|
38
|
-
lastEl.focus()
|
|
39
|
-
} else if (!e.shiftKey && current === lastEl) {
|
|
40
|
-
e.preventDefault()
|
|
41
|
-
firstEl.focus()
|
|
42
|
-
} else {
|
|
43
|
-
const back = e.shiftKey
|
|
44
|
-
clearTimeout(check)
|
|
45
|
-
check = window.setTimeout(() => {
|
|
46
|
-
if (root.contains(document.activeElement)) return
|
|
47
|
-
const now = focusables(root)
|
|
48
|
-
now[back ? now.length - 1 : 0]?.focus({ preventScroll: true })
|
|
49
|
-
})
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
root.addEventListener('keydown', onKey)
|
|
53
|
-
return () => {
|
|
54
|
-
clearTimeout(check)
|
|
55
|
-
root.removeEventListener('keydown', onKey)
|
|
56
|
-
// Give focus back only if it is still in the layer, so a click elsewhere keeps its own focus.
|
|
57
|
-
const now = document.activeElement
|
|
58
|
-
const stillInside = !now || now === document.body || root.contains(now)
|
|
59
|
-
if (restore && stillInside && previous && document.contains(previous)) previous.focus({ preventScroll: true })
|
|
60
|
-
}
|
|
17
|
+
return trapFocus(root, { initialFocus: initialFocus?.current, restore })
|
|
61
18
|
}, [active])
|
|
62
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
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { easing, motionMs } from '../motion'
|
|
2
|
+
|
|
3
|
+
// Folds an alert's height to zero, so content below slides up instead of jumping, then calls done.
|
|
4
|
+
export function foldAway(el: HTMLElement, done: () => void) {
|
|
5
|
+
const ms = motionMs('slow')
|
|
6
|
+
if (ms === 0 || !el.animate) return done()
|
|
7
|
+
const h = el.offsetHeight
|
|
8
|
+
const anim = el.animate(
|
|
9
|
+
[
|
|
10
|
+
{ height: `${h}px`, opacity: 1, transform: 'scale(1)' },
|
|
11
|
+
{ height: `${h}px`, opacity: 0, transform: 'scale(0.98)', offset: 0.45 },
|
|
12
|
+
{ height: '0px', opacity: 0, transform: 'scale(0.98)', paddingTop: '0px', paddingBottom: '0px', marginTop: '0px', marginBottom: '0px', borderWidth: '0px' },
|
|
13
|
+
],
|
|
14
|
+
{ duration: ms, easing: easing('morph'), fill: 'forwards' },
|
|
15
|
+
)
|
|
16
|
+
anim.onfinish = done
|
|
17
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// A row with no room wraps onto more rows. Each row stays joined, with round ends of its own, so the
|
|
2
|
+
// buttons that start and end a row are marked as they fall. Returns the function that stops watching.
|
|
3
|
+
export function markRows(root: HTMLElement) {
|
|
4
|
+
const mark = () => {
|
|
5
|
+
const kids = [...root.children] as HTMLElement[]
|
|
6
|
+
kids.forEach((k, i) => {
|
|
7
|
+
const prev = kids[i - 1], next = kids[i + 1]
|
|
8
|
+
k.toggleAttribute('data-row-start', !prev || prev.offsetTop !== k.offsetTop)
|
|
9
|
+
k.toggleAttribute('data-row-end', !next || next.offsetTop !== k.offsetTop)
|
|
10
|
+
})
|
|
11
|
+
}
|
|
12
|
+
mark()
|
|
13
|
+
const ro = new ResizeObserver(mark)
|
|
14
|
+
ro.observe(root)
|
|
15
|
+
const mo = new MutationObserver(mark)
|
|
16
|
+
mo.observe(root, { childList: true })
|
|
17
|
+
return () => {
|
|
18
|
+
ro.disconnect()
|
|
19
|
+
mo.disconnect()
|
|
20
|
+
}
|
|
21
|
+
}
|