@thekestongroup/ui 0.16.0 → 0.18.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/dist/components/ActionList/ActionList.vue.d.ts +13 -2
- package/dist/components/AsyncState/AsyncState.vue.d.ts +53 -0
- package/dist/components/ConfirmDialog/ConfirmDialog.vue.d.ts +62 -0
- package/dist/components/InputRichText/InputRichText.vue.d.ts +12 -6
- package/dist/components/Prose/Prose.vue.d.ts +36 -0
- package/dist/components/ResultState/ResultState.vue.d.ts +48 -0
- package/dist/components/Steps/Steps.vue.d.ts +16 -5
- package/dist/i18n/en.d.ts +16 -0
- package/dist/index.d.ts +8 -0
- package/dist/keston-ui.js +2149 -1749
- package/dist/lib/initials.d.ts +6 -1
- package/package.json +3 -1
- package/src/components/ActionList/ActionList.stories.ts +34 -1
- package/src/components/ActionList/ActionList.vue +27 -5
- package/src/components/AsyncState/AsyncState.stories.ts +46 -0
- package/src/components/AsyncState/AsyncState.vue +78 -0
- package/src/components/Button/Button.vue +4 -4
- package/src/components/ConfirmDialog/ConfirmDialog.stories.ts +54 -0
- package/src/components/ConfirmDialog/ConfirmDialog.vue +119 -0
- package/src/components/InputRichText/InputRichText.stories.ts +19 -0
- package/src/components/InputRichText/InputRichText.vue +129 -13
- package/src/components/Notification/Toaster.vue +3 -1
- package/src/components/Prose/Prose.stories.ts +46 -0
- package/src/components/Prose/Prose.vue +54 -0
- package/src/components/ResultState/ResultState.stories.ts +44 -0
- package/src/components/ResultState/ResultState.vue +76 -0
- package/src/components/Steps/Steps.stories.ts +18 -0
- package/src/components/Steps/Steps.vue +28 -8
- package/src/i18n/en.ts +12 -2
- package/src/index.ts +8 -0
- package/src/lib/initials.test.ts +19 -0
- package/src/lib/initials.ts +12 -3
- package/src/styles/theme.css +11 -2
package/dist/lib/initials.d.ts
CHANGED
|
@@ -1,2 +1,7 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* "Ben Smith" → "BS", "Ben" → "B", "Mary Jane Watson" → "MW". Empty for an
|
|
3
|
+
* empty name. Anything in brackets is a note, not part of the name, so it's
|
|
4
|
+
* left out ("Keston Admin (support)" → "KA"), and so is anything that isn't a
|
|
5
|
+
* letter at the start of a word ("'Jo' Bloggs" → "JB").
|
|
6
|
+
*/
|
|
2
7
|
export declare function initials(name: string): string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thekestongroup/ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.18.0",
|
|
4
4
|
"description": "Keston UI — Vue 3 + Reka UI + Tailwind CSS component library",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE",
|
|
6
6
|
"repository": {
|
|
@@ -34,6 +34,7 @@
|
|
|
34
34
|
"docs:preview": "vitepress preview site",
|
|
35
35
|
"new": "node scripts/new-component.mjs",
|
|
36
36
|
"changeset": "changeset",
|
|
37
|
+
"tokens": "node scripts/build-tokens.mjs",
|
|
37
38
|
"test": "vitest run --project unit",
|
|
38
39
|
"test:a11y": "VITE_THEME=light vitest run --project stories && VITE_THEME=dark vitest run --project stories",
|
|
39
40
|
"test:watch": "vitest"
|
|
@@ -56,6 +57,7 @@
|
|
|
56
57
|
"@tiptap/extension-document": "^3.33.1",
|
|
57
58
|
"@tiptap/extension-hard-break": "^3.33.1",
|
|
58
59
|
"@tiptap/extension-italic": "^3.33.1",
|
|
60
|
+
"@tiptap/extension-link": "^3.33.1",
|
|
59
61
|
"@tiptap/extension-paragraph": "^3.33.1",
|
|
60
62
|
"@tiptap/extension-text": "^3.33.1",
|
|
61
63
|
"@tiptap/extension-underline": "^3.33.1",
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type { Meta, StoryObj } from '@storybook/vue3-vite'
|
|
2
|
-
import { Building2, Search } from '@lucide/vue'
|
|
2
|
+
import { Building2, Search, UserRound } from '@lucide/vue'
|
|
3
3
|
import ActionList from './ActionList.vue'
|
|
4
4
|
import Avatar from '../Avatar/Avatar.vue'
|
|
5
5
|
import Badge from '../Badge/Badge.vue'
|
|
6
6
|
import Button from '../Button/Button.vue'
|
|
7
|
+
import Card from '../Card/Card.vue'
|
|
7
8
|
|
|
8
9
|
const meta = {
|
|
9
10
|
title: 'Components/Navigation/ActionList',
|
|
@@ -57,3 +58,35 @@ export const WithAfter: Story = {
|
|
|
57
58
|
</ActionList>`,
|
|
58
59
|
}),
|
|
59
60
|
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Plain: no box, a line under each row, no arrows, and a note at the top
|
|
64
|
+
* right ("Needs a code"). For a list that is the main thing on its card,
|
|
65
|
+
* like Keston ID's account chooser.
|
|
66
|
+
*/
|
|
67
|
+
export const Plain: Story = {
|
|
68
|
+
args: {
|
|
69
|
+
label: 'Signed-in accounts',
|
|
70
|
+
appearance: 'plain',
|
|
71
|
+
chevron: false,
|
|
72
|
+
items: [
|
|
73
|
+
{ key: '1', label: 'Ben Smith', description: 'ben.smith@keston.school' },
|
|
74
|
+
{ key: '2', label: 'Ben Smith', description: 'b.smith@kestontrust.org', note: 'Needs a code' },
|
|
75
|
+
{ key: '3', label: 'Ben Smith', description: 'ben@keston.school', note: 'Not a Keston Trust account', disabled: true },
|
|
76
|
+
{ key: 'another', label: 'Use another account', icon: UserRound },
|
|
77
|
+
],
|
|
78
|
+
},
|
|
79
|
+
render: (args) => ({
|
|
80
|
+
components: { ActionList, Avatar, Card },
|
|
81
|
+
setup: () => ({ args }),
|
|
82
|
+
template: `
|
|
83
|
+
<Card>
|
|
84
|
+
<ActionList v-bind="args">
|
|
85
|
+
<template #leading="{ item }">
|
|
86
|
+
<Avatar v-if="item.key !== 'another'" :user="{ name: item.label }" size="md" decorative />
|
|
87
|
+
<span v-else class="flex size-10 shrink-0 items-center justify-center"><component :is="item.icon" class="size-5 text-ink/65" aria-hidden="true" /></span>
|
|
88
|
+
</template>
|
|
89
|
+
</ActionList>
|
|
90
|
+
</Card>`,
|
|
91
|
+
}),
|
|
92
|
+
}
|
|
@@ -21,13 +21,17 @@ export interface ActionListItem {
|
|
|
21
21
|
current?: boolean
|
|
22
22
|
/** Show a spinner in place of the arrow, e.g. while switching to it. */
|
|
23
23
|
loading?: boolean
|
|
24
|
+
/** A short note at the top right of the row, e.g. "Signed out" or "Needs a code". */
|
|
25
|
+
note?: string
|
|
24
26
|
}
|
|
25
27
|
|
|
26
28
|
/**
|
|
27
29
|
* A list of things to pick one of and go to: accounts to switch to,
|
|
28
30
|
* organisations, connected apps. Each row is a single button or link with an
|
|
29
31
|
* optional icon or avatar, a name and a line under it, and an arrow, in a
|
|
30
|
-
* bordered box with lines between rows.
|
|
32
|
+
* bordered box with lines between rows. `appearance="plain"` drops the box
|
|
33
|
+
* (rows sit straight on the card, with a line under each), for a list that
|
|
34
|
+
* is the main thing on its card, like an account chooser.
|
|
31
35
|
*
|
|
32
36
|
* Rows without `to` / `href` are buttons that emit `select`.
|
|
33
37
|
*
|
|
@@ -41,10 +45,17 @@ export interface ActionListProps {
|
|
|
41
45
|
label: string
|
|
42
46
|
/** Component used for rows with `to`, e.g. RouterLink. */
|
|
43
47
|
linkComponent?: string | Component
|
|
48
|
+
/** boxed (default): a bordered box. plain: no box, a line under each row, rows lined up with the text around them. */
|
|
49
|
+
appearance?: 'boxed' | 'plain'
|
|
50
|
+
/** Show the arrow at the end of each row. */
|
|
51
|
+
chevron?: boolean
|
|
44
52
|
class?: HTMLAttributes['class']
|
|
45
53
|
}
|
|
46
54
|
|
|
47
|
-
const props = defineProps<ActionListProps>()
|
|
55
|
+
const props = withDefaults(defineProps<ActionListProps>(), {
|
|
56
|
+
appearance: 'boxed',
|
|
57
|
+
chevron: true
|
|
58
|
+
})
|
|
48
59
|
const emit = defineEmits<{ select: [item: ActionListItem] }>()
|
|
49
60
|
|
|
50
61
|
defineSlots<{
|
|
@@ -71,12 +82,21 @@ function onClick(item: ActionListItem) {
|
|
|
71
82
|
if (!item.disabled && item.to === undefined && item.href === undefined) emit('select', item)
|
|
72
83
|
}
|
|
73
84
|
|
|
85
|
+
const lists = {
|
|
86
|
+
boxed: 'divide-y divide-ink/10 overflow-hidden rounded-lg border border-ink/10 bg-surface shadow-xs',
|
|
87
|
+
// No box: a line under every row (the last too), and the rows' padding
|
|
88
|
+
// pulled back so avatars line up with the text above the list.
|
|
89
|
+
plain: '-mx-3 divide-y divide-ink/10 border-b border-ink/10'
|
|
90
|
+
}
|
|
91
|
+
|
|
74
92
|
// The whole row presses; hover and press tint it, focus rings it inside the box.
|
|
75
93
|
const row = [
|
|
76
94
|
'flex min-w-0 flex-1 cursor-pointer items-center gap-3 px-3 py-3 text-left text-ink no-underline transition-colors',
|
|
77
95
|
'not-disabled:hover:bg-hover not-disabled:active:bg-pressed aria-[current=true]:bg-selected',
|
|
78
96
|
'outline-2 -outline-offset-2 outline-transparent focus-visible:outline-focus',
|
|
79
|
-
|
|
97
|
+
// Disabled rows fade, except their note, which often says why (e.g. "Not
|
|
98
|
+
// a Harbour & Home account") and must stay readable.
|
|
99
|
+
'disabled:cursor-not-allowed disabled:[&>:not([data-note])]:opacity-40'
|
|
80
100
|
]
|
|
81
101
|
</script>
|
|
82
102
|
|
|
@@ -84,7 +104,7 @@ const row = [
|
|
|
84
104
|
<!-- overflow-hidden: the rows' tint follows the rounded corners. -->
|
|
85
105
|
<ul
|
|
86
106
|
:aria-label="label"
|
|
87
|
-
:class="cn('flex flex-col
|
|
107
|
+
:class="cn('flex flex-col', lists[appearance], props.class)"
|
|
88
108
|
>
|
|
89
109
|
<li v-for="item in items" :key="item.key ?? item.label" class="flex items-center">
|
|
90
110
|
<component
|
|
@@ -105,8 +125,10 @@ const row = [
|
|
|
105
125
|
</span>
|
|
106
126
|
<span v-if="item.description" class="truncate text-xs text-ink/65">{{ item.description }}</span>
|
|
107
127
|
</span>
|
|
128
|
+
<!-- The note: top right, read with the row's name. -->
|
|
129
|
+
<span v-if="item.note" data-note class="shrink-0 self-start text-xs text-ink/65">{{ item.note }}</span>
|
|
108
130
|
<Spinner v-if="item.loading" size="sm" />
|
|
109
|
-
<ChevronRight v-else-if="!item.disabled" class="size-4 shrink-0 text-ink/55" aria-hidden="true" />
|
|
131
|
+
<ChevronRight v-else-if="chevron && !item.disabled" class="size-4 shrink-0 text-ink/55" aria-hidden="true" />
|
|
110
132
|
</component>
|
|
111
133
|
<div v-if="$slots.after" class="shrink-0 pr-3 empty:hidden">
|
|
112
134
|
<slot name="after" :item="item" />
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/vue3-vite'
|
|
2
|
+
import { Inbox } from '@lucide/vue'
|
|
3
|
+
import AsyncState from './AsyncState.vue'
|
|
4
|
+
import Button from '../Button/Button.vue'
|
|
5
|
+
import Card from '../Card/Card.vue'
|
|
6
|
+
|
|
7
|
+
const meta = {
|
|
8
|
+
title: 'Components/Data/AsyncState',
|
|
9
|
+
component: AsyncState,
|
|
10
|
+
tags: ['autodocs'],
|
|
11
|
+
args: {
|
|
12
|
+
loading: false,
|
|
13
|
+
error: null,
|
|
14
|
+
empty: false,
|
|
15
|
+
emptyTitle: 'No applications yet',
|
|
16
|
+
emptyDescription: 'Applications appear here as families send them.',
|
|
17
|
+
emptyIcon: Inbox,
|
|
18
|
+
retryable: true,
|
|
19
|
+
card: true,
|
|
20
|
+
},
|
|
21
|
+
render: (args) => ({
|
|
22
|
+
components: { AsyncState, Button, Card },
|
|
23
|
+
setup: () => ({ args }),
|
|
24
|
+
template: `
|
|
25
|
+
<div class="max-w-xl">
|
|
26
|
+
<AsyncState v-bind="args">
|
|
27
|
+
<Card title="Applications">3 applications.</Card>
|
|
28
|
+
<template #empty-actions><Button size="sm">Add an application</Button></template>
|
|
29
|
+
</AsyncState>
|
|
30
|
+
</div>`,
|
|
31
|
+
}),
|
|
32
|
+
} satisfies Meta<typeof AsyncState>
|
|
33
|
+
|
|
34
|
+
export default meta
|
|
35
|
+
type Story = StoryObj<typeof meta>
|
|
36
|
+
|
|
37
|
+
/** Loaded, with something in it: the content. */
|
|
38
|
+
export const Loaded: Story = {}
|
|
39
|
+
|
|
40
|
+
export const Loading: Story = { args: { loading: true } }
|
|
41
|
+
|
|
42
|
+
/** Couldn't load: the reason and Try again (emits retry). */
|
|
43
|
+
export const Error: Story = { args: { error: 'The server took too long to answer.' } }
|
|
44
|
+
|
|
45
|
+
/** Loaded, with nothing in it: what goes here and what to do. */
|
|
46
|
+
export const Empty: Story = { args: { empty: true } }
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import type { Component, HTMLAttributes } from 'vue'
|
|
3
|
+
import { useI18n } from 'vue-i18n'
|
|
4
|
+
import { RotateCw, TriangleAlert } from '@lucide/vue'
|
|
5
|
+
import { cn } from '../../lib/cn'
|
|
6
|
+
import Button from '../Button/Button.vue'
|
|
7
|
+
import Card from '../Card/Card.vue'
|
|
8
|
+
import EmptyState from '../EmptyState/EmptyState.vue'
|
|
9
|
+
import Spinner from '../Spinner/Spinner.vue'
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The three states every page or panel that loads data has, the same way
|
|
13
|
+
* everywhere:
|
|
14
|
+
* - error: "Couldn't load …" with the reason and Try again (emits `retry`);
|
|
15
|
+
* - loading: a spinner, centred;
|
|
16
|
+
* - empty: an EmptyState with what goes here and what to do;
|
|
17
|
+
* - otherwise the content (default slot).
|
|
18
|
+
*
|
|
19
|
+
* In that order, so an error wins over stale content. With `card`, the
|
|
20
|
+
* error and empty states sit in a Card, as on a page of Cards.
|
|
21
|
+
*
|
|
22
|
+
* Slots: default (the content), empty (instead of the EmptyState), empty-actions
|
|
23
|
+
* (under the empty state, e.g. "Add a student").
|
|
24
|
+
*/
|
|
25
|
+
export interface AsyncStateProps {
|
|
26
|
+
loading?: boolean
|
|
27
|
+
/** Why it couldn't load. Shows the error state. */
|
|
28
|
+
error?: string | null
|
|
29
|
+
/** Loaded, with nothing in it. Shows the empty state. */
|
|
30
|
+
empty?: boolean
|
|
31
|
+
/** The error's title. Default "Couldn't load this". */
|
|
32
|
+
errorTitle?: string
|
|
33
|
+
/** Show Try again under the error (emits `retry`). */
|
|
34
|
+
retryable?: boolean
|
|
35
|
+
/** The empty state's title, e.g. "No applications yet". */
|
|
36
|
+
emptyTitle?: string
|
|
37
|
+
emptyDescription?: string
|
|
38
|
+
emptyIcon?: Component
|
|
39
|
+
/** What the spinner says to screen readers. Default "Loading". */
|
|
40
|
+
loadingLabel?: string
|
|
41
|
+
/** Put the error and empty states in a Card. */
|
|
42
|
+
card?: boolean
|
|
43
|
+
class?: HTMLAttributes['class']
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const { t } = useI18n()
|
|
47
|
+
const props = defineProps<AsyncStateProps>()
|
|
48
|
+
const emit = defineEmits<{ retry: [] }>()
|
|
49
|
+
|
|
50
|
+
defineSlots<{
|
|
51
|
+
default?(): unknown
|
|
52
|
+
empty?(): unknown
|
|
53
|
+
'empty-actions'?(): unknown
|
|
54
|
+
}>()
|
|
55
|
+
</script>
|
|
56
|
+
|
|
57
|
+
<template>
|
|
58
|
+
<component :is="card ? Card : 'div'" v-if="error" :class="props.class">
|
|
59
|
+
<EmptyState :icon="TriangleAlert" :title="errorTitle ?? t('ui.asyncState.error')" :description="error" role="alert">
|
|
60
|
+
<template v-if="retryable" #actions>
|
|
61
|
+
<Button size="sm" @click="emit('retry')">
|
|
62
|
+
<template #leading><RotateCw /></template>{{ t('ui.asyncState.retry') }}
|
|
63
|
+
</Button>
|
|
64
|
+
</template>
|
|
65
|
+
</EmptyState>
|
|
66
|
+
</component>
|
|
67
|
+
<div v-else-if="loading" :class="cn('flex justify-center py-12', props.class)">
|
|
68
|
+
<Spinner :label="loadingLabel" />
|
|
69
|
+
</div>
|
|
70
|
+
<component :is="card ? Card : 'div'" v-else-if="empty" :class="props.class">
|
|
71
|
+
<slot name="empty">
|
|
72
|
+
<EmptyState :icon="emptyIcon" :title="emptyTitle" :description="emptyDescription">
|
|
73
|
+
<template v-if="$slots['empty-actions']" #actions><slot name="empty-actions" /></template>
|
|
74
|
+
</EmptyState>
|
|
75
|
+
</slot>
|
|
76
|
+
</component>
|
|
77
|
+
<slot v-else />
|
|
78
|
+
</template>
|
|
@@ -164,16 +164,16 @@ const base = [
|
|
|
164
164
|
// Hover / pressed only apply when the button is usable. The theme's state
|
|
165
165
|
// colours (theme.css, "States") keep this the same as every other component:
|
|
166
166
|
// - coloured fills (primary, danger) darken
|
|
167
|
-
// - basic
|
|
168
|
-
//
|
|
167
|
+
// - basic takes the control colours: a step above whatever it sits on (a
|
|
168
|
+
// card, a menu, the page), lightening in dark mode rather than darkening
|
|
169
169
|
// - ghost has no fill, so it takes the see-through hover / pressed tints. Its
|
|
170
170
|
// border stays (transparent) so it lines up with the other variants.
|
|
171
171
|
const interactive = 'not-disabled:not-aria-disabled:hover:brightness-90 not-disabled:not-aria-disabled:active:brightness-80'
|
|
172
|
-
const
|
|
172
|
+
const controlInteractive = 'not-disabled:not-aria-disabled:hover:bg-control-hover not-disabled:not-aria-disabled:active:bg-control-pressed'
|
|
173
173
|
const ghostInteractive = 'not-disabled:not-aria-disabled:hover:bg-hover not-disabled:not-aria-disabled:active:bg-pressed'
|
|
174
174
|
|
|
175
175
|
const variants: Record<NonNullable<ButtonProps['variant']>, string> = {
|
|
176
|
-
basic: `bg-
|
|
176
|
+
basic: `bg-control text-ink shadow-xs ${controlInteractive}`,
|
|
177
177
|
primary: `bg-primary text-white ${interactive}`,
|
|
178
178
|
ghost: `bg-transparent text-ink border-transparent ${ghostInteractive}`,
|
|
179
179
|
danger: `bg-red text-white ${interactive}`
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/vue3-vite'
|
|
2
|
+
import { ref } from 'vue'
|
|
3
|
+
import { Trash2 } from '@lucide/vue'
|
|
4
|
+
import ConfirmDialog from './ConfirmDialog.vue'
|
|
5
|
+
import Button from '../Button/Button.vue'
|
|
6
|
+
import type { ButtonStatus } from '../Button/Button.vue'
|
|
7
|
+
|
|
8
|
+
const meta = {
|
|
9
|
+
title: 'Components/Overlay/ConfirmDialog',
|
|
10
|
+
component: ConfirmDialog,
|
|
11
|
+
tags: ['autodocs'],
|
|
12
|
+
args: {
|
|
13
|
+
title: 'Delete 3 applications?',
|
|
14
|
+
description: "They're removed for everyone at the school. This can't be undone.",
|
|
15
|
+
confirmLabel: 'Delete applications',
|
|
16
|
+
danger: true,
|
|
17
|
+
},
|
|
18
|
+
render: (args) => ({
|
|
19
|
+
components: { ConfirmDialog, Button },
|
|
20
|
+
setup() {
|
|
21
|
+
const open = ref(false)
|
|
22
|
+
const status = ref<ButtonStatus>('idle')
|
|
23
|
+
// Pretend to delete for a second, then close.
|
|
24
|
+
function confirm() {
|
|
25
|
+
status.value = 'loading'
|
|
26
|
+
setTimeout(() => {
|
|
27
|
+
status.value = 'idle'
|
|
28
|
+
open.value = false
|
|
29
|
+
}, 1000)
|
|
30
|
+
}
|
|
31
|
+
return { args, open, status, confirm, Trash2 }
|
|
32
|
+
},
|
|
33
|
+
template: `
|
|
34
|
+
<ConfirmDialog v-bind="args" v-model:open="open" :status="status" loading-text="Deleting…" @confirm="confirm">
|
|
35
|
+
<Button variant="danger"><template #leading><component :is="Trash2" /></template>Delete</Button>
|
|
36
|
+
</ConfirmDialog>`,
|
|
37
|
+
}),
|
|
38
|
+
} satisfies Meta<typeof ConfirmDialog>
|
|
39
|
+
|
|
40
|
+
export default meta
|
|
41
|
+
type Story = StoryObj<typeof meta>
|
|
42
|
+
|
|
43
|
+
/** Something that can't be undone: a danger action, focus starting on Cancel. */
|
|
44
|
+
export const Default: Story = {}
|
|
45
|
+
|
|
46
|
+
/** Not destructive, e.g. leaving an organisation you can rejoin: a primary action. */
|
|
47
|
+
export const NotDangerous: Story = {
|
|
48
|
+
args: {
|
|
49
|
+
title: 'Leave Keston Prep?',
|
|
50
|
+
description: "You'll lose access to its apps. An admin there can invite you again.",
|
|
51
|
+
confirmLabel: 'Leave',
|
|
52
|
+
danger: false,
|
|
53
|
+
},
|
|
54
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed, ref, type HTMLAttributes } from 'vue'
|
|
3
|
+
import { useI18n } from 'vue-i18n'
|
|
4
|
+
import {
|
|
5
|
+
AlertDialogCancel,
|
|
6
|
+
AlertDialogContent,
|
|
7
|
+
AlertDialogDescription,
|
|
8
|
+
AlertDialogOverlay,
|
|
9
|
+
AlertDialogPortal,
|
|
10
|
+
AlertDialogRoot,
|
|
11
|
+
AlertDialogTitle,
|
|
12
|
+
AlertDialogTrigger
|
|
13
|
+
} from 'reka-ui'
|
|
14
|
+
import { cn } from '../../lib/cn'
|
|
15
|
+
import Button, { type ButtonStatus } from '../Button/Button.vue'
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* "Are you sure?" before something that can't easily be undone: deleting,
|
|
19
|
+
* leaving, removing access. A small panel in the middle of the screen with a
|
|
20
|
+
* title that asks the question, what will happen, and Cancel / the action.
|
|
21
|
+
*
|
|
22
|
+
* Focus starts on Cancel, so pressing Enter by accident doesn't do it.
|
|
23
|
+
* Escape and Cancel close it; clicking outside doesn't (it's a decision).
|
|
24
|
+
* Built on Reka UI's AlertDialog, so it's announced as an alert dialog.
|
|
25
|
+
*
|
|
26
|
+
* Open it with `v-model:open`, or put the button that opens it in the
|
|
27
|
+
* default slot. While `status` is loading, the action shows a spinner and
|
|
28
|
+
* the dialog can't be closed; set it back to idle (and `open` to false) when
|
|
29
|
+
* the work is done.
|
|
30
|
+
*
|
|
31
|
+
* Slots: default (the trigger), description (instead of `description`, for
|
|
32
|
+
* bold text or a list of what will be lost).
|
|
33
|
+
*/
|
|
34
|
+
export interface ConfirmDialogProps {
|
|
35
|
+
/** The question, e.g. "Delete 3 applications?" */
|
|
36
|
+
title: string
|
|
37
|
+
/** What will happen, and whether it can be undone. */
|
|
38
|
+
description?: string
|
|
39
|
+
/** The action's text: a verb, e.g. "Delete applications". Default "Confirm". */
|
|
40
|
+
confirmLabel?: string
|
|
41
|
+
/** Default "Cancel". */
|
|
42
|
+
cancelLabel?: string
|
|
43
|
+
/** Destroys something: the action is a danger Button. */
|
|
44
|
+
danger?: boolean
|
|
45
|
+
/** Progress of the action, e.g. loading while it runs. */
|
|
46
|
+
status?: ButtonStatus
|
|
47
|
+
/** Text beside the spinner while loading, e.g. "Deleting…". */
|
|
48
|
+
loadingText?: string
|
|
49
|
+
class?: HTMLAttributes['class']
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const { t } = useI18n()
|
|
53
|
+
const props = withDefaults(defineProps<ConfirmDialogProps>(), {
|
|
54
|
+
status: 'idle'
|
|
55
|
+
})
|
|
56
|
+
const open = defineModel<boolean>('open', { default: false })
|
|
57
|
+
const emit = defineEmits<{
|
|
58
|
+
/** The action was pressed. Close it yourself (`open = false`) when it's done. */
|
|
59
|
+
confirm: []
|
|
60
|
+
}>()
|
|
61
|
+
|
|
62
|
+
defineSlots<{
|
|
63
|
+
default?(): unknown
|
|
64
|
+
description?(): unknown
|
|
65
|
+
}>()
|
|
66
|
+
|
|
67
|
+
const busy = computed(() => props.status === 'loading')
|
|
68
|
+
const cancelButton = ref<{ $el?: HTMLElement }>()
|
|
69
|
+
|
|
70
|
+
// Can't be closed while the action runs.
|
|
71
|
+
function onOpenChange(value: boolean) {
|
|
72
|
+
if (!value && busy.value) return
|
|
73
|
+
open.value = value
|
|
74
|
+
}
|
|
75
|
+
</script>
|
|
76
|
+
|
|
77
|
+
<template>
|
|
78
|
+
<AlertDialogRoot :open="open" @update:open="onOpenChange">
|
|
79
|
+
<AlertDialogTrigger v-if="$slots.default" as-child>
|
|
80
|
+
<slot />
|
|
81
|
+
</AlertDialogTrigger>
|
|
82
|
+
<AlertDialogPortal>
|
|
83
|
+
<AlertDialogOverlay class="fixed inset-0 z-50 bg-black/40 data-[state=open]:animate-fade-in data-[state=closed]:animate-fade-out" />
|
|
84
|
+
<AlertDialogContent
|
|
85
|
+
:class="cn(
|
|
86
|
+
'fixed top-1/2 left-1/2 z-50 flex w-[calc(100vw-2rem)] max-w-md -translate-x-1/2 -translate-y-1/2 flex-col gap-4',
|
|
87
|
+
'rounded-lg border border-ink/10 bg-surface-elevated p-6 text-ink shadow-xl outline-none',
|
|
88
|
+
'data-[state=open]:animate-fade-in data-[state=closed]:animate-fade-out',
|
|
89
|
+
props.class
|
|
90
|
+
)"
|
|
91
|
+
@escape-key-down="busy && $event.preventDefault()"
|
|
92
|
+
@open-auto-focus.prevent="cancelButton?.$el?.focus()"
|
|
93
|
+
>
|
|
94
|
+
<div class="flex flex-col gap-2">
|
|
95
|
+
<AlertDialogTitle class="text-lg font-bold">{{ title }}</AlertDialogTitle>
|
|
96
|
+
<AlertDialogDescription v-if="description || $slots.description" as="div" class="text-sm text-ink/65">
|
|
97
|
+
<slot name="description">{{ description }}</slot>
|
|
98
|
+
</AlertDialogDescription>
|
|
99
|
+
</div>
|
|
100
|
+
<!-- Cancel on the left, the action on the right; stacked on narrow
|
|
101
|
+
screens with the action on top. -->
|
|
102
|
+
<div class="flex flex-col-reverse gap-2 sm:flex-row sm:justify-end">
|
|
103
|
+
<AlertDialogCancel as-child>
|
|
104
|
+
<Button ref="cancelButton" :disabled="busy">{{ cancelLabel ?? t('ui.confirmDialog.cancel') }}</Button>
|
|
105
|
+
</AlertDialogCancel>
|
|
106
|
+
<!-- Not AlertDialogAction's own close: it stays open while the work runs. -->
|
|
107
|
+
<Button
|
|
108
|
+
:variant="danger ? 'danger' : 'primary'"
|
|
109
|
+
:status="status"
|
|
110
|
+
:loading-text="loadingText"
|
|
111
|
+
@click="emit('confirm')"
|
|
112
|
+
>
|
|
113
|
+
{{ confirmLabel ?? t('ui.confirmDialog.confirm') }}
|
|
114
|
+
</Button>
|
|
115
|
+
</div>
|
|
116
|
+
</AlertDialogContent>
|
|
117
|
+
</AlertDialogPortal>
|
|
118
|
+
</AlertDialogRoot>
|
|
119
|
+
</template>
|
|
@@ -98,3 +98,22 @@ export const AutoSave: Story = {
|
|
|
98
98
|
export const WithErrorText: Story = { args: { errorText: "Add a note before saving" } };
|
|
99
99
|
|
|
100
100
|
export const Disabled: Story = { args: { disabled: true } };
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* With a link: Link (or Ctrl/⌘+K) opens a panel for the address. Only
|
|
104
|
+
* https://, mailto: and tel: are accepted; https:// addresses typed or pasted
|
|
105
|
+
* become links by themselves. Put the cursor in the link to change or remove it.
|
|
106
|
+
*/
|
|
107
|
+
export const WithLink: Story = {
|
|
108
|
+
args: { label: "Sign-in page text" },
|
|
109
|
+
render: (args) => ({
|
|
110
|
+
components: { InputRichText },
|
|
111
|
+
setup: () => ({
|
|
112
|
+
args,
|
|
113
|
+
value: ref(
|
|
114
|
+
'<p><strong>New to StockTrack?</strong> Use your <em>work</em> email. For help, see the <a href="https://example.com/help">IT help centre</a> or call <a href="tel:08000000000">0800 000 0000</a>.</p>',
|
|
115
|
+
),
|
|
116
|
+
}),
|
|
117
|
+
template: `<div class="max-w-xl"><InputRichText v-bind="args" v-model="value" /></div>`,
|
|
118
|
+
}),
|
|
119
|
+
};
|