@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.
Files changed (51) hide show
  1. package/dist/components/ActionList/ActionList.vue.d.ts +13 -2
  2. package/dist/components/AppLauncher/AppLauncher.vue.d.ts +8 -0
  3. package/dist/components/AsyncState/AsyncState.vue.d.ts +53 -0
  4. package/dist/components/ConfirmDialog/ConfirmDialog.vue.d.ts +62 -0
  5. package/dist/components/Footer/Footer.vue.d.ts +2 -2
  6. package/dist/components/Header/Header.vue.d.ts +19 -1
  7. package/dist/components/InputRichText/InputRichText.vue.d.ts +12 -6
  8. package/dist/components/Prose/Prose.vue.d.ts +36 -0
  9. package/dist/components/ResultState/ResultState.vue.d.ts +48 -0
  10. package/dist/components/SegmentedControl/SegmentedControl.vue.d.ts +50 -0
  11. package/dist/components/Steps/Steps.vue.d.ts +16 -5
  12. package/dist/components/ThemeSwitcher/ThemeSwitcher.vue.d.ts +8 -1
  13. package/dist/i18n/en.d.ts +17 -0
  14. package/dist/index.d.ts +11 -1
  15. package/dist/keston-ui.js +2305 -1773
  16. package/dist/lib/initials.d.ts +6 -1
  17. package/package.json +3 -1
  18. package/src/components/ActionList/ActionList.stories.ts +34 -1
  19. package/src/components/ActionList/ActionList.vue +27 -5
  20. package/src/components/AppLauncher/AppLauncher.vue +22 -1
  21. package/src/components/AppLauncher/apps.ts +2 -2
  22. package/src/components/AppShell/AppShell.vue +2 -1
  23. package/src/components/AsyncState/AsyncState.stories.ts +46 -0
  24. package/src/components/AsyncState/AsyncState.vue +78 -0
  25. package/src/components/Button/Button.vue +4 -4
  26. package/src/components/ConfirmDialog/ConfirmDialog.stories.ts +54 -0
  27. package/src/components/ConfirmDialog/ConfirmDialog.vue +119 -0
  28. package/src/components/Footer/Footer.stories.ts +3 -3
  29. package/src/components/Footer/Footer.vue +5 -4
  30. package/src/components/Footer/footer.test.ts +2 -2
  31. package/src/components/Footer/links.ts +3 -3
  32. package/src/components/FormField/FormField.vue +5 -1
  33. package/src/components/Header/Header.stories.ts +25 -12
  34. package/src/components/Header/Header.vue +38 -4
  35. package/src/components/InputRichText/InputRichText.stories.ts +19 -0
  36. package/src/components/InputRichText/InputRichText.vue +129 -13
  37. package/src/components/Notification/Toaster.vue +3 -1
  38. package/src/components/Prose/Prose.stories.ts +46 -0
  39. package/src/components/Prose/Prose.vue +54 -0
  40. package/src/components/ResultState/ResultState.stories.ts +44 -0
  41. package/src/components/ResultState/ResultState.vue +76 -0
  42. package/src/components/SegmentedControl/SegmentedControl.stories.ts +57 -0
  43. package/src/components/SegmentedControl/SegmentedControl.vue +93 -0
  44. package/src/components/Steps/Steps.stories.ts +18 -0
  45. package/src/components/Steps/Steps.vue +28 -8
  46. package/src/components/ThemeSwitcher/ThemeSwitcher.vue +24 -2
  47. package/src/i18n/en.ts +13 -3
  48. package/src/index.ts +11 -1
  49. package/src/lib/initials.test.ts +19 -0
  50. package/src/lib/initials.ts +12 -3
  51. package/src/styles/theme.css +25 -2
@@ -1,2 +1,7 @@
1
- /** "Ben Smith" → "BS", "Ben" → "B", "Mary Jane Watson" → "MW". Empty for an empty name. */
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.16.0",
3
+ "version": "0.19.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
- 'disabled:cursor-not-allowed disabled:opacity-40'
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 divide-y divide-ink/10 overflow-hidden rounded-lg border border-ink/10 bg-surface shadow-xs', props.class)"
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" />
@@ -26,6 +26,8 @@ export interface AppLauncherApp {
26
26
  href: string
27
27
  /** An icon component, or the name of one of the Keston app icons (id, admin, work, utilities, design). */
28
28
  icon?: Component | string
29
+ /** Signs in with Keston ID, so it's given the `loginHint`. Default true. */
30
+ signsIn?: boolean
29
31
  }
30
32
 
31
33
  /**
@@ -45,12 +47,31 @@ export interface AppLauncherProps {
45
47
  align?: 'start' | 'end'
46
48
  /** Name of the button for screen readers. Default "Keston apps". */
47
49
  label?: string
50
+ /**
51
+ * The signed-in person's email. Added to the other apps' links as
52
+ * `?login_hint=`, so they sign in as the same account without asking
53
+ * which. AppShell passes its `user`'s email.
54
+ */
55
+ loginHint?: string
48
56
  class?: HTMLAttributes['class']
49
57
  }
50
58
 
51
59
  const { t } = useI18n()
52
60
  const props = withDefaults(defineProps<AppLauncherProps>(), { apps: () => kestonApps, align: 'end' })
53
61
 
62
+ // The other apps that sign in get ?login_hint=email; the current one, and
63
+ // sites that don't sign in (the design system), don't.
64
+ function hrefOf(app: AppLauncherApp): string {
65
+ if (!props.loginHint || app.id === props.current || app.signsIn === false) return app.href
66
+ try {
67
+ const url = new URL(app.href)
68
+ url.searchParams.set('login_hint', props.loginHint)
69
+ return url.toString()
70
+ } catch {
71
+ return app.href
72
+ }
73
+ }
74
+
54
75
  function iconOf(app: AppLauncherApp): Component {
55
76
  if (typeof app.icon === 'string') return builtInIcons[app.icon] ?? AppWindow
56
77
  return app.icon ?? AppWindow
@@ -67,7 +88,7 @@ function iconOf(app: AppLauncherApp): Component {
67
88
  <ul>
68
89
  <li v-for="app in apps" :key="app.id">
69
90
  <a
70
- :href="app.href"
91
+ :href="hrefOf(app)"
71
92
  :aria-current="app.id === current ? 'page' : undefined"
72
93
  :class="cn(
73
94
  'flex items-center gap-3 rounded-lg px-3 py-2 text-sm font-bold text-ink outline-none hover:bg-hover focus-visible:outline-2 focus-visible:outline-focus',
@@ -5,6 +5,6 @@ export const kestonApps: AppLauncherApp[] = [
5
5
  { id: 'id', label: 'Keston ID', href: 'https://id.keston.co', icon: 'id' },
6
6
  { id: 'admin', label: 'Admin', href: 'https://admin.keston.co', icon: 'admin' },
7
7
  { id: 'work', label: 'Work', href: 'https://work.keston.co', icon: 'work' },
8
- { id: 'utilities', label: 'Utilities', href: 'https://utilities.keston.co', icon: 'utilities' },
9
- { id: 'design', label: 'Design system', href: 'https://ui.keston.co', icon: 'design' }
8
+ { id: 'utilities', label: 'Utilities', href: 'https://utilities.keston.co', icon: 'utilities', signsIn: false },
9
+ { id: 'design', label: 'Design system', href: 'https://ui.keston.co', icon: 'design', signsIn: false }
10
10
  ]
@@ -158,7 +158,8 @@ const sidebarId = `${uid}-sidebar`
158
158
  >
159
159
  <!-- First in the header, to the left of the menu / collapse button. -->
160
160
  <template v-if="launcher" #start>
161
- <AppLauncher align="start" v-bind="launcher === true ? {} : launcher" class="-ml-2.5" />
161
+ <!-- The other apps sign in as the same account (login_hint). -->
162
+ <AppLauncher align="start" :login-hint="user?.email" v-bind="launcher === true ? {} : launcher" class="-ml-2.5" />
162
163
  </template>
163
164
  <template #leading>
164
165
  <!-- Wide screens: in place of the menu button (same look and spot),
@@ -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 (surface fill) takes the solid surface-hover / -pressed colours,
168
- // which lighten in dark mode rather than darken
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 surfaceInteractive = 'not-disabled:not-aria-disabled:hover:bg-surface-hover not-disabled:not-aria-disabled:active:bg-surface-pressed'
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-surface text-ink shadow-xs ${surfaceInteractive}`,
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>
@@ -18,7 +18,7 @@ export default meta
18
18
  type Story = StoryObj<typeof meta>
19
19
 
20
20
  /**
21
- * Playground: use the controls below. Help & support and the legal links on the left; the app's name, version and build,
21
+ * Playground: use the controls below. Help and the legal links on the left; the app's name, version and build,
22
22
  * and the copyright, on the right. Narrow the preview to see it stack.
23
23
  */
24
24
  export const Default: Story = {}
@@ -49,8 +49,8 @@ export const WithGroupLinks: Story = {
49
49
  export const CustomLinks: Story = {
50
50
  args: {
51
51
  links: [
52
- { label: 'Help & support', href: '#help', newTab: false },
53
- { label: 'Privacy Policy', href: '#privacy', newTab: false },
52
+ { label: 'Help', href: '#help', newTab: false },
53
+ { label: 'Privacy', href: '#privacy', newTab: false },
54
54
  { label: 'Terms of use', href: '#terms', newTab: false },
55
55
  ],
56
56
  },
@@ -19,7 +19,7 @@ export interface FooterLink {
19
19
  }
20
20
 
21
21
  /**
22
- * The bottom of an app's page: on the left Help & support and the legal links (Privacy Policy, Terms & Conditions), and
22
+ * The bottom of an app's page: on the left Help and the legal links (Privacy, Terms), and
23
23
  * on the right the app's name, version and build (so a bug report can say exactly which build) with
24
24
  * the copyright. The same in every Keston app; pass the app's `version` and `build`.
25
25
  *
@@ -35,7 +35,7 @@ export interface FooterLink {
35
35
  * Slots: nav (instead of the whole link list), end (after the copyright).
36
36
  */
37
37
  export interface FooterProps {
38
- /** The links on the left. Default: `kestonFooterLinks` (Help & support, Privacy Policy, Terms & Conditions). */
38
+ /** The links on the left. Default: `kestonFooterLinks` (Help, Privacy, Terms). */
39
39
  links?: FooterLink[]
40
40
  /** More links after a divider, e.g. Contact us, or `kestonGroupLinks` to point at the other Keston apps. */
41
41
  moreLinks?: FooterLink[]
@@ -116,10 +116,11 @@ function linkAttrs(link: FooterLink) {
116
116
  </nav>
117
117
 
118
118
  <div :class="cn('flex flex-wrap items-center gap-x-3 gap-y-2 sm:justify-end', ui?.meta)">
119
- <!-- Language and appearance: compact dropdowns, labelled for screen readers. -->
119
+ <!-- Language (a compact dropdown) and appearance (Light / Dark / System
120
+ side by side), labelled for screen readers. -->
120
121
  <div v-if="showLanguages || themeSwitcher" class="flex flex-wrap items-center gap-2">
121
122
  <LanguageSwitcher v-if="showLanguages" hide-label class="w-44" />
122
- <ThemeSwitcher v-if="themeSwitcher" hide-label class="w-44" />
123
+ <ThemeSwitcher v-if="themeSwitcher" hide-label appearance="segmented" />
123
124
  </div>
124
125
  <p v-if="appName || version || build" class="flex flex-wrap items-baseline gap-x-1.5">
125
126
  <span v-if="appName" class="font-bold text-ink/80">{{ appName }}</span>
@@ -27,8 +27,8 @@ describe('version', () => {
27
27
  })
28
28
 
29
29
  describe('kestonFooterLinks', () => {
30
- it('are Help & support, Privacy Policy and Terms & Conditions, on secure thekestongroup.com addresses', () => {
31
- expect(kestonFooterLinks.map((l) => l.label)).toEqual(['Help & support', 'Privacy Policy', 'Terms & Conditions'])
30
+ it('are Help, Privacy and Terms, on secure thekestongroup.com addresses', () => {
31
+ expect(kestonFooterLinks.map((l) => l.label)).toEqual(['Help', 'Privacy', 'Terms'])
32
32
  for (const link of kestonFooterLinks) expect(link.href).toMatch(/^https:\/\/thekestongroup\.com\/(help|privacy|terms)$/)
33
33
  })
34
34
  })
@@ -5,9 +5,9 @@ import type { FooterLink } from './Footer.vue'
5
5
  * Apps can pass their own `links`, or add to these with `moreLinks`.
6
6
  */
7
7
  export const kestonFooterLinks: FooterLink[] = [
8
- { label: 'Help & support', href: 'https://thekestongroup.com/help' },
9
- { label: 'Privacy Policy', href: 'https://thekestongroup.com/privacy' },
10
- { label: 'Terms & Conditions', href: 'https://thekestongroup.com/terms' }
8
+ { label: 'Help', href: 'https://thekestongroup.com/help' },
9
+ { label: 'Privacy', href: 'https://thekestongroup.com/privacy' },
10
+ { label: 'Terms', href: 'https://thekestongroup.com/terms' }
11
11
  ]
12
12
 
13
13
  /** Links to the rest of the Keston Group. Not shown by default: pass them as `moreLinks` where an app should offer them. */
@@ -117,7 +117,11 @@ const box = [
117
117
  'has-focus-visible:outline-focus',
118
118
  // A control can mark itself data-pointer-focus to hide the ring while it
119
119
  // holds focus that came from the mouse (Select, after its list closes).
120
- 'has-[[data-pointer-focus]]:outline-transparent!'
120
+ 'has-[[data-pointer-focus]]:outline-transparent!',
121
+ // Filled in by the browser (saved email or password): the whole field is
122
+ // tinted, rounded corners and padding included, rather than the browser
123
+ // painting a square behind the text only (theme.css keeps that off).
124
+ 'has-[input:autofill]:bg-autofill has-[input:-webkit-autofill]:bg-autofill'
121
125
  ]
122
126
 
123
127
  const statusBorder: Record<FormFieldStatus, string> = {