@thekestongroup/ui 0.16.0 → 0.19.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/AppLauncher/AppLauncher.vue.d.ts +8 -0
- package/dist/components/AsyncState/AsyncState.vue.d.ts +53 -0
- package/dist/components/ConfirmDialog/ConfirmDialog.vue.d.ts +62 -0
- package/dist/components/Footer/Footer.vue.d.ts +2 -2
- package/dist/components/Header/Header.vue.d.ts +19 -1
- 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/SegmentedControl/SegmentedControl.vue.d.ts +50 -0
- package/dist/components/Steps/Steps.vue.d.ts +16 -5
- package/dist/components/ThemeSwitcher/ThemeSwitcher.vue.d.ts +8 -1
- package/dist/i18n/en.d.ts +17 -0
- package/dist/index.d.ts +11 -1
- package/dist/keston-ui.js +2305 -1773
- 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/AppLauncher/AppLauncher.vue +22 -1
- package/src/components/AppLauncher/apps.ts +2 -2
- package/src/components/AppShell/AppShell.vue +2 -1
- 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/Footer/Footer.stories.ts +3 -3
- package/src/components/Footer/Footer.vue +5 -4
- package/src/components/Footer/footer.test.ts +2 -2
- package/src/components/Footer/links.ts +3 -3
- package/src/components/FormField/FormField.vue +5 -1
- package/src/components/Header/Header.stories.ts +25 -12
- package/src/components/Header/Header.vue +38 -4
- 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/SegmentedControl/SegmentedControl.stories.ts +57 -0
- package/src/components/SegmentedControl/SegmentedControl.vue +93 -0
- package/src/components/Steps/Steps.stories.ts +18 -0
- package/src/components/Steps/Steps.vue +28 -8
- package/src/components/ThemeSwitcher/ThemeSwitcher.vue +24 -2
- package/src/i18n/en.ts +13 -3
- package/src/index.ts +11 -1
- package/src/lib/initials.test.ts +19 -0
- package/src/lib/initials.ts +12 -3
- package/src/styles/theme.css +25 -2
|
@@ -195,19 +195,32 @@ export const WithMiddle: Story = {
|
|
|
195
195
|
}),
|
|
196
196
|
};
|
|
197
197
|
|
|
198
|
-
|
|
198
|
+
// A made-up app icon (a rounded square with a K) and lockup, as data URLs.
|
|
199
|
+
const sampleIcon =
|
|
200
|
+
"data:image/svg+xml," +
|
|
201
|
+
encodeURIComponent(
|
|
202
|
+
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><rect width="24" height="24" rx="6" fill="#023750"/><path d="M8 6v12M8 12l7-6M10.5 10l5 8" stroke="#fff" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round" fill="none"/></svg>',
|
|
203
|
+
);
|
|
204
|
+
const sampleLockup =
|
|
205
|
+
"data:image/svg+xml," +
|
|
206
|
+
encodeURIComponent(
|
|
207
|
+
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 150 24"><rect width="24" height="24" rx="6" fill="#023750"/><path d="M8 6v12M8 12l7-6M10.5 10l5 8" stroke="#fff" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round" fill="none"/><text x="32" y="18" font-family="Lato, sans-serif" font-weight="700" font-size="16" fill="#023750">Admissions</text></svg>',
|
|
208
|
+
);
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* logo: the app's icon before its name, sized to the text and inside the
|
|
212
|
+
* title link (hover it). Pass `{ light, dark }` for a dark-mode version.
|
|
213
|
+
*/
|
|
199
214
|
export const WithLogo: Story = {
|
|
200
|
-
args: {
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
</Header>`,
|
|
210
|
-
}),
|
|
215
|
+
args: { logo: sampleIcon, titleTo: "#home" },
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* lockup: icon and name in one image, in place of the title text. Its alt
|
|
220
|
+
* text is the title.
|
|
221
|
+
*/
|
|
222
|
+
export const WithLockup: Story = {
|
|
223
|
+
args: { lockup: sampleLockup, titleTo: "#home" },
|
|
211
224
|
};
|
|
212
225
|
|
|
213
226
|
/** Stays at the top while the page scrolls (the default). Scroll the box below. */
|
|
@@ -19,6 +19,9 @@ export interface HeaderUser {
|
|
|
19
19
|
|
|
20
20
|
export type HeaderUserAction = 'account-settings' | 'switch-account' | 'log-out'
|
|
21
21
|
|
|
22
|
+
/** An image, with an optional version for dark mode (e.g. white). */
|
|
23
|
+
export type HeaderImage = string | { light: string; dark?: string }
|
|
24
|
+
|
|
22
25
|
/**
|
|
23
26
|
* The bar across the top of every Keston app. It is the same in every app:
|
|
24
27
|
* a menu button (to open the Sidebar on small screens), the app's name, an
|
|
@@ -26,7 +29,9 @@ export type HeaderUserAction = 'account-settings' | 'switch-account' | 'log-out'
|
|
|
26
29
|
* the right (Account settings, Switch account, Log out). Each part can be
|
|
27
30
|
* overridden with a slot.
|
|
28
31
|
*
|
|
29
|
-
*
|
|
32
|
+
* The app's brand: `title` with a `logo` (icon) beside it, or a `lockup` (one image).
|
|
33
|
+
*
|
|
34
|
+
* Slots: start (the very first thing, before the menu button, e.g. the app launcher; give it a `-ml-2.5` button to line up with the padding), leading (before the title), title, default (the middle,
|
|
30
35
|
* fills the space between title and trailing), trailing (actions before the
|
|
31
36
|
* account menu), account (replaces the account menu, or the Sign in button),
|
|
32
37
|
* account-menu (extra content in the account menu, above Switch account /
|
|
@@ -37,6 +42,17 @@ export type HeaderUserAction = 'account-settings' | 'switch-account' | 'log-out'
|
|
|
37
42
|
export interface HeaderProps {
|
|
38
43
|
/** Name of the app or area, shown next to the menu button. */
|
|
39
44
|
title?: string
|
|
45
|
+
/**
|
|
46
|
+
* The app's icon, before its name: sized to the text (20px) and part of
|
|
47
|
+
* the title link. Decorative: the name is what's read out. Use this or
|
|
48
|
+
* `lockup`.
|
|
49
|
+
*/
|
|
50
|
+
logo?: HeaderImage
|
|
51
|
+
/**
|
|
52
|
+
* The app's lockup (icon and name in one image), in place of the title
|
|
53
|
+
* text, 24px tall and part of the title link. Its alt text is `title`.
|
|
54
|
+
*/
|
|
55
|
+
lockup?: HeaderImage
|
|
40
56
|
/**
|
|
41
57
|
* Make the title a link, e.g. to the app's dashboard: passed as `to` to
|
|
42
58
|
* `linkComponent` (e.g. a route), or as `href` without one.
|
|
@@ -139,6 +155,10 @@ const titleLinkClass = [
|
|
|
139
155
|
'outline-2 outline-offset-1 outline-transparent focus-visible:outline-focus forced-colors:not-focus-visible:outline-0'
|
|
140
156
|
]
|
|
141
157
|
|
|
158
|
+
const image = (i: HeaderImage | undefined) => (typeof i === 'string' ? { light: i, dark: undefined } : i)
|
|
159
|
+
const logoImage = computed(() => image(props.logo))
|
|
160
|
+
const lockupImage = computed(() => image(props.lockup))
|
|
161
|
+
|
|
142
162
|
function runAction(action: HeaderUserAction, close: () => void) {
|
|
143
163
|
close()
|
|
144
164
|
// Vue can't emit a name held in a variable with full typing, so switch.
|
|
@@ -176,13 +196,27 @@ function runAction(action: HeaderUserAction, close: () => void) {
|
|
|
176
196
|
|
|
177
197
|
<slot name="leading" />
|
|
178
198
|
|
|
199
|
+
<!-- The app's name (with its icon), or its lockup: all inside the title
|
|
200
|
+
link, so the whole thing goes home and gets the hover background. -->
|
|
179
201
|
<component
|
|
180
202
|
:is="titleLink ? linkComponent : 'span'"
|
|
181
|
-
v-if="title || $slots.title"
|
|
203
|
+
v-if="title || lockup || $slots.title"
|
|
182
204
|
v-bind="titleLink"
|
|
183
|
-
:class="cn('min-w-0
|
|
205
|
+
:class="cn('flex min-w-0 items-center gap-2 text-base font-bold', titleLink && titleLinkClass, ui?.title)"
|
|
184
206
|
>
|
|
185
|
-
<slot name="title">
|
|
207
|
+
<slot name="title">
|
|
208
|
+
<template v-if="lockupImage">
|
|
209
|
+
<img :src="lockupImage.light" :alt="title ?? ''" :class="cn('h-6 w-auto max-w-full', lockupImage.dark && 'dark:hidden')" />
|
|
210
|
+
<img v-if="lockupImage.dark" :src="lockupImage.dark" :alt="title ?? ''" class="hidden h-6 w-auto max-w-full dark:block" />
|
|
211
|
+
</template>
|
|
212
|
+
<template v-else>
|
|
213
|
+
<template v-if="logoImage">
|
|
214
|
+
<img :src="logoImage.light" alt="" :class="cn('size-5 shrink-0', logoImage.dark && 'dark:hidden')" />
|
|
215
|
+
<img v-if="logoImage.dark" :src="logoImage.dark" alt="" class="hidden size-5 shrink-0 dark:block" />
|
|
216
|
+
</template>
|
|
217
|
+
<span class="truncate">{{ title }}</span>
|
|
218
|
+
</template>
|
|
219
|
+
</slot>
|
|
186
220
|
</component>
|
|
187
221
|
|
|
188
222
|
<div :class="cn('flex min-w-0 flex-1 items-center', ui?.middle)">
|
|
@@ -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
|
+
};
|
|
@@ -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>
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from "@storybook/vue3-vite";
|
|
2
|
+
import { List, LayoutGrid, Monitor, Moon, Sun } from "@lucide/vue";
|
|
3
|
+
import { ref } from "vue";
|
|
4
|
+
import SegmentedControl from "./SegmentedControl.vue";
|
|
5
|
+
|
|
6
|
+
const meta = {
|
|
7
|
+
title: "Components/Form/SegmentedControl",
|
|
8
|
+
component: SegmentedControl,
|
|
9
|
+
tags: ["autodocs"],
|
|
10
|
+
parameters: { layout: "padded" },
|
|
11
|
+
args: {
|
|
12
|
+
label: "Appearance",
|
|
13
|
+
options: [
|
|
14
|
+
{ label: "Light", value: "light", icon: Sun },
|
|
15
|
+
{ label: "Dark", value: "dark", icon: Moon },
|
|
16
|
+
{ label: "System", value: "system", icon: Monitor },
|
|
17
|
+
],
|
|
18
|
+
},
|
|
19
|
+
render: (args) => ({
|
|
20
|
+
components: { SegmentedControl },
|
|
21
|
+
setup: () => ({ args, value: ref(args.options[0]?.value) }),
|
|
22
|
+
template: `<SegmentedControl v-bind="args" v-model="value" />`,
|
|
23
|
+
}),
|
|
24
|
+
} satisfies Meta<typeof SegmentedControl>;
|
|
25
|
+
|
|
26
|
+
export default meta;
|
|
27
|
+
type Story = StoryObj<typeof meta>;
|
|
28
|
+
|
|
29
|
+
/** Light, Dark or System, with icons. Arrow keys move the choice. */
|
|
30
|
+
export const Default: Story = {};
|
|
31
|
+
|
|
32
|
+
/** Small, with the label for screen readers only: for a footer or toolbar. */
|
|
33
|
+
export const Small: Story = { args: { size: "sm", hideLabel: true } };
|
|
34
|
+
|
|
35
|
+
/** Icons only: each label is the option's accessible name and its tooltip. */
|
|
36
|
+
export const IconOnly: Story = {
|
|
37
|
+
args: {
|
|
38
|
+
label: "View",
|
|
39
|
+
iconOnly: true,
|
|
40
|
+
options: [
|
|
41
|
+
{ label: "List", value: "list", icon: List },
|
|
42
|
+
{ label: "Grid", value: "grid", icon: LayoutGrid },
|
|
43
|
+
],
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/** Without icons, one option turned off. */
|
|
48
|
+
export const Plain: Story = {
|
|
49
|
+
args: {
|
|
50
|
+
label: "Period",
|
|
51
|
+
options: [
|
|
52
|
+
{ label: "Day", value: "day" },
|
|
53
|
+
{ label: "Week", value: "week" },
|
|
54
|
+
{ label: "Term", value: "term", disabled: true },
|
|
55
|
+
],
|
|
56
|
+
},
|
|
57
|
+
};
|