@thekestongroup/ui 0.2.1 → 0.3.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 +90 -32
- package/dist/components/Age/Age.vue.d.ts +19 -0
- package/dist/components/AppShell/AppShell.vue.d.ts +108 -0
- package/dist/components/Avatar/Avatar.vue.d.ts +34 -0
- package/dist/components/AvatarGroup/AvatarGroup.vue.d.ts +25 -0
- package/dist/components/Badge/Badge.vue.d.ts +41 -0
- package/dist/components/Breadcrumb/Breadcrumb.vue.d.ts +39 -0
- package/dist/components/Button/Button.vue.d.ts +69 -0
- package/dist/components/Calendar/Calendar.vue.d.ts +34 -0
- package/dist/components/Card/Card.vue.d.ts +56 -0
- package/dist/components/Checkbox/Checkbox.vue.d.ts +40 -0
- package/dist/components/Checklist/Checklist.vue.d.ts +18 -0
- package/dist/components/Chip/Chip.vue.d.ts +44 -0
- package/dist/components/Divider/Divider.vue.d.ts +36 -0
- package/dist/components/{ToastItem.vue.d.ts → FormField/FieldMessage.vue.d.ts} +10 -2
- package/dist/components/FormField/FormField.vue.d.ts +61 -0
- package/dist/components/Header/Header.vue.d.ts +104 -0
- package/dist/components/InfoTip/InfoTip.vue.d.ts +20 -0
- package/dist/components/Input/Input.vue.d.ts +56 -0
- package/dist/components/InputCode/InputCode.vue.d.ts +53 -0
- package/dist/components/InputDate/InputDate.vue.d.ts +49 -0
- package/dist/components/InputNumber/InputNumber.vue.d.ts +44 -0
- package/dist/components/InputPassword/InputPassword.vue.d.ts +51 -0
- package/dist/components/InputRichText/InputRichText.vue.d.ts +44 -0
- package/dist/components/Link/Link.vue.d.ts +39 -0
- package/dist/components/Notification/Notification.vue.d.ts +62 -0
- package/dist/components/Notification/NotificationPane.vue.d.ts +38 -0
- package/dist/components/Notification/Toaster.vue.d.ts +51 -0
- package/dist/components/Notification/notification.samples.d.ts +3 -0
- package/dist/components/Notification/notifications.d.ts +115 -0
- package/dist/components/PageHeader/PageHeader.vue.d.ts +43 -0
- package/dist/components/Popover/Popover.vue.d.ts +83 -0
- package/dist/components/Popover/popover.d.ts +16 -0
- package/dist/components/Progress/Progress.vue.d.ts +26 -0
- package/dist/components/RadioGroup/RadioGroup.vue.d.ts +45 -0
- package/dist/components/RelativeTime/RelativeTime.vue.d.ts +22 -0
- package/dist/components/Select/Select.vue.d.ts +110 -0
- package/dist/components/Sidebar/Sidebar.vue.d.ts +106 -0
- package/dist/components/Sidebar/sidebar.d.ts +10 -0
- package/dist/components/Slideover/Slideover.vue.d.ts +125 -0
- package/dist/components/Spinner/Spinner.vue.d.ts +30 -0
- package/dist/components/StatTile/StatTile.vue.d.ts +46 -0
- package/dist/components/SummaryList/SummaryList.vue.d.ts +62 -0
- package/dist/components/Switch/Switch.vue.d.ts +39 -0
- package/dist/components/Table/Table.vue.d.ts +82 -0
- package/dist/components/Table/table.d.ts +36 -0
- package/dist/components/Tooltip/Tooltip.vue.d.ts +46 -0
- package/dist/index.d.ts +89 -25
- package/dist/keston-ui.js +4963 -14785
- package/dist/lib/cn.d.ts +4 -0
- package/dist/lib/dates.d.ts +27 -0
- package/dist/lib/initials.d.ts +2 -0
- package/dist/lib/parseDate.d.ts +44 -0
- package/dist/lib/useNow.d.ts +3 -0
- package/package.json +53 -24
- package/src/components/.gitkeep +0 -0
- package/src/components/Age/Age.stories.ts +24 -0
- package/src/components/Age/Age.vue +56 -0
- package/src/components/AppShell/AppShell.stories.ts +124 -0
- package/src/components/AppShell/AppShell.vue +212 -0
- package/src/components/Avatar/Avatar.stories.ts +56 -0
- package/src/components/Avatar/Avatar.vue +118 -0
- package/src/components/AvatarGroup/AvatarGroup.stories.ts +47 -0
- package/src/components/AvatarGroup/AvatarGroup.vue +97 -0
- package/src/components/Badge/Badge.stories.ts +92 -0
- package/src/components/Badge/Badge.vue +67 -0
- package/src/components/Breadcrumb/Breadcrumb.stories.ts +58 -0
- package/src/components/Breadcrumb/Breadcrumb.vue +109 -0
- package/src/components/Button/Button.mdx +79 -0
- package/src/components/Button/Button.stories.ts +207 -0
- package/src/components/Button/Button.vue +266 -0
- package/src/components/Calendar/Calendar.stories.ts +51 -0
- package/src/components/Calendar/Calendar.vue +364 -0
- package/src/components/Card/Card.stories.ts +109 -0
- package/src/components/Card/Card.vue +115 -0
- package/src/components/Checkbox/Checkbox.stories.ts +102 -0
- package/src/components/Checkbox/Checkbox.vue +102 -0
- package/src/components/Checklist/Checklist.stories.ts +67 -0
- package/src/components/Checklist/Checklist.vue +38 -0
- package/src/components/Chip/Chip.stories.ts +71 -0
- package/src/components/Chip/Chip.vue +86 -0
- package/src/components/Divider/Divider.stories.ts +57 -0
- package/src/components/Divider/Divider.vue +58 -0
- package/src/components/FormField/FieldMessage.vue +81 -0
- package/src/components/FormField/FormField.stories.ts +55 -0
- package/src/components/FormField/FormField.vue +160 -0
- package/src/components/Header/Header.stories.ts +168 -0
- package/src/components/Header/Header.vue +232 -0
- package/src/components/InfoTip/InfoTip.stories.ts +63 -0
- package/src/components/InfoTip/InfoTip.vue +50 -0
- package/src/components/Input/Input.stories.ts +206 -0
- package/src/components/Input/Input.vue +90 -0
- package/src/components/InputCode/InputCode.stories.ts +85 -0
- package/src/components/InputCode/InputCode.vue +145 -0
- package/src/components/InputDate/InputDate.stories.ts +58 -0
- package/src/components/InputDate/InputDate.vue +258 -0
- package/src/components/InputNumber/InputNumber.stories.ts +63 -0
- package/src/components/InputNumber/InputNumber.vue +109 -0
- package/src/components/InputPassword/InputPassword.stories.ts +105 -0
- package/src/components/InputPassword/InputPassword.vue +132 -0
- package/src/components/InputRichText/InputRichText.stories.ts +100 -0
- package/src/components/InputRichText/InputRichText.vue +194 -0
- package/src/components/Link/Link.stories.ts +73 -0
- package/src/components/Link/Link.vue +56 -0
- package/src/components/Notification/Notification.stories.ts +196 -0
- package/src/components/Notification/Notification.vue +136 -0
- package/src/components/Notification/NotificationPane.vue +187 -0
- package/src/components/Notification/Toaster.vue +446 -0
- package/src/components/Notification/notification.samples.ts +45 -0
- package/src/components/Notification/notifications.test.ts +99 -0
- package/src/components/Notification/notifications.ts +172 -0
- package/src/components/PageHeader/PageHeader.stories.ts +79 -0
- package/src/components/PageHeader/PageHeader.vue +66 -0
- package/src/components/Popover/Popover.stories.ts +135 -0
- package/src/components/Popover/Popover.vue +192 -0
- package/src/components/Popover/popover.ts +20 -0
- package/src/components/Progress/Progress.stories.ts +74 -0
- package/src/components/Progress/Progress.vue +75 -0
- package/src/components/RadioGroup/RadioGroup.stories.ts +90 -0
- package/src/components/RadioGroup/RadioGroup.vue +132 -0
- package/src/components/RelativeTime/RelativeTime.stories.ts +74 -0
- package/src/components/RelativeTime/RelativeTime.vue +51 -0
- package/src/components/Select/Select.mdx +202 -0
- package/src/components/Select/Select.stories.ts +223 -0
- package/src/components/Select/Select.vue +630 -0
- package/src/components/Sidebar/Sidebar.stories.ts +192 -0
- package/src/components/Sidebar/Sidebar.vue +382 -0
- package/src/components/Sidebar/sidebar.ts +20 -0
- package/src/components/Slideover/Slideover.stories.ts +225 -0
- package/src/components/Slideover/Slideover.vue +365 -0
- package/src/components/Spinner/Spinner.stories.ts +79 -0
- package/src/components/Spinner/Spinner.vue +97 -0
- package/src/components/StatTile/StatTile.stories.ts +75 -0
- package/src/components/StatTile/StatTile.vue +89 -0
- package/src/components/SummaryList/SummaryList.stories.ts +103 -0
- package/src/components/SummaryList/SummaryList.vue +127 -0
- package/src/components/Switch/Switch.stories.ts +100 -0
- package/src/components/Switch/Switch.vue +96 -0
- package/src/components/Table/Table.stories.ts +206 -0
- package/src/components/Table/Table.vue +220 -0
- package/src/components/Table/table.test.ts +65 -0
- package/src/components/Table/table.ts +70 -0
- package/src/components/Tooltip/Tooltip.stories.ts +57 -0
- package/src/components/Tooltip/Tooltip.vue +86 -0
- package/src/examples/AppPages.stories.ts +500 -0
- package/src/examples/FormLayout.stories.ts +185 -0
- package/src/examples/KestonIdPages.stories.ts +415 -0
- package/src/examples/SchoolPages.stories.ts +665 -0
- package/src/index.ts +114 -36
- package/src/lib/cn.ts +4 -0
- package/src/lib/dates.test.ts +68 -0
- package/src/lib/dates.ts +86 -0
- package/src/lib/initials.ts +8 -0
- package/src/lib/parseDate.test.ts +331 -0
- package/src/lib/parseDate.ts +561 -0
- package/src/lib/useNow.ts +20 -0
- package/src/styles/theme.css +101 -0
- package/dist/components/AppLauncher.vue.d.ts +0 -10
- package/dist/components/Avatar.vue.d.ts +0 -16
- package/dist/components/Button.vue.d.ts +0 -27
- package/dist/components/Checkbox.vue.d.ts +0 -18
- package/dist/components/CloseButton.vue.d.ts +0 -6
- package/dist/components/Dialog.vue.d.ts +0 -23
- package/dist/components/Drawer.vue.d.ts +0 -34
- package/dist/components/DropdownMenu.vue.d.ts +0 -21
- package/dist/components/DropdownMenuItem.vue.d.ts +0 -19
- package/dist/components/DropdownMenuSeparator.vue.d.ts +0 -6
- package/dist/components/Input.vue.d.ts +0 -14
- package/dist/components/Label.vue.d.ts +0 -16
- package/dist/components/NotificationsMenu.vue.d.ts +0 -3
- package/dist/components/Popover.vue.d.ts +0 -23
- package/dist/components/ProfileSwitcher.vue.d.ts +0 -24
- package/dist/components/Select.vue.d.ts +0 -28
- package/dist/components/Separator.vue.d.ts +0 -11
- package/dist/components/ToastRenderer.vue.d.ts +0 -3
- package/dist/components/Toaster.vue.d.ts +0 -3
- package/dist/components/Tooltip.vue.d.ts +0 -23
- package/dist/components/TopBar.vue.d.ts +0 -34
- package/dist/favicon-old.svg +0 -1
- package/dist/favicon.svg +0 -1
- package/dist/keston-ui.cjs +0 -15
- package/dist/lib/toast.d.ts +0 -29
- package/dist/lib/types.d.ts +0 -5
- package/src/components/AppLauncher.vue +0 -63
- package/src/components/Avatar.vue +0 -51
- package/src/components/Button.vue +0 -54
- package/src/components/Checkbox.vue +0 -47
- package/src/components/CloseButton.vue +0 -24
- package/src/components/Dialog.vue +0 -65
- package/src/components/Drawer.vue +0 -202
- package/src/components/DropdownMenu.vue +0 -41
- package/src/components/DropdownMenuItem.vue +0 -28
- package/src/components/DropdownMenuSeparator.vue +0 -12
- package/src/components/Input.vue +0 -21
- package/src/components/Label.vue +0 -15
- package/src/components/NotificationsMenu.vue +0 -115
- package/src/components/Popover.vue +0 -46
- package/src/components/ProfileSwitcher.vue +0 -113
- package/src/components/Select.vue +0 -97
- package/src/components/Separator.vue +0 -30
- package/src/components/ToastItem.vue +0 -158
- package/src/components/ToastRenderer.vue +0 -113
- package/src/components/Toaster.vue +0 -11
- package/src/components/Tooltip.vue +0 -48
- package/src/components/TopBar.vue +0 -52
- package/src/lib/toast.ts +0 -95
- package/src/lib/types.ts +0 -5
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed, useId, type HTMLAttributes } from 'vue'
|
|
3
|
+
import { CircleCheck, CircleX, Info, TriangleAlert, X } from '@lucide/vue'
|
|
4
|
+
import { cn } from '../../lib/cn'
|
|
5
|
+
import Button from '../Button/Button.vue'
|
|
6
|
+
import RelativeTime from '../RelativeTime/RelativeTime.vue'
|
|
7
|
+
import { type NotificationAction, type NotificationInput, type NotificationType } from './notifications'
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* One notification: an icon for its type, a title, a description, an
|
|
11
|
+
* optional action button, and a close ×.
|
|
12
|
+
*
|
|
13
|
+
* - appearance "card" (default): a white panel with a border. On a page, or
|
|
14
|
+
* as a toast (Toaster adds the shadow).
|
|
15
|
+
* - appearance "row": no border, for lists, e.g. NotificationPane. Shows the
|
|
16
|
+
* time, and a dot when unread.
|
|
17
|
+
*
|
|
18
|
+
* The description can be formatted with a render function, e.g.
|
|
19
|
+
* `() => ['Your password expires in ', h('b', '7 days'), '.']`, or the
|
|
20
|
+
* default slot.
|
|
21
|
+
*/
|
|
22
|
+
export interface NotificationProps {
|
|
23
|
+
type?: NotificationType
|
|
24
|
+
title: string
|
|
25
|
+
description?: NotificationInput['description']
|
|
26
|
+
action?: NotificationAction
|
|
27
|
+
/** When it happened. Shown in the row appearance, e.g. "2 hours ago", with the exact time on hover. */
|
|
28
|
+
createdAt?: Date
|
|
29
|
+
/** Row appearance: show the unread dot. */
|
|
30
|
+
unread?: boolean
|
|
31
|
+
appearance?: 'card' | 'row'
|
|
32
|
+
/**
|
|
33
|
+
* Card appearance: one line, for quick confirmations, e.g. "✓ Student
|
|
34
|
+
* disabled [Undo] ×". The title only (no description); the action sits on
|
|
35
|
+
* the right, before the ×.
|
|
36
|
+
*/
|
|
37
|
+
compact?: boolean
|
|
38
|
+
/** Show the close ×. */
|
|
39
|
+
dismissible?: boolean
|
|
40
|
+
/** The ×'s accessible name. Default "Dismiss: {title}". */
|
|
41
|
+
dismissLabel?: string
|
|
42
|
+
/** What "now" is for the relative time. Default the live time. */
|
|
43
|
+
now?: Date
|
|
44
|
+
class?: HTMLAttributes['class']
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const props = withDefaults(defineProps<NotificationProps>(), {
|
|
48
|
+
type: 'info',
|
|
49
|
+
appearance: 'card',
|
|
50
|
+
dismissible: true
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
const emit = defineEmits<{ dismiss: []; action: [] }>()
|
|
54
|
+
|
|
55
|
+
defineSlots<{
|
|
56
|
+
default?(): unknown
|
|
57
|
+
actions?(): unknown
|
|
58
|
+
}>()
|
|
59
|
+
|
|
60
|
+
const titleId = `${useId()}-title`
|
|
61
|
+
|
|
62
|
+
const types = {
|
|
63
|
+
info: { icon: Info, colour: 'text-blue', word: 'Information' },
|
|
64
|
+
success: { icon: CircleCheck, colour: 'text-green', word: 'Success' },
|
|
65
|
+
warning: { icon: TriangleAlert, colour: 'text-yellow', word: 'Warning' },
|
|
66
|
+
error: { icon: CircleX, colour: 'text-red', word: 'Error' }
|
|
67
|
+
} as const
|
|
68
|
+
|
|
69
|
+
// A string, or a render function (for bold text, links).
|
|
70
|
+
const Description = () => (typeof props.description === 'function' ? props.description() : props.description)
|
|
71
|
+
|
|
72
|
+
// Compact only changes the card; in a list (row) it reads like the others.
|
|
73
|
+
const oneLine = computed(() => props.compact && props.appearance === 'card')
|
|
74
|
+
|
|
75
|
+
function runAction() {
|
|
76
|
+
props.action?.onSelect?.()
|
|
77
|
+
emit('action')
|
|
78
|
+
}
|
|
79
|
+
</script>
|
|
80
|
+
|
|
81
|
+
<template>
|
|
82
|
+
<div
|
|
83
|
+
:aria-labelledby="titleId"
|
|
84
|
+
role="group"
|
|
85
|
+
:class="
|
|
86
|
+
cn(
|
|
87
|
+
'relative flex text-sm text-black',
|
|
88
|
+
oneLine ? 'items-center gap-3' : 'gap-3',
|
|
89
|
+
appearance === 'row' ? 'px-4 py-3' : 'rounded border border-black/15 bg-white',
|
|
90
|
+
appearance === 'card' && (oneLine ? cn('py-1.5 pl-5', dismissible ? 'pr-1.5' : 'pr-4') : 'py-4 pr-4 pl-5'),
|
|
91
|
+
appearance === 'row' && unread && 'bg-blue/5',
|
|
92
|
+
props.class
|
|
93
|
+
)
|
|
94
|
+
"
|
|
95
|
+
>
|
|
96
|
+
<component :is="types[type].icon" :class="cn('size-4 shrink-0', !oneLine && 'mt-0.5', types[type].colour)" aria-hidden="true" />
|
|
97
|
+
|
|
98
|
+
<div :class="cn('flex min-w-0 flex-1', oneLine ? 'items-center gap-3' : 'flex-col gap-1')">
|
|
99
|
+
<p :id="titleId" :class="cn('font-bold', oneLine && 'min-w-0 flex-1 py-1')">
|
|
100
|
+
<span class="sr-only">{{ types[type].word }}: </span>{{ title }}
|
|
101
|
+
</p>
|
|
102
|
+
|
|
103
|
+
<div v-if="!oneLine && (description || $slots.default)" class="text-black/65 [&_a]:font-bold [&_a]:text-primary [&_a]:underline [&_b]:font-bold [&_b]:text-black [&_strong]:font-bold [&_strong]:text-black">
|
|
104
|
+
<slot><Description /></slot>
|
|
105
|
+
</div>
|
|
106
|
+
|
|
107
|
+
<p v-if="appearance === 'row' && (createdAt || unread)" class="flex items-center gap-1.5 text-xs text-black/65">
|
|
108
|
+
<span v-if="unread" class="size-2 shrink-0 rounded-full bg-primary" aria-hidden="true" />
|
|
109
|
+
<span v-if="unread" class="sr-only">Unread, </span>
|
|
110
|
+
<RelativeTime v-if="createdAt" :date="createdAt" :now="now" />
|
|
111
|
+
</p>
|
|
112
|
+
|
|
113
|
+
<div v-if="action || $slots.actions" :class="cn('flex gap-2', oneLine ? 'shrink-0' : 'mt-2 flex-wrap')">
|
|
114
|
+
<slot name="actions">
|
|
115
|
+
<Button v-if="action?.href" size="sm" as-child @click="runAction">
|
|
116
|
+
<a :href="action.href">{{ action.label }}</a>
|
|
117
|
+
</Button>
|
|
118
|
+
<Button v-else-if="action" size="sm" @click="runAction">{{ action.label }}</Button>
|
|
119
|
+
</slot>
|
|
120
|
+
</div>
|
|
121
|
+
</div>
|
|
122
|
+
|
|
123
|
+
<Button
|
|
124
|
+
v-if="dismissible"
|
|
125
|
+
variant="ghost"
|
|
126
|
+
size="sm"
|
|
127
|
+
square
|
|
128
|
+
:class="cn('shrink-0', !oneLine && '-mt-1 -mr-1.5')"
|
|
129
|
+
data-dismiss
|
|
130
|
+
:aria-label="dismissLabel ?? `Dismiss: ${title}`"
|
|
131
|
+
@click="emit('dismiss')"
|
|
132
|
+
>
|
|
133
|
+
<X />
|
|
134
|
+
</Button>
|
|
135
|
+
</div>
|
|
136
|
+
</template>
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed, nextTick, ref, useId, watch, type HTMLAttributes } from 'vue'
|
|
3
|
+
import { Bell, BellOff } from '@lucide/vue'
|
|
4
|
+
import { cn } from '../../lib/cn'
|
|
5
|
+
import Button from '../Button/Button.vue'
|
|
6
|
+
import Popover from '../Popover/Popover.vue'
|
|
7
|
+
import Notification from './Notification.vue'
|
|
8
|
+
import { useNotifications, type Notifications } from './notifications'
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The bell in the Header, with a count of unread notifications, that opens
|
|
12
|
+
* a panel of past notifications: newest first, each with a × to remove it,
|
|
13
|
+
* and Clear all. Put it in the Header's `trailing` slot (AppShell's
|
|
14
|
+
* `header-trailing`).
|
|
15
|
+
*
|
|
16
|
+
* Opening it shows what's unread (a dot on each); closing it marks them all
|
|
17
|
+
* read.
|
|
18
|
+
*/
|
|
19
|
+
export interface NotificationPaneProps {
|
|
20
|
+
/** The list to show. Default the shared one from `useNotifications()`. */
|
|
21
|
+
notifications?: Notifications
|
|
22
|
+
/** Panel heading, and the bell's name. */
|
|
23
|
+
label?: string
|
|
24
|
+
/** Shown when there are none. */
|
|
25
|
+
emptyText?: string
|
|
26
|
+
ui?: { content?: HTMLAttributes['class']; trigger?: HTMLAttributes['class'] }
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const props = withDefaults(defineProps<NotificationPaneProps>(), {
|
|
30
|
+
label: 'Notifications',
|
|
31
|
+
emptyText: "You're all caught up."
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
const open = defineModel<boolean>('open', { default: false })
|
|
35
|
+
|
|
36
|
+
const store = computed(() => props.notifications ?? useNotifications())
|
|
37
|
+
const items = computed(() => store.value.items)
|
|
38
|
+
const unread = computed(() => store.value.unreadCount.value)
|
|
39
|
+
// The name uses the same text as the badge ("99+"), so voice control users
|
|
40
|
+
// can say what they see.
|
|
41
|
+
const countText = computed(() => (unread.value > 99 ? '99+' : String(unread.value)))
|
|
42
|
+
const triggerLabel = computed(() => (unread.value ? `${props.label}, ${countText.value} unread` : props.label))
|
|
43
|
+
|
|
44
|
+
const headingId = `${useId()}-heading`
|
|
45
|
+
const heading = ref<HTMLElement>()
|
|
46
|
+
const list = ref<HTMLElement>()
|
|
47
|
+
|
|
48
|
+
// Tell the list, so the Toaster puts toasts away while the pane shows them.
|
|
49
|
+
watch(open, (isOpen) => store.value.setPaneOpen(isOpen), { immediate: true })
|
|
50
|
+
|
|
51
|
+
// Open when something else asks, e.g. the Toaster's "+3 more", and move
|
|
52
|
+
// focus into the pane (the button pressed is gone with the toasts).
|
|
53
|
+
watch(
|
|
54
|
+
() => store.value.paneRequests,
|
|
55
|
+
async () => {
|
|
56
|
+
open.value = true
|
|
57
|
+
await nextTick()
|
|
58
|
+
requestAnimationFrame(() => requestAnimationFrame(() => heading.value?.focus()))
|
|
59
|
+
}
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
// Mark everything read when the panel closes, so the dots show while open.
|
|
63
|
+
watch(open, (isOpen, wasOpen) => {
|
|
64
|
+
if (!isOpen && wasOpen) store.value.markAllRead()
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
// Clear all fades the list out first, then clears it when the fade ends and
|
|
68
|
+
// eases the pane's height down to the empty state's. `emptied` plays the
|
|
69
|
+
// empty state's arrival, only when the last one was just removed here, not
|
|
70
|
+
// every time the pane opens empty.
|
|
71
|
+
const pane = ref<HTMLElement>()
|
|
72
|
+
const clearing = ref(false)
|
|
73
|
+
const emptied = ref(false)
|
|
74
|
+
|
|
75
|
+
const reducedMotion = () => window.matchMedia('(prefers-reduced-motion: reduce)').matches
|
|
76
|
+
|
|
77
|
+
// Closing mid-fade unmounts the list before its animation ends, so finish
|
|
78
|
+
// the clear now.
|
|
79
|
+
watch(open, (isOpen) => {
|
|
80
|
+
if (isOpen) emptied.value = false
|
|
81
|
+
else if (clearing.value) finishClear()
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
// After removing one, focus moves to the × of the one that took its place
|
|
85
|
+
// (or the one before), so keyboard users keep their place. With none left,
|
|
86
|
+
// focus goes to the heading.
|
|
87
|
+
async function dismiss(id: string, index: number) {
|
|
88
|
+
store.value.dismiss(id)
|
|
89
|
+
if (!items.value.length) emptied.value = true
|
|
90
|
+
await nextTick()
|
|
91
|
+
const buttons = list.value?.querySelectorAll<HTMLElement>('[data-dismiss]') ?? []
|
|
92
|
+
const next = buttons[Math.min(index, buttons.length - 1)]
|
|
93
|
+
;(next ?? heading.value)?.focus()
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function clearAll() {
|
|
97
|
+
if (clearing.value) return
|
|
98
|
+
// With reduced motion there's no fade (and so no animationend): clear now.
|
|
99
|
+
if (reducedMotion()) finishClear()
|
|
100
|
+
else clearing.value = true
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
async function finishClear() {
|
|
104
|
+
const from = pane.value?.offsetHeight
|
|
105
|
+
clearing.value = false
|
|
106
|
+
store.value.clear()
|
|
107
|
+
emptied.value = true
|
|
108
|
+
await nextTick()
|
|
109
|
+
heading.value?.focus()
|
|
110
|
+
// The height is only known once the empty state is in, so animate from the
|
|
111
|
+
// old height to the new one (Tailwind's 300ms ease-out, as `empty-in`).
|
|
112
|
+
const to = pane.value?.offsetHeight
|
|
113
|
+
if (pane.value && from && to && from !== to && !reducedMotion()) {
|
|
114
|
+
pane.value.animate(
|
|
115
|
+
[
|
|
116
|
+
{ height: `${from}px`, overflow: 'hidden' },
|
|
117
|
+
{ height: `${to}px`, overflow: 'hidden' }
|
|
118
|
+
],
|
|
119
|
+
{ duration: 300, easing: 'cubic-bezier(0, 0, 0.2, 1)' }
|
|
120
|
+
)
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
</script>
|
|
124
|
+
|
|
125
|
+
<template>
|
|
126
|
+
<Popover
|
|
127
|
+
v-model:open="open"
|
|
128
|
+
:content="{ align: 'end', collisionPadding: 8 }"
|
|
129
|
+
:ui="{ content: cn('flex max-h-(--reka-popover-content-available-height) w-96 overflow-clip max-w-[calc(100vw-1rem)] flex-col', ui?.content) }"
|
|
130
|
+
>
|
|
131
|
+
<Button variant="ghost" square :aria-label="triggerLabel" :class="cn('relative overflow-visible', ui?.trigger)">
|
|
132
|
+
<Bell />
|
|
133
|
+
<span
|
|
134
|
+
v-if="unread"
|
|
135
|
+
class="absolute top-1 left-1/2 ml-1 flex h-4 min-w-4 items-center justify-center rounded-full bg-red px-1 text-xs leading-none font-bold text-white ring-2 ring-white"
|
|
136
|
+
aria-hidden="true"
|
|
137
|
+
>
|
|
138
|
+
{{ countText }}
|
|
139
|
+
</span>
|
|
140
|
+
</Button>
|
|
141
|
+
|
|
142
|
+
<template #content="{ close }">
|
|
143
|
+
<section ref="pane" :aria-labelledby="headingId" class="flex min-h-0 flex-col">
|
|
144
|
+
<div class="flex h-11 shrink-0 items-center justify-between gap-2 border-b border-black/15 pr-2 pl-4">
|
|
145
|
+
<h2 :id="headingId" ref="heading" tabindex="-1" class="font-bold outline-none">{{ label }}</h2>
|
|
146
|
+
<Button v-if="items.length" variant="ghost" size="sm" :disabled="clearing" @click="clearAll">
|
|
147
|
+
Clear all
|
|
148
|
+
</Button>
|
|
149
|
+
</div>
|
|
150
|
+
|
|
151
|
+
<!-- inert while fading, so nothing in it can be clicked or focused on its way out. -->
|
|
152
|
+
<ul
|
|
153
|
+
v-if="items.length"
|
|
154
|
+
ref="list"
|
|
155
|
+
:inert="clearing"
|
|
156
|
+
:class="cn('min-h-0 overflow-y-auto overscroll-contain [scrollbar-width:thin]', clearing && 'animate-fade-out')"
|
|
157
|
+
@animationend.self="clearing && finishClear()"
|
|
158
|
+
>
|
|
159
|
+
<li v-for="(item, index) in items" :key="item.id" class="border-b border-black/15 last:border-b-0">
|
|
160
|
+
<Notification
|
|
161
|
+
appearance="row"
|
|
162
|
+
:type="item.type"
|
|
163
|
+
:title="item.title"
|
|
164
|
+
:description="item.description"
|
|
165
|
+
:action="item.action"
|
|
166
|
+
:created-at="item.createdAt"
|
|
167
|
+
:unread="!item.read"
|
|
168
|
+
@dismiss="dismiss(item.id, index)"
|
|
169
|
+
@action="close()"
|
|
170
|
+
/>
|
|
171
|
+
</li>
|
|
172
|
+
</ul>
|
|
173
|
+
|
|
174
|
+
<div
|
|
175
|
+
v-else
|
|
176
|
+
:class="cn('flex flex-col items-center gap-2 px-4 py-10 text-center text-sm text-black/65', emptied && 'motion-safe:animate-empty-in')"
|
|
177
|
+
>
|
|
178
|
+
<BellOff
|
|
179
|
+
:class="cn('size-6 origin-top text-black/40', emptied && 'motion-safe:animate-bell-wobble')"
|
|
180
|
+
aria-hidden="true"
|
|
181
|
+
/>
|
|
182
|
+
{{ emptyText }}
|
|
183
|
+
</div>
|
|
184
|
+
</section>
|
|
185
|
+
</template>
|
|
186
|
+
</Popover>
|
|
187
|
+
</template>
|