@thekestongroup/ui 0.15.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.
Files changed (78) hide show
  1. package/dist/components/ActionList/ActionList.vue.d.ts +74 -0
  2. package/dist/components/Alert/Alert.vue.d.ts +55 -0
  3. package/dist/components/AsyncState/AsyncState.vue.d.ts +53 -0
  4. package/dist/components/AvatarGroup/AvatarGroup.vue.d.ts +1 -1
  5. package/dist/components/BarChart/BarChart.vue.d.ts +37 -0
  6. package/dist/components/BarChart/ChartData.vue.d.ts +20 -0
  7. package/dist/components/Button/Button.vue.d.ts +1 -1
  8. package/dist/components/Collapsible/Collapsible.vue.d.ts +48 -0
  9. package/dist/components/ConfirmDialog/ConfirmDialog.vue.d.ts +62 -0
  10. package/dist/components/FileUpload/FileUpload.vue.d.ts +55 -0
  11. package/dist/components/Footer/Footer.vue.d.ts +11 -1
  12. package/dist/components/Header/Header.vue.d.ts +1 -1
  13. package/dist/components/InputRichText/InputRichText.vue.d.ts +12 -6
  14. package/dist/components/LineChart/LineChart.vue.d.ts +37 -0
  15. package/dist/components/Notification/Notification.vue.d.ts +2 -2
  16. package/dist/components/Progress/Progress.vue.d.ts +14 -1
  17. package/dist/components/Prose/Prose.vue.d.ts +36 -0
  18. package/dist/components/ResultState/ResultState.vue.d.ts +48 -0
  19. package/dist/components/Slideover/Slideover.vue.d.ts +7 -5
  20. package/dist/components/Spinner/Spinner.vue.d.ts +1 -1
  21. package/dist/components/Steps/Steps.vue.d.ts +16 -5
  22. package/dist/components/ThemeSwitcher/ThemeSwitcher.vue.d.ts +18 -0
  23. package/dist/i18n/en.d.ts +43 -0
  24. package/dist/index.d.ts +25 -0
  25. package/dist/keston-ui.js +5287 -4028
  26. package/dist/lib/chart.d.ts +32 -0
  27. package/dist/lib/initials.d.ts +6 -1
  28. package/dist/lib/theme.d.ts +23 -0
  29. package/package.json +10 -3
  30. package/src/components/ActionList/ActionList.stories.ts +92 -0
  31. package/src/components/ActionList/ActionList.vue +138 -0
  32. package/src/components/Alert/Alert.stories.ts +65 -0
  33. package/src/components/Alert/Alert.vue +110 -0
  34. package/src/components/AsyncState/AsyncState.stories.ts +46 -0
  35. package/src/components/AsyncState/AsyncState.vue +78 -0
  36. package/src/components/BarChart/BarChart.stories.ts +62 -0
  37. package/src/components/BarChart/BarChart.vue +153 -0
  38. package/src/components/BarChart/ChartData.vue +64 -0
  39. package/src/components/Button/Button.vue +4 -4
  40. package/src/components/Calendar/Calendar.vue +3 -2
  41. package/src/components/CardSelect/CardSelect.vue +1 -1
  42. package/src/components/Checkbox/Checkbox.vue +1 -1
  43. package/src/components/CheckboxGroup/CheckboxGroup.vue +1 -1
  44. package/src/components/Collapsible/Collapsible.stories.ts +32 -0
  45. package/src/components/Collapsible/Collapsible.vue +68 -0
  46. package/src/components/ConfirmDialog/ConfirmDialog.stories.ts +54 -0
  47. package/src/components/ConfirmDialog/ConfirmDialog.vue +119 -0
  48. package/src/components/FileUpload/FileUpload.stories.ts +38 -0
  49. package/src/components/FileUpload/FileUpload.vue +150 -0
  50. package/src/components/Footer/Footer.stories.ts +10 -2
  51. package/src/components/Footer/Footer.vue +22 -4
  52. package/src/components/Header/Header.stories.ts +20 -0
  53. package/src/components/InputRichText/InputRichText.stories.ts +19 -0
  54. package/src/components/InputRichText/InputRichText.vue +129 -13
  55. package/src/components/LineChart/LineChart.stories.ts +47 -0
  56. package/src/components/LineChart/LineChart.vue +173 -0
  57. package/src/components/Notification/Toaster.vue +3 -1
  58. package/src/components/Progress/Progress.stories.ts +18 -0
  59. package/src/components/Progress/Progress.vue +57 -0
  60. package/src/components/Prose/Prose.stories.ts +46 -0
  61. package/src/components/Prose/Prose.vue +54 -0
  62. package/src/components/RadioGroup/RadioGroup.vue +2 -2
  63. package/src/components/ResultState/ResultState.stories.ts +44 -0
  64. package/src/components/ResultState/ResultState.vue +76 -0
  65. package/src/components/Select/Select.vue +6 -4
  66. package/src/components/Slideover/Slideover.vue +107 -31
  67. package/src/components/Steps/Steps.stories.ts +18 -0
  68. package/src/components/Steps/Steps.vue +28 -8
  69. package/src/components/ThemeSwitcher/ThemeSwitcher.stories.ts +22 -0
  70. package/src/components/ThemeSwitcher/ThemeSwitcher.vue +48 -0
  71. package/src/components/Tooltip/Tooltip.vue +1 -1
  72. package/src/i18n/en.ts +29 -7
  73. package/src/index.ts +25 -0
  74. package/src/lib/chart.ts +47 -0
  75. package/src/lib/initials.test.ts +19 -0
  76. package/src/lib/initials.ts +12 -3
  77. package/src/lib/theme.ts +75 -0
  78. package/src/styles/theme.css +34 -2
@@ -0,0 +1,32 @@
1
+ /** One series in a chart: a name for the legend and table, and its colour slot. */
2
+ export interface ChartSeries {
3
+ /** The key of this series' number in each point's `values`. */
4
+ key: string;
5
+ /** Its name in the legend, the tooltip and the table, e.g. "Failed". */
6
+ label: string;
7
+ /**
8
+ * Which of the eight chart colours (1–8). Default: the series' place in
9
+ * the list. Set it so a series keeps its colour when others are filtered
10
+ * out, e.g. failed sign-ins always red (8).
11
+ */
12
+ color?: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8;
13
+ }
14
+ /** One point along the chart: a day, a month, a school. */
15
+ export interface ChartPoint {
16
+ /** Short label under the bar or along the axis, e.g. "Mon". */
17
+ label: string;
18
+ /** Full label for the tooltip and table, e.g. "Monday 24 November". Default `label`. */
19
+ fullLabel?: string;
20
+ /** A number for each series, by its key. Missing counts as 0. */
21
+ values: Record<string, number | null | undefined>;
22
+ }
23
+ export declare function seriesColor(series: ChartSeries, index: number): string;
24
+ export declare const valueOf: (point: ChartPoint, key: string) => number;
25
+ /**
26
+ * A clean top for the value axis and the ticks up to it: 0, 5, 10, 15
27
+ * rather than 0, 4.3, 8.6, 12.9. About `count` steps of 1, 2, 2.5 or 5 × 10ⁿ.
28
+ */
29
+ export declare function niceScale(max: number, count?: number): {
30
+ max: number;
31
+ ticks: number[];
32
+ };
@@ -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;
@@ -0,0 +1,23 @@
1
+ import { Ref } from 'vue';
2
+ /**
3
+ * Light, dark or following the device. Keston UI's colours switch with the
4
+ * `data-theme` attribute on `<html>` (see theme.css, "Dark mode").
5
+ */
6
+ export type Theme = 'light' | 'dark' | 'system';
7
+ /**
8
+ * Applies the person's saved choice (or `fallback` if there is none) and keeps
9
+ * other tabs in step. Call it once in main.ts, before mounting, so the page
10
+ * doesn't flash the wrong colours:
11
+ *
12
+ * initTheme() // follows the device until someone picks
13
+ * initTheme('light') // an app that starts light
14
+ */
15
+ export declare function initTheme(fallback?: Theme): void;
16
+ /**
17
+ * The current theme and a way to change it, e.g. for ThemeSwitcher. A change
18
+ * applies at once and is remembered in this browser.
19
+ */
20
+ export declare function useTheme(): {
21
+ theme: Readonly<Ref<Theme>>;
22
+ setTheme: (theme: Theme) => void;
23
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thekestongroup/ui",
3
- "version": "0.15.0",
3
+ "version": "0.18.0",
4
4
  "description": "Keston UI — Vue 3 + Reka UI + Tailwind CSS component library",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "repository": {
@@ -34,7 +34,9 @@
34
34
  "docs:preview": "vitepress preview site",
35
35
  "new": "node scripts/new-component.mjs",
36
36
  "changeset": "changeset",
37
- "test": "vitest run",
37
+ "tokens": "node scripts/build-tokens.mjs",
38
+ "test": "vitest run --project unit",
39
+ "test:a11y": "VITE_THEME=light vitest run --project stories && VITE_THEME=dark vitest run --project stories",
38
40
  "test:watch": "vitest"
39
41
  },
40
42
  "peerDependencies": {
@@ -55,6 +57,7 @@
55
57
  "@tiptap/extension-document": "^3.33.1",
56
58
  "@tiptap/extension-hard-break": "^3.33.1",
57
59
  "@tiptap/extension-italic": "^3.33.1",
60
+ "@tiptap/extension-link": "^3.33.1",
58
61
  "@tiptap/extension-paragraph": "^3.33.1",
59
62
  "@tiptap/extension-text": "^3.33.1",
60
63
  "@tiptap/extension-underline": "^3.33.1",
@@ -69,12 +72,16 @@
69
72
  "@changesets/cli": "^3.0.3",
70
73
  "@storybook/addon-a11y": "^10.6.5",
71
74
  "@storybook/addon-docs": "^10.6.5",
75
+ "@storybook/addon-vitest": "^10.6.9",
72
76
  "@storybook/builder-vite": "^10.6.5",
73
77
  "@storybook/vue3-vite": "^10.6.5",
74
78
  "@tailwindcss/vite": "^4.3.4",
75
79
  "@types/node": "^26.6.6",
76
80
  "@vitejs/plugin-vue": "^6.0.10",
81
+ "@vitest/browser": "^5.1.2",
82
+ "@vitest/browser-playwright": "^5.1.2",
77
83
  "@vue/tsconfig": "^0.9.1",
84
+ "playwright": "^1.65.1",
78
85
  "remark-gfm": "^4.0.1",
79
86
  "storybook": "^10.6.5",
80
87
  "tailwindcss": "^4.3.4",
@@ -82,7 +89,7 @@
82
89
  "vite": "^8.3.5",
83
90
  "vite-plugin-dts": "^5.1.2",
84
91
  "vitepress": "1.6.4",
85
- "vitest": "^5.1.0",
92
+ "vitest": "^5.1.2",
86
93
  "vue": "^3.5.44",
87
94
  "vue-i18n": "^11.4.20",
88
95
  "vue-tsc": "^3.3.14"
@@ -0,0 +1,92 @@
1
+ import type { Meta, StoryObj } from '@storybook/vue3-vite'
2
+ import { Building2, Search, UserRound } from '@lucide/vue'
3
+ import ActionList from './ActionList.vue'
4
+ import Avatar from '../Avatar/Avatar.vue'
5
+ import Badge from '../Badge/Badge.vue'
6
+ import Button from '../Button/Button.vue'
7
+ import Card from '../Card/Card.vue'
8
+
9
+ const meta = {
10
+ title: 'Components/Navigation/ActionList',
11
+ component: ActionList,
12
+ tags: ['autodocs'],
13
+ args: {
14
+ label: 'Your organisations',
15
+ items: [
16
+ { label: 'The Keston School', description: 'keston.school', icon: Building2, current: true },
17
+ { label: 'Keston Prep', description: 'prep.keston.school', icon: Building2 },
18
+ { label: 'Keston Sixth Form', description: "You don't have access to manage it", icon: Building2, disabled: true },
19
+ { label: 'Browse all organisations', description: 'Search every organisation on Keston', icon: Search },
20
+ ],
21
+ },
22
+ decorators: [() => ({ template: '<div class="max-w-md"><story /></div>' })],
23
+ } satisfies Meta<typeof ActionList>
24
+
25
+ export default meta
26
+ type Story = StoryObj<typeof meta>
27
+
28
+ export const Default: Story = {}
29
+
30
+ /** Accounts: an Avatar in the leading slot, a Badge after the name, one switching. */
31
+ export const Accounts: Story = {
32
+ args: {
33
+ label: 'Signed-in accounts',
34
+ items: [
35
+ { key: '1', label: 'Ben Smith', description: 'ben.smith@keston.school' },
36
+ { key: '2', label: 'Jo Bloggs', description: 'jo.bloggs@keston.school', loading: true },
37
+ ],
38
+ },
39
+ render: (args) => ({
40
+ components: { ActionList, Avatar, Badge },
41
+ setup: () => ({ args }),
42
+ template: `
43
+ <ActionList v-bind="args">
44
+ <template #leading="{ item }"><Avatar :user="{ name: item.label }" size="md" decorative /></template>
45
+ <template #badges="{ item }"><Badge v-if="item.key === '1'" size="sm" color="green">Using now</Badge></template>
46
+ </ActionList>`,
47
+ }),
48
+ }
49
+
50
+ /** A second action beside a row, outside its button: e.g. Leave. */
51
+ export const WithAfter: Story = {
52
+ render: (args) => ({
53
+ components: { ActionList, Button },
54
+ setup: () => ({ args }),
55
+ template: `
56
+ <ActionList v-bind="args">
57
+ <template #after="{ item }"><Button v-if="item.label === 'Keston Prep'" size="sm">Leave</Button></template>
58
+ </ActionList>`,
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
+ }
@@ -0,0 +1,138 @@
1
+ <script setup lang="ts">
2
+ import type { Component, HTMLAttributes } from 'vue'
3
+ import { ChevronRight } from '@lucide/vue'
4
+ import { cn } from '../../lib/cn'
5
+ import Spinner from '../Spinner/Spinner.vue'
6
+
7
+ export interface ActionListItem {
8
+ /** Unique key. Default the label. */
9
+ key?: string
10
+ label: string
11
+ /** A second line, e.g. an email address or a domain. */
12
+ description?: string
13
+ /** An icon before the text (or use the leading slot, e.g. for an Avatar). */
14
+ icon?: Component
15
+ /** Go somewhere through `linkComponent` (e.g. RouterLink), which receives `to`. */
16
+ to?: unknown
17
+ /** Go to a URL. */
18
+ href?: string
19
+ disabled?: boolean
20
+ /** The one you're on now (aria-current). */
21
+ current?: boolean
22
+ /** Show a spinner in place of the arrow, e.g. while switching to it. */
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
26
+ }
27
+
28
+ /**
29
+ * A list of things to pick one of and go to: accounts to switch to,
30
+ * organisations, connected apps. Each row is a single button or link with an
31
+ * optional icon or avatar, a name and a line under it, and an arrow, in a
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.
35
+ *
36
+ * Rows without `to` / `href` are buttons that emit `select`.
37
+ *
38
+ * Slots, each given `{ item }`: leading (before the text, e.g. an Avatar),
39
+ * badges (after the name, e.g. "Current"), after (beside the row, outside
40
+ * the button, e.g. a Leave button).
41
+ */
42
+ export interface ActionListProps {
43
+ items: ActionListItem[]
44
+ /** What the list is, for screen readers, e.g. "Signed-in accounts". */
45
+ label: string
46
+ /** Component used for rows with `to`, e.g. RouterLink. */
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
52
+ class?: HTMLAttributes['class']
53
+ }
54
+
55
+ const props = withDefaults(defineProps<ActionListProps>(), {
56
+ appearance: 'boxed',
57
+ chevron: true
58
+ })
59
+ const emit = defineEmits<{ select: [item: ActionListItem] }>()
60
+
61
+ defineSlots<{
62
+ leading?(props: { item: ActionListItem }): unknown
63
+ badges?(props: { item: ActionListItem }): unknown
64
+ after?(props: { item: ActionListItem }): unknown
65
+ }>()
66
+
67
+ function tagFor(item: ActionListItem) {
68
+ if (item.disabled) return 'button'
69
+ if (item.to !== undefined) return props.linkComponent ?? 'a'
70
+ if (item.href !== undefined) return 'a'
71
+ return 'button'
72
+ }
73
+
74
+ function attrsFor(item: ActionListItem) {
75
+ if (item.disabled) return { type: 'button', disabled: true }
76
+ if (item.to !== undefined) return { to: item.to }
77
+ if (item.href !== undefined) return { href: item.href }
78
+ return { type: 'button' }
79
+ }
80
+
81
+ function onClick(item: ActionListItem) {
82
+ if (!item.disabled && item.to === undefined && item.href === undefined) emit('select', item)
83
+ }
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
+
92
+ // The whole row presses; hover and press tint it, focus rings it inside the box.
93
+ const row = [
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',
95
+ 'not-disabled:hover:bg-hover not-disabled:active:bg-pressed aria-[current=true]:bg-selected',
96
+ 'outline-2 -outline-offset-2 outline-transparent focus-visible:outline-focus',
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'
100
+ ]
101
+ </script>
102
+
103
+ <template>
104
+ <!-- overflow-hidden: the rows' tint follows the rounded corners. -->
105
+ <ul
106
+ :aria-label="label"
107
+ :class="cn('flex flex-col', lists[appearance], props.class)"
108
+ >
109
+ <li v-for="item in items" :key="item.key ?? item.label" class="flex items-center">
110
+ <component
111
+ :is="tagFor(item)"
112
+ v-bind="attrsFor(item)"
113
+ :aria-current="item.current ? 'true' : undefined"
114
+ :aria-busy="item.loading || undefined"
115
+ :class="row"
116
+ @click="onClick(item)"
117
+ >
118
+ <slot name="leading" :item="item">
119
+ <component :is="item.icon" v-if="item.icon" class="size-5 shrink-0 text-ink/65" aria-hidden="true" />
120
+ </slot>
121
+ <span class="flex min-w-0 flex-1 flex-col">
122
+ <span class="flex min-w-0 items-center gap-2">
123
+ <span class="truncate text-sm font-bold">{{ item.label }}</span>
124
+ <slot name="badges" :item="item" />
125
+ </span>
126
+ <span v-if="item.description" class="truncate text-xs text-ink/65">{{ item.description }}</span>
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>
130
+ <Spinner v-if="item.loading" size="sm" />
131
+ <ChevronRight v-else-if="chevron && !item.disabled" class="size-4 shrink-0 text-ink/55" aria-hidden="true" />
132
+ </component>
133
+ <div v-if="$slots.after" class="shrink-0 pr-3 empty:hidden">
134
+ <slot name="after" :item="item" />
135
+ </div>
136
+ </li>
137
+ </ul>
138
+ </template>
@@ -0,0 +1,65 @@
1
+ import type { Meta, StoryObj } from '@storybook/vue3-vite'
2
+ import { LifeBuoy } from '@lucide/vue'
3
+ import Alert from './Alert.vue'
4
+ import Button from '../Button/Button.vue'
5
+
6
+ const meta = {
7
+ title: 'Components/Element/Alert',
8
+ component: Alert,
9
+ tags: ['autodocs'],
10
+ args: {
11
+ type: 'info',
12
+ title: 'Term dates have changed',
13
+ description: 'The autumn term now starts on Wednesday 3 September.',
14
+ appearance: 'card',
15
+ dismissible: false,
16
+ live: false,
17
+ },
18
+ decorators: [() => ({ template: '<div class="max-w-2xl"><story /></div>' })],
19
+ } satisfies Meta<typeof Alert>
20
+
21
+ export default meta
22
+ type Story = StoryObj<typeof meta>
23
+
24
+ export const Default: Story = {}
25
+
26
+ /** The four types, each with its own icon and colour, and its name for screen readers. */
27
+ export const Types: Story = {
28
+ render: () => ({
29
+ components: { Alert },
30
+ template: `
31
+ <div class="flex flex-col gap-3">
32
+ <Alert type="info" title="Term dates have changed" description="The autumn term now starts on Wednesday 3 September." />
33
+ <Alert type="success" title="All services are running" />
34
+ <Alert type="warning" title="Keston Admin is slow at the moment" description="We're looking into it. Your changes are still saved." />
35
+ <Alert type="error" title="3 students couldn't be moved" description="Their year group is missing. Add it, then try again." />
36
+ </div>`,
37
+ }),
38
+ }
39
+
40
+ /** With actions on the right (under the text on narrow screens). */
41
+ export const WithActions: Story = {
42
+ render: () => ({
43
+ components: { Alert, Button },
44
+ template: `
45
+ <Alert type="warning" title="Your password expires in 7 days" description="Choose a new one before it does.">
46
+ <template #actions><Button size="sm">Change password</Button></template>
47
+ </Alert>`,
48
+ }),
49
+ }
50
+
51
+ /** Banner: full width, under the Header, for something about the whole app. */
52
+ export const Banner: Story = {
53
+ decorators: [() => ({ template: '<div><story /></div>' })],
54
+ render: () => ({
55
+ components: { Alert, Button },
56
+ setup: () => ({ LifeBuoy }),
57
+ template: `
58
+ <Alert appearance="banner" :icon="LifeBuoy">
59
+ You're using a Keston support account in <b>The Keston School</b> until 17:30.
60
+ <template #actions><Button size="sm">End session</Button></template>
61
+ </Alert>`,
62
+ }),
63
+ }
64
+
65
+ export const Dismissible: Story = { args: { dismissible: true } }
@@ -0,0 +1,110 @@
1
+ <script setup lang="ts">
2
+ import { computed, type Component, type HTMLAttributes } from 'vue'
3
+ import { useI18n } from 'vue-i18n'
4
+ import { CircleCheck, CircleX, Info, TriangleAlert, X } from '@lucide/vue'
5
+ import { cn } from '../../lib/cn'
6
+ import Button from '../Button/Button.vue'
7
+
8
+ /**
9
+ * A message that stays on the page until it's dealt with: a problem to fix,
10
+ * a warning, something that went well, or information people need here.
11
+ * For something that has just happened, use a toast Notification instead.
12
+ *
13
+ * Two appearances:
14
+ * - card (default): a rounded box in the page's flow, e.g. above a form.
15
+ * - banner: full width, no corners, a line under it, e.g. under the Header
16
+ * for something that affects the whole app ("You're using a support
17
+ * account").
18
+ *
19
+ * Slots: default (the description, for links or bold text), actions (Buttons
20
+ * on the right; under the text on narrow screens), icon (replaces the icon).
21
+ */
22
+ export interface AlertProps {
23
+ type?: 'info' | 'success' | 'warning' | 'error'
24
+ /** The message, in a few words. Bold. */
25
+ title?: string
26
+ /** More detail under the title. Or use the default slot. */
27
+ description?: string
28
+ appearance?: 'card' | 'banner'
29
+ /** A different icon from the type's own. */
30
+ icon?: Component
31
+ /** Show × to close it; emits `dismiss`. */
32
+ dismissible?: boolean
33
+ /**
34
+ * Announce it to screen readers when it appears (or changes). For alerts
35
+ * shown in response to something, e.g. a save that failed. Not for ones
36
+ * that are on the page from the start.
37
+ */
38
+ live?: boolean
39
+ class?: HTMLAttributes['class']
40
+ }
41
+
42
+ const { t } = useI18n()
43
+ const props = withDefaults(defineProps<AlertProps>(), {
44
+ type: 'info',
45
+ appearance: 'card'
46
+ })
47
+
48
+ const emit = defineEmits<{ dismiss: [] }>()
49
+
50
+ defineSlots<{
51
+ default?(): unknown
52
+ actions?(): unknown
53
+ icon?(): unknown
54
+ }>()
55
+
56
+ // The colour is a tint of the type's text colour, so it reads in both modes.
57
+ const types = {
58
+ info: { icon: Info, text: 'text-blue-fg', box: 'border-blue-fg/30 bg-blue-fg/8' },
59
+ success: { icon: CircleCheck, text: 'text-green-fg', box: 'border-green-fg/30 bg-green-fg/8' },
60
+ warning: { icon: TriangleAlert, text: 'text-yellow-fg', box: 'border-yellow-fg/40 bg-yellow-fg/10' },
61
+ error: { icon: CircleX, text: 'text-red-fg', box: 'border-red-fg/30 bg-red-fg/8' }
62
+ } as const
63
+
64
+ const look = computed(() => types[props.type])
65
+
66
+ // Errors interrupt (role=alert); everything else waits its turn (status).
67
+ const role = computed(() => (props.live ? (props.type === 'error' ? 'alert' : 'status') : undefined))
68
+
69
+ const appearances = {
70
+ card: 'rounded-lg border p-4',
71
+ banner: 'border-b px-4 py-3 sm:px-6'
72
+ }
73
+ </script>
74
+
75
+ <template>
76
+ <div
77
+ :role="role"
78
+ :class="cn('flex flex-wrap items-start gap-x-3 gap-y-2 text-sm text-ink', appearances[appearance], look.box, props.class)"
79
+ >
80
+ <span :class="cn('flex h-5 shrink-0 items-center', look.text)">
81
+ <slot name="icon">
82
+ <component :is="icon ?? look.icon" class="size-4" aria-hidden="true" />
83
+ </slot>
84
+ </span>
85
+ <div class="flex min-w-0 flex-1 basis-48 flex-col gap-0.5">
86
+ <!-- The type in words for screen readers, as the colour and icon don't say it. -->
87
+ <p v-if="title" class="font-bold">
88
+ <span class="sr-only">{{ t(`ui.alert.${type}`) }}: </span>{{ title }}
89
+ </p>
90
+ <div v-if="description || $slots.default" :class="title ? 'text-ink/80' : ''">
91
+ <span v-if="!title" class="sr-only">{{ t(`ui.alert.${type}`) }}: </span>
92
+ <slot>{{ description }}</slot>
93
+ </div>
94
+ </div>
95
+ <div v-if="$slots.actions" class="flex shrink-0 flex-wrap items-center gap-2 self-center">
96
+ <slot name="actions" />
97
+ </div>
98
+ <Button
99
+ v-if="dismissible"
100
+ variant="ghost"
101
+ size="sm"
102
+ square
103
+ :aria-label="t('ui.alert.dismiss')"
104
+ class="-my-1 -mr-1 shrink-0"
105
+ @click="emit('dismiss')"
106
+ >
107
+ <X />
108
+ </Button>
109
+ </div>
110
+ </template>
@@ -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>