@thekestongroup/ui 0.14.0 → 0.16.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 (124) hide show
  1. package/dist/components/ActionList/ActionList.vue.d.ts +63 -0
  2. package/dist/components/Alert/Alert.vue.d.ts +55 -0
  3. package/dist/components/AvatarGroup/AvatarGroup.vue.d.ts +1 -1
  4. package/dist/components/BarChart/BarChart.vue.d.ts +37 -0
  5. package/dist/components/BarChart/ChartData.vue.d.ts +20 -0
  6. package/dist/components/Button/Button.vue.d.ts +1 -1
  7. package/dist/components/Collapsible/Collapsible.vue.d.ts +48 -0
  8. package/dist/components/FileUpload/FileUpload.vue.d.ts +55 -0
  9. package/dist/components/Footer/Footer.vue.d.ts +11 -1
  10. package/dist/components/Header/Header.vue.d.ts +1 -1
  11. package/dist/components/LineChart/LineChart.vue.d.ts +37 -0
  12. package/dist/components/Notification/Notification.vue.d.ts +2 -2
  13. package/dist/components/Popover/popover.d.ts +3 -2
  14. package/dist/components/Progress/Progress.vue.d.ts +14 -1
  15. package/dist/components/Slideover/Slideover.vue.d.ts +7 -5
  16. package/dist/components/Spinner/Spinner.vue.d.ts +2 -2
  17. package/dist/components/ThemeSwitcher/ThemeSwitcher.vue.d.ts +18 -0
  18. package/dist/i18n/en.d.ts +27 -0
  19. package/dist/index.d.ts +17 -0
  20. package/dist/keston-ui.js +4369 -3509
  21. package/dist/lib/chart.d.ts +32 -0
  22. package/dist/lib/theme.d.ts +23 -0
  23. package/package.json +8 -3
  24. package/src/components/ActionList/ActionList.stories.ts +59 -0
  25. package/src/components/ActionList/ActionList.vue +116 -0
  26. package/src/components/Alert/Alert.stories.ts +65 -0
  27. package/src/components/Alert/Alert.vue +110 -0
  28. package/src/components/AppLauncher/AppLauncher.vue +3 -3
  29. package/src/components/AppShell/AppShell.stories.ts +2 -2
  30. package/src/components/AppShell/AppShell.vue +2 -2
  31. package/src/components/Avatar/Avatar.vue +3 -3
  32. package/src/components/AvatarGroup/AvatarGroup.vue +4 -4
  33. package/src/components/Badge/Badge.vue +2 -2
  34. package/src/components/BarChart/BarChart.stories.ts +62 -0
  35. package/src/components/BarChart/BarChart.vue +153 -0
  36. package/src/components/BarChart/ChartData.vue +64 -0
  37. package/src/components/Breadcrumb/Breadcrumb.vue +5 -5
  38. package/src/components/Button/Button.stories.ts +1 -1
  39. package/src/components/Button/Button.vue +12 -9
  40. package/src/components/Calendar/Calendar.stories.ts +2 -2
  41. package/src/components/Calendar/Calendar.vue +11 -10
  42. package/src/components/Card/Card.stories.ts +5 -5
  43. package/src/components/Card/Card.vue +3 -3
  44. package/src/components/CardSelect/CardSelect.vue +10 -7
  45. package/src/components/ChangeIndicator/ChangeIndicator.vue +2 -2
  46. package/src/components/Checkbox/Checkbox.vue +5 -5
  47. package/src/components/CheckboxGroup/CheckboxGroup.stories.ts +1 -1
  48. package/src/components/CheckboxGroup/CheckboxGroup.vue +2 -2
  49. package/src/components/Checklist/Checklist.vue +3 -3
  50. package/src/components/Chip/Chip.stories.ts +1 -1
  51. package/src/components/Chip/Chip.vue +2 -2
  52. package/src/components/Collapsible/Collapsible.stories.ts +32 -0
  53. package/src/components/Collapsible/Collapsible.vue +68 -0
  54. package/src/components/Divider/Divider.vue +4 -4
  55. package/src/components/EmptyState/EmptyState.vue +3 -3
  56. package/src/components/FileUpload/FileUpload.stories.ts +38 -0
  57. package/src/components/FileUpload/FileUpload.vue +150 -0
  58. package/src/components/Footer/Footer.stories.ts +10 -2
  59. package/src/components/Footer/Footer.vue +26 -8
  60. package/src/components/FormField/FieldMessage.vue +3 -3
  61. package/src/components/FormField/FormField.stories.ts +1 -1
  62. package/src/components/FormField/FormField.vue +8 -3
  63. package/src/components/Header/Header.stories.ts +28 -8
  64. package/src/components/Header/Header.vue +6 -6
  65. package/src/components/InfoTip/InfoTip.stories.ts +1 -1
  66. package/src/components/InfoTip/InfoTip.vue +1 -1
  67. package/src/components/Input/Input.vue +1 -1
  68. package/src/components/InputCode/InputCode.stories.ts +1 -1
  69. package/src/components/InputCode/InputCode.vue +4 -4
  70. package/src/components/InputDate/InputDate.stories.ts +1 -1
  71. package/src/components/InputDate/InputDate.vue +5 -5
  72. package/src/components/InputNumber/InputNumber.stories.ts +1 -1
  73. package/src/components/InputNumber/InputNumber.vue +6 -6
  74. package/src/components/InputPassword/InputPassword.vue +4 -4
  75. package/src/components/InputRichText/InputRichText.stories.ts +1 -1
  76. package/src/components/InputRichText/InputRichText.vue +3 -3
  77. package/src/components/InputTextArea/InputTextArea.vue +1 -1
  78. package/src/components/LineChart/LineChart.stories.ts +47 -0
  79. package/src/components/LineChart/LineChart.vue +173 -0
  80. package/src/components/Link/Link.stories.ts +4 -4
  81. package/src/components/Link/Link.vue +1 -1
  82. package/src/components/Menu/Menu.vue +6 -5
  83. package/src/components/Notification/Notification.stories.ts +3 -3
  84. package/src/components/Notification/Notification.vue +9 -9
  85. package/src/components/Notification/NotificationPane.vue +3 -3
  86. package/src/components/Notification/Toaster.vue +1 -1
  87. package/src/components/PageHeader/PageHeader.vue +2 -2
  88. package/src/components/Popover/Popover.stories.ts +2 -2
  89. package/src/components/Popover/popover.ts +4 -3
  90. package/src/components/Progress/Progress.stories.ts +18 -0
  91. package/src/components/Progress/Progress.vue +58 -1
  92. package/src/components/RadioGroup/RadioGroup.vue +7 -7
  93. package/src/components/RelativeTime/RelativeTime.stories.ts +1 -1
  94. package/src/components/Select/Select.stories.ts +1 -1
  95. package/src/components/Select/Select.vue +26 -20
  96. package/src/components/SettingsRow/SettingsRow.vue +1 -1
  97. package/src/components/Sidebar/Sidebar.stories.ts +2 -2
  98. package/src/components/Sidebar/Sidebar.vue +9 -9
  99. package/src/components/Slideover/Slideover.stories.ts +5 -5
  100. package/src/components/Slideover/Slideover.vue +111 -35
  101. package/src/components/Spinner/Spinner.stories.ts +7 -7
  102. package/src/components/Spinner/Spinner.vue +1 -1
  103. package/src/components/StatTile/StatTile.stories.ts +2 -2
  104. package/src/components/StatTile/StatTile.vue +6 -6
  105. package/src/components/Steps/Steps.vue +2 -2
  106. package/src/components/SummaryList/SummaryList.vue +8 -8
  107. package/src/components/Switch/Switch.vue +3 -3
  108. package/src/components/Table/Table.vue +12 -12
  109. package/src/components/Tabs/Tabs.vue +4 -4
  110. package/src/components/ThemeSwitcher/ThemeSwitcher.stories.ts +22 -0
  111. package/src/components/ThemeSwitcher/ThemeSwitcher.vue +48 -0
  112. package/src/components/Tooltip/Tooltip.stories.ts +1 -1
  113. package/src/components/Tooltip/Tooltip.vue +1 -1
  114. package/src/components/UnsavedChangesBar/UnsavedChangesBar.stories.ts +1 -1
  115. package/src/components/UnsavedChangesBar/UnsavedChangesBar.vue +1 -1
  116. package/src/examples/AppPages.stories.ts +3 -3
  117. package/src/examples/FormLayout.stories.ts +3 -3
  118. package/src/examples/KestonIdPages.stories.ts +18 -18
  119. package/src/examples/SchoolPages.stories.ts +5 -5
  120. package/src/i18n/en.ts +16 -4
  121. package/src/index.ts +17 -0
  122. package/src/lib/chart.ts +47 -0
  123. package/src/lib/theme.ts +75 -0
  124. package/src/styles/theme.css +117 -5
@@ -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
+ };
@@ -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.14.0",
3
+ "version": "0.16.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,8 @@
34
34
  "docs:preview": "vitepress preview site",
35
35
  "new": "node scripts/new-component.mjs",
36
36
  "changeset": "changeset",
37
- "test": "vitest run",
37
+ "test": "vitest run --project unit",
38
+ "test:a11y": "VITE_THEME=light vitest run --project stories && VITE_THEME=dark vitest run --project stories",
38
39
  "test:watch": "vitest"
39
40
  },
40
41
  "peerDependencies": {
@@ -69,12 +70,16 @@
69
70
  "@changesets/cli": "^3.0.3",
70
71
  "@storybook/addon-a11y": "^10.6.5",
71
72
  "@storybook/addon-docs": "^10.6.5",
73
+ "@storybook/addon-vitest": "^10.6.9",
72
74
  "@storybook/builder-vite": "^10.6.5",
73
75
  "@storybook/vue3-vite": "^10.6.5",
74
76
  "@tailwindcss/vite": "^4.3.4",
75
77
  "@types/node": "^26.6.6",
76
78
  "@vitejs/plugin-vue": "^6.0.10",
79
+ "@vitest/browser": "^5.1.2",
80
+ "@vitest/browser-playwright": "^5.1.2",
77
81
  "@vue/tsconfig": "^0.9.1",
82
+ "playwright": "^1.65.1",
78
83
  "remark-gfm": "^4.0.1",
79
84
  "storybook": "^10.6.5",
80
85
  "tailwindcss": "^4.3.4",
@@ -82,7 +87,7 @@
82
87
  "vite": "^8.3.5",
83
88
  "vite-plugin-dts": "^5.1.2",
84
89
  "vitepress": "1.6.4",
85
- "vitest": "^5.1.0",
90
+ "vitest": "^5.1.2",
86
91
  "vue": "^3.5.44",
87
92
  "vue-i18n": "^11.4.20",
88
93
  "vue-tsc": "^3.3.14"
@@ -0,0 +1,59 @@
1
+ import type { Meta, StoryObj } from '@storybook/vue3-vite'
2
+ import { Building2, Search } 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
+
8
+ const meta = {
9
+ title: 'Components/Navigation/ActionList',
10
+ component: ActionList,
11
+ tags: ['autodocs'],
12
+ args: {
13
+ label: 'Your organisations',
14
+ items: [
15
+ { label: 'The Keston School', description: 'keston.school', icon: Building2, current: true },
16
+ { label: 'Keston Prep', description: 'prep.keston.school', icon: Building2 },
17
+ { label: 'Keston Sixth Form', description: "You don't have access to manage it", icon: Building2, disabled: true },
18
+ { label: 'Browse all organisations', description: 'Search every organisation on Keston', icon: Search },
19
+ ],
20
+ },
21
+ decorators: [() => ({ template: '<div class="max-w-md"><story /></div>' })],
22
+ } satisfies Meta<typeof ActionList>
23
+
24
+ export default meta
25
+ type Story = StoryObj<typeof meta>
26
+
27
+ export const Default: Story = {}
28
+
29
+ /** Accounts: an Avatar in the leading slot, a Badge after the name, one switching. */
30
+ export const Accounts: Story = {
31
+ args: {
32
+ label: 'Signed-in accounts',
33
+ items: [
34
+ { key: '1', label: 'Ben Smith', description: 'ben.smith@keston.school' },
35
+ { key: '2', label: 'Jo Bloggs', description: 'jo.bloggs@keston.school', loading: true },
36
+ ],
37
+ },
38
+ render: (args) => ({
39
+ components: { ActionList, Avatar, Badge },
40
+ setup: () => ({ args }),
41
+ template: `
42
+ <ActionList v-bind="args">
43
+ <template #leading="{ item }"><Avatar :user="{ name: item.label }" size="md" decorative /></template>
44
+ <template #badges="{ item }"><Badge v-if="item.key === '1'" size="sm" color="green">Using now</Badge></template>
45
+ </ActionList>`,
46
+ }),
47
+ }
48
+
49
+ /** A second action beside a row, outside its button: e.g. Leave. */
50
+ export const WithAfter: Story = {
51
+ render: (args) => ({
52
+ components: { ActionList, Button },
53
+ setup: () => ({ args }),
54
+ template: `
55
+ <ActionList v-bind="args">
56
+ <template #after="{ item }"><Button v-if="item.label === 'Keston Prep'" size="sm">Leave</Button></template>
57
+ </ActionList>`,
58
+ }),
59
+ }
@@ -0,0 +1,116 @@
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
+ }
25
+
26
+ /**
27
+ * A list of things to pick one of and go to: accounts to switch to,
28
+ * organisations, connected apps. Each row is a single button or link with an
29
+ * optional icon or avatar, a name and a line under it, and an arrow, in a
30
+ * bordered box with lines between rows.
31
+ *
32
+ * Rows without `to` / `href` are buttons that emit `select`.
33
+ *
34
+ * Slots, each given `{ item }`: leading (before the text, e.g. an Avatar),
35
+ * badges (after the name, e.g. "Current"), after (beside the row, outside
36
+ * the button, e.g. a Leave button).
37
+ */
38
+ export interface ActionListProps {
39
+ items: ActionListItem[]
40
+ /** What the list is, for screen readers, e.g. "Signed-in accounts". */
41
+ label: string
42
+ /** Component used for rows with `to`, e.g. RouterLink. */
43
+ linkComponent?: string | Component
44
+ class?: HTMLAttributes['class']
45
+ }
46
+
47
+ const props = defineProps<ActionListProps>()
48
+ const emit = defineEmits<{ select: [item: ActionListItem] }>()
49
+
50
+ defineSlots<{
51
+ leading?(props: { item: ActionListItem }): unknown
52
+ badges?(props: { item: ActionListItem }): unknown
53
+ after?(props: { item: ActionListItem }): unknown
54
+ }>()
55
+
56
+ function tagFor(item: ActionListItem) {
57
+ if (item.disabled) return 'button'
58
+ if (item.to !== undefined) return props.linkComponent ?? 'a'
59
+ if (item.href !== undefined) return 'a'
60
+ return 'button'
61
+ }
62
+
63
+ function attrsFor(item: ActionListItem) {
64
+ if (item.disabled) return { type: 'button', disabled: true }
65
+ if (item.to !== undefined) return { to: item.to }
66
+ if (item.href !== undefined) return { href: item.href }
67
+ return { type: 'button' }
68
+ }
69
+
70
+ function onClick(item: ActionListItem) {
71
+ if (!item.disabled && item.to === undefined && item.href === undefined) emit('select', item)
72
+ }
73
+
74
+ // The whole row presses; hover and press tint it, focus rings it inside the box.
75
+ const row = [
76
+ '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
+ 'not-disabled:hover:bg-hover not-disabled:active:bg-pressed aria-[current=true]:bg-selected',
78
+ 'outline-2 -outline-offset-2 outline-transparent focus-visible:outline-focus',
79
+ 'disabled:cursor-not-allowed disabled:opacity-40'
80
+ ]
81
+ </script>
82
+
83
+ <template>
84
+ <!-- overflow-hidden: the rows' tint follows the rounded corners. -->
85
+ <ul
86
+ :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)"
88
+ >
89
+ <li v-for="item in items" :key="item.key ?? item.label" class="flex items-center">
90
+ <component
91
+ :is="tagFor(item)"
92
+ v-bind="attrsFor(item)"
93
+ :aria-current="item.current ? 'true' : undefined"
94
+ :aria-busy="item.loading || undefined"
95
+ :class="row"
96
+ @click="onClick(item)"
97
+ >
98
+ <slot name="leading" :item="item">
99
+ <component :is="item.icon" v-if="item.icon" class="size-5 shrink-0 text-ink/65" aria-hidden="true" />
100
+ </slot>
101
+ <span class="flex min-w-0 flex-1 flex-col">
102
+ <span class="flex min-w-0 items-center gap-2">
103
+ <span class="truncate text-sm font-bold">{{ item.label }}</span>
104
+ <slot name="badges" :item="item" />
105
+ </span>
106
+ <span v-if="item.description" class="truncate text-xs text-ink/65">{{ item.description }}</span>
107
+ </span>
108
+ <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" />
110
+ </component>
111
+ <div v-if="$slots.after" class="shrink-0 pr-3 empty:hidden">
112
+ <slot name="after" :item="item" />
113
+ </div>
114
+ </li>
115
+ </ul>
116
+ </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>
@@ -70,12 +70,12 @@ function iconOf(app: AppLauncherApp): Component {
70
70
  :href="app.href"
71
71
  :aria-current="app.id === current ? 'page' : undefined"
72
72
  :class="cn(
73
- 'flex items-center gap-3 rounded-lg px-3 py-2 text-sm font-bold text-black outline-none hover:bg-black/5 focus-visible:outline-2 focus-visible:outline-focus',
74
- app.id === current && 'bg-black/5'
73
+ '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',
74
+ app.id === current && 'bg-selected'
75
75
  )"
76
76
  @click="close()"
77
77
  >
78
- <span class="flex size-8 shrink-0 items-center justify-center rounded-lg bg-black/5">
78
+ <span class="flex size-8 shrink-0 items-center justify-center rounded-lg bg-ink/5">
79
79
  <component :is="iconOf(app)" class="size-5" aria-hidden="true" />
80
80
  </span>
81
81
  <span class="min-w-0 truncate">{{ app.label }}</span>
@@ -44,7 +44,7 @@ const meta = {
44
44
  <Button variant="ghost" square aria-label="Notifications"><Bell /></Button>
45
45
  </template>
46
46
  <h1 class="text-2xl font-bold">{{ current }}</h1>
47
- <p v-for="n in 40" :key="n" class="mt-3 text-sm text-black/65">
47
+ <p v-for="n in 40" :key="n" class="mt-3 text-sm text-ink/65">
48
48
  Line {{ n }}. Scroll: the header stays at the top and the sidebar stays beside the page.
49
49
  </p>
50
50
  </AppShell>`,
@@ -136,7 +136,7 @@ export const WithBreadcrumb: Story = {
136
136
  <AppShell v-bind="args" :items="items" :ui="{ main: 'p-6' }">
137
137
  <Breadcrumb :items="trail" />
138
138
  <h1 class="mt-2 text-2xl font-bold">{{ current }}</h1>
139
- <p class="mt-3 text-sm text-black/65">Choose pages in the sidebar: the breadcrumb follows.</p>
139
+ <p class="mt-3 text-sm text-ink/65">Choose pages in the sidebar: the breadcrumb follows.</p>
140
140
  </AppShell>`,
141
141
  }),
142
142
  };
@@ -129,11 +129,11 @@ const sidebarId = `${uid}-sidebar`
129
129
  <!-- One provider for every Tooltip in the app, so moving from one to the
130
130
  next shows it without waiting again. -->
131
131
  <TooltipProvider :delay-duration="400" :skip-delay-duration="300">
132
- <div :class="cn('flex min-h-dvh flex-col bg-background text-black', props.class)">
132
+ <div :class="cn('flex min-h-dvh flex-col bg-background text-ink', props.class)">
133
133
  <!-- First thing keyboard users reach: jumps past the header and sidebar. -->
134
134
  <a
135
135
  :href="`#${mainId}`"
136
- class="sr-only z-50 rounded bg-white px-4 py-2 text-sm focus:not-sr-only focus:fixed focus:top-2 focus:left-2 focus:outline-2 focus:outline-focus"
136
+ class="sr-only z-50 rounded bg-surface px-4 py-2 text-sm focus:not-sr-only focus:fixed focus:top-2 focus:left-2 focus:outline-2 focus:outline-focus"
137
137
  >
138
138
  Skip to content
139
139
  </a>
@@ -83,7 +83,7 @@ const circle = 'relative inline-flex shrink-0 items-center justify-center overfl
83
83
 
84
84
  <template #content>
85
85
  <div class="flex flex-col">
86
- <p v-if="user.organisation" class="truncate px-4 pt-3 text-xs font-bold text-black/65 uppercase">
86
+ <p v-if="user.organisation" class="truncate px-4 pt-3 text-xs font-bold text-ink/65 uppercase">
87
87
  {{ user.organisation }}
88
88
  </p>
89
89
  <div class="flex items-center gap-3 px-4 py-3">
@@ -93,11 +93,11 @@ const circle = 'relative inline-flex shrink-0 items-center justify-center overfl
93
93
  </span>
94
94
  <div class="flex min-w-0 flex-col">
95
95
  <span class="truncate font-bold">{{ user.name }}</span>
96
- <span v-if="user.role" class="truncate text-sm text-black/65">{{ user.role }}</span>
96
+ <span v-if="user.role" class="truncate text-sm text-ink/65">{{ user.role }}</span>
97
97
  <a
98
98
  v-if="user.email"
99
99
  :href="`mailto:${user.email}`"
100
- class="truncate rounded-sm text-sm text-black/65 underline-offset-2 hover:text-black hover:underline outline-2 outline-offset-1 outline-transparent focus-visible:outline-focus"
100
+ class="truncate rounded-sm text-sm text-ink/65 underline-offset-2 hover:text-ink hover:underline outline-2 outline-offset-1 outline-transparent focus-visible:outline-focus"
101
101
  >
102
102
  {{ user.email }}
103
103
  </a>
@@ -66,18 +66,18 @@ const counterSizes: Record<NonNullable<AvatarProps['size']>, string> = {
66
66
  <span
67
67
  v-for="(user, i) in shown"
68
68
  :key="`${user.name}-${i}`"
69
- :class="cn('relative flex rounded-full ring-white hover:z-10 focus-within:z-10', rings[size], i > 0 && overlaps[size])"
69
+ :class="cn('relative flex rounded-full ring-surface hover:z-10 focus-within:z-10', rings[size], i > 0 && overlaps[size])"
70
70
  >
71
71
  <Avatar :user="user" :size="size" :profile="profile" />
72
72
  </span>
73
73
 
74
- <span v-if="hidden.length" :class="cn('relative flex rounded-full ring-white hover:z-10 focus-within:z-10', rings[size], overlaps[size])">
74
+ <span v-if="hidden.length" :class="cn('relative flex rounded-full ring-surface hover:z-10 focus-within:z-10', rings[size], overlaps[size])">
75
75
  <Popover mode="hover" :open-delay="300" :close-delay="150" :content="{ side: 'bottom', align: 'start', sideOffset: 6 }" :ui="{ content: 'w-56' }">
76
76
  <button
77
77
  type="button"
78
78
  :aria-label="t('ui.avatarGroup.more', { count: hidden.length, names: hidden.map((u) => u.name).join(', ') })"
79
79
  :class="cn(
80
- 'inline-flex shrink-0 cursor-pointer items-center justify-center rounded-full bg-surface font-bold text-black select-none',
80
+ 'inline-flex shrink-0 cursor-pointer items-center justify-center rounded-full bg-surface-muted font-bold text-ink select-none',
81
81
  'outline-2 outline-offset-1 outline-transparent transition focus-visible:outline-focus',
82
82
  counterSizes[size]
83
83
  )"
@@ -89,7 +89,7 @@ const counterSizes: Record<NonNullable<AvatarProps['size']>, string> = {
89
89
  <li v-for="(user, i) in hidden" :key="`${user.name}-${i}`" class="flex items-center gap-2">
90
90
  <Avatar :user="user" size="xs" decorative />
91
91
  <span class="min-w-0 truncate">{{ user.name }}</span>
92
- <span v-if="user.role" class="ml-auto shrink-0 truncate text-xs text-black/65">{{ user.role }}</span>
92
+ <span v-if="user.role" class="ml-auto shrink-0 truncate text-xs text-ink/65">{{ user.role }}</span>
93
93
  </li>
94
94
  </ul>
95
95
  </template>
@@ -39,10 +39,10 @@ defineSlots<{
39
39
 
40
40
  // The same border and colours as Button's variants (basic white, the rest
41
41
  // solid with white text, except yellow, which needs black text to be readable).
42
- const base = 'inline-flex shrink-0 items-center whitespace-nowrap rounded-full border border-black/15 font-bold'
42
+ const base = 'inline-flex shrink-0 items-center whitespace-nowrap rounded-full border border-ink/10 font-bold'
43
43
 
44
44
  const colors: Record<NonNullable<BadgeProps['color']>, string> = {
45
- basic: 'bg-white text-black',
45
+ basic: 'bg-surface text-ink',
46
46
  primary: 'bg-primary text-white',
47
47
  red: 'bg-red text-white',
48
48
  green: 'bg-green text-white',
@@ -0,0 +1,62 @@
1
+ import type { Meta, StoryObj } from '@storybook/vue3-vite'
2
+ import BarChart from './BarChart.vue'
3
+ import Card from '../Card/Card.vue'
4
+
5
+ const week = [
6
+ { label: 'Mon', fullLabel: 'Monday 24 November', values: { success: 182, failed: 6 } },
7
+ { label: 'Tue', fullLabel: 'Tuesday 25 November', values: { success: 201, failed: 3 } },
8
+ { label: 'Wed', fullLabel: 'Wednesday 26 November', values: { success: 176, failed: 14 } },
9
+ { label: 'Thu', fullLabel: 'Thursday 27 November', values: { success: 190, failed: 2 } },
10
+ { label: 'Fri', fullLabel: 'Friday 28 November', values: { success: 158, failed: 4 } },
11
+ { label: 'Sat', fullLabel: 'Saturday 29 November', values: { success: 12, failed: 0 } },
12
+ { label: 'Sun', fullLabel: 'Sunday 30 November', values: { success: 9, failed: 1 } },
13
+ ]
14
+
15
+ const meta = {
16
+ title: 'Components/Data/BarChart',
17
+ component: BarChart,
18
+ tags: ['autodocs'],
19
+ args: {
20
+ label: 'Sign-ins this week',
21
+ categoryLabel: 'Date',
22
+ data: week,
23
+ series: [
24
+ { key: 'success', label: 'Succeeded' },
25
+ { key: 'failed', label: 'Failed', color: 8 },
26
+ ],
27
+ stacked: true,
28
+ },
29
+ render: (args) => ({
30
+ components: { BarChart, Card },
31
+ setup: () => ({ args }),
32
+ template: `
33
+ <Card title="Sign-ins this week" description="Succeeded and failed, by day." class="max-w-2xl">
34
+ <BarChart v-bind="args" />
35
+ </Card>`,
36
+ }),
37
+ } satisfies Meta<typeof BarChart>
38
+
39
+ export default meta
40
+ type Story = StoryObj<typeof meta>
41
+
42
+ /** Stacked: the parts of each day's total. Hover a column for its numbers; "Show as table" for all of them. */
43
+ export const Default: Story = {}
44
+
45
+ /** Side by side, to compare the series rather than see the total. */
46
+ export const SideBySide: Story = { args: { stacked: false } }
47
+
48
+ /** One series: no legend, as the Card's title says what it is. */
49
+ export const OneSeries: Story = {
50
+ args: {
51
+ label: 'Applications by year group',
52
+ categoryLabel: 'Year group',
53
+ data: [
54
+ { label: 'Y7', fullLabel: 'Year 7', values: { count: 142 } },
55
+ { label: 'Y8', fullLabel: 'Year 8', values: { count: 18 } },
56
+ { label: 'Y9', fullLabel: 'Year 9', values: { count: 23 } },
57
+ { label: 'Y10', fullLabel: 'Year 10', values: { count: 11 } },
58
+ { label: 'Y12', fullLabel: 'Year 12', values: { count: 87 } },
59
+ ],
60
+ series: [{ key: 'count', label: 'Applications' }],
61
+ },
62
+ }