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,90 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed, nextTick, onBeforeUnmount, onMounted, ref, watch } from 'vue'
|
|
3
|
+
import { bodyAt, createThemeIcon, RAYS, raysAt } from '../../internal/motion/themeIcon'
|
|
4
|
+
import { themeReveal } from '../../internal/motion/themeReveal'
|
|
5
|
+
import IconButton from '../IconButton/IconButton.vue'
|
|
6
|
+
import styles from './ThemeToggle.module.css'
|
|
7
|
+
|
|
8
|
+
export type Theme = 'light' | 'dark'
|
|
9
|
+
|
|
10
|
+
// The Vue ThemeToggle: the same button, icon morph and circle reveal as the React one. themeScript, for
|
|
11
|
+
// <head>, is in internal/motion/themeReveal.ts.
|
|
12
|
+
const props = withDefaults(
|
|
13
|
+
defineProps<{
|
|
14
|
+
/** The theme, with v-model:theme. Leave it out and the toggle sets data-theme on <html> itself. */
|
|
15
|
+
theme?: Theme
|
|
16
|
+
/** Where the choice is remembered when the toggle runs the page. Match it in themeScript. */
|
|
17
|
+
storageKey?: string
|
|
18
|
+
/** The new theme grows from the button in a circle over the screen. Turn it off for an instant change. */
|
|
19
|
+
reveal?: boolean
|
|
20
|
+
/** The button's size, the same as IconButton. */
|
|
21
|
+
size?: 'sm' | 'md' | 'lg'
|
|
22
|
+
}>(),
|
|
23
|
+
{ theme: undefined, storageKey: 'gooee-theme', reveal: true, size: 'sm' },
|
|
24
|
+
)
|
|
25
|
+
/** update:theme: the new theme on every flip. */
|
|
26
|
+
const emit = defineEmits<{ 'update:theme': [theme: Theme] }>()
|
|
27
|
+
|
|
28
|
+
const controlled = computed(() => props.theme !== undefined)
|
|
29
|
+
const own = ref<Theme>('light')
|
|
30
|
+
const theme = computed(() => props.theme ?? own.value)
|
|
31
|
+
const next = computed<Theme>(() => (theme.value === 'dark' ? 'light' : 'dark'))
|
|
32
|
+
|
|
33
|
+
// Read after mount: the server cannot know the page's theme, and themeScript has already set it.
|
|
34
|
+
onMounted(() => {
|
|
35
|
+
if (!controlled.value) own.value = document.documentElement.dataset.theme === 'dark' ? 'dark' : 'light'
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
// Shows the theme the button switches to: the moon in light, the sun in dark (motion/themeIcon.ts).
|
|
39
|
+
const body = ref<SVGPathElement | null>(null)
|
|
40
|
+
const icon = createThemeIcon(() => body.value, theme.value === 'dark' ? 0 : 1)
|
|
41
|
+
// A theme set from outside (or the first paint): morph to it, unless a press already started that morph.
|
|
42
|
+
watch(
|
|
43
|
+
theme,
|
|
44
|
+
(t) => {
|
|
45
|
+
const to = t === 'dark' ? 0 : 1
|
|
46
|
+
if (icon.aim !== to) icon.morphTo(to)
|
|
47
|
+
},
|
|
48
|
+
{ flush: 'post' },
|
|
49
|
+
)
|
|
50
|
+
onBeforeUnmount(icon.destroy)
|
|
51
|
+
|
|
52
|
+
// The theme is in the page once Vue has drawn it, so the view transition photographs the new page.
|
|
53
|
+
const apply = async () => {
|
|
54
|
+
const to = next.value
|
|
55
|
+
if (!controlled.value) {
|
|
56
|
+
document.documentElement.dataset.theme = to
|
|
57
|
+
try {
|
|
58
|
+
localStorage.setItem(props.storageKey, to)
|
|
59
|
+
} catch {
|
|
60
|
+
// Not saved, so it lasts only this visit; the theme still changes.
|
|
61
|
+
}
|
|
62
|
+
own.value = to
|
|
63
|
+
}
|
|
64
|
+
emit('update:theme', to)
|
|
65
|
+
await nextTick()
|
|
66
|
+
}
|
|
67
|
+
// The icon answers the press at once; the theme change, and its circle, start two frames later, so
|
|
68
|
+
// the first motion is on screen before the page is held still to be photographed.
|
|
69
|
+
const flip = (e: MouseEvent) => {
|
|
70
|
+
const origin = e.currentTarget as Element
|
|
71
|
+
icon.morphTo(next.value === 'dark' ? 0 : 1)
|
|
72
|
+
requestAnimationFrame(() =>
|
|
73
|
+
requestAnimationFrame(() => {
|
|
74
|
+
if (props.reveal) themeReveal(origin, apply)
|
|
75
|
+
else void apply()
|
|
76
|
+
}),
|
|
77
|
+
)
|
|
78
|
+
}
|
|
79
|
+
</script>
|
|
80
|
+
|
|
81
|
+
<template>
|
|
82
|
+
<IconButton :label="`Switch to ${next} theme`" variant="secondary" :size="size" @click="flip">
|
|
83
|
+
<template #icon>
|
|
84
|
+
<svg :class="styles.icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
|
|
85
|
+
<path ref="body" :d="bodyAt(icon.shown)" />
|
|
86
|
+
<path :class="styles.rays" :d="RAYS" :style="raysAt(icon.shown)" />
|
|
87
|
+
</svg>
|
|
88
|
+
</template>
|
|
89
|
+
</IconButton>
|
|
90
|
+
</template>
|
|
@@ -1,26 +1,13 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
createContext,
|
|
5
|
-
useCallback,
|
|
6
|
-
useContext,
|
|
7
|
-
useEffect,
|
|
8
|
-
useLayoutEffect,
|
|
9
|
-
useMemo,
|
|
10
|
-
useRef,
|
|
11
|
-
useState,
|
|
12
|
-
type PointerEvent,
|
|
13
|
-
type ReactNode,
|
|
14
|
-
} from 'react'
|
|
3
|
+
import { createContext, useCallback, useContext, useEffect, useLayoutEffect, useMemo, useRef, useState, type ReactNode } from 'react'
|
|
15
4
|
import { CheckCircleIcon, ErrorIcon, InfoIcon, XIcon } from '../../internal/icons'
|
|
16
|
-
import { castShadow, frames, layer, morphEase, motionFor, shadowOf } from '../../internal/liquidMatter'
|
|
17
|
-
import { BEND, body, budScene, exitToward, loopsPath, pincher, sdBox, trace, type Box, type Pt } from '../../internal/liquidPath'
|
|
18
5
|
import { motionMs } from '../../internal/motion'
|
|
19
|
-
import {
|
|
6
|
+
import { createToastBud, createToastSwipe, toastId, toastLayout, toastSay, toastStack, toastTimer, watchToastHeight, type ToastLeaving, type ToastOrigin, type ToastVariant } from '../../internal/motion/toast'
|
|
20
7
|
import { Spinner } from '../Spinner'
|
|
21
8
|
import styles from './Toast.module.css'
|
|
22
9
|
|
|
23
|
-
export type ToastVariant
|
|
10
|
+
export type { ToastVariant }
|
|
24
11
|
|
|
25
12
|
export type ToastOptions = {
|
|
26
13
|
title: string
|
|
@@ -30,10 +17,10 @@ export type ToastOptions = {
|
|
|
30
17
|
duration?: number
|
|
31
18
|
action?: { label: string; onClick: () => void }
|
|
32
19
|
/** Where the action happened: the element pressed, or a point on screen. Within 240px of the toast, the drop buds out of it and a dismiss flows back into it. Further away, or without it, the drop buds out of the window's edge. */
|
|
33
|
-
origin?:
|
|
20
|
+
origin?: ToastOrigin
|
|
34
21
|
}
|
|
35
22
|
|
|
36
|
-
type Item = ToastOptions & { id: number; leaving:
|
|
23
|
+
type Item = ToastOptions & { id: number; leaving: ToastLeaving }
|
|
37
24
|
|
|
38
25
|
type Api = {
|
|
39
26
|
toast: (opts: ToastOptions) => number
|
|
@@ -60,12 +47,6 @@ export type ToastProviderProps = {
|
|
|
60
47
|
dismissLabel?: string
|
|
61
48
|
}
|
|
62
49
|
|
|
63
|
-
let nextId = 1
|
|
64
|
-
const GAP = 8
|
|
65
|
-
const PEEK = 10
|
|
66
|
-
// px per second: a toast thrown sideways this fast goes, however short the throw.
|
|
67
|
-
const THROW_SPEED = 600
|
|
68
|
-
|
|
69
50
|
export function ToastProvider({ children, visible = 3, label = 'Notifications', dismissLabel = 'Dismiss' }: ToastProviderProps) {
|
|
70
51
|
const [items, setItems] = useState<Item[]>([])
|
|
71
52
|
const [heights, setHeights] = useState<Record<number, number>>({})
|
|
@@ -82,9 +63,7 @@ export function ToastProvider({ children, visible = 3, label = 'Notifications',
|
|
|
82
63
|
}, [])
|
|
83
64
|
|
|
84
65
|
const say = (opts: Partial<ToastOptions>, variant?: ToastVariant) => {
|
|
85
|
-
const
|
|
86
|
-
// The same text twice is not read again, so a trailing space makes it change.
|
|
87
|
-
const fresh = (prev: string) => (prev === text ? `${text} ` : text)
|
|
66
|
+
const fresh = (prev: string) => toastSay(prev, opts)
|
|
88
67
|
if (variant === 'error') setUrgent(fresh)
|
|
89
68
|
else setAnnounce(fresh)
|
|
90
69
|
}
|
|
@@ -102,7 +81,7 @@ export function ToastProvider({ children, visible = 3, label = 'Notifications',
|
|
|
102
81
|
const api = useMemo<Api>(
|
|
103
82
|
() => ({
|
|
104
83
|
toast: (opts) => {
|
|
105
|
-
const id =
|
|
84
|
+
const id = toastId()
|
|
106
85
|
setItems((list) => [...list, { duration: 5000, variant: 'default', ...opts, id, leaving: false }])
|
|
107
86
|
say(opts, opts.variant)
|
|
108
87
|
return id
|
|
@@ -116,18 +95,7 @@ export function ToastProvider({ children, visible = 3, label = 'Notifications',
|
|
|
116
95
|
[remove],
|
|
117
96
|
)
|
|
118
97
|
|
|
119
|
-
const
|
|
120
|
-
const order = [...items].reverse()
|
|
121
|
-
let offset = 0
|
|
122
|
-
const layout = order.map((t) => {
|
|
123
|
-
const liveIndex = live.length - 1 - live.findIndex((x) => x.id === t.id)
|
|
124
|
-
const index = t.leaving ? -1 : liveIndex
|
|
125
|
-
const y = offset
|
|
126
|
-
if (!t.leaving) offset += (heights[t.id] ?? 64) + GAP
|
|
127
|
-
return { t, index, y }
|
|
128
|
-
})
|
|
129
|
-
const frontHeight = live.length ? heights[live[live.length - 1].id] ?? 64 : 0
|
|
130
|
-
const stackHeight = expanded ? offset : frontHeight + Math.min(live.length - 1, visible - 1) * PEEK
|
|
98
|
+
const { layout, frontHeight, height } = toastLayout(items, heights, expanded, visible)
|
|
131
99
|
|
|
132
100
|
return (
|
|
133
101
|
<ToastCtx.Provider value={api}>
|
|
@@ -139,7 +107,7 @@ export function ToastProvider({ children, visible = 3, label = 'Notifications',
|
|
|
139
107
|
// Toasts are not part of an open dialog, but tapping one should not close it.
|
|
140
108
|
data-gooee-layer-ignore=""
|
|
141
109
|
aria-label={label}
|
|
142
|
-
style={{ height
|
|
110
|
+
style={{ height, ['--front-h' as string]: `${frontHeight}px` }}
|
|
143
111
|
onPointerEnter={(e) => e.pointerType === 'mouse' && setExpanded(true)}
|
|
144
112
|
onPointerLeave={(e) => e.pointerType === 'mouse' && setExpanded(false)}
|
|
145
113
|
onFocus={() => setExpanded(true)}
|
|
@@ -184,186 +152,36 @@ const icons: Record<ToastVariant, ReactNode> = {
|
|
|
184
152
|
loading: <Spinner size="sm" label={null} />,
|
|
185
153
|
}
|
|
186
154
|
|
|
187
|
-
const onScreen = (r: DOMRect) => r.width > 0 && r.bottom > 0 && r.right > 0 && r.top < window.innerHeight && r.left < window.innerWidth
|
|
188
|
-
const gapBetween = (a: DOMRect, b: DOMRect) => Math.hypot(Math.max(0, a.left - b.right, b.left - a.right), Math.max(0, a.top - b.bottom, b.top - a.bottom))
|
|
189
|
-
// An origin further than this from the toast would send the drop across the screen.
|
|
190
|
-
const NEAR = 240
|
|
191
|
-
|
|
192
|
-
/**
|
|
193
|
-
* Bud: a drop buds out of `origin`, hangs on a neck that breaks, and grows into the toast (`way` in),
|
|
194
|
-
* or the toast flows back into it (out). With no origin, or one far away, the drop buds out of the
|
|
195
|
-
* window's edge nearest the stack, under the toast. An SVG over the page draws it; the toast itself
|
|
196
|
-
* shows only at the end. Returns a stop, or null when motion is reduced.
|
|
197
|
-
*/
|
|
198
|
-
function bud(toast: HTMLElement, origin: ToastOptions['origin'], way: 'in' | 'out') {
|
|
199
|
-
const ms = motionFor(way === 'in' ? 'morph' : 'morph-out')
|
|
200
|
-
if (!ms) return null
|
|
201
|
-
const t = toast.getBoundingClientRect()
|
|
202
|
-
const look = getComputedStyle(toast)
|
|
203
|
-
const line = parseFloat(look.borderTopWidth) || 0
|
|
204
|
-
const T: Box = { cx: t.left + t.width / 2, cy: t.top + t.height / 2, hw: t.width / 2, hh: t.height / 2, r: Math.min(t.height / 2, parseFloat(look.borderTopLeftRadius) || 0) }
|
|
205
|
-
let O: Box | null = null
|
|
206
|
-
let exit: Pt = [0, 0]
|
|
207
|
-
let n: Pt = [0, 1]
|
|
208
|
-
let rd = BEND + 3.5
|
|
209
|
-
let cut = false
|
|
210
|
-
const o = origin instanceof HTMLElement ? (origin.isConnected ? origin.getBoundingClientRect() : null) : origin ? new DOMRect(origin.x, origin.y, 1, 1) : null
|
|
211
|
-
const near = !!o && onScreen(o) && gapBetween(o, t) <= NEAR
|
|
212
|
-
if (near && origin instanceof HTMLElement) {
|
|
213
|
-
const h = Math.min(o.width, o.height) / 2
|
|
214
|
-
O = { cx: o.left + o.width / 2, cy: o.top + o.height / 2, hw: o.width / 2, hh: o.height / 2, r: Math.min(h, parseFloat(getComputedStyle(origin).borderTopLeftRadius) || 0) }
|
|
215
|
-
rd = Math.min(rd, Math.max(BEND + 0.5, h * 0.6))
|
|
216
|
-
;({ at: exit, n } = exitToward(O, T, rd))
|
|
217
|
-
cut = true
|
|
218
|
-
} else if (near && origin && !(origin instanceof HTMLElement)) exit = [origin.x, origin.y]
|
|
219
|
-
// Too close to hang a drop between them, or no origin to use: it buds out of the window's edge. The
|
|
220
|
-
// edge is a body just past the screen, its top a stroke's width out, so only the drop and its neck show.
|
|
221
|
-
if (!near || sdBox(exit[0], exit[1], T) < rd * 4) {
|
|
222
|
-
const down = T.cy > window.innerHeight / 2 ? 1 : -1
|
|
223
|
-
rd = BEND + 3.5
|
|
224
|
-
const y = down > 0 ? window.innerHeight + line : -line
|
|
225
|
-
O = { cx: T.cx, cy: y + down * rd * 2, hw: rd * 6, hh: rd * 2, r: rd * 2 }
|
|
226
|
-
exit = [T.cx, y]
|
|
227
|
-
n = [0, -down]
|
|
228
|
-
cut = false
|
|
229
|
-
}
|
|
230
|
-
const { svg, paths } = layer(document.body, styles.bud, null)
|
|
231
|
-
const path = paths[0]
|
|
232
|
-
// The toast's own fill, edge and shadow. The edge is drawn on the outline, so the outline sits half
|
|
233
|
-
// its width inside the toast's box, and the last frame lands on the box exactly.
|
|
234
|
-
path.style.fill = look.backgroundColor
|
|
235
|
-
path.style.stroke = look.borderTopColor
|
|
236
|
-
path.style.strokeWidth = `${line}px`
|
|
237
|
-
castShadow(svg, shadowOf(toast).shadows)
|
|
238
|
-
const inset = line / 2
|
|
239
|
-
const T2: Box = { cx: T.cx, cy: T.cy, hw: T.hw - inset, hh: T.hh - inset, r: Math.max(0, T.r - inset) }
|
|
240
|
-
// The origin keeps its own look: the drawing is cut out where it is.
|
|
241
|
-
if (O && cut) {
|
|
242
|
-
const ns = 'http://www.w3.org/2000/svg'
|
|
243
|
-
const clip = svg.appendChild(document.createElementNS(ns, 'clipPath'))
|
|
244
|
-
const id = `gooee-bud-${Math.random().toString(36).slice(2)}`
|
|
245
|
-
clip.id = id
|
|
246
|
-
const hole = clip.appendChild(document.createElementNS(ns, 'path'))
|
|
247
|
-
const r = Math.min(O.r + 1, O.hh + 1)
|
|
248
|
-
hole.setAttribute('clip-rule', 'evenodd')
|
|
249
|
-
hole.setAttribute(
|
|
250
|
-
'd',
|
|
251
|
-
`M-1 -1H${window.innerWidth + 1}V${window.innerHeight + 1}H-1Z` +
|
|
252
|
-
`M${O.cx - O.hw - 1 + r} ${O.cy - O.hh - 1}H${O.cx + O.hw + 1 - r}A${r} ${r} 0 0 1 ${O.cx + O.hw + 1} ${O.cy - O.hh - 1 + r}V${O.cy + O.hh + 1 - r}A${r} ${r} 0 0 1 ${O.cx + O.hw + 1 - r} ${O.cy + O.hh + 1}H${O.cx - O.hw - 1 + r}A${r} ${r} 0 0 1 ${O.cx - O.hw - 1} ${O.cy + O.hh + 1 - r}V${O.cy - O.hh - 1 + r}A${r} ${r} 0 0 1 ${O.cx - O.hw - 1 + r} ${O.cy - O.hh - 1}Z`,
|
|
253
|
-
)
|
|
254
|
-
path.setAttribute('clip-path', `url(#${id})`)
|
|
255
|
-
}
|
|
256
|
-
const e = morphEase()
|
|
257
|
-
const recoil = motionFor('fast')
|
|
258
|
-
const pin = pincher(e, recoil)
|
|
259
|
-
const across: [number, number] = [n[1], n[0]]
|
|
260
|
-
const anchor: Pt = O ? (n[0] === 0 ? [exit[0], O.cy] : [O.cx, exit[1]]) : exit
|
|
261
|
-
// Once the drop is free it is never joined again, even where the toast sits close to the edge: going
|
|
262
|
-
// in, after the broken neck has sprung back; going out, until the drop hangs again.
|
|
263
|
-
let broke = 0
|
|
264
|
-
// The toast shows once the drop has its shape: at the end going in, at the start going out.
|
|
265
|
-
const show = toast.animate({ opacity: way === 'in' ? [0, 0, 1] : [1, 0, 0], offset: way === 'in' ? [0, 0.82, 1] : [0, 0.15, 1] }, { duration: ms, fill: 'forwards' })
|
|
266
|
-
const stop = frames(
|
|
267
|
-
ms,
|
|
268
|
-
(k, now) => {
|
|
269
|
-
const u = way === 'in' ? k : 1 - k
|
|
270
|
-
const D = budScene(e, u, O, T2, exit, n, rd)
|
|
271
|
-
let sdf = body(D).sdf
|
|
272
|
-
if (O) {
|
|
273
|
-
const free = way === 'in' ? (broke && now - broke >= recoil) || u >= 0.6 : u >= 0.4
|
|
274
|
-
if (free) {
|
|
275
|
-
const a = body(O).sdf
|
|
276
|
-
const b = sdf
|
|
277
|
-
sdf = (x, y) => Math.min(a(x, y), b(x, y))
|
|
278
|
-
} else {
|
|
279
|
-
const p = pin(body(O, anchor), body(D), now)
|
|
280
|
-
if (p.pieces === 2 && !broke) broke = now
|
|
281
|
-
sdf = p.sdf
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
const seeds: Array<[number, number, number, number]> = [[D.cx, D.cy, ...across]]
|
|
285
|
-
if (O) seeds.unshift([anchor[0], anchor[1], ...across])
|
|
286
|
-
path.setAttribute('d', loopsPath(trace(sdf, seeds)))
|
|
287
|
-
// A drop from a point fades in where it starts.
|
|
288
|
-
if (!O) svg.style.opacity = String(Math.min(1, u / 0.1))
|
|
289
|
-
},
|
|
290
|
-
() => {
|
|
291
|
-
svg.remove()
|
|
292
|
-
if (way === 'in') show.cancel()
|
|
293
|
-
},
|
|
294
|
-
)
|
|
295
|
-
return () => {
|
|
296
|
-
stop()
|
|
297
|
-
svg.remove()
|
|
298
|
-
show.cancel()
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
|
|
302
155
|
function ToastItem({ item, index, y, expanded, hidden, onHeight, onDismiss, dismissLabel }: ItemProps) {
|
|
303
156
|
const ref = useRef<HTMLLIElement>(null)
|
|
304
|
-
const swipe = useRef<{ x: number; dx: number; speed: ReturnType<typeof speedTracker> } | null>(null)
|
|
305
157
|
const [dragging, setDragging] = useState(false)
|
|
306
158
|
const [hover, setHover] = useState(false)
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
el?.setAttribute('data-fluid', '')
|
|
319
|
-
stop.current = release(at.current, to, speed, paint, () => {
|
|
320
|
-
if (to === 0) el?.removeAttribute('data-fluid')
|
|
321
|
-
})
|
|
322
|
-
}
|
|
159
|
+
const latest = useRef({ item, onDismiss })
|
|
160
|
+
latest.current = { item, onDismiss }
|
|
161
|
+
// Thrown sideways, it flies off at the speed of the swipe (motion/toast.ts).
|
|
162
|
+
const swipeRef = useRef<ReturnType<typeof createToastSwipe>>(null)
|
|
163
|
+
swipeRef.current ??= createToastSwipe(() => ref.current, {
|
|
164
|
+
leaving: () => latest.current.item.leaving !== false,
|
|
165
|
+
dragging: setDragging,
|
|
166
|
+
dismiss: (way) => latest.current.onDismiss(way),
|
|
167
|
+
})
|
|
168
|
+
const swipe = swipeRef.current
|
|
169
|
+
useEffect(() => () => swipe.stop(), [swipe])
|
|
323
170
|
|
|
324
|
-
// A drop buds out of the origin, or out of the window's edge, and grows into the toast; a dismiss
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
const budding = useRef<false | 'in' | 'out'>(false)
|
|
329
|
-
const stopBud = useRef<(() => void) | null>(null)
|
|
330
|
-
const front = useRef(false)
|
|
171
|
+
// A drop buds out of the origin, or out of the window's edge, and grows into the toast; a dismiss flows back the same way.
|
|
172
|
+
const budRef = useRef<ReturnType<typeof createToastBud>>(null)
|
|
173
|
+
budRef.current ??= createToastBud(() => ref.current, () => latest.current.item.origin, styles.bud)
|
|
174
|
+
const budding = budRef.current
|
|
331
175
|
useLayoutEffect(() => {
|
|
332
|
-
if (!item.leaving)
|
|
176
|
+
if (!item.leaving) budding.place(index)
|
|
333
177
|
})
|
|
334
|
-
useLayoutEffect(() =>
|
|
335
|
-
|
|
336
|
-
if (!el) return
|
|
337
|
-
const thrown = item.leaving && item.leaving !== 'down'
|
|
338
|
-
if (thrown || (item.leaving && !front.current)) {
|
|
339
|
-
if (budding.current === 'in') stopBud.current?.()
|
|
340
|
-
budding.current = false
|
|
341
|
-
if (!thrown) delete el.dataset.liquid
|
|
342
|
-
return
|
|
343
|
-
}
|
|
344
|
-
stopBud.current?.()
|
|
345
|
-
const way = item.leaving ? 'out' : 'in'
|
|
346
|
-
// The bud stands in for the part's CSS entry and exit; marked first, so the toast is measured in its place.
|
|
347
|
-
el.dataset.liquid = ''
|
|
348
|
-
stopBud.current = bud(el, item.origin, way)
|
|
349
|
-
budding.current = stopBud.current ? way : false
|
|
350
|
-
}, [item.leaving])
|
|
351
|
-
useEffect(
|
|
352
|
-
() => () => {
|
|
353
|
-
if (budding.current === 'in') stopBud.current?.()
|
|
354
|
-
},
|
|
355
|
-
[],
|
|
356
|
-
)
|
|
178
|
+
useLayoutEffect(() => budding.change(item.leaving), [item.leaving])
|
|
179
|
+
useEffect(() => () => budding.destroy(), [budding])
|
|
357
180
|
|
|
358
181
|
useLayoutEffect(() => {
|
|
359
182
|
const el = ref.current
|
|
360
183
|
if (!el) return
|
|
361
|
-
|
|
362
|
-
const measure = () => onHeight(el.scrollHeight + el.offsetHeight - el.clientHeight)
|
|
363
|
-
const ro = new ResizeObserver(measure)
|
|
364
|
-
ro.observe(el)
|
|
365
|
-
measure()
|
|
366
|
-
return () => ro.disconnect()
|
|
184
|
+
return watchToastHeight(el, onHeight)
|
|
367
185
|
}, [])
|
|
368
186
|
|
|
369
187
|
const paused = expanded || hover || dragging || item.leaving !== false
|
|
@@ -373,58 +191,10 @@ function ToastItem({ item, index, y, expanded, hidden, onHeight, onDismiss, dism
|
|
|
373
191
|
}, [item.duration, item.variant])
|
|
374
192
|
useEffect(() => {
|
|
375
193
|
if (paused || !Number.isFinite(remaining.current) || item.variant === 'loading') return
|
|
376
|
-
|
|
377
|
-
let t = window.setTimeout(() => onDismiss('down'), remaining.current)
|
|
378
|
-
const onVis = () => {
|
|
379
|
-
if (document.hidden) {
|
|
380
|
-
window.clearTimeout(t)
|
|
381
|
-
remaining.current -= performance.now() - start
|
|
382
|
-
} else {
|
|
383
|
-
start = performance.now()
|
|
384
|
-
t = window.setTimeout(() => onDismiss('down'), remaining.current)
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
document.addEventListener('visibilitychange', onVis)
|
|
388
|
-
return () => {
|
|
389
|
-
window.clearTimeout(t)
|
|
390
|
-
if (!document.hidden) remaining.current -= performance.now() - start
|
|
391
|
-
document.removeEventListener('visibilitychange', onVis)
|
|
392
|
-
}
|
|
194
|
+
return toastTimer(remaining, () => onDismiss('down'))
|
|
393
195
|
}, [paused, item.variant, item.duration])
|
|
394
196
|
|
|
395
|
-
const
|
|
396
|
-
if ((e.target as HTMLElement).closest('button') || item.leaving) return
|
|
397
|
-
stop.current()
|
|
398
|
-
// Caught mid-glide, it carries on from where it is.
|
|
399
|
-
swipe.current = { x: e.clientX - at.current, dx: at.current, speed: speedTracker() }
|
|
400
|
-
swipe.current.speed.add(at.current)
|
|
401
|
-
e.currentTarget.setPointerCapture(e.pointerId)
|
|
402
|
-
setDragging(true)
|
|
403
|
-
}
|
|
404
|
-
const onPointerMove = (e: PointerEvent<HTMLLIElement>) => {
|
|
405
|
-
const s = swipe.current
|
|
406
|
-
if (!s) return
|
|
407
|
-
s.dx = e.clientX - s.x
|
|
408
|
-
s.speed.add(s.dx)
|
|
409
|
-
paint(s.dx)
|
|
410
|
-
}
|
|
411
|
-
const onPointerUp = (e: PointerEvent<HTMLLIElement>) => {
|
|
412
|
-
const s = swipe.current
|
|
413
|
-
swipe.current = null
|
|
414
|
-
setDragging(false)
|
|
415
|
-
if (!s) return
|
|
416
|
-
const speed = e.type === 'pointercancel' ? 0 : s.speed.speed()
|
|
417
|
-
const thrown = Math.abs(speed) > THROW_SPEED && Math.abs(s.dx) > 20
|
|
418
|
-
if (e.type !== 'pointercancel' && (Math.abs(s.dx) > 80 || thrown)) {
|
|
419
|
-
// It leaves the way it was thrown, or the way it was pulled when let go slowly.
|
|
420
|
-
const way = Math.sign(thrown ? speed : s.dx)
|
|
421
|
-
fling(way * (ref.current?.offsetWidth ?? 0) * 1.1, speed)
|
|
422
|
-
onDismiss(way < 0 ? 'left' : 'right')
|
|
423
|
-
} else fling(0, speed)
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
const stackedY = expanded ? -y : -Math.min(index, 3) * PEEK
|
|
427
|
-
const scale = expanded ? 1 : 1 - Math.min(index, 3) * 0.05
|
|
197
|
+
const { y: stackedY, scale } = toastStack(index, y, expanded)
|
|
428
198
|
|
|
429
199
|
return (
|
|
430
200
|
<li
|
|
@@ -443,10 +213,10 @@ function ToastItem({ item, index, y, expanded, hidden, onHeight, onDismiss, dism
|
|
|
443
213
|
inert={hidden || undefined}
|
|
444
214
|
onPointerEnter={() => setHover(true)}
|
|
445
215
|
onPointerLeave={() => setHover(false)}
|
|
446
|
-
onPointerDown={
|
|
447
|
-
onPointerMove={
|
|
448
|
-
onPointerUp={
|
|
449
|
-
onPointerCancel={
|
|
216
|
+
onPointerDown={swipe.down}
|
|
217
|
+
onPointerMove={swipe.move}
|
|
218
|
+
onPointerUp={swipe.up}
|
|
219
|
+
onPointerCancel={swipe.up}
|
|
450
220
|
>
|
|
451
221
|
{icons[item.variant ?? 'default'] && <span className={styles.icon} data-variant={item.variant}>{icons[item.variant ?? 'default']}</span>}
|
|
452
222
|
<div className={styles.text}>
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { inject, type InjectionKey } from 'vue'
|
|
3
|
+
import type { ToastLeaving, ToastOrigin, ToastVariant } from '../../internal/motion/toast'
|
|
4
|
+
|
|
5
|
+
export type { ToastVariant }
|
|
6
|
+
|
|
7
|
+
export type ToastOptions = {
|
|
8
|
+
title: string
|
|
9
|
+
description?: string
|
|
10
|
+
variant?: ToastVariant
|
|
11
|
+
/** Milliseconds before it leaves. Infinity keeps it until dismissed. */
|
|
12
|
+
duration?: number
|
|
13
|
+
action?: { label: string; onClick: () => void }
|
|
14
|
+
/** Where the action happened: the element pressed, or a point on screen. Within 240px of the toast, the drop buds out of it and a dismiss flows back into it. Further away, or without it, the drop buds out of the window's edge. */
|
|
15
|
+
origin?: ToastOrigin
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export type ToastItemData = ToastOptions & { id: number; leaving: ToastLeaving }
|
|
19
|
+
|
|
20
|
+
export type ToastApi = {
|
|
21
|
+
toast: (opts: ToastOptions) => number
|
|
22
|
+
update: (id: number, opts: Partial<ToastOptions>) => void
|
|
23
|
+
dismiss: (id: number) => void
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** Lets a second Vue app on the page send toasts through one provider: provide(toastKey, useToast()). */
|
|
27
|
+
export const toastKey: InjectionKey<ToastApi> = Symbol('gooee-toast')
|
|
28
|
+
|
|
29
|
+
/** Sends toasts from anywhere inside a ToastProvider (this file's default export). */
|
|
30
|
+
export function useToast(): ToastApi {
|
|
31
|
+
const c = inject(toastKey, null)
|
|
32
|
+
if (!c) throw new Error('useToast needs a <ToastProvider> above it')
|
|
33
|
+
return c
|
|
34
|
+
}
|
|
35
|
+
</script>
|
|
36
|
+
|
|
37
|
+
<script setup lang="ts">
|
|
38
|
+
import { computed, onBeforeUnmount, provide, ref, shallowRef } from 'vue'
|
|
39
|
+
import { motionMs } from '../../internal/motion'
|
|
40
|
+
import { toastId, toastLayout, toastSay } from '../../internal/motion/toast'
|
|
41
|
+
import ToastItem from './ToastItem.vue'
|
|
42
|
+
import styles from './Toast.module.css'
|
|
43
|
+
|
|
44
|
+
// The Vue ToastProvider: the same look (Toast.module.css), stack, bud and throw as the React one.
|
|
45
|
+
// Wrap your app in it; anything inside can call useToast().
|
|
46
|
+
|
|
47
|
+
const props = withDefaults(
|
|
48
|
+
defineProps<{
|
|
49
|
+
/** How many toasts stay visible in the stack. */
|
|
50
|
+
visible?: number
|
|
51
|
+
/** Name of the notification region for screen readers. */
|
|
52
|
+
label?: string
|
|
53
|
+
/** Screen reader name for each close button. The toast title is added after it. */
|
|
54
|
+
dismissLabel?: string
|
|
55
|
+
}>(),
|
|
56
|
+
{ visible: 3, label: 'Notifications', dismissLabel: 'Dismiss' },
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
const items = shallowRef<ToastItemData[]>([])
|
|
60
|
+
const heights = shallowRef<Record<number, number>>({})
|
|
61
|
+
const expanded = ref(false)
|
|
62
|
+
const announce = ref('')
|
|
63
|
+
const urgent = ref('')
|
|
64
|
+
const timers = new Set<number>()
|
|
65
|
+
onBeforeUnmount(() => timers.forEach((t) => window.clearTimeout(t)))
|
|
66
|
+
|
|
67
|
+
const say = (opts: Partial<ToastOptions>, variant?: ToastVariant) => {
|
|
68
|
+
if (variant === 'error') urgent.value = toastSay(urgent.value, opts)
|
|
69
|
+
else announce.value = toastSay(announce.value, opts)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const remove = (id: number, dir: ToastLeaving = 'down') => {
|
|
73
|
+
items.value = items.value.map((t) => (t.id === id && !t.leaving ? { ...t, leaving: dir } : t))
|
|
74
|
+
const timer = window.setTimeout(() => {
|
|
75
|
+
timers.delete(timer)
|
|
76
|
+
items.value = items.value.filter((t) => t.id !== id)
|
|
77
|
+
const { [id]: _, ...rest } = heights.value
|
|
78
|
+
heights.value = rest
|
|
79
|
+
}, motionMs('morph-out'))
|
|
80
|
+
timers.add(timer)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
provide(toastKey, {
|
|
84
|
+
toast: (opts) => {
|
|
85
|
+
const id = toastId()
|
|
86
|
+
items.value = [...items.value, { duration: 5000, variant: 'default', ...opts, id, leaving: false }]
|
|
87
|
+
say(opts, opts.variant)
|
|
88
|
+
return id
|
|
89
|
+
},
|
|
90
|
+
update: (id, opts) => {
|
|
91
|
+
const variant = items.value.find((t) => t.id === id)?.variant
|
|
92
|
+
items.value = items.value.map((t) => (t.id === id ? { ...t, ...opts } : t))
|
|
93
|
+
if (opts.title) say(opts, opts.variant ?? variant)
|
|
94
|
+
},
|
|
95
|
+
dismiss: (id) => remove(id),
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
const stack = computed(() => toastLayout(items.value, heights.value, expanded.value, props.visible))
|
|
99
|
+
const setHeight = (id: number, h: number) => {
|
|
100
|
+
if (heights.value[id] !== h) heights.value = { ...heights.value, [id]: h }
|
|
101
|
+
}
|
|
102
|
+
const onFocusOut = (e: FocusEvent) => !(e.currentTarget as HTMLElement).contains(e.relatedTarget as Node | null) && (expanded.value = false)
|
|
103
|
+
</script>
|
|
104
|
+
|
|
105
|
+
<template>
|
|
106
|
+
<slot />
|
|
107
|
+
<!-- In the body, so a parent's stacking or overflow never hides the stack. -->
|
|
108
|
+
<Teleport to="body">
|
|
109
|
+
<div :class="styles.srOnly" role="status" aria-live="polite" aria-atomic="true">{{ announce }}</div>
|
|
110
|
+
<div :class="styles.srOnly" role="alert" aria-atomic="true">{{ urgent }}</div>
|
|
111
|
+
<!-- Toasts are not part of an open dialog, but tapping one should not close it. -->
|
|
112
|
+
<section
|
|
113
|
+
:class="styles.viewport"
|
|
114
|
+
data-gooee-layer-ignore=""
|
|
115
|
+
:aria-label="label"
|
|
116
|
+
:style="{ height: `${stack.height}px`, '--front-h': `${stack.frontHeight}px` }"
|
|
117
|
+
@pointerenter="(e: PointerEvent) => e.pointerType === 'mouse' && (expanded = true)"
|
|
118
|
+
@pointerleave="(e: PointerEvent) => e.pointerType === 'mouse' && (expanded = false)"
|
|
119
|
+
@focusin="expanded = true"
|
|
120
|
+
@focusout="onFocusOut"
|
|
121
|
+
>
|
|
122
|
+
<ol :class="styles.list">
|
|
123
|
+
<ToastItem
|
|
124
|
+
v-for="{ t, index, y } in stack.layout"
|
|
125
|
+
:key="t.id"
|
|
126
|
+
:item="t"
|
|
127
|
+
:index="index"
|
|
128
|
+
:y="y"
|
|
129
|
+
:expanded="expanded"
|
|
130
|
+
:hidden="index >= props.visible"
|
|
131
|
+
:dismiss-label="dismissLabel"
|
|
132
|
+
@height="(h: number) => setHeight(t.id, h)"
|
|
133
|
+
@dismiss="(dir: ToastLeaving) => remove(t.id, dir)"
|
|
134
|
+
/>
|
|
135
|
+
</ol>
|
|
136
|
+
</section>
|
|
137
|
+
</Teleport>
|
|
138
|
+
</template>
|