@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
|
@@ -10,21 +10,30 @@ import HardBreak from '@tiptap/extension-hard-break'
|
|
|
10
10
|
import Bold from '@tiptap/extension-bold'
|
|
11
11
|
import Italic from '@tiptap/extension-italic'
|
|
12
12
|
import Underline from '@tiptap/extension-underline'
|
|
13
|
+
import Link from '@tiptap/extension-link'
|
|
13
14
|
import { Placeholder, UndoRedo } from '@tiptap/extensions'
|
|
14
|
-
import { Bold as BoldIcon, Italic as ItalicIcon, Underline as UnderlineIcon } from '@lucide/vue'
|
|
15
|
+
import { Bold as BoldIcon, Italic as ItalicIcon, Link as LinkIcon, Underline as UnderlineIcon } from '@lucide/vue'
|
|
15
16
|
import { cn } from '../../lib/cn'
|
|
16
17
|
import FormField, { type FormFieldStatus } from '../FormField/FormField.vue'
|
|
17
18
|
import Button from '../Button/Button.vue'
|
|
18
19
|
import Tooltip from '../Tooltip/Tooltip.vue'
|
|
20
|
+
import Popover from '../Popover/Popover.vue'
|
|
21
|
+
import Input from '../Input/Input.vue'
|
|
19
22
|
|
|
20
23
|
/**
|
|
21
|
-
* Several lines of text with bold, italic and
|
|
22
|
-
* student or
|
|
23
|
-
* colours, so
|
|
24
|
-
*
|
|
24
|
+
* Several lines of text with bold, italic, underline and links, e.g. notes
|
|
25
|
+
* on a student, or a company's sign-in page text with a link to its help
|
|
26
|
+
* pages. No headings, lists or colours, so text looks the same everywhere.
|
|
27
|
+
* Pasted text keeps those and loses everything else.
|
|
25
28
|
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
29
|
+
* Links: the Link button or Ctrl/⌘+K opens a small panel for the address.
|
|
30
|
+
* Only https://, mailto: and tel: addresses are allowed (never javascript:
|
|
31
|
+
* or plain http). Typed and pasted https:// addresses become links too.
|
|
32
|
+
* Links open in the same tab, so nobody is sent to a new tab unannounced.
|
|
33
|
+
*
|
|
34
|
+
* The value is HTML using only <p>, <br>, <strong>, <em>, <u> and
|
|
35
|
+
* <a href rel>. Sanitise it on the server like any HTML from a browser
|
|
36
|
+
* before showing it elsewhere.
|
|
28
37
|
*/
|
|
29
38
|
export interface InputRichTextProps {
|
|
30
39
|
/** Visible label. Always set it: it is also the editor's accessible name. */
|
|
@@ -55,6 +64,9 @@ const props = withDefaults(defineProps<InputRichTextProps>(), {
|
|
|
55
64
|
/** The text as HTML; an empty string when there's nothing in it. */
|
|
56
65
|
const model = defineModel<string>({ default: '' })
|
|
57
66
|
|
|
67
|
+
// Addresses a link may have: secure web pages, email and phone.
|
|
68
|
+
const SAFE_LINK = /^(https:\/\/[^\s]+|mailto:[^\s]+|tel:[+\d][\d\s()-]*)$/i
|
|
69
|
+
|
|
58
70
|
// An empty editor still holds an empty paragraph; report that as ''.
|
|
59
71
|
const html = () => (editor.value?.isEmpty ? '' : (editor.value?.getHTML() ?? ''))
|
|
60
72
|
|
|
@@ -69,6 +81,25 @@ const editor = useEditor({
|
|
|
69
81
|
Bold,
|
|
70
82
|
Italic,
|
|
71
83
|
Underline,
|
|
84
|
+
Link.extend({
|
|
85
|
+
// Ctrl/⌘+K opens the link panel, as in most editors.
|
|
86
|
+
addKeyboardShortcuts: () => ({
|
|
87
|
+
'Mod-k': () => {
|
|
88
|
+
openLink()
|
|
89
|
+
return true
|
|
90
|
+
}
|
|
91
|
+
})
|
|
92
|
+
}).configure({
|
|
93
|
+
openOnClick: false,
|
|
94
|
+
autolink: true,
|
|
95
|
+
linkOnPaste: true,
|
|
96
|
+
defaultProtocol: 'https',
|
|
97
|
+
protocols: ['mailto', 'tel'],
|
|
98
|
+
isAllowedUri: (url) => SAFE_LINK.test(url),
|
|
99
|
+
shouldAutoLink: (url) => /^https:\/\//i.test(url),
|
|
100
|
+
// Same tab, no referrer; no target, so no unannounced new tabs.
|
|
101
|
+
HTMLAttributes: { rel: 'noopener noreferrer nofollow', target: null, class: null }
|
|
102
|
+
}),
|
|
72
103
|
UndoRedo,
|
|
73
104
|
Placeholder.configure({ placeholder: () => props.placeholder ?? '' })
|
|
74
105
|
],
|
|
@@ -82,10 +113,54 @@ const editor = useEditor({
|
|
|
82
113
|
|
|
83
114
|
// Which formats are on at the cursor (or for the next text typed), for the
|
|
84
115
|
// toolbar's pressed state. Tiptap's isActive() isn't reactive by itself.
|
|
85
|
-
type Mark = 'bold' | 'italic' | 'underline'
|
|
86
|
-
const active = ref<Record<Mark, boolean>>({ bold: false, italic: false, underline: false })
|
|
116
|
+
type Mark = 'bold' | 'italic' | 'underline' | 'link'
|
|
117
|
+
const active = ref<Record<Mark, boolean>>({ bold: false, italic: false, underline: false, link: false })
|
|
87
118
|
function updateActive(e: Editor) {
|
|
88
|
-
active.value = {
|
|
119
|
+
active.value = {
|
|
120
|
+
bold: e.isActive('bold'),
|
|
121
|
+
italic: e.isActive('italic'),
|
|
122
|
+
underline: e.isActive('underline'),
|
|
123
|
+
link: e.isActive('link')
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// ── Links ───────────────────────────────────────────────────────────────────
|
|
128
|
+
// A small panel under the Link button: the address, then Add / Update and
|
|
129
|
+
// (on a link) Remove. With text selected, the address is put on that text;
|
|
130
|
+
// with nothing selected, the address itself is added as the link's text.
|
|
131
|
+
const linkOpen = ref(false)
|
|
132
|
+
const linkHref = ref('')
|
|
133
|
+
const linkError = ref<string>()
|
|
134
|
+
// Set here rather than in the template: vue-tsc misreads a literal "//" in
|
|
135
|
+
// a template attribute inside nested slots as a comment.
|
|
136
|
+
const linkPlaceholder = 'https://'
|
|
137
|
+
|
|
138
|
+
function openLink() {
|
|
139
|
+
if (props.disabled || !editor.value) return
|
|
140
|
+
linkHref.value = (editor.value.getAttributes('link').href as string | undefined) ?? ''
|
|
141
|
+
linkError.value = undefined
|
|
142
|
+
linkOpen.value = true
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function applyLink() {
|
|
146
|
+
const e = editor.value
|
|
147
|
+
if (!e) return
|
|
148
|
+
const href = linkHref.value.trim()
|
|
149
|
+
if (!SAFE_LINK.test(href)) {
|
|
150
|
+
linkError.value = t('ui.inputRichText.linkInvalid')
|
|
151
|
+
return
|
|
152
|
+
}
|
|
153
|
+
if (e.state.selection.empty && !e.isActive('link')) {
|
|
154
|
+
e.chain().focus().insertContent({ type: 'text', text: href, marks: [{ type: 'link', attrs: { href } }] }).run()
|
|
155
|
+
} else {
|
|
156
|
+
e.chain().focus().extendMarkRange('link').setLink({ href }).run()
|
|
157
|
+
}
|
|
158
|
+
linkOpen.value = false
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function removeLink() {
|
|
162
|
+
editor.value?.chain().focus().extendMarkRange('link').unsetLink().run()
|
|
163
|
+
linkOpen.value = false
|
|
89
164
|
}
|
|
90
165
|
|
|
91
166
|
// A value set from outside (e.g. a form reset) replaces the text; the
|
|
@@ -145,6 +220,7 @@ const editable = [
|
|
|
145
220
|
// 16px on touch screens, so iPhone doesn't zoom in when it's tapped.
|
|
146
221
|
'min-h-24 max-h-80 overflow-y-auto px-3 py-2 text-sm pointer-coarse:text-base outline-none cursor-text',
|
|
147
222
|
'[&_p+p]:mt-2',
|
|
223
|
+
'[&_a]:text-primary-fg [&_a]:underline [&_a]:underline-offset-2',
|
|
148
224
|
'[&_p.is-editor-empty:first-child]:before:pointer-events-none [&_p.is-editor-empty:first-child]:before:float-left',
|
|
149
225
|
'[&_p.is-editor-empty:first-child]:before:h-0 [&_p.is-editor-empty:first-child]:before:text-ink/55',
|
|
150
226
|
'[&_p.is-editor-empty:first-child]:before:content-[attr(data-placeholder)]'
|
|
@@ -163,7 +239,7 @@ const editable = [
|
|
|
163
239
|
:disabled="disabled"
|
|
164
240
|
:class="props.class"
|
|
165
241
|
>
|
|
166
|
-
<template #default="
|
|
242
|
+
<template #default="field">
|
|
167
243
|
<!-- Fills FormField's box: negative margins cancel its padding, so the
|
|
168
244
|
toolbar's line and the text area run to the edges. -->
|
|
169
245
|
<div class="-mx-3 -my-2 flex min-w-0 flex-1 flex-col self-stretch">
|
|
@@ -171,7 +247,7 @@ const editable = [
|
|
|
171
247
|
<div
|
|
172
248
|
role="toolbar"
|
|
173
249
|
:aria-label="t('ui.inputRichText.formattingFor', { label })"
|
|
174
|
-
:aria-controls="
|
|
250
|
+
:aria-controls="field.id"
|
|
175
251
|
class="flex items-center gap-0.5 border-b border-ink/10 px-1.5 py-1 [&_svg]:opacity-100!"
|
|
176
252
|
@mousedown.prevent
|
|
177
253
|
>
|
|
@@ -190,8 +266,48 @@ const editable = [
|
|
|
190
266
|
<component :is="mark.icon" />
|
|
191
267
|
</Button>
|
|
192
268
|
</Tooltip>
|
|
269
|
+
<!-- Link: opens a panel for the address (also Ctrl/⌘+K). -->
|
|
270
|
+
<Popover v-model:open="linkOpen" :content="{ side: 'bottom', align: 'start', sideOffset: 6 }">
|
|
271
|
+
<template #default>
|
|
272
|
+
<Tooltip :text="`${t('ui.inputRichText.link')} (${mod}K)`" :disabled="disabled">
|
|
273
|
+
<Button
|
|
274
|
+
variant="ghost"
|
|
275
|
+
size="sm"
|
|
276
|
+
square
|
|
277
|
+
:aria-label="t('ui.inputRichText.link')"
|
|
278
|
+
aria-haspopup="dialog"
|
|
279
|
+
:aria-keyshortcuts="`${isMac ? 'Meta' : 'Control'}+K`"
|
|
280
|
+
:disabled="disabled"
|
|
281
|
+
:class="active.link && 'bg-selected'"
|
|
282
|
+
@click.prevent="openLink"
|
|
283
|
+
>
|
|
284
|
+
<LinkIcon />
|
|
285
|
+
</Button>
|
|
286
|
+
</Tooltip>
|
|
287
|
+
</template>
|
|
288
|
+
<template #content>
|
|
289
|
+
<form class="flex w-72 flex-col gap-3 p-3" novalidate @submit.prevent="applyLink" @mousedown.stop>
|
|
290
|
+
<Input
|
|
291
|
+
v-model="linkHref"
|
|
292
|
+
:label="t('ui.inputRichText.linkAddress')"
|
|
293
|
+
type="url"
|
|
294
|
+
inputmode="url"
|
|
295
|
+
:placeholder="linkPlaceholder"
|
|
296
|
+
autocomplete="off"
|
|
297
|
+
spellcheck="false"
|
|
298
|
+
:error-text="linkError"
|
|
299
|
+
/>
|
|
300
|
+
<div class="flex justify-end gap-2">
|
|
301
|
+
<Button v-if="active.link" size="sm" variant="ghost" @click="removeLink">{{ t('ui.inputRichText.removeLink') }}</Button>
|
|
302
|
+
<Button size="sm" variant="primary" type="submit">
|
|
303
|
+
{{ active.link ? t('ui.inputRichText.updateLink') : t('ui.inputRichText.addLink') }}
|
|
304
|
+
</Button>
|
|
305
|
+
</div>
|
|
306
|
+
</form>
|
|
307
|
+
</template>
|
|
308
|
+
</Popover>
|
|
193
309
|
</div>
|
|
194
|
-
<EditorAttributes :ids="
|
|
310
|
+
<EditorAttributes :ids="field" />
|
|
195
311
|
<EditorContent :editor="editor" :class="cn('min-w-0', disabled && 'cursor-not-allowed [&_*]:cursor-not-allowed')" />
|
|
196
312
|
</div>
|
|
197
313
|
</template>
|
|
@@ -422,11 +422,13 @@ const positions = {
|
|
|
422
422
|
)
|
|
423
423
|
"
|
|
424
424
|
>
|
|
425
|
+
<!-- It floats over the page with the toasts: the floating-panel
|
|
426
|
+
colour, with the same 5% hover as everything else. -->
|
|
425
427
|
<button
|
|
426
428
|
type="button"
|
|
427
429
|
:class="
|
|
428
430
|
cn(
|
|
429
|
-
'flex cursor-pointer items-center justify-center overflow-hidden border border-ink/10 bg-surface font-bold whitespace-nowrap text-ink shadow-md hover:bg-surface-
|
|
431
|
+
'flex cursor-pointer items-center justify-center overflow-hidden border border-ink/10 bg-surface-elevated font-bold whitespace-nowrap text-ink shadow-md hover:bg-[color-mix(in_oklab,var(--color-surface-elevated)_95%,var(--color-ink))]',
|
|
430
432
|
'h-7 w-24 rounded-2xl text-xs',
|
|
431
433
|
hidden && 'in-data-expanded:h-9 in-data-expanded:w-full in-data-expanded:rounded in-data-expanded:text-sm',
|
|
432
434
|
'transition-[width,height,border-radius,font-size,background-color] duration-300 ease-out motion-reduce:transition-none',
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/vue3-vite'
|
|
2
|
+
import Prose from './Prose.vue'
|
|
3
|
+
|
|
4
|
+
const meta = {
|
|
5
|
+
title: 'Components/Element/Prose',
|
|
6
|
+
component: Prose,
|
|
7
|
+
tags: ['autodocs'],
|
|
8
|
+
args: { size: 'base' },
|
|
9
|
+
render: (args) => ({
|
|
10
|
+
components: { Prose },
|
|
11
|
+
setup: () => ({ args }),
|
|
12
|
+
template: `
|
|
13
|
+
<Prose v-bind="args">
|
|
14
|
+
<h1>Privacy policy</h1>
|
|
15
|
+
<p>This policy explains what personal information The Keston Group collects when you use our apps, why, and your rights. Read the <a href="#terms">terms</a> too.</p>
|
|
16
|
+
<h2>What we collect</h2>
|
|
17
|
+
<p>We collect only what we need to run the service:</p>
|
|
18
|
+
<ul>
|
|
19
|
+
<li>Your name and work email, from your organisation.</li>
|
|
20
|
+
<li>When and where you sign in, to keep your account secure.</li>
|
|
21
|
+
<li>Settings you ask us to remember.</li>
|
|
22
|
+
</ul>
|
|
23
|
+
<h3>How long we keep it</h3>
|
|
24
|
+
<p>Sign-in records are kept for <strong>12 months</strong>, then deleted. Run <code>pnpm tokens</code> to see a code sample.</p>
|
|
25
|
+
<blockquote>We never sell your information or use it for advertising.</blockquote>
|
|
26
|
+
<h2>Your rights</h2>
|
|
27
|
+
<ol>
|
|
28
|
+
<li>See the information we hold about you.</li>
|
|
29
|
+
<li>Ask us to correct or delete it.</li>
|
|
30
|
+
</ol>
|
|
31
|
+
<table>
|
|
32
|
+
<thead><tr><th>Data</th><th>Kept for</th></tr></thead>
|
|
33
|
+
<tbody><tr><td>Sign-ins</td><td>12 months</td></tr><tr><td>Audit logs</td><td>7 years</td></tr></tbody>
|
|
34
|
+
</table>
|
|
35
|
+
<p><small>Last updated 30 November 2026.</small></p>
|
|
36
|
+
</Prose>`,
|
|
37
|
+
}),
|
|
38
|
+
} satisfies Meta<typeof Prose>
|
|
39
|
+
|
|
40
|
+
export default meta
|
|
41
|
+
type Story = StoryObj<typeof meta>
|
|
42
|
+
|
|
43
|
+
export const Default: Story = {}
|
|
44
|
+
|
|
45
|
+
/** Smaller, for help text in a panel or card. */
|
|
46
|
+
export const Small: Story = { args: { size: 'sm' } }
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import type { HTMLAttributes } from 'vue'
|
|
3
|
+
import { cn } from '../../lib/cn'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Long-form text written as plain HTML: privacy policies, terms, help
|
|
7
|
+
* articles, release notes. Gives headings, paragraphs, lists, links, quotes,
|
|
8
|
+
* code and tables Keston's look without a class on each, at a readable line
|
|
9
|
+
* length (about 65 characters).
|
|
10
|
+
*
|
|
11
|
+
* Headings follow the guide's scale: h1 text-2xl (when the page has no
|
|
12
|
+
* PageHeader), h2 text-lg, h3 text-base, h4 text-sm. Links look and behave
|
|
13
|
+
* like Link (Keston blue, underlined, focus ring); use Link itself for
|
|
14
|
+
* links that open in a new tab, so they get its icon and screen-reader text.
|
|
15
|
+
*
|
|
16
|
+
* Not for app screens: those are built from components.
|
|
17
|
+
*/
|
|
18
|
+
export interface ProseProps {
|
|
19
|
+
/** The text size. base (default) for reading pages, sm in a panel or card. */
|
|
20
|
+
size?: 'sm' | 'base'
|
|
21
|
+
class?: HTMLAttributes['class']
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const props = withDefaults(defineProps<ProseProps>(), { size: 'base' })
|
|
25
|
+
|
|
26
|
+
const prose = [
|
|
27
|
+
'max-w-prose text-ink [&>*+*]:mt-4',
|
|
28
|
+
// Headings: space above to separate sections, less below to tie them to their text.
|
|
29
|
+
'[&_h1]:text-2xl [&_h1]:font-bold',
|
|
30
|
+
'[&_h2]:mt-10 [&_h2]:text-lg [&_h2]:font-bold [&_h2+*]:mt-2',
|
|
31
|
+
'[&_h3]:mt-8 [&_h3]:text-base [&_h3]:font-bold [&_h3+*]:mt-2',
|
|
32
|
+
'[&_h4]:mt-6 [&_h4]:text-sm [&_h4]:font-bold [&_h4+*]:mt-1',
|
|
33
|
+
// Lists.
|
|
34
|
+
'[&_ul]:list-disc [&_ol]:list-decimal [&_ul,&_ol]:pl-6 [&_li+li]:mt-1 [&_li::marker]:text-ink/55',
|
|
35
|
+
// Links, as Link.
|
|
36
|
+
'[&_a]:text-primary-fg [&_a]:underline [&_a]:underline-offset-2 [&_a]:rounded-sm',
|
|
37
|
+
'[&_a]:outline-2 [&_a]:outline-offset-1 [&_a]:outline-transparent [&_a:focus-visible]:outline-focus',
|
|
38
|
+
// Quotes, code, rules, small print.
|
|
39
|
+
'[&_blockquote]:border-l-2 [&_blockquote]:border-ink/10 [&_blockquote]:pl-4 [&_blockquote]:text-ink/65',
|
|
40
|
+
'[&_code]:rounded-sm [&_code]:bg-surface-muted [&_code]:px-1 [&_code]:font-mono [&_code]:text-[0.875em]',
|
|
41
|
+
'[&_hr]:border-ink/10 [&_small]:text-ink/65 [&_strong]:font-bold',
|
|
42
|
+
// Tables: lines between rows, headings quieter.
|
|
43
|
+
'[&_table]:w-full [&_table]:text-left [&_table]:text-sm [&_th]:py-2 [&_th]:pr-4 [&_th]:font-normal [&_th]:text-ink/65',
|
|
44
|
+
'[&_td]:py-2 [&_td]:pr-4 [&_tr]:border-b [&_tr]:border-ink/10'
|
|
45
|
+
]
|
|
46
|
+
|
|
47
|
+
const sizes = { sm: 'text-sm leading-relaxed', base: 'text-base leading-relaxed' }
|
|
48
|
+
</script>
|
|
49
|
+
|
|
50
|
+
<template>
|
|
51
|
+
<div :class="cn(prose, sizes[size], props.class)">
|
|
52
|
+
<slot />
|
|
53
|
+
</div>
|
|
54
|
+
</template>
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/vue3-vite'
|
|
2
|
+
import ResultState from './ResultState.vue'
|
|
3
|
+
import Button from '../Button/Button.vue'
|
|
4
|
+
import Card from '../Card/Card.vue'
|
|
5
|
+
|
|
6
|
+
const meta = {
|
|
7
|
+
title: 'Components/Data/ResultState',
|
|
8
|
+
component: ResultState,
|
|
9
|
+
tags: ['autodocs'],
|
|
10
|
+
args: {
|
|
11
|
+
type: 'success',
|
|
12
|
+
title: '3 users added',
|
|
13
|
+
description: "They'll get an email with how to sign in for the first time.",
|
|
14
|
+
focus: false,
|
|
15
|
+
},
|
|
16
|
+
render: (args) => ({
|
|
17
|
+
components: { ResultState, Button, Card },
|
|
18
|
+
setup: () => ({ args }),
|
|
19
|
+
template: `
|
|
20
|
+
<Card class="max-w-xl">
|
|
21
|
+
<ResultState v-bind="args">
|
|
22
|
+
<template #actions>
|
|
23
|
+
<Button>Add more users</Button>
|
|
24
|
+
<Button variant="primary">Done</Button>
|
|
25
|
+
</template>
|
|
26
|
+
</ResultState>
|
|
27
|
+
</Card>`,
|
|
28
|
+
}),
|
|
29
|
+
} satisfies Meta<typeof ResultState>
|
|
30
|
+
|
|
31
|
+
export default meta
|
|
32
|
+
type Story = StoryObj<typeof meta>
|
|
33
|
+
|
|
34
|
+
export const Success: Story = {}
|
|
35
|
+
|
|
36
|
+
/** Nothing happened. */
|
|
37
|
+
export const Error: Story = {
|
|
38
|
+
args: { type: 'error', title: 'Nobody was added', description: 'Every email address is already in use. Check the list and try again.' },
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Partly worked: say what didn't. */
|
|
42
|
+
export const Warning: Story = {
|
|
43
|
+
args: { type: 'warning', title: '2 of 3 users added', description: "jo@keston.school couldn't be added: that email is already in use." },
|
|
44
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { onMounted, ref, type Component, type HTMLAttributes } from 'vue'
|
|
3
|
+
import { CircleCheck, CircleX, Info, TriangleAlert } from '@lucide/vue'
|
|
4
|
+
import { cn } from '../../lib/cn'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The end of a task: what happened, and what next. "3 users added", "Nobody
|
|
8
|
+
* was added", "Password changed". A large icon, a heading, a line or two,
|
|
9
|
+
* and actions (e.g. Add more, Done), centred.
|
|
10
|
+
*
|
|
11
|
+
* It usually replaces the form that was just sent, so focus moves to its
|
|
12
|
+
* heading when it appears and screen readers read the outcome. Turn that off
|
|
13
|
+
* with `:focus="false"` when it's on the page from the start.
|
|
14
|
+
*
|
|
15
|
+
* For a list or table with nothing in it, use EmptyState.
|
|
16
|
+
*
|
|
17
|
+
* Slots: description (instead of `description`), default (under the
|
|
18
|
+
* description, e.g. a list of what failed), actions.
|
|
19
|
+
*/
|
|
20
|
+
export interface ResultStateProps {
|
|
21
|
+
/** success (default), error (nothing happened), warning (partly), info. Sets the icon and its colour. */
|
|
22
|
+
type?: 'success' | 'error' | 'warning' | 'info'
|
|
23
|
+
/** What happened, e.g. "3 users added". */
|
|
24
|
+
title: string
|
|
25
|
+
/** What it means or what to do next. */
|
|
26
|
+
description?: string
|
|
27
|
+
/** A different icon from the type's own. */
|
|
28
|
+
icon?: Component
|
|
29
|
+
/** The heading's level, to fit the page outline. */
|
|
30
|
+
headingLevel?: 1 | 2 | 3
|
|
31
|
+
/** Move focus to the heading when it appears. */
|
|
32
|
+
focus?: boolean
|
|
33
|
+
class?: HTMLAttributes['class']
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const props = withDefaults(defineProps<ResultStateProps>(), {
|
|
37
|
+
type: 'success',
|
|
38
|
+
headingLevel: 2,
|
|
39
|
+
focus: true
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
defineSlots<{
|
|
43
|
+
default?(): unknown
|
|
44
|
+
description?(): unknown
|
|
45
|
+
actions?(): unknown
|
|
46
|
+
}>()
|
|
47
|
+
|
|
48
|
+
const types = {
|
|
49
|
+
success: { icon: CircleCheck, colour: 'text-green-fg' },
|
|
50
|
+
error: { icon: CircleX, colour: 'text-red-fg' },
|
|
51
|
+
warning: { icon: TriangleAlert, colour: 'text-yellow-fg' },
|
|
52
|
+
info: { icon: Info, colour: 'text-blue-fg' }
|
|
53
|
+
} as const
|
|
54
|
+
|
|
55
|
+
const heading = ref<HTMLElement>()
|
|
56
|
+
onMounted(() => {
|
|
57
|
+
if (props.focus) heading.value?.focus()
|
|
58
|
+
})
|
|
59
|
+
</script>
|
|
60
|
+
|
|
61
|
+
<template>
|
|
62
|
+
<div :class="cn('flex flex-col items-center gap-2 px-4 py-8 text-center', props.class)">
|
|
63
|
+
<component :is="icon ?? types[type].icon" :class="cn('mb-1 size-10', types[type].colour)" aria-hidden="true" />
|
|
64
|
+
<!-- Focusable only by script, with no ring: it's not a control. -->
|
|
65
|
+
<component :is="`h${headingLevel}`" ref="heading" tabindex="-1" class="text-xl font-bold outline-none">
|
|
66
|
+
{{ title }}
|
|
67
|
+
</component>
|
|
68
|
+
<div v-if="description || $slots.description" class="max-w-prose text-sm text-ink/65">
|
|
69
|
+
<slot name="description">{{ description }}</slot>
|
|
70
|
+
</div>
|
|
71
|
+
<slot />
|
|
72
|
+
<div v-if="$slots.actions" class="mt-3 flex flex-wrap justify-center gap-2">
|
|
73
|
+
<slot name="actions" />
|
|
74
|
+
</div>
|
|
75
|
+
</div>
|
|
76
|
+
</template>
|
|
@@ -36,3 +36,21 @@ export const WithButtons: Story = {
|
|
|
36
36
|
</div>`,
|
|
37
37
|
}),
|
|
38
38
|
};
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* With `v-model:step`, finished segments go back to their step ("Back to
|
|
42
|
+
* step 1: User info"). Steps ahead can't be picked.
|
|
43
|
+
*/
|
|
44
|
+
export const GoBack: Story = {
|
|
45
|
+
render: (args) => ({
|
|
46
|
+
components: { Steps, Button },
|
|
47
|
+
setup: () => ({ args, step: ref(2) }),
|
|
48
|
+
template: `
|
|
49
|
+
<div class="flex flex-col gap-4">
|
|
50
|
+
<Steps v-bind="args" v-model:step="step" />
|
|
51
|
+
<div class="flex gap-2">
|
|
52
|
+
<Button size="sm" :disabled="step === args.steps.length - 1" @click="step++">Next</Button>
|
|
53
|
+
</div>
|
|
54
|
+
</div>`,
|
|
55
|
+
}),
|
|
56
|
+
};
|
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
-
import type
|
|
2
|
+
import { computed, getCurrentInstance, type HTMLAttributes } from 'vue'
|
|
3
3
|
import { I18nT } from 'vue-i18n'
|
|
4
4
|
import { cn } from '../../lib/cn'
|
|
5
5
|
import Progress from '../Progress/Progress.vue'
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Where someone is in a set of steps: a segment for each step, filled up to
|
|
9
|
-
* the current one, and "Step 2 of 3
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
9
|
+
* the current one, and "Step 2 of 3 – Licences" under it, as in Slideover's
|
|
10
|
+
* multi-step form. Put it at the top of a multi-step form on a page, or in a
|
|
11
|
+
* Slideover you drive yourself. The words are announced when the step
|
|
12
|
+
* changes.
|
|
13
|
+
*
|
|
14
|
+
* With `v-model:step`, finished segments are buttons ("Back to step 1: User
|
|
15
|
+
* info") that go back to that step; steps ahead can't be picked, so each
|
|
16
|
+
* step's checks still run in order. With just `:step`, it only shows where
|
|
17
|
+
* you are.
|
|
13
18
|
*/
|
|
14
19
|
export interface StepsProps {
|
|
15
20
|
/** The name of each step, in order, e.g. `['User info', 'Licences']`. */
|
|
@@ -18,21 +23,36 @@ export interface StepsProps {
|
|
|
18
23
|
step: number
|
|
19
24
|
/** What the steps are for, e.g. "Add a user". The progress bar's accessible name; not shown. */
|
|
20
25
|
label: string
|
|
26
|
+
/** Stops going back, e.g. while a step saves. */
|
|
27
|
+
disabled?: boolean
|
|
21
28
|
class?: HTMLAttributes['class']
|
|
22
29
|
}
|
|
23
30
|
|
|
24
31
|
const props = defineProps<StepsProps>()
|
|
32
|
+
const emit = defineEmits<{ 'update:step': [step: number] }>()
|
|
33
|
+
|
|
34
|
+
// Going back is offered only when someone is listening (v-model:step).
|
|
35
|
+
const instance = getCurrentInstance()
|
|
36
|
+
const canGoBack = computed(() => !!instance?.vnode.props?.['onUpdate:step'])
|
|
25
37
|
</script>
|
|
26
38
|
|
|
27
39
|
<template>
|
|
28
|
-
<div :class="cn('flex flex-col gap-
|
|
40
|
+
<div :class="cn('flex flex-col gap-2', props.class)">
|
|
41
|
+
<Progress
|
|
42
|
+
:label="label"
|
|
43
|
+
segments
|
|
44
|
+
:value="step + 1"
|
|
45
|
+
:max="steps.length"
|
|
46
|
+
:segment-labels="canGoBack ? steps : undefined"
|
|
47
|
+
:disabled="disabled"
|
|
48
|
+
@select="emit('update:step', $event)"
|
|
49
|
+
/>
|
|
29
50
|
<p class="text-sm text-ink/65" aria-live="polite">
|
|
30
|
-
<I18nT keypath="ui.steps.
|
|
51
|
+
<I18nT keypath="ui.steps.stepOfDash" scope="global" tag="span">
|
|
31
52
|
<template #current>{{ step + 1 }}</template>
|
|
32
53
|
<template #total>{{ steps.length }}</template>
|
|
33
54
|
<template #name><span class="text-ink">{{ steps[step] }}</span></template>
|
|
34
55
|
</I18nT>
|
|
35
56
|
</p>
|
|
36
|
-
<Progress :label="label" segments :value="step + 1" :max="steps.length" />
|
|
37
57
|
</div>
|
|
38
58
|
</template>
|
package/src/i18n/en.ts
CHANGED
|
@@ -75,7 +75,13 @@ export const en = {
|
|
|
75
75
|
formattingFor: 'Formatting for {label}',
|
|
76
76
|
bold: 'Bold',
|
|
77
77
|
italic: 'Italic',
|
|
78
|
-
underline: 'Underline'
|
|
78
|
+
underline: 'Underline',
|
|
79
|
+
link: 'Link',
|
|
80
|
+
linkAddress: 'Link address',
|
|
81
|
+
addLink: 'Add link',
|
|
82
|
+
updateLink: 'Update link',
|
|
83
|
+
removeLink: 'Remove link',
|
|
84
|
+
linkInvalid: 'Enter an address starting with https://, mailto: or tel:'
|
|
79
85
|
},
|
|
80
86
|
alert: { info: 'Information', success: 'Success', warning: 'Warning', error: 'Error', dismiss: 'Dismiss' },
|
|
81
87
|
fileUpload: {
|
|
@@ -84,6 +90,8 @@ export const en = {
|
|
|
84
90
|
dropFile: 'Drop a file here, or choose one.',
|
|
85
91
|
dropFiles: 'Drop files here, or choose them.'
|
|
86
92
|
},
|
|
93
|
+
confirmDialog: { confirm: 'Confirm', cancel: 'Cancel' },
|
|
94
|
+
asyncState: { error: "Couldn't load this", retry: 'Try again' },
|
|
87
95
|
languageSwitcher: { label: 'Language' },
|
|
88
96
|
themeSwitcher: { label: 'Appearance', light: 'Light', dark: 'Dark', system: 'Match device' },
|
|
89
97
|
notifications: {
|
|
@@ -131,7 +139,9 @@ export const en = {
|
|
|
131
139
|
statTile: { up: 'Up', down: 'Down', flat: 'No change' },
|
|
132
140
|
steps: {
|
|
133
141
|
stepOf: 'Step {current} of {total}',
|
|
134
|
-
stepOfNamed: 'Step {current} of {total}: {name}'
|
|
142
|
+
stepOfNamed: 'Step {current} of {total}: {name}',
|
|
143
|
+
/** Under the segments, e.g. "Step 2 of 3 – Licences", as in Slideover. */
|
|
144
|
+
stepOfDash: 'Step {current} of {total} – {name}'
|
|
135
145
|
},
|
|
136
146
|
summaryList: { notSet: 'Not set' },
|
|
137
147
|
table: {
|
package/src/index.ts
CHANGED
|
@@ -49,6 +49,8 @@ export { default as Alert } from './components/Alert/Alert.vue'
|
|
|
49
49
|
export type { AlertProps } from './components/Alert/Alert.vue'
|
|
50
50
|
export { default as Collapsible } from './components/Collapsible/Collapsible.vue'
|
|
51
51
|
export type { CollapsibleProps } from './components/Collapsible/Collapsible.vue'
|
|
52
|
+
export { default as Prose } from './components/Prose/Prose.vue'
|
|
53
|
+
export type { ProseProps } from './components/Prose/Prose.vue'
|
|
52
54
|
|
|
53
55
|
// Form
|
|
54
56
|
export { default as FormField } from './components/FormField/FormField.vue'
|
|
@@ -109,6 +111,10 @@ export { default as BarChart } from './components/BarChart/BarChart.vue'
|
|
|
109
111
|
export type { BarChartProps } from './components/BarChart/BarChart.vue'
|
|
110
112
|
export { default as LineChart } from './components/LineChart/LineChart.vue'
|
|
111
113
|
export type { LineChartProps } from './components/LineChart/LineChart.vue'
|
|
114
|
+
export { default as AsyncState } from './components/AsyncState/AsyncState.vue'
|
|
115
|
+
export type { AsyncStateProps } from './components/AsyncState/AsyncState.vue'
|
|
116
|
+
export { default as ResultState } from './components/ResultState/ResultState.vue'
|
|
117
|
+
export type { ResultStateProps } from './components/ResultState/ResultState.vue'
|
|
112
118
|
|
|
113
119
|
// Navigation
|
|
114
120
|
export { default as Breadcrumb } from './components/Breadcrumb/Breadcrumb.vue'
|
|
@@ -153,6 +159,8 @@ export type {
|
|
|
153
159
|
} from './components/Notification/notifications'
|
|
154
160
|
export { default as UnsavedChangesBar } from './components/UnsavedChangesBar/UnsavedChangesBar.vue'
|
|
155
161
|
export type { UnsavedChangesBarProps } from './components/UnsavedChangesBar/UnsavedChangesBar.vue'
|
|
162
|
+
export { default as ConfirmDialog } from './components/ConfirmDialog/ConfirmDialog.vue'
|
|
163
|
+
export type { ConfirmDialogProps } from './components/ConfirmDialog/ConfirmDialog.vue'
|
|
156
164
|
|
|
157
165
|
// Languages
|
|
158
166
|
export { createKestonI18n, uiMessages, en } from './i18n'
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
2
|
+
import { initials } from './initials'
|
|
3
|
+
|
|
4
|
+
describe('initials', () => {
|
|
5
|
+
it.each([
|
|
6
|
+
['Ben Smith', 'BS'],
|
|
7
|
+
['Ben', 'B'],
|
|
8
|
+
['Mary Jane Watson', 'MW'],
|
|
9
|
+
[' ben smith ', 'BS'],
|
|
10
|
+
['', ''],
|
|
11
|
+
['Keston Admin (support)', 'KA'],
|
|
12
|
+
['Jo Bloggs [guest]', 'JB'],
|
|
13
|
+
["'Jo' Bloggs", 'JB'],
|
|
14
|
+
['Élodie Durand', 'ÉD'],
|
|
15
|
+
['(support)', ''],
|
|
16
|
+
])('%j → %j', (name, want) => {
|
|
17
|
+
expect(initials(name)).toBe(want)
|
|
18
|
+
})
|
|
19
|
+
})
|
package/src/lib/initials.ts
CHANGED
|
@@ -1,8 +1,17 @@
|
|
|
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 function initials(name: string): string {
|
|
3
|
-
const words = name
|
|
8
|
+
const words = name
|
|
9
|
+
.replace(/\([^)]*\)|\[[^\]]*\]/g, ' ')
|
|
10
|
+
.split(/\s+/)
|
|
11
|
+
.map((word) => word.replace(/^[^\p{L}\p{N}]+/u, ''))
|
|
12
|
+
.filter(Boolean)
|
|
4
13
|
if (!words.length) return ''
|
|
5
14
|
const first = words[0]!
|
|
6
15
|
const last = words.length > 1 ? words[words.length - 1]! : ''
|
|
7
|
-
return (first[0]! + (last[0] ?? '')).toUpperCase()
|
|
16
|
+
return ([...first][0]! + ([...last][0] ?? '')).toUpperCase()
|
|
8
17
|
}
|