gooee 0.52.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -3
- package/package.json +6 -2
- package/scripts/add.js +181 -42
- package/src/base.css +3 -1
- package/src/components/Accordion/Accordion.module.css +7 -5
- package/src/components/Accordion/Accordion.tsx +13 -11
- package/src/components/Accordion/Accordion.vue +16 -15
- package/src/components/Accordion/AccordionItem.vue +8 -7
- package/src/components/Alert/Alert.module.css +9 -7
- package/src/components/Alert/Alert.tsx +25 -16
- package/src/components/Alert/Alert.vue +31 -27
- package/src/components/AlertDialog/AlertDialog.module.css +2 -0
- package/src/components/AlertDialog/AlertDialog.tsx +8 -7
- package/src/components/AlertDialog/AlertDialog.vue +25 -23
- package/src/components/AnimatedNumber/AnimatedNumber.module.css +5 -3
- package/src/components/AnimatedNumber/AnimatedNumber.tsx +6 -6
- package/src/components/AnimatedNumber/AnimatedNumber.vue +5 -5
- package/src/components/AspectRatio/AspectRatio.module.css +2 -0
- package/src/components/AspectRatio/AspectRatio.tsx +3 -3
- package/src/components/AspectRatio/AspectRatio.vue +5 -8
- package/src/components/Avatar/Avatar.module.css +10 -8
- package/src/components/Avatar/Avatar.tsx +4 -3
- package/src/components/Avatar/Avatar.vue +17 -19
- package/src/components/Avatar/index.ts +0 -2
- package/src/components/AvatarGroup/AvatarGroup.module.css +11 -9
- package/src/components/AvatarGroup/AvatarGroup.tsx +4 -4
- package/src/components/AvatarGroup/AvatarGroup.vue +13 -16
- package/src/components/Badge/Badge.module.css +6 -4
- package/src/components/Badge/Badge.tsx +3 -3
- package/src/components/Badge/Badge.vue +15 -14
- package/src/components/Breadcrumb/Breadcrumb.module.css +5 -3
- package/src/components/Breadcrumb/Breadcrumb.tsx +20 -12
- package/src/components/Breadcrumb/Breadcrumb.vue +33 -25
- package/src/components/Button/Button.module.css +16 -14
- package/src/components/Button/Button.tsx +6 -4
- package/src/components/Button/Button.vue +42 -33
- package/src/components/ButtonGroup/ButtonGroup.module.css +2 -0
- package/src/components/ButtonGroup/ButtonGroup.tsx +1 -1
- package/src/components/ButtonGroup/ButtonGroup.vue +9 -12
- package/src/components/Card/Card.module.css +6 -4
- package/src/components/Card/Card.tsx +6 -6
- package/src/components/Card/Card.vue +18 -21
- package/src/components/Center/Center.module.css +2 -0
- package/src/components/Center/Center.tsx +1 -1
- package/src/components/Center/Center.vue +18 -15
- package/src/components/Checkbox/Checkbox.module.css +10 -8
- package/src/components/Checkbox/Checkbox.tsx +7 -5
- package/src/components/Checkbox/Checkbox.vue +29 -31
- package/src/components/CheckboxGroup/CheckboxGroup.module.css +3 -1
- package/src/components/CheckboxGroup/CheckboxGroup.tsx +4 -4
- package/src/components/CheckboxGroup/CheckboxGroup.vue +33 -30
- package/src/components/Cluster/Cluster.module.css +2 -0
- package/src/components/Cluster/Cluster.tsx +1 -1
- package/src/components/Cluster/Cluster.vue +21 -17
- package/src/components/CodeBlock/CodeBlock.module.css +12 -10
- package/src/components/CodeBlock/CodeBlock.tsx +18 -10
- package/src/components/CodeBlock/CodeBlock.vue +30 -27
- package/src/components/CodeBlock/highlight.ts +1 -1
- package/src/components/Collapsible/Collapsible.module.css +7 -5
- package/src/components/Collapsible/Collapsible.tsx +7 -6
- package/src/components/Collapsible/Collapsible.vue +30 -26
- package/src/components/Container/Container.module.css +2 -0
- package/src/components/Container/Container.tsx +1 -1
- package/src/components/Container/Container.vue +13 -12
- package/src/components/CopyButton/CopyButton.module.css +20 -18
- package/src/components/CopyButton/CopyButton.tsx +21 -14
- package/src/components/CopyButton/CopyButton.vue +41 -31
- package/src/components/Dial/Dial.module.css +26 -11
- package/src/components/Dial/Dial.tsx +18 -18
- package/src/components/Dial/Dial.vue +57 -60
- package/src/components/Dialog/Dialog.module.css +4 -2
- package/src/components/Dialog/Dialog.tsx +22 -13
- package/src/components/Dialog/Dialog.vue +34 -30
- package/src/components/Divider/Divider.module.css +5 -3
- package/src/components/Divider/Divider.tsx +6 -4
- package/src/components/Divider/Divider.vue +13 -16
- package/src/components/DropdownMenu/DropdownMenu.module.css +8 -6
- package/src/components/DropdownMenu/DropdownMenu.tsx +11 -8
- package/src/components/DropdownMenu/DropdownMenu.vue +24 -27
- package/src/components/EmptyState/EmptyState.module.css +6 -4
- package/src/components/EmptyState/EmptyState.tsx +6 -6
- package/src/components/EmptyState/EmptyState.vue +14 -17
- package/src/components/Fab/Fab.module.css +19 -17
- package/src/components/Fab/Fab.tsx +11 -9
- package/src/components/Fab/Fab.vue +29 -26
- package/src/components/Fieldset/Fieldset.module.css +2 -0
- package/src/components/Fieldset/Fieldset.tsx +4 -3
- package/src/components/Fieldset/Fieldset.vue +4 -4
- package/src/components/FormField/FormField.module.css +5 -3
- package/src/components/FormField/FormField.tsx +7 -7
- package/src/components/FormField/FormField.vue +4 -4
- package/src/components/Grid/Grid.module.css +2 -0
- package/src/components/Grid/Grid.tsx +1 -1
- package/src/components/Grid/Grid.vue +25 -22
- package/src/components/HoldToConfirm/HoldToConfirm.module.css +13 -11
- package/src/components/HoldToConfirm/HoldToConfirm.tsx +11 -9
- package/src/components/HoldToConfirm/HoldToConfirm.vue +37 -32
- package/src/components/IconButton/IconButton.module.css +7 -5
- package/src/components/IconButton/IconButton.tsx +2 -1
- package/src/components/IconButton/IconButton.vue +15 -14
- package/src/components/Input/Input.module.css +12 -10
- package/src/components/Input/Input.tsx +9 -7
- package/src/components/Input/Input.vue +45 -35
- package/src/components/InputGroup/InputGroup.module.css +8 -6
- package/src/components/InputGroup/InputGroup.tsx +5 -4
- package/src/components/InputGroup/InputGroup.vue +41 -36
- package/src/components/Kbd/Kbd.module.css +9 -7
- package/src/components/Kbd/Kbd.tsx +1 -1
- package/src/components/Kbd/Kbd.vue +1 -1
- package/src/components/Link/Link.module.css +4 -2
- package/src/components/Link/Link.tsx +4 -3
- package/src/components/Link/Link.vue +13 -16
- package/src/components/LivePill/LivePill.module.css +39 -37
- package/src/components/LivePill/LivePill.tsx +11 -10
- package/src/components/LivePill/LivePill.vue +38 -40
- package/src/components/Meter/Meter.module.css +5 -3
- package/src/components/Meter/Meter.tsx +9 -8
- package/src/components/Meter/Meter.vue +52 -43
- package/src/components/MorphButton/MorphButton.module.css +11 -9
- package/src/components/MorphButton/MorphButton.tsx +20 -10
- package/src/components/MorphButton/MorphButton.vue +29 -25
- package/src/components/NumberInput/NumberInput.module.css +7 -5
- package/src/components/NumberInput/NumberInput.tsx +11 -8
- package/src/components/NumberInput/NumberInput.vue +69 -57
- package/src/components/Pagination/Pagination.module.css +147 -5
- package/src/components/Pagination/Pagination.tsx +216 -41
- package/src/components/Pagination/Pagination.vue +201 -36
- package/src/components/Pagination/labels.ts +38 -0
- package/src/components/PasswordInput/PasswordInput.module.css +10 -8
- package/src/components/PasswordInput/PasswordInput.tsx +15 -7
- package/src/components/PasswordInput/PasswordInput.vue +20 -16
- package/src/components/PasswordInput/index.ts +1 -1
- package/src/components/PickerWheel/DateWheel.vue +20 -12
- package/src/components/PickerWheel/PickerWheel.module.css +15 -6
- package/src/components/PickerWheel/PickerWheel.tsx +70 -44
- package/src/components/PickerWheel/PickerWheel.vue +39 -38
- package/src/components/PickerWheel/TimeWheel.vue +23 -21
- package/src/components/PickerWheel/WheelColumn.vue +7 -5
- package/src/components/Popover/Popover.module.css +5 -3
- package/src/components/Popover/Popover.tsx +17 -8
- package/src/components/Popover/Popover.vue +26 -25
- package/src/components/ProgressBar/ProgressBar.module.css +4 -2
- package/src/components/ProgressBar/ProgressBar.tsx +6 -5
- package/src/components/ProgressBar/ProgressBar.vue +28 -25
- package/src/components/Prose/Prose.module.css +5 -3
- package/src/components/Prose/Prose.tsx +1 -1
- package/src/components/Prose/Prose.vue +5 -8
- package/src/components/Radio/Radio.module.css +10 -8
- package/src/components/Radio/Radio.tsx +10 -8
- package/src/components/Radio/Radio.vue +8 -8
- package/src/components/Radio/RadioGroup.vue +33 -35
- package/src/components/Radio/radioContext.ts +12 -0
- package/src/components/Retime/Retime.vue +25 -22
- package/src/components/RulerScrubber/RulerScrubber.module.css +11 -2
- package/src/components/RulerScrubber/RulerScrubber.tsx +19 -18
- package/src/components/RulerScrubber/RulerScrubber.vue +50 -54
- package/src/components/ScrollArea/ScrollArea.module.css +17 -15
- package/src/components/ScrollArea/ScrollArea.tsx +5 -4
- package/src/components/ScrollArea/ScrollArea.vue +15 -17
- package/src/components/SearchInput/SearchInput.module.css +6 -4
- package/src/components/SearchInput/SearchInput.tsx +15 -8
- package/src/components/SearchInput/SearchInput.vue +20 -17
- package/src/components/SearchInput/index.ts +1 -1
- package/src/components/SegmentedControl/SegmentedControl.module.css +7 -5
- package/src/components/SegmentedControl/SegmentedControl.tsx +9 -5
- package/src/components/SegmentedControl/SegmentedControl.vue +25 -29
- package/src/components/Select/Select.module.css +19 -17
- package/src/components/Select/Select.tsx +30 -17
- package/src/components/Select/Select.vue +62 -57
- package/src/components/Sheet/Sheet.module.css +6 -4
- package/src/components/Sheet/Sheet.tsx +39 -29
- package/src/components/Sheet/Sheet.vue +46 -40
- package/src/components/Skeleton/Skeleton.module.css +4 -2
- package/src/components/Skeleton/Skeleton.tsx +3 -2
- package/src/components/Skeleton/Skeleton.vue +16 -18
- package/src/components/Slider/Slider.module.css +14 -12
- package/src/components/Slider/Slider.tsx +20 -9
- package/src/components/Slider/Slider.vue +47 -37
- package/src/components/Spinner/Spinner.module.css +2 -0
- package/src/components/Spinner/Spinner.tsx +3 -3
- package/src/components/Spinner/Spinner.vue +9 -12
- package/src/components/Split/Split.module.css +2 -0
- package/src/components/Split/Split.tsx +3 -3
- package/src/components/Split/Split.vue +19 -17
- package/src/components/SplitFlap/SplitFlap.module.css +9 -7
- package/src/components/SplitFlap/SplitFlap.tsx +2 -2
- package/src/components/SplitFlap/SplitFlap.vue +24 -21
- package/src/components/Stack/Stack.module.css +2 -0
- package/src/components/Stack/Stack.tsx +1 -1
- package/src/components/Stack/Stack.vue +13 -12
- package/src/components/SwipeDeck/SwipeDeck.module.css +13 -11
- package/src/components/SwipeDeck/SwipeDeck.tsx +23 -28
- package/src/components/SwipeDeck/SwipeDeck.vue +32 -38
- package/src/components/Switch/Switch.module.css +10 -8
- package/src/components/Switch/Switch.tsx +6 -5
- package/src/components/Switch/Switch.vue +22 -24
- package/src/components/Table/Table.module.css +24 -22
- package/src/components/Table/Table.tsx +27 -30
- package/src/components/Table/Table.vue +93 -79
- package/src/components/TableOfContents/TableOfContents.module.css +9 -7
- package/src/components/TableOfContents/TableOfContents.tsx +8 -8
- package/src/components/TableOfContents/TableOfContents.vue +20 -23
- package/src/components/Tabs/Tab.vue +3 -0
- package/src/components/Tabs/TabList.vue +2 -2
- package/src/components/Tabs/TabPanel.vue +2 -0
- package/src/components/Tabs/Tabs.module.css +4 -2
- package/src/components/Tabs/Tabs.tsx +10 -5
- package/src/components/Tabs/Tabs.vue +1 -1
- package/src/components/Tag/Tag.module.css +12 -10
- package/src/components/Tag/Tag.tsx +13 -15
- package/src/components/Tag/Tag.vue +12 -14
- package/src/components/Textarea/Textarea.module.css +8 -6
- package/src/components/Textarea/Textarea.tsx +4 -3
- package/src/components/Textarea/Textarea.vue +32 -34
- package/src/components/ThemeToggle/ThemeToggle.module.css +2 -0
- package/src/components/ThemeToggle/ThemeToggle.tsx +7 -7
- package/src/components/ThemeToggle/ThemeToggle.vue +24 -22
- package/src/components/Toast/Toast.module.css +17 -15
- package/src/components/Toast/Toast.tsx +51 -34
- package/src/components/Toast/Toast.vue +35 -24
- package/src/components/Toast/ToastItem.vue +17 -16
- package/src/components/Toggle/Toggle.module.css +11 -9
- package/src/components/Toggle/Toggle.tsx +3 -2
- package/src/components/Toggle/Toggle.vue +13 -15
- package/src/components/Tooltip/Tooltip.module.css +5 -3
- package/src/components/Tooltip/Tooltip.tsx +1 -0
- package/src/components/Tooltip/Tooltip.vue +13 -18
- package/src/components/VisuallyHidden/VisuallyHidden.module.css +2 -0
- package/src/components/VisuallyHidden/VisuallyHidden.tsx +1 -1
- package/src/components/VisuallyHidden/VisuallyHidden.vue +5 -8
- package/src/{internal → icons}/icons.module.css +4 -2
- package/src/{internal → icons}/icons.tsx +15 -16
- package/src/internal/FieldMessage.module.css +5 -3
- package/src/internal/FieldMessage.tsx +2 -2
- package/src/internal/FieldMessage.vue +2 -2
- package/src/internal/Roll.module.css +5 -3
- package/src/internal/feel.ts +12 -10
- package/src/internal/fling.ts +3 -3
- package/src/internal/liquid.ts +12 -10
- package/src/internal/liquidMatter.ts +1 -1
- package/src/internal/liquidMore.ts +7 -7
- package/src/internal/motion/checkbox.ts +4 -4
- package/src/internal/motion/fling.ts +19 -9
- package/src/internal/motion/holdToConfirm.ts +3 -3
- package/src/internal/motion/index.ts +8 -6
- package/src/internal/motion/liquid.ts +16 -4
- package/src/internal/motion/liquidMatter.ts +8 -6
- package/src/internal/motion/liquidMore.ts +44 -25
- package/src/internal/motion/livePill.ts +1 -1
- package/src/internal/motion/numberInput.ts +2 -2
- package/src/internal/motion/pickerWheel.ts +7 -4
- package/src/internal/motion/ruler.ts +1 -1
- package/src/internal/motion/scrollArea.ts +3 -3
- package/src/internal/motion/scrollFrame.ts +9 -7
- package/src/internal/motion/scrubber.ts +39 -20
- package/src/internal/motion/slider.ts +38 -4
- package/src/internal/motion/softPress.ts +10 -9
- package/src/internal/motion/splitFlap.ts +4 -4
- package/src/internal/motion/swipeDeck.ts +38 -7
- package/src/internal/motion/table.ts +3 -6
- package/src/internal/motion/themeIcon.ts +1 -1
- package/src/internal/motion/themeReveal.ts +1 -1
- package/src/internal/motion/toast.ts +3 -3
- package/src/internal/motion.ts +7 -8
- package/src/internal/scrollFrame.ts +3 -3
- package/src/internal/useScrub.ts +1 -15
- package/src/internal/vue/useScrub.ts +2 -6
- package/src/tokens.css +81 -421
- package/src/{internal/vueIcons.ts → icons/vue.ts} +5 -5
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
|
|
3
3
|
import { createContext, useCallback, useContext, useEffect, useLayoutEffect, useMemo, useRef, useState, type ReactNode } from 'react'
|
|
4
|
-
import { CheckCircleIcon, ErrorIcon, InfoIcon, XIcon } from '../../
|
|
4
|
+
import { CheckCircleIcon, ErrorIcon, InfoIcon, XIcon } from '../../icons/icons'
|
|
5
5
|
import { motionMs } from '../../internal/motion'
|
|
6
|
-
import { createToastBud, createToastSwipe, toastId, toastLayout, toastSay, toastStack, toastTimer, watchToastHeight, type ToastLeaving, type ToastOrigin, type
|
|
6
|
+
import { createToastBud, createToastSwipe, toastId, toastLayout, toastSay, toastStack, toastTimer, watchToastHeight, type ToastLeaving, type ToastOrigin, type ToastTone } from '../../internal/motion/toast'
|
|
7
7
|
import { Spinner } from '../Spinner'
|
|
8
8
|
import styles from './Toast.module.css'
|
|
9
9
|
|
|
10
|
-
export type {
|
|
10
|
+
export type { ToastTone }
|
|
11
11
|
|
|
12
12
|
export type ToastOptions = {
|
|
13
13
|
title: string
|
|
14
14
|
description?: string
|
|
15
|
-
|
|
15
|
+
/** Sets the icon and colour. Danger is announced at once. */
|
|
16
|
+
tone?: ToastTone
|
|
17
|
+
/** Shows a spinner and keeps the toast until you update it with loading: false. */
|
|
18
|
+
loading?: boolean
|
|
16
19
|
/** Milliseconds before it leaves. Infinity keeps it until dismissed. */
|
|
17
20
|
duration?: number
|
|
18
21
|
action?: { label: string; onClick: () => void }
|
|
@@ -36,18 +39,26 @@ export function useToast(): Api {
|
|
|
36
39
|
return c
|
|
37
40
|
}
|
|
38
41
|
|
|
42
|
+
export type ToastLabels = {
|
|
43
|
+
/** Name of each close button. The toast title is added after it. */
|
|
44
|
+
dismiss: string
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const defaultLabels: ToastLabels = { dismiss: 'Dismiss' }
|
|
48
|
+
|
|
39
49
|
export type ToastProviderProps = {
|
|
40
50
|
/** Your app. Anything inside can call useToast. */
|
|
41
51
|
children: ReactNode
|
|
42
|
-
/**
|
|
43
|
-
|
|
52
|
+
/** Most toasts shown in the stack at once. */
|
|
53
|
+
max?: number
|
|
44
54
|
/** Name of the notification region for screen readers. */
|
|
45
55
|
label?: string
|
|
46
|
-
/** Screen reader
|
|
47
|
-
|
|
56
|
+
/** Screen reader text, so you can translate it. Missing keys use the English defaults. */
|
|
57
|
+
labels?: Partial<ToastLabels>
|
|
48
58
|
}
|
|
49
59
|
|
|
50
|
-
export function ToastProvider({ children,
|
|
60
|
+
export function ToastProvider({ children, max = 3, label = 'Notifications', labels: labelsProp }: ToastProviderProps) {
|
|
61
|
+
const labels = { ...defaultLabels, ...labelsProp }
|
|
51
62
|
const [items, setItems] = useState<Item[]>([])
|
|
52
63
|
const [heights, setHeights] = useState<Record<number, number>>({})
|
|
53
64
|
const [expanded, setExpanded] = useState(false)
|
|
@@ -62,9 +73,9 @@ export function ToastProvider({ children, visible = 3, label = 'Notifications',
|
|
|
62
73
|
return () => pending.forEach((t) => window.clearTimeout(t))
|
|
63
74
|
}, [])
|
|
64
75
|
|
|
65
|
-
const say = (opts: Partial<ToastOptions>,
|
|
76
|
+
const say = (opts: Partial<ToastOptions>, tone?: ToastTone) => {
|
|
66
77
|
const fresh = (prev: string) => toastSay(prev, opts)
|
|
67
|
-
if (
|
|
78
|
+
if (tone === 'danger') setUrgent(fresh)
|
|
68
79
|
else setAnnounce(fresh)
|
|
69
80
|
}
|
|
70
81
|
|
|
@@ -82,28 +93,29 @@ export function ToastProvider({ children, visible = 3, label = 'Notifications',
|
|
|
82
93
|
() => ({
|
|
83
94
|
toast: (opts) => {
|
|
84
95
|
const id = toastId()
|
|
85
|
-
setItems((list) => [...list, { duration: 5000,
|
|
86
|
-
say(opts, opts.
|
|
96
|
+
setItems((list) => [...list, { duration: 5000, tone: 'neutral', ...opts, id, leaving: false }])
|
|
97
|
+
say(opts, opts.tone)
|
|
87
98
|
return id
|
|
88
99
|
},
|
|
89
100
|
update: (id, opts) => {
|
|
90
101
|
setItems((list) => list.map((t) => (t.id === id ? { ...t, ...opts } : t)))
|
|
91
|
-
if (opts.title) say(opts, opts.
|
|
102
|
+
if (opts.title) say(opts, opts.tone ?? itemsRef.current.find((t) => t.id === id)?.tone)
|
|
92
103
|
},
|
|
93
104
|
dismiss: (id) => remove(id),
|
|
94
105
|
}),
|
|
95
106
|
[remove],
|
|
96
107
|
)
|
|
97
108
|
|
|
98
|
-
const { layout, frontHeight, height } = toastLayout(items, heights, expanded,
|
|
109
|
+
const { layout, frontHeight, height } = toastLayout(items, heights, expanded, max)
|
|
99
110
|
|
|
100
111
|
return (
|
|
101
|
-
<ToastCtx
|
|
112
|
+
<ToastCtx value={api}>
|
|
102
113
|
{children}
|
|
103
114
|
<div className={styles.srOnly} role="status" aria-live="polite" aria-atomic="true">{announce}</div>
|
|
104
115
|
<div className={styles.srOnly} role="alert" aria-atomic="true">{urgent}</div>
|
|
105
116
|
<section
|
|
106
117
|
className={styles.viewport}
|
|
118
|
+
data-slot="toast-viewport"
|
|
107
119
|
// Toasts are not part of an open dialog, but tapping one should not close it.
|
|
108
120
|
data-gooee-layer-ignore=""
|
|
109
121
|
aria-label={label}
|
|
@@ -113,7 +125,7 @@ export function ToastProvider({ children, visible = 3, label = 'Notifications',
|
|
|
113
125
|
onFocus={() => setExpanded(true)}
|
|
114
126
|
onBlur={(e) => !e.currentTarget.contains(e.relatedTarget) && setExpanded(false)}
|
|
115
127
|
>
|
|
116
|
-
<ol className={styles.list}>
|
|
128
|
+
<ol className={styles.list} data-slot="toast-list">
|
|
117
129
|
{layout.map(({ t, index, y }) => (
|
|
118
130
|
<ToastItem
|
|
119
131
|
key={t.id}
|
|
@@ -121,15 +133,15 @@ export function ToastProvider({ children, visible = 3, label = 'Notifications',
|
|
|
121
133
|
index={index}
|
|
122
134
|
y={y}
|
|
123
135
|
expanded={expanded}
|
|
124
|
-
hidden={index >=
|
|
136
|
+
hidden={index >= max}
|
|
125
137
|
onHeight={(h) => setHeights((m) => (m[t.id] === h ? m : { ...m, [t.id]: h }))}
|
|
126
138
|
onDismiss={(dir) => remove(t.id, dir)}
|
|
127
|
-
|
|
139
|
+
labels={labels}
|
|
128
140
|
/>
|
|
129
141
|
))}
|
|
130
142
|
</ol>
|
|
131
143
|
</section>
|
|
132
|
-
</ToastCtx
|
|
144
|
+
</ToastCtx>
|
|
133
145
|
)
|
|
134
146
|
}
|
|
135
147
|
|
|
@@ -141,18 +153,17 @@ type ItemProps = {
|
|
|
141
153
|
hidden: boolean
|
|
142
154
|
onHeight: (h: number) => void
|
|
143
155
|
onDismiss: (dir: Item['leaving']) => void
|
|
144
|
-
|
|
156
|
+
labels: ToastLabels
|
|
145
157
|
}
|
|
146
158
|
|
|
147
|
-
const icons: Record<
|
|
148
|
-
|
|
159
|
+
const icons: Record<ToastTone, ReactNode> = {
|
|
160
|
+
neutral: null,
|
|
149
161
|
success: <CheckCircleIcon />,
|
|
150
|
-
|
|
162
|
+
danger: <ErrorIcon />,
|
|
151
163
|
info: <InfoIcon />,
|
|
152
|
-
loading: <Spinner size="sm" label={null} />,
|
|
153
164
|
}
|
|
154
165
|
|
|
155
|
-
function ToastItem({ item, index, y, expanded, hidden, onHeight, onDismiss,
|
|
166
|
+
function ToastItem({ item, index, y, expanded, hidden, onHeight, onDismiss, labels }: ItemProps) {
|
|
156
167
|
const ref = useRef<HTMLLIElement>(null)
|
|
157
168
|
const [dragging, setDragging] = useState(false)
|
|
158
169
|
const [hover, setHover] = useState(false)
|
|
@@ -188,11 +199,11 @@ function ToastItem({ item, index, y, expanded, hidden, onHeight, onDismiss, dism
|
|
|
188
199
|
const remaining = useRef(item.duration ?? 5000)
|
|
189
200
|
useEffect(() => {
|
|
190
201
|
remaining.current = item.duration ?? 5000
|
|
191
|
-
}, [item.duration, item.
|
|
202
|
+
}, [item.duration, item.tone, item.loading])
|
|
192
203
|
useEffect(() => {
|
|
193
|
-
if (paused || !Number.isFinite(remaining.current) || item.
|
|
204
|
+
if (paused || !Number.isFinite(remaining.current) || item.loading) return
|
|
194
205
|
return toastTimer(remaining, () => onDismiss('down'))
|
|
195
|
-
}, [paused, item.
|
|
206
|
+
}, [paused, item.tone, item.loading, item.duration])
|
|
196
207
|
|
|
197
208
|
const { y: stackedY, scale } = toastStack(index, y, expanded)
|
|
198
209
|
|
|
@@ -200,6 +211,7 @@ function ToastItem({ item, index, y, expanded, hidden, onHeight, onDismiss, dism
|
|
|
200
211
|
<li
|
|
201
212
|
ref={ref}
|
|
202
213
|
className={styles.toast}
|
|
214
|
+
data-slot="toast"
|
|
203
215
|
data-leaving={item.leaving || undefined}
|
|
204
216
|
data-dragging={dragging || undefined}
|
|
205
217
|
data-hidden={hidden || undefined}
|
|
@@ -218,15 +230,20 @@ function ToastItem({ item, index, y, expanded, hidden, onHeight, onDismiss, dism
|
|
|
218
230
|
onPointerUp={swipe.up}
|
|
219
231
|
onPointerCancel={swipe.up}
|
|
220
232
|
>
|
|
221
|
-
{
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
233
|
+
{(item.loading || icons[item.tone ?? 'neutral']) && (
|
|
234
|
+
<span className={styles.icon} data-slot="toast-icon" data-tone={item.loading ? undefined : item.tone}>
|
|
235
|
+
{item.loading ? <Spinner size="sm" label={null} /> : icons[item.tone ?? 'neutral']}
|
|
236
|
+
</span>
|
|
237
|
+
)}
|
|
238
|
+
<div className={styles.text} data-slot="toast-content">
|
|
239
|
+
<p className={styles.title} data-slot="toast-title">{item.title}</p>
|
|
240
|
+
{item.description && <p className={styles.description} data-slot="toast-description">{item.description}</p>}
|
|
225
241
|
</div>
|
|
226
242
|
{item.action && (
|
|
227
243
|
<button
|
|
228
244
|
type="button"
|
|
229
245
|
className={styles.action}
|
|
246
|
+
data-slot="toast-action"
|
|
230
247
|
onClick={() => {
|
|
231
248
|
item.action?.onClick()
|
|
232
249
|
onDismiss('down')
|
|
@@ -235,7 +252,7 @@ function ToastItem({ item, index, y, expanded, hidden, onHeight, onDismiss, dism
|
|
|
235
252
|
{item.action.label}
|
|
236
253
|
</button>
|
|
237
254
|
)}
|
|
238
|
-
<button type="button" className={styles.close} aria-label={`${
|
|
255
|
+
<button type="button" className={styles.close} data-slot="toast-close" aria-label={`${labels.dismiss}: ${item.title}`} onClick={() => onDismiss('down')}>
|
|
239
256
|
<XIcon />
|
|
240
257
|
</button>
|
|
241
258
|
</li>
|
|
@@ -1,13 +1,21 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import { inject, type InjectionKey } from 'vue'
|
|
3
|
-
import type { ToastLeaving, ToastOrigin,
|
|
3
|
+
import type { ToastLeaving, ToastOrigin, ToastTone } from '../../internal/motion/toast'
|
|
4
4
|
|
|
5
|
-
export type {
|
|
5
|
+
export type { ToastTone }
|
|
6
|
+
|
|
7
|
+
export type ToastLabels = {
|
|
8
|
+
/** Name of each close button. The toast title is added after it. */
|
|
9
|
+
dismiss: string
|
|
10
|
+
}
|
|
6
11
|
|
|
7
12
|
export type ToastOptions = {
|
|
8
13
|
title: string
|
|
9
14
|
description?: string
|
|
10
|
-
|
|
15
|
+
/** Sets the icon and colour. Danger is announced at once. */
|
|
16
|
+
tone?: ToastTone
|
|
17
|
+
/** Shows a spinner and keeps the toast until you update it with loading: false. */
|
|
18
|
+
loading?: boolean
|
|
11
19
|
/** Milliseconds before it leaves. Infinity keeps it until dismissed. */
|
|
12
20
|
duration?: number
|
|
13
21
|
action?: { label: string; onClick: () => void }
|
|
@@ -44,17 +52,19 @@ import styles from './Toast.module.css'
|
|
|
44
52
|
// The Vue ToastProvider: the same look (Toast.module.css), stack, bud and throw as the React one.
|
|
45
53
|
// Wrap your app in it; anything inside can call useToast().
|
|
46
54
|
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
55
|
+
const {
|
|
56
|
+
max = 3,
|
|
57
|
+
label = 'Notifications',
|
|
58
|
+
labels,
|
|
59
|
+
} = defineProps<{
|
|
60
|
+
/** Most toasts shown in the stack at once. */
|
|
61
|
+
max?: number
|
|
62
|
+
/** Name of the notification region for screen readers. */
|
|
63
|
+
label?: string
|
|
64
|
+
/** Screen reader text, so you can translate it. Missing keys use the English defaults. */
|
|
65
|
+
labels?: Partial<ToastLabels>
|
|
66
|
+
}>()
|
|
67
|
+
const text = computed(() => ({ dismiss: 'Dismiss', ...labels }))
|
|
58
68
|
|
|
59
69
|
const items = shallowRef<ToastItemData[]>([])
|
|
60
70
|
const heights = shallowRef<Record<number, number>>({})
|
|
@@ -64,8 +74,8 @@ const urgent = ref('')
|
|
|
64
74
|
const timers = new Set<number>()
|
|
65
75
|
onBeforeUnmount(() => timers.forEach((t) => window.clearTimeout(t)))
|
|
66
76
|
|
|
67
|
-
const say = (opts: Partial<ToastOptions>,
|
|
68
|
-
if (
|
|
77
|
+
const say = (opts: Partial<ToastOptions>, tone?: ToastTone) => {
|
|
78
|
+
if (tone === 'danger') urgent.value = toastSay(urgent.value, opts)
|
|
69
79
|
else announce.value = toastSay(announce.value, opts)
|
|
70
80
|
}
|
|
71
81
|
|
|
@@ -83,19 +93,19 @@ const remove = (id: number, dir: ToastLeaving = 'down') => {
|
|
|
83
93
|
provide(toastKey, {
|
|
84
94
|
toast: (opts) => {
|
|
85
95
|
const id = toastId()
|
|
86
|
-
items.value = [...items.value, { duration: 5000,
|
|
87
|
-
say(opts, opts.
|
|
96
|
+
items.value = [...items.value, { duration: 5000, tone: 'neutral', ...opts, id, leaving: false }]
|
|
97
|
+
say(opts, opts.tone)
|
|
88
98
|
return id
|
|
89
99
|
},
|
|
90
100
|
update: (id, opts) => {
|
|
91
|
-
const
|
|
101
|
+
const tone = items.value.find((t) => t.id === id)?.tone
|
|
92
102
|
items.value = items.value.map((t) => (t.id === id ? { ...t, ...opts } : t))
|
|
93
|
-
if (opts.title) say(opts, opts.
|
|
103
|
+
if (opts.title) say(opts, opts.tone ?? tone)
|
|
94
104
|
},
|
|
95
105
|
dismiss: (id) => remove(id),
|
|
96
106
|
})
|
|
97
107
|
|
|
98
|
-
const stack = computed(() => toastLayout(items.value, heights.value, expanded.value,
|
|
108
|
+
const stack = computed(() => toastLayout(items.value, heights.value, expanded.value, max))
|
|
99
109
|
const setHeight = (id: number, h: number) => {
|
|
100
110
|
if (heights.value[id] !== h) heights.value = { ...heights.value, [id]: h }
|
|
101
111
|
}
|
|
@@ -111,6 +121,7 @@ const onFocusOut = (e: FocusEvent) => !(e.currentTarget as HTMLElement).contains
|
|
|
111
121
|
<!-- Toasts are not part of an open dialog, but tapping one should not close it. -->
|
|
112
122
|
<section
|
|
113
123
|
:class="styles.viewport"
|
|
124
|
+
data-slot="toast-viewport"
|
|
114
125
|
data-gooee-layer-ignore=""
|
|
115
126
|
:aria-label="label"
|
|
116
127
|
:style="{ height: `${stack.height}px`, '--front-h': `${stack.frontHeight}px` }"
|
|
@@ -119,7 +130,7 @@ const onFocusOut = (e: FocusEvent) => !(e.currentTarget as HTMLElement).contains
|
|
|
119
130
|
@focusin="expanded = true"
|
|
120
131
|
@focusout="onFocusOut"
|
|
121
132
|
>
|
|
122
|
-
<ol :class="styles.list">
|
|
133
|
+
<ol :class="styles.list" data-slot="toast-list">
|
|
123
134
|
<ToastItem
|
|
124
135
|
v-for="{ t, index, y } in stack.layout"
|
|
125
136
|
:key="t.id"
|
|
@@ -127,8 +138,8 @@ const onFocusOut = (e: FocusEvent) => !(e.currentTarget as HTMLElement).contains
|
|
|
127
138
|
:index="index"
|
|
128
139
|
:y="y"
|
|
129
140
|
:expanded="expanded"
|
|
130
|
-
:hidden="index >=
|
|
131
|
-
:
|
|
141
|
+
:hidden="index >= max"
|
|
142
|
+
:labels="text"
|
|
132
143
|
@height="(h: number) => setHeight(t.id, h)"
|
|
133
144
|
@dismiss="(dir: ToastLeaving) => remove(t.id, dir)"
|
|
134
145
|
/>
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue'
|
|
3
3
|
import { createToastBud, createToastSwipe, toastStack, toastTimer, watchToastHeight, type ToastLeaving } from '../../internal/motion/toast'
|
|
4
|
-
import { CheckCircleIcon, ErrorIcon, InfoIcon, XIcon } from '../../
|
|
4
|
+
import { CheckCircleIcon, ErrorIcon, InfoIcon, XIcon } from '../../icons/vue'
|
|
5
5
|
import Spinner from '../Spinner/Spinner.vue'
|
|
6
|
-
import type { ToastItemData } from './Toast.vue'
|
|
6
|
+
import type { ToastItemData, ToastLabels } from './Toast.vue'
|
|
7
7
|
import styles from './Toast.module.css'
|
|
8
8
|
|
|
9
9
|
// One toast of the Vue ToastProvider (Toast.vue).
|
|
10
10
|
|
|
11
|
-
const props = defineProps<{ item: ToastItemData; index: number; y: number; expanded: boolean; hidden: boolean;
|
|
11
|
+
const props = defineProps<{ item: ToastItemData; index: number; y: number; expanded: boolean; hidden: boolean; labels: ToastLabels }>()
|
|
12
12
|
const emit = defineEmits<{ height: [h: number]; dismiss: [dir: ToastLeaving] }>()
|
|
13
13
|
|
|
14
14
|
const el = ref<HTMLElement | null>(null)
|
|
@@ -49,11 +49,11 @@ watch(
|
|
|
49
49
|
// It leaves on its own, but waits while hovered, focused, held or hidden.
|
|
50
50
|
const paused = computed(() => props.expanded || hover.value || dragging.value || props.item.leaving !== false)
|
|
51
51
|
const remaining = { current: props.item.duration ?? 5000 }
|
|
52
|
-
watch([() => props.item.duration, () => props.item.
|
|
52
|
+
watch([() => props.item.duration, () => props.item.tone, () => props.item.loading], () => (remaining.current = props.item.duration ?? 5000))
|
|
53
53
|
watch(
|
|
54
|
-
[paused, () => props.item.
|
|
54
|
+
[paused, () => props.item.tone, () => props.item.loading, () => props.item.duration],
|
|
55
55
|
(_, __, onCleanup) => {
|
|
56
|
-
if (paused.value || !Number.isFinite(remaining.current) || props.item.
|
|
56
|
+
if (paused.value || !Number.isFinite(remaining.current) || props.item.loading || typeof window === 'undefined') return
|
|
57
57
|
onCleanup(toastTimer(remaining, () => dismiss('down')))
|
|
58
58
|
},
|
|
59
59
|
{ immediate: true },
|
|
@@ -76,6 +76,7 @@ const onAction = () => {
|
|
|
76
76
|
<li
|
|
77
77
|
ref="el"
|
|
78
78
|
:class="styles.toast"
|
|
79
|
+
data-slot="toast"
|
|
79
80
|
:data-leaving="item.leaving || undefined"
|
|
80
81
|
:data-dragging="dragging || undefined"
|
|
81
82
|
:data-hidden="hidden || undefined"
|
|
@@ -90,18 +91,18 @@ const onAction = () => {
|
|
|
90
91
|
@pointerup="swipe.up"
|
|
91
92
|
@pointercancel="swipe.up"
|
|
92
93
|
>
|
|
93
|
-
<span v-if="item.
|
|
94
|
-
<
|
|
95
|
-
<
|
|
96
|
-
<
|
|
97
|
-
<
|
|
94
|
+
<span v-if="item.loading || (item.tone && item.tone !== 'neutral')" :class="styles.icon" data-slot="toast-icon" :data-tone="item.loading ? undefined : item.tone">
|
|
95
|
+
<Spinner v-if="item.loading" size="sm" :label="null" />
|
|
96
|
+
<CheckCircleIcon v-else-if="item.tone === 'success'" />
|
|
97
|
+
<ErrorIcon v-else-if="item.tone === 'danger'" />
|
|
98
|
+
<InfoIcon v-else />
|
|
98
99
|
</span>
|
|
99
|
-
<div :class="styles.text">
|
|
100
|
-
<p :class="styles.title">{{ item.title }}</p>
|
|
101
|
-
<p v-if="item.description" :class="styles.description">{{ item.description }}</p>
|
|
100
|
+
<div :class="styles.text" data-slot="toast-content">
|
|
101
|
+
<p :class="styles.title" data-slot="toast-title">{{ item.title }}</p>
|
|
102
|
+
<p v-if="item.description" :class="styles.description" data-slot="toast-description">{{ item.description }}</p>
|
|
102
103
|
</div>
|
|
103
|
-
<button v-if="item.action" type="button" :class="styles.action" @click="onAction">{{ item.action.label }}</button>
|
|
104
|
-
<button type="button" :class="styles.close" :aria-label="`${
|
|
104
|
+
<button v-if="item.action" type="button" :class="styles.action" data-slot="toast-action" @click="onAction">{{ item.action.label }}</button>
|
|
105
|
+
<button type="button" :class="styles.close" data-slot="toast-close" :aria-label="`${labels.dismiss}: ${item.title}`" @click="dismiss('down')">
|
|
105
106
|
<XIcon />
|
|
106
107
|
</button>
|
|
107
108
|
</li>
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
@layer gooee.components {
|
|
1
2
|
.root {
|
|
2
3
|
--h: var(--gooee-control-h-md);
|
|
3
4
|
position: relative;
|
|
@@ -20,11 +21,11 @@
|
|
|
20
21
|
user-select: none;
|
|
21
22
|
-webkit-tap-highlight-color: transparent;
|
|
22
23
|
transition:
|
|
23
|
-
background-color var(--gooee-motion-fast) var(--gooee-ease-
|
|
24
|
-
border-color var(--gooee-motion-fast) var(--gooee-ease-
|
|
25
|
-
color var(--gooee-motion-fast) var(--gooee-ease-
|
|
26
|
-
box-shadow var(--gooee-motion-fast) var(--gooee-ease-
|
|
27
|
-
transform var(--gooee-motion-slow) var(--gooee-ease-
|
|
24
|
+
background-color var(--gooee-motion-fast) var(--gooee-ease-morph),
|
|
25
|
+
border-color var(--gooee-motion-fast) var(--gooee-ease-morph),
|
|
26
|
+
color var(--gooee-motion-fast) var(--gooee-ease-morph),
|
|
27
|
+
box-shadow var(--gooee-motion-fast) var(--gooee-ease-morph),
|
|
28
|
+
transform var(--gooee-motion-slow) var(--gooee-ease-morph);
|
|
28
29
|
}
|
|
29
30
|
|
|
30
31
|
/* Invisible hit area, as in Button, so the small size still gets a 44px target. */
|
|
@@ -58,8 +59,8 @@
|
|
|
58
59
|
.iconOnly.sm .icon { font-size: var(--gooee-icon-md); }
|
|
59
60
|
|
|
60
61
|
@media (hover: hover) {
|
|
61
|
-
.root:hover:not(:disabled):not([data-on]) { background: var(--gooee-color-surface-hover); }
|
|
62
|
-
.root[data-on]:hover:not(:disabled) { background: var(--gooee-color-accent-hover); }
|
|
62
|
+
.root:hover:not(:disabled):not([data-state="on"]) { background: var(--gooee-color-surface-hover); }
|
|
63
|
+
.root[data-state="on"]:hover:not(:disabled) { background: var(--gooee-color-accent-hover); }
|
|
63
64
|
}
|
|
64
65
|
|
|
65
66
|
.root:focus-visible {
|
|
@@ -77,11 +78,11 @@
|
|
|
77
78
|
.iconOnly:active:not(:disabled)::after { inset: -9%; }
|
|
78
79
|
|
|
79
80
|
/* A solid fill, so the pressed state never rests on a faint shade. */
|
|
80
|
-
.root[data-on] {
|
|
81
|
+
.root[data-state="on"] {
|
|
81
82
|
border-color: var(--gooee-color-accent);
|
|
82
83
|
background: var(--gooee-color-accent);
|
|
83
84
|
color: var(--gooee-color-accent-fg);
|
|
84
|
-
animation: pop var(--gooee-motion-slow) var(--gooee-ease-
|
|
85
|
+
animation: pop var(--gooee-motion-slow) var(--gooee-ease-morph);
|
|
85
86
|
}
|
|
86
87
|
|
|
87
88
|
.root:disabled {
|
|
@@ -92,3 +93,4 @@
|
|
|
92
93
|
@keyframes pop {
|
|
93
94
|
50% { transform: scale(calc(2 - var(--gooee-press-scale))); }
|
|
94
95
|
}
|
|
96
|
+
}
|
|
@@ -37,13 +37,14 @@ export function Toggle({
|
|
|
37
37
|
type={type}
|
|
38
38
|
aria-pressed={pressed}
|
|
39
39
|
className={cx(styles.root, styles[size], !children && styles.iconOnly, className)}
|
|
40
|
-
data-
|
|
40
|
+
data-slot="toggle"
|
|
41
|
+
data-state={pressed ? 'on' : 'off'}
|
|
41
42
|
onClick={(e: MouseEvent<HTMLButtonElement>) => {
|
|
42
43
|
onClick?.(e)
|
|
43
44
|
if (!e.defaultPrevented) setPressed(!pressed)
|
|
44
45
|
}}
|
|
45
46
|
>
|
|
46
|
-
{icon && <span className={styles.icon}>{icon}</span>}
|
|
47
|
+
{icon && <span className={styles.icon} data-slot="toggle-icon">{icon}</span>}
|
|
47
48
|
{children}
|
|
48
49
|
</button>
|
|
49
50
|
)
|
|
@@ -6,22 +6,19 @@ import styles from './Toggle.module.css'
|
|
|
6
6
|
// other attributes and listeners go to the button.
|
|
7
7
|
defineOptions({ inheritAttrs: false })
|
|
8
8
|
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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 })
|
|
9
|
+
const { defaultPressed = false, size = 'md', type = 'button' } = defineProps<{
|
|
10
|
+
/** Starting pressed state when there is no v-model. */
|
|
11
|
+
defaultPressed?: boolean
|
|
12
|
+
/** Height and text size, the same as Button. */
|
|
13
|
+
size?: 'sm' | 'md' | 'lg'
|
|
14
|
+
type?: 'button' | 'submit' | 'reset'
|
|
15
|
+
}>()
|
|
16
|
+
/** Pressed state. Use v-model, or leave it out and the toggle keeps its own state. */
|
|
17
|
+
const model = defineModel<boolean | undefined>({ type: Boolean, default: undefined })
|
|
21
18
|
const slots = useSlots() as { default?: () => unknown; icon?: () => unknown }
|
|
22
19
|
const attrs = useAttrs()
|
|
23
20
|
|
|
24
|
-
const own = ref(
|
|
21
|
+
const own = ref(defaultPressed)
|
|
25
22
|
const pressed = computed(() => model.value ?? own.value)
|
|
26
23
|
const rest = computed(() => {
|
|
27
24
|
const { onClick: _onClick, ...others } = attrs
|
|
@@ -43,10 +40,11 @@ const onClick = (e: MouseEvent) => {
|
|
|
43
40
|
:type="type"
|
|
44
41
|
:aria-pressed="pressed"
|
|
45
42
|
:class="[styles.root, styles[size], !slots.default && styles.iconOnly]"
|
|
46
|
-
|
|
43
|
+
data-slot="toggle"
|
|
44
|
+
:data-state="pressed ? 'on' : 'off'"
|
|
47
45
|
@click="onClick"
|
|
48
46
|
>
|
|
49
|
-
<span v-if="slots.icon" :class="styles.icon"><slot name="icon" /></span>
|
|
47
|
+
<span v-if="slots.icon" :class="styles.icon" data-slot="toggle-icon"><slot name="icon" /></span>
|
|
50
48
|
<slot />
|
|
51
49
|
</button>
|
|
52
50
|
</template>
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
@layer gooee.components {
|
|
1
2
|
.tip {
|
|
2
3
|
--dx: 0px;
|
|
3
4
|
--dy: var(--gooee-shift-sm);
|
|
4
5
|
z-index: var(--gooee-z-tooltip);
|
|
5
|
-
max-width: var(--gooee-tooltip-w);
|
|
6
|
+
max-width: var(--gooee-tooltip-w, 260px);
|
|
6
7
|
padding: var(--gooee-space-2) var(--gooee-space-4);
|
|
7
8
|
border-radius: var(--gooee-radius-sm);
|
|
8
9
|
background: var(--gooee-color-inverse);
|
|
@@ -10,7 +11,7 @@
|
|
|
10
11
|
font-size: var(--gooee-text-sm);
|
|
11
12
|
line-height: var(--gooee-leading-snug);
|
|
12
13
|
box-shadow: var(--gooee-shadow-2);
|
|
13
|
-
animation: tipIn var(--gooee-motion-base) var(--gooee-ease-
|
|
14
|
+
animation: tipIn var(--gooee-motion-base) var(--gooee-ease-morph);
|
|
14
15
|
}
|
|
15
16
|
|
|
16
17
|
.tip[data-side="bottom"] { --dy: calc(var(--gooee-shift-sm) * -1); }
|
|
@@ -18,7 +19,7 @@
|
|
|
18
19
|
.tip[data-side="right"] { --dy: 0px; --dx: calc(var(--gooee-shift-sm) * -1); }
|
|
19
20
|
|
|
20
21
|
.tip[data-state="closed"] {
|
|
21
|
-
animation: tipOut var(--gooee-motion-fast) var(--gooee-ease-
|
|
22
|
+
animation: tipOut var(--gooee-motion-fast) var(--gooee-ease-morph) forwards;
|
|
22
23
|
}
|
|
23
24
|
|
|
24
25
|
/* The morph (internal/liquid.ts) grows the tip out of its target instead; the fade stands down. */
|
|
@@ -32,3 +33,4 @@
|
|
|
32
33
|
@keyframes tipOut {
|
|
33
34
|
to { opacity: 0; transform: scale(var(--gooee-pop-scale)); }
|
|
34
35
|
}
|
|
36
|
+
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { onBeforeUnmount, ref, shallowRef, useId, watch, type VNode } from 'vue'
|
|
3
3
|
import type { Side } from '../../internal/motion/floating'
|
|
4
4
|
import { dismissable } from '../../internal/motion/layers'
|
|
5
|
-
import {
|
|
5
|
+
import { createMorph } from '../../internal/motion/liquid'
|
|
6
6
|
import { createTipTimer, tipEdge } from '../../internal/motion/tooltip'
|
|
7
7
|
import { useFloating } from '../../internal/vue/useFloating'
|
|
8
8
|
import { usePresence } from '../../internal/vue/usePresence'
|
|
@@ -12,17 +12,14 @@ import styles from './Tooltip.module.css'
|
|
|
12
12
|
// The Vue Tooltip: the same look (Tooltip.module.css), timing and growth as the React one.
|
|
13
13
|
// The default slot is the trigger: one focusable element, such as a Button.
|
|
14
14
|
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}>(),
|
|
24
|
-
{ side: 'top' },
|
|
25
|
-
)
|
|
15
|
+
const { side = 'top', delay } = defineProps<{
|
|
16
|
+
/** Short text shown on hover and focus. It also describes the trigger to screen readers. The content slot replaces it. */
|
|
17
|
+
content?: string
|
|
18
|
+
/** Preferred side of the trigger. It flips when there is no room. */
|
|
19
|
+
side?: Side
|
|
20
|
+
/** Delay before showing on hover. Defaults to the tooltip delay token. */
|
|
21
|
+
delay?: number
|
|
22
|
+
}>()
|
|
26
23
|
const slots = defineSlots<{ default?: () => VNode[]; content?: () => unknown }>()
|
|
27
24
|
|
|
28
25
|
const id = useId()
|
|
@@ -31,19 +28,16 @@ const anchor = shallowRef<HTMLElement | null>(null)
|
|
|
31
28
|
const setAnchor = elementRef(anchor)
|
|
32
29
|
const tip = ref<HTMLElement | null>(null)
|
|
33
30
|
const { mounted, state } = usePresence(open, 'morph-out')
|
|
34
|
-
const { style, side: placed, ready } = useFloating(anchor, tip, mounted, () => ({ side
|
|
31
|
+
const { style, side: placed, ready } = useFloating(anchor, tip, mounted, () => ({ side, offset: 8 }))
|
|
35
32
|
// Vue sets a bare number as no length at all, so the place gets its unit here.
|
|
36
33
|
// 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 =
|
|
38
|
-
() => tip.value,
|
|
39
|
-
() => tipEdge(anchor.value, placed.value),
|
|
40
|
-
)
|
|
34
|
+
const liquid = createMorph(() => tip.value, { origin: () => tipEdge(anchor.value, placed.value) })
|
|
41
35
|
watch([state, () => mounted.value && ready.value], ([s, on]) => on && liquid.play(s), { flush: 'post' })
|
|
42
36
|
|
|
43
37
|
// When it shows and hides (motion/tooltip.ts).
|
|
44
38
|
const timer = createTipTimer(
|
|
45
39
|
(v) => (open.value = v),
|
|
46
|
-
() =>
|
|
40
|
+
() => delay,
|
|
47
41
|
)
|
|
48
42
|
|
|
49
43
|
// Esc hides it without moving focus (WCAG 1.4.13), and only it, not a dialog behind it.
|
|
@@ -83,6 +77,7 @@ const trigger = () => {
|
|
|
83
77
|
ref="tip"
|
|
84
78
|
role="tooltip"
|
|
85
79
|
:class="styles.tip"
|
|
80
|
+
data-slot="tooltip-content"
|
|
86
81
|
:data-state="state"
|
|
87
82
|
:data-side="placed"
|
|
88
83
|
:style="style"
|
|
@@ -8,5 +8,5 @@ export type VisuallyHiddenProps = ComponentPropsWithRef<'span'> & {
|
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
export function VisuallyHidden({ focusable = false, className, ...rest }: VisuallyHiddenProps) {
|
|
11
|
-
return <span className={cx(focusable ? styles.focusable : styles.root, className)} {...rest} />
|
|
11
|
+
return <span className={cx(focusable ? styles.focusable : styles.root, className)} data-slot="visually-hidden" {...rest} />
|
|
12
12
|
}
|