@thekestongroup/ui 0.2.1 → 0.3.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 (207) hide show
  1. package/README.md +90 -32
  2. package/dist/components/Age/Age.vue.d.ts +19 -0
  3. package/dist/components/AppShell/AppShell.vue.d.ts +108 -0
  4. package/dist/components/Avatar/Avatar.vue.d.ts +34 -0
  5. package/dist/components/AvatarGroup/AvatarGroup.vue.d.ts +25 -0
  6. package/dist/components/Badge/Badge.vue.d.ts +41 -0
  7. package/dist/components/Breadcrumb/Breadcrumb.vue.d.ts +39 -0
  8. package/dist/components/Button/Button.vue.d.ts +69 -0
  9. package/dist/components/Calendar/Calendar.vue.d.ts +34 -0
  10. package/dist/components/Card/Card.vue.d.ts +56 -0
  11. package/dist/components/Checkbox/Checkbox.vue.d.ts +40 -0
  12. package/dist/components/Checklist/Checklist.vue.d.ts +18 -0
  13. package/dist/components/Chip/Chip.vue.d.ts +44 -0
  14. package/dist/components/Divider/Divider.vue.d.ts +36 -0
  15. package/dist/components/{ToastItem.vue.d.ts → FormField/FieldMessage.vue.d.ts} +10 -2
  16. package/dist/components/FormField/FormField.vue.d.ts +61 -0
  17. package/dist/components/Header/Header.vue.d.ts +104 -0
  18. package/dist/components/InfoTip/InfoTip.vue.d.ts +20 -0
  19. package/dist/components/Input/Input.vue.d.ts +56 -0
  20. package/dist/components/InputCode/InputCode.vue.d.ts +53 -0
  21. package/dist/components/InputDate/InputDate.vue.d.ts +49 -0
  22. package/dist/components/InputNumber/InputNumber.vue.d.ts +44 -0
  23. package/dist/components/InputPassword/InputPassword.vue.d.ts +51 -0
  24. package/dist/components/InputRichText/InputRichText.vue.d.ts +44 -0
  25. package/dist/components/Link/Link.vue.d.ts +39 -0
  26. package/dist/components/Notification/Notification.vue.d.ts +62 -0
  27. package/dist/components/Notification/NotificationPane.vue.d.ts +38 -0
  28. package/dist/components/Notification/Toaster.vue.d.ts +51 -0
  29. package/dist/components/Notification/notification.samples.d.ts +3 -0
  30. package/dist/components/Notification/notifications.d.ts +115 -0
  31. package/dist/components/PageHeader/PageHeader.vue.d.ts +43 -0
  32. package/dist/components/Popover/Popover.vue.d.ts +83 -0
  33. package/dist/components/Popover/popover.d.ts +16 -0
  34. package/dist/components/Progress/Progress.vue.d.ts +26 -0
  35. package/dist/components/RadioGroup/RadioGroup.vue.d.ts +45 -0
  36. package/dist/components/RelativeTime/RelativeTime.vue.d.ts +22 -0
  37. package/dist/components/Select/Select.vue.d.ts +110 -0
  38. package/dist/components/Sidebar/Sidebar.vue.d.ts +106 -0
  39. package/dist/components/Sidebar/sidebar.d.ts +10 -0
  40. package/dist/components/Slideover/Slideover.vue.d.ts +125 -0
  41. package/dist/components/Spinner/Spinner.vue.d.ts +30 -0
  42. package/dist/components/StatTile/StatTile.vue.d.ts +46 -0
  43. package/dist/components/SummaryList/SummaryList.vue.d.ts +62 -0
  44. package/dist/components/Switch/Switch.vue.d.ts +39 -0
  45. package/dist/components/Table/Table.vue.d.ts +82 -0
  46. package/dist/components/Table/table.d.ts +36 -0
  47. package/dist/components/Tooltip/Tooltip.vue.d.ts +46 -0
  48. package/dist/index.d.ts +89 -25
  49. package/dist/keston-ui.js +4963 -14785
  50. package/dist/lib/cn.d.ts +4 -0
  51. package/dist/lib/dates.d.ts +27 -0
  52. package/dist/lib/initials.d.ts +2 -0
  53. package/dist/lib/parseDate.d.ts +44 -0
  54. package/dist/lib/useNow.d.ts +3 -0
  55. package/package.json +53 -24
  56. package/src/components/.gitkeep +0 -0
  57. package/src/components/Age/Age.stories.ts +24 -0
  58. package/src/components/Age/Age.vue +56 -0
  59. package/src/components/AppShell/AppShell.stories.ts +124 -0
  60. package/src/components/AppShell/AppShell.vue +212 -0
  61. package/src/components/Avatar/Avatar.stories.ts +56 -0
  62. package/src/components/Avatar/Avatar.vue +118 -0
  63. package/src/components/AvatarGroup/AvatarGroup.stories.ts +47 -0
  64. package/src/components/AvatarGroup/AvatarGroup.vue +97 -0
  65. package/src/components/Badge/Badge.stories.ts +92 -0
  66. package/src/components/Badge/Badge.vue +67 -0
  67. package/src/components/Breadcrumb/Breadcrumb.stories.ts +58 -0
  68. package/src/components/Breadcrumb/Breadcrumb.vue +109 -0
  69. package/src/components/Button/Button.mdx +79 -0
  70. package/src/components/Button/Button.stories.ts +207 -0
  71. package/src/components/Button/Button.vue +266 -0
  72. package/src/components/Calendar/Calendar.stories.ts +51 -0
  73. package/src/components/Calendar/Calendar.vue +364 -0
  74. package/src/components/Card/Card.stories.ts +109 -0
  75. package/src/components/Card/Card.vue +115 -0
  76. package/src/components/Checkbox/Checkbox.stories.ts +102 -0
  77. package/src/components/Checkbox/Checkbox.vue +102 -0
  78. package/src/components/Checklist/Checklist.stories.ts +67 -0
  79. package/src/components/Checklist/Checklist.vue +38 -0
  80. package/src/components/Chip/Chip.stories.ts +71 -0
  81. package/src/components/Chip/Chip.vue +86 -0
  82. package/src/components/Divider/Divider.stories.ts +57 -0
  83. package/src/components/Divider/Divider.vue +58 -0
  84. package/src/components/FormField/FieldMessage.vue +81 -0
  85. package/src/components/FormField/FormField.stories.ts +55 -0
  86. package/src/components/FormField/FormField.vue +160 -0
  87. package/src/components/Header/Header.stories.ts +168 -0
  88. package/src/components/Header/Header.vue +232 -0
  89. package/src/components/InfoTip/InfoTip.stories.ts +63 -0
  90. package/src/components/InfoTip/InfoTip.vue +50 -0
  91. package/src/components/Input/Input.stories.ts +206 -0
  92. package/src/components/Input/Input.vue +90 -0
  93. package/src/components/InputCode/InputCode.stories.ts +85 -0
  94. package/src/components/InputCode/InputCode.vue +145 -0
  95. package/src/components/InputDate/InputDate.stories.ts +58 -0
  96. package/src/components/InputDate/InputDate.vue +258 -0
  97. package/src/components/InputNumber/InputNumber.stories.ts +63 -0
  98. package/src/components/InputNumber/InputNumber.vue +109 -0
  99. package/src/components/InputPassword/InputPassword.stories.ts +105 -0
  100. package/src/components/InputPassword/InputPassword.vue +132 -0
  101. package/src/components/InputRichText/InputRichText.stories.ts +100 -0
  102. package/src/components/InputRichText/InputRichText.vue +194 -0
  103. package/src/components/Link/Link.stories.ts +73 -0
  104. package/src/components/Link/Link.vue +56 -0
  105. package/src/components/Notification/Notification.stories.ts +196 -0
  106. package/src/components/Notification/Notification.vue +136 -0
  107. package/src/components/Notification/NotificationPane.vue +187 -0
  108. package/src/components/Notification/Toaster.vue +446 -0
  109. package/src/components/Notification/notification.samples.ts +45 -0
  110. package/src/components/Notification/notifications.test.ts +99 -0
  111. package/src/components/Notification/notifications.ts +172 -0
  112. package/src/components/PageHeader/PageHeader.stories.ts +79 -0
  113. package/src/components/PageHeader/PageHeader.vue +66 -0
  114. package/src/components/Popover/Popover.stories.ts +135 -0
  115. package/src/components/Popover/Popover.vue +192 -0
  116. package/src/components/Popover/popover.ts +20 -0
  117. package/src/components/Progress/Progress.stories.ts +74 -0
  118. package/src/components/Progress/Progress.vue +75 -0
  119. package/src/components/RadioGroup/RadioGroup.stories.ts +90 -0
  120. package/src/components/RadioGroup/RadioGroup.vue +132 -0
  121. package/src/components/RelativeTime/RelativeTime.stories.ts +74 -0
  122. package/src/components/RelativeTime/RelativeTime.vue +51 -0
  123. package/src/components/Select/Select.mdx +202 -0
  124. package/src/components/Select/Select.stories.ts +223 -0
  125. package/src/components/Select/Select.vue +630 -0
  126. package/src/components/Sidebar/Sidebar.stories.ts +192 -0
  127. package/src/components/Sidebar/Sidebar.vue +382 -0
  128. package/src/components/Sidebar/sidebar.ts +20 -0
  129. package/src/components/Slideover/Slideover.stories.ts +225 -0
  130. package/src/components/Slideover/Slideover.vue +365 -0
  131. package/src/components/Spinner/Spinner.stories.ts +79 -0
  132. package/src/components/Spinner/Spinner.vue +97 -0
  133. package/src/components/StatTile/StatTile.stories.ts +75 -0
  134. package/src/components/StatTile/StatTile.vue +89 -0
  135. package/src/components/SummaryList/SummaryList.stories.ts +103 -0
  136. package/src/components/SummaryList/SummaryList.vue +127 -0
  137. package/src/components/Switch/Switch.stories.ts +100 -0
  138. package/src/components/Switch/Switch.vue +96 -0
  139. package/src/components/Table/Table.stories.ts +206 -0
  140. package/src/components/Table/Table.vue +220 -0
  141. package/src/components/Table/table.test.ts +65 -0
  142. package/src/components/Table/table.ts +70 -0
  143. package/src/components/Tooltip/Tooltip.stories.ts +57 -0
  144. package/src/components/Tooltip/Tooltip.vue +86 -0
  145. package/src/examples/AppPages.stories.ts +500 -0
  146. package/src/examples/FormLayout.stories.ts +185 -0
  147. package/src/examples/KestonIdPages.stories.ts +415 -0
  148. package/src/examples/SchoolPages.stories.ts +665 -0
  149. package/src/index.ts +114 -36
  150. package/src/lib/cn.ts +4 -0
  151. package/src/lib/dates.test.ts +68 -0
  152. package/src/lib/dates.ts +86 -0
  153. package/src/lib/initials.ts +8 -0
  154. package/src/lib/parseDate.test.ts +331 -0
  155. package/src/lib/parseDate.ts +561 -0
  156. package/src/lib/useNow.ts +20 -0
  157. package/src/styles/theme.css +101 -0
  158. package/dist/components/AppLauncher.vue.d.ts +0 -10
  159. package/dist/components/Avatar.vue.d.ts +0 -16
  160. package/dist/components/Button.vue.d.ts +0 -27
  161. package/dist/components/Checkbox.vue.d.ts +0 -18
  162. package/dist/components/CloseButton.vue.d.ts +0 -6
  163. package/dist/components/Dialog.vue.d.ts +0 -23
  164. package/dist/components/Drawer.vue.d.ts +0 -34
  165. package/dist/components/DropdownMenu.vue.d.ts +0 -21
  166. package/dist/components/DropdownMenuItem.vue.d.ts +0 -19
  167. package/dist/components/DropdownMenuSeparator.vue.d.ts +0 -6
  168. package/dist/components/Input.vue.d.ts +0 -14
  169. package/dist/components/Label.vue.d.ts +0 -16
  170. package/dist/components/NotificationsMenu.vue.d.ts +0 -3
  171. package/dist/components/Popover.vue.d.ts +0 -23
  172. package/dist/components/ProfileSwitcher.vue.d.ts +0 -24
  173. package/dist/components/Select.vue.d.ts +0 -28
  174. package/dist/components/Separator.vue.d.ts +0 -11
  175. package/dist/components/ToastRenderer.vue.d.ts +0 -3
  176. package/dist/components/Toaster.vue.d.ts +0 -3
  177. package/dist/components/Tooltip.vue.d.ts +0 -23
  178. package/dist/components/TopBar.vue.d.ts +0 -34
  179. package/dist/favicon-old.svg +0 -1
  180. package/dist/favicon.svg +0 -1
  181. package/dist/keston-ui.cjs +0 -15
  182. package/dist/lib/toast.d.ts +0 -29
  183. package/dist/lib/types.d.ts +0 -5
  184. package/src/components/AppLauncher.vue +0 -63
  185. package/src/components/Avatar.vue +0 -51
  186. package/src/components/Button.vue +0 -54
  187. package/src/components/Checkbox.vue +0 -47
  188. package/src/components/CloseButton.vue +0 -24
  189. package/src/components/Dialog.vue +0 -65
  190. package/src/components/Drawer.vue +0 -202
  191. package/src/components/DropdownMenu.vue +0 -41
  192. package/src/components/DropdownMenuItem.vue +0 -28
  193. package/src/components/DropdownMenuSeparator.vue +0 -12
  194. package/src/components/Input.vue +0 -21
  195. package/src/components/Label.vue +0 -15
  196. package/src/components/NotificationsMenu.vue +0 -115
  197. package/src/components/Popover.vue +0 -46
  198. package/src/components/ProfileSwitcher.vue +0 -113
  199. package/src/components/Select.vue +0 -97
  200. package/src/components/Separator.vue +0 -30
  201. package/src/components/ToastItem.vue +0 -158
  202. package/src/components/ToastRenderer.vue +0 -113
  203. package/src/components/Toaster.vue +0 -11
  204. package/src/components/Tooltip.vue +0 -48
  205. package/src/components/TopBar.vue +0 -52
  206. package/src/lib/toast.ts +0 -95
  207. package/src/lib/types.ts +0 -5
@@ -0,0 +1,97 @@
1
+ <script setup lang="ts">
2
+ import { computed, type HTMLAttributes } from 'vue'
3
+ import { ProgressRoot } from 'reka-ui'
4
+ import { cn } from '../../lib/cn'
5
+
6
+ /**
7
+ * A circular progress indicator.
8
+ *
9
+ * - No `value` (or `null`): continuous spinner, for waits of unknown length.
10
+ * - `value` from 0 to `max`: a ring that fills as the value goes up.
11
+ *
12
+ * It takes the surrounding text colour, like an icon, so put a text colour
13
+ * class on it or its parent (e.g. `class="text-primary"`).
14
+ */
15
+ export interface SpinnerProps {
16
+ /** Progress from 0 to `max`. Leave out (or null) for a continuous spinner. */
17
+ value?: number | null
18
+ /** The value that means complete. */
19
+ max?: number
20
+ /** sm 16px (button icon size) · md 24px · lg 48px */
21
+ size?: 'sm' | 'md' | 'lg'
22
+ /** What is loading, read by screen readers, e.g. "Uploading report". */
23
+ label?: string
24
+ /** Show the percentage in the middle. Only on `lg`, and only with a value. */
25
+ showValue?: boolean
26
+ class?: HTMLAttributes['class']
27
+ }
28
+
29
+ const props = withDefaults(defineProps<SpinnerProps>(), {
30
+ max: 100,
31
+ size: 'md',
32
+ label: 'Loading'
33
+ })
34
+
35
+ const indeterminate = computed(() => props.value === null || props.value === undefined)
36
+ // 0–1, kept within range so a value over max still draws a full ring.
37
+ const fraction = computed(() =>
38
+ indeterminate.value ? 0 : Math.min(Math.max((props.value as number) / props.max, 0), 1)
39
+ )
40
+ const percent = computed(() => Math.round(fraction.value * 100))
41
+
42
+ // Ring geometry, in a 24×24 viewBox.
43
+ const radius = 10
44
+ const circumference = 2 * Math.PI * radius
45
+ // Continuous: a quarter of the ring spins. Otherwise the arc grows with the value.
46
+ const dashOffset = computed(() => circumference * (indeterminate.value ? 0.75 : 1 - fraction.value))
47
+
48
+ const sizes: Record<NonNullable<SpinnerProps['size']>, string> = {
49
+ sm: 'size-4',
50
+ md: 'size-6',
51
+ lg: 'size-12'
52
+ }
53
+ </script>
54
+
55
+ <template>
56
+ <ProgressRoot
57
+ as="span"
58
+ :model-value="indeterminate ? null : fraction * max"
59
+ :max="max"
60
+ :aria-label="label"
61
+ :class="cn('relative inline-flex shrink-0 items-center justify-center', sizes[size], props.class)"
62
+ >
63
+ <svg
64
+ viewBox="0 0 24 24"
65
+ fill="none"
66
+ aria-hidden="true"
67
+ :class="cn(
68
+ 'size-full -rotate-90',
69
+ indeterminate && 'animate-spin motion-reduce:animate-[spin_2s_linear_infinite]'
70
+ )"
71
+ >
72
+ <!-- Track -->
73
+ <circle cx="12" cy="12" :r="radius" stroke="currentColor" stroke-opacity="0.2" stroke-width="2.5" />
74
+ <!-- Arc. Hidden at exactly 0%, where a round line cap would still draw a dot. -->
75
+ <circle
76
+ cx="12"
77
+ cy="12"
78
+ :r="radius"
79
+ stroke="currentColor"
80
+ stroke-width="2.5"
81
+ stroke-linecap="round"
82
+ :stroke-dasharray="circumference"
83
+ :stroke-dashoffset="dashOffset"
84
+ :stroke-opacity="!indeterminate && fraction === 0 ? 0 : 1"
85
+ class="transition-[stroke-dashoffset] duration-300 ease-out motion-reduce:transition-none"
86
+ />
87
+ </svg>
88
+
89
+ <span
90
+ v-if="showValue && size === 'lg' && !indeterminate"
91
+ aria-hidden="true"
92
+ class="absolute text-xs tabular-nums"
93
+ >
94
+ {{ percent }}%
95
+ </span>
96
+ </ProgressRoot>
97
+ </template>
@@ -0,0 +1,75 @@
1
+ import type { Meta, StoryObj } from "@storybook/vue3-vite";
2
+ import { CalendarCheck, FileText, Users, UserX } from "@lucide/vue";
3
+ import StatTile from "./StatTile.vue";
4
+
5
+ const meta = {
6
+ title: "Components/Data/StatTile",
7
+ component: StatTile,
8
+ tags: ["autodocs"],
9
+ parameters: { backgrounds: { disable: true } },
10
+ argTypes: {
11
+ trend: { options: [undefined, "up", "down", "flat"], control: { type: "inline-radio" } },
12
+ sentiment: { options: [undefined, "positive", "negative", "neutral"], control: { type: "inline-radio" } },
13
+ },
14
+ args: {
15
+ label: "Open applications",
16
+ value: "48",
17
+ change: "+12%",
18
+ changeLabel: "on last year",
19
+ trend: "up",
20
+ class: "max-w-xs",
21
+ },
22
+ decorators: [() => ({ template: '<div class="bg-background p-6"><story /></div>' })],
23
+ } satisfies Meta<typeof StatTile>;
24
+
25
+ export default meta;
26
+ type Story = StoryObj<typeof meta>;
27
+
28
+ /** Playground. */
29
+ export const Default: Story = {};
30
+
31
+ /** Just a label and a number. */
32
+ export const Plain: Story = { args: { change: undefined, changeLabel: undefined, trend: undefined } };
33
+
34
+ /** Down is good for absences: sentiment="positive" makes it green. */
35
+ export const DownIsGood: Story = {
36
+ args: { label: "Unauthorised absences", value: "2.1%", change: "−0.4 pts", changeLabel: "this term", trend: "down", sentiment: "positive", icon: UserX },
37
+ };
38
+
39
+ /** In a grid, as on a dashboard. Tiles fill the row and wrap as space allows. */
40
+ export const Grid: Story = {
41
+ render: () => ({
42
+ components: { StatTile },
43
+ setup: () => ({ Users, FileText, CalendarCheck, UserX }),
44
+ template: `
45
+ <div class="grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-4">
46
+ <StatTile label="Students on roll" value="1,204" :icon="Users" change="+38" change-label="since September" trend="up" />
47
+ <StatTile label="Open applications" value="48" :icon="FileText" change="+12%" change-label="on last year" trend="up" />
48
+ <StatTile label="Attendance" value="95.8%" :icon="CalendarCheck" change="0.0 pts" change-label="on last week" trend="flat" />
49
+ <StatTile label="Persistent absence" value="7.4%" :icon="UserX" change="+0.9 pts" change-label="this term" trend="up" sentiment="negative" />
50
+ </div>`,
51
+ }),
52
+ };
53
+
54
+ /** With a description and a footer link. */
55
+ export const WithDescriptionAndFooter: Story = {
56
+ args: { description: "Waiting for an interview or a decision.", change: undefined, changeLabel: undefined, trend: undefined },
57
+ render: (args) => ({
58
+ components: { StatTile },
59
+ setup: () => ({ args }),
60
+ template: `
61
+ <StatTile v-bind="args">
62
+ <template #footer><a href="#" class="font-bold text-primary underline-offset-2 hover:underline">View applications</a></template>
63
+ </StatTile>`,
64
+ }),
65
+ };
66
+
67
+ /** A unit in smaller text, using the value slot. */
68
+ export const WithUnit: Story = {
69
+ args: { label: "Average class size", change: undefined, changeLabel: undefined, trend: undefined },
70
+ render: (args) => ({
71
+ components: { StatTile },
72
+ setup: () => ({ args }),
73
+ template: `<StatTile v-bind="args"><template #value>27.4 <span class="text-sm font-normal text-black/65">students</span></template></StatTile>`,
74
+ }),
75
+ };
@@ -0,0 +1,89 @@
1
+ <script setup lang="ts">
2
+ import { computed, type Component, type HTMLAttributes } from 'vue'
3
+ import { ArrowDownRight, ArrowRight, ArrowUpRight } from '@lucide/vue'
4
+ import { cn } from '../../lib/cn'
5
+ import Card from '../Card/Card.vue'
6
+
7
+ /**
8
+ * One number that matters, in a small Card: "Open applications 48".
9
+ * Put several in a grid. Optionally with how it's changed ("+12% on last
10
+ * year") and a short description.
11
+ *
12
+ * Slots: value (e.g. a value with a unit in smaller text), description,
13
+ * footer (e.g. a "View all" link).
14
+ */
15
+ export interface StatTileProps {
16
+ /** What the number is, e.g. "Open applications". */
17
+ label: string
18
+ /** The number, already formatted, e.g. "1,204" or "96%". */
19
+ value?: string | number
20
+ /** Icon before the label. Decorative. */
21
+ icon?: Component
22
+ /** How it's changed, already formatted, e.g. "+12%" or "−3". */
23
+ change?: string
24
+ /** What the change is against, e.g. "on last year". Read after the change. */
25
+ changeLabel?: string
26
+ /** Which way it went. Sets the arrow. */
27
+ trend?: 'up' | 'down' | 'flat'
28
+ /**
29
+ * Whether the change is good, which sets the colour: green good, red bad,
30
+ * grey neutral. Defaults to up good, down bad, flat neutral. Set it when
31
+ * down is good, e.g. absences.
32
+ */
33
+ sentiment?: 'positive' | 'negative' | 'neutral'
34
+ /** Grey text under the value. */
35
+ description?: string
36
+ class?: HTMLAttributes['class']
37
+ }
38
+
39
+ const props = defineProps<StatTileProps>()
40
+
41
+ defineSlots<{
42
+ value?(): unknown
43
+ description?(): unknown
44
+ footer?(): unknown
45
+ }>()
46
+
47
+ const tone = computed(() => {
48
+ if (props.sentiment) return props.sentiment
49
+ if (props.trend === 'up') return 'positive'
50
+ if (props.trend === 'down') return 'negative'
51
+ return 'neutral'
52
+ })
53
+
54
+ const toneClasses = { positive: 'text-green', negative: 'text-red', neutral: 'text-black/65' } as const
55
+ const trendIcon = computed(() =>
56
+ props.trend === 'up' ? ArrowUpRight : props.trend === 'down' ? ArrowDownRight : props.trend === 'flat' ? ArrowRight : undefined
57
+ )
58
+ // The arrow is decorative, so say the direction in words for screen readers.
59
+ const trendWords = { up: 'Up', down: 'Down', flat: 'No change' } as const
60
+ </script>
61
+
62
+ <template>
63
+ <Card padding="sm" :class="props.class" :ui="{ body: 'gap-1' }">
64
+ <p class="flex items-center gap-2 text-sm text-black/65">
65
+ <component :is="icon" v-if="icon" class="size-4 shrink-0" aria-hidden="true" />
66
+ {{ label }}
67
+ </p>
68
+
69
+ <div class="flex flex-wrap items-baseline gap-x-2 gap-y-1">
70
+ <p class="text-2xl font-bold tabular-nums">
71
+ <slot name="value">{{ value ?? '—' }}</slot>
72
+ </p>
73
+ <p v-if="change || trend" :class="cn('inline-flex items-center gap-0.5 text-sm', toneClasses[tone])">
74
+ <component :is="trendIcon" v-if="trendIcon" class="size-4 shrink-0" aria-hidden="true" />
75
+ <span v-if="trend" class="sr-only">{{ trendWords[trend] }}</span>
76
+ <span v-if="change" class="font-bold tabular-nums">{{ change }}</span>
77
+ <span v-if="changeLabel" class="text-black/65">&nbsp;{{ changeLabel }}</span>
78
+ </p>
79
+ </div>
80
+
81
+ <p v-if="description || $slots.description" class="text-sm text-black/65">
82
+ <slot name="description">{{ description }}</slot>
83
+ </p>
84
+
85
+ <div v-if="$slots.footer" class="mt-2 text-sm">
86
+ <slot name="footer" />
87
+ </div>
88
+ </Card>
89
+ </template>
@@ -0,0 +1,103 @@
1
+ import type { Meta, StoryObj } from "@storybook/vue3-vite";
2
+ import Badge from "../Badge/Badge.vue";
3
+ import Button from "../Button/Button.vue";
4
+ import Card from "../Card/Card.vue";
5
+ import SummaryList, { type SummaryListProps } from "./SummaryList.vue";
6
+
7
+ const details = [
8
+ { label: "Name", value: "Amelia Clarke" },
9
+ { label: "Date of birth", value: "14 March 2015" },
10
+ { label: "Year group", value: "Year 7 (September 2027)" },
11
+ { label: "Current school", value: "Hillside Primary School", description: "Since September 2019" },
12
+ { label: "Parent or carer", value: "Sarah Clarke" },
13
+ { label: "Email", value: "sarah.clarke@example.com" },
14
+ { label: "Medical needs", value: null },
15
+ ];
16
+
17
+ const meta = {
18
+ title: "Components/Data/SummaryList",
19
+ // A generic component, which Meta<typeof SummaryList> can't describe, so the args are typed by its props.
20
+ component: SummaryList as any,
21
+ tags: ["autodocs"],
22
+ parameters: { backgrounds: { disable: true } },
23
+ argTypes: {
24
+ layout: { options: ["rows", "compact", "stacked"], control: { type: "inline-radio" } },
25
+ labelWidth: { options: ["sm", "md", "lg"], control: { type: "inline-radio" } },
26
+ },
27
+ args: { items: details, layout: "rows", labelWidth: "md" },
28
+ decorators: [() => ({ template: '<div class="bg-background p-6"><div class="max-w-2xl"><story /></div></div>' })],
29
+ render: (args) => ({
30
+ components: { SummaryList, Card },
31
+ setup: () => ({ args }),
32
+ template: `<Card title="Applicant"><SummaryList v-bind="args" /></Card>`,
33
+ }),
34
+ } satisfies Meta<SummaryListProps>;
35
+
36
+ export default meta;
37
+ type Story = StoryObj<typeof meta>;
38
+
39
+ /** Rows: label beside value, a line between. Stacks when the card is narrow. An empty value shows "—". */
40
+ export const Default: Story = {};
41
+
42
+ /** A Change action per row, for checking answers before submitting. */
43
+ export const WithActions: Story = {
44
+ render: (args) => ({
45
+ components: { SummaryList, Card, Button },
46
+ setup: () => ({ args }),
47
+ template: `
48
+ <Card title="Check the application">
49
+ <SummaryList v-bind="args">
50
+ <template #action="{ item }">
51
+ <Button variant="ghost" size="sm">Change<span class="sr-only"> {{ item.label.toLowerCase() }}</span></Button>
52
+ </template>
53
+ </SummaryList>
54
+ </Card>`,
55
+ }),
56
+ };
57
+
58
+ /** Compact: figures right-aligned, for a summary card or sidebar. */
59
+ export const Compact: Story = {
60
+ args: {
61
+ layout: "compact",
62
+ items: [
63
+ { label: "Moving up a year", value: "1,042" },
64
+ { label: "Leaving (Year 13)", value: "162" },
65
+ { label: "Joining Year 7", value: "180" },
66
+ { label: "On roll in September", value: "1,222", emphasis: true },
67
+ ],
68
+ },
69
+ decorators: [() => ({ template: '<div class="bg-background p-6"><div class="max-w-xs"><story /></div></div>' })],
70
+ render: (args) => ({
71
+ components: { SummaryList, Card },
72
+ setup: () => ({ args }),
73
+ template: `<Card as="aside" title="Summary" padding="sm"><SummaryList v-bind="args" /></Card>`,
74
+ }),
75
+ };
76
+
77
+ /** Stacked: label above value, in up to 3 columns. With a Badge in the value slot. */
78
+ export const Stacked: Story = {
79
+ args: {
80
+ layout: "stacked",
81
+ items: [
82
+ { label: "Class", value: "8Y/En2" },
83
+ { label: "Teacher", value: "Mr Blissett" },
84
+ { label: "Room", value: "E14" },
85
+ { label: "Students", value: "27" },
86
+ { label: "Status", value: "Active" },
87
+ { label: "Timetable", value: "Week A, periods 2 and 5" },
88
+ ],
89
+ },
90
+ render: (args) => ({
91
+ components: { SummaryList, Card, Badge },
92
+ setup: () => ({ args }),
93
+ template: `
94
+ <Card title="8Y/En2">
95
+ <SummaryList v-bind="args">
96
+ <template #value="{ item }">
97
+ <Badge v-if="item.label === 'Status'" size="sm" color="green">{{ item.value }}</Badge>
98
+ <template v-else>{{ item.value }}</template>
99
+ </template>
100
+ </SummaryList>
101
+ </Card>`,
102
+ }),
103
+ };
@@ -0,0 +1,127 @@
1
+ <script setup lang="ts" generic="Item extends SummaryListItem">
2
+ import type { HTMLAttributes } from 'vue'
3
+ import { cn } from '../../lib/cn'
4
+
5
+ /**
6
+ * Labelled values, e.g. a record's details or a summary before you submit:
7
+ * "Email office@keston.school". A description list (`<dl>`) underneath.
8
+ *
9
+ * Layouts:
10
+ * - rows (default): label on the left, value beside it, a line between rows.
11
+ * Stacks the label above the value when the container is narrow (under
12
+ * 384px). With an action per row (e.g. Change) for check-your-answers pages.
13
+ * - compact: label left, value right-aligned, no lines. For figures in a
14
+ * sidebar or summary card ("Moving up a year 1,204").
15
+ * - stacked: label above value, in a grid of up to 3 columns as space
16
+ * allows. For a lot of short facts.
17
+ *
18
+ * Slots: value (scoped `{ item, index }`, for a Badge, link, etc.), action
19
+ * (scoped, e.g. a Change button).
20
+ */
21
+ export interface SummaryListItem {
22
+ label: string
23
+ /** Shown as text. Empty shows "—" (read as "Not set"). Use the value slot for anything richer. */
24
+ value?: string | number | null
25
+ /** Smaller grey text under the value. */
26
+ description?: string
27
+ /** Bold value, e.g. a total. */
28
+ emphasis?: boolean
29
+ }
30
+
31
+ export interface SummaryListProps<Item extends SummaryListItem = SummaryListItem> {
32
+ items: Item[]
33
+ layout?: 'rows' | 'compact' | 'stacked'
34
+ /** Width of the label column in the rows layout. */
35
+ labelWidth?: 'sm' | 'md' | 'lg'
36
+ /** What an empty value is read as. */
37
+ emptyLabel?: string
38
+ class?: HTMLAttributes['class']
39
+ }
40
+
41
+ const props = withDefaults(defineProps<SummaryListProps<Item>>(), {
42
+ layout: 'rows',
43
+ labelWidth: 'md',
44
+ emptyLabel: 'Not set'
45
+ })
46
+
47
+ defineSlots<{
48
+ value?(props: { item: Item; index: number }): unknown
49
+ action?(props: { item: Item; index: number }): unknown
50
+ }>()
51
+
52
+ const isEmpty = (value: SummaryListItem['value']) => value === null || value === undefined || value === ''
53
+
54
+ // 128 / 192 / 256px label column, from the container's @sm (384px).
55
+ const labelWidths = {
56
+ sm: '@sm:grid-cols-[8rem_1fr_auto]',
57
+ md: '@sm:grid-cols-[12rem_1fr_auto]',
58
+ lg: '@sm:grid-cols-[16rem_1fr_auto]'
59
+ } as const
60
+ </script>
61
+
62
+ <template>
63
+ <div :class="cn('@container text-sm text-black', props.class)">
64
+ <dl
65
+ :class="
66
+ cn(
67
+ layout === 'rows' && 'flex flex-col',
68
+ layout === 'compact' && 'grid grid-cols-[1fr_auto] gap-x-4 gap-y-2',
69
+ layout === 'stacked' && 'grid grid-cols-1 gap-x-6 gap-y-4 @sm:grid-cols-2 @2xl:grid-cols-3'
70
+ )
71
+ "
72
+ >
73
+ <!-- rows -->
74
+ <template v-if="layout === 'rows'">
75
+ <div
76
+ v-for="(item, index) in items"
77
+ :key="item.label"
78
+ :class="
79
+ cn(
80
+ 'grid grid-cols-[1fr_auto] gap-x-4 gap-y-1 border-b border-black/15 py-3 first:pt-0 last:border-b-0 last:pb-0',
81
+ labelWidths[labelWidth]
82
+ )
83
+ "
84
+ >
85
+ <dt class="col-span-2 text-black/65 @sm:col-span-1">{{ item.label }}</dt>
86
+ <dd :class="cn('min-w-0 break-words', item.emphasis && 'font-bold', !$slots.action && 'col-span-2')">
87
+ <slot name="value" :item="item" :index="index">
88
+ <template v-if="!isEmpty(item.value)">{{ item.value }}</template>
89
+ <template v-else><span class="text-black/40" aria-hidden="true">—</span><span class="sr-only">{{ emptyLabel }}</span></template>
90
+ </slot>
91
+ <span v-if="item.description" class="mt-0.5 block text-black/65">{{ item.description }}</span>
92
+ </dd>
93
+ <dd v-if="$slots.action" class="justify-self-end">
94
+ <slot name="action" :item="item" :index="index" />
95
+ </dd>
96
+ </div>
97
+ </template>
98
+
99
+ <!-- compact and stacked: one div per pair keeps dt/dd together for screen readers -->
100
+ <template v-else>
101
+ <div
102
+ v-for="(item, index) in items"
103
+ :key="item.label"
104
+ :class="layout === 'compact' ? 'col-span-2 grid grid-cols-subgrid items-baseline' : 'flex min-w-0 flex-col gap-1'"
105
+ >
106
+ <dt class="text-black/65">{{ item.label }}</dt>
107
+ <dd
108
+ :class="
109
+ cn(
110
+ 'min-w-0 break-words',
111
+ layout === 'compact' && 'text-right font-bold tabular-nums',
112
+ item.emphasis && 'font-bold'
113
+ )
114
+ "
115
+ >
116
+ <slot name="value" :item="item" :index="index">
117
+ <template v-if="!isEmpty(item.value)">{{ item.value }}</template>
118
+ <template v-else><span class="text-black/40" aria-hidden="true">—</span><span class="sr-only">{{ emptyLabel }}</span></template>
119
+ </slot>
120
+ <span v-if="item.description" class="mt-0.5 block font-normal text-black/65">{{ item.description }}</span>
121
+ <span v-if="$slots.action" class="mt-1 block font-normal"><slot name="action" :item="item" :index="index" /></span>
122
+ </dd>
123
+ </div>
124
+ </template>
125
+ </dl>
126
+ </div>
127
+ </template>
@@ -0,0 +1,100 @@
1
+ import type { Meta, StoryObj } from "@storybook/vue3-vite";
2
+ import { ref } from "vue";
3
+ import Switch, { type SwitchProps } from "./Switch.vue";
4
+
5
+ const meta = {
6
+ title: "Components/Form/Switch",
7
+ component: Switch,
8
+ tags: ["autodocs"],
9
+ argTypes: {
10
+ status: { options: [undefined, "error", "success", "loading"], control: { type: "inline-radio" } },
11
+ },
12
+ args: {
13
+ label: "Email me when an application arrives",
14
+ description: "",
15
+ disabled: false,
16
+ },
17
+ decorators: [() => ({ template: '<div class="max-w-80"><story /></div>' })],
18
+ render: (args) => ({
19
+ components: { Switch },
20
+ setup: () => ({ args, value: ref(false) }),
21
+ template: '<Switch v-bind="args" v-model="value" />',
22
+ }),
23
+ } satisfies Meta<typeof Switch>;
24
+
25
+ export default meta;
26
+ type Story = StoryObj<typeof meta>;
27
+
28
+ /** Playground: use the controls below. */
29
+ export const Default: Story = {};
30
+
31
+ export const WithDescription: Story = {
32
+ args: {
33
+ label: "Weekly summary",
34
+ description: "A Monday email with new applications, interviews and offers.",
35
+ },
36
+ };
37
+
38
+ /**
39
+ * A setting saved as soon as it's flipped: "Saving…" while it saves, then
40
+ * "Saved". Here the save is faked with a delay, and every third one fails,
41
+ * putting the switch back.
42
+ */
43
+ export const SavesStraightAway: Story = {
44
+ args: { label: "Show students' photos in registers" },
45
+ render: (args) => ({
46
+ components: { Switch },
47
+ setup() {
48
+ const value = ref(true);
49
+ const status = ref<SwitchProps["status"]>();
50
+ const statusText = ref<string>();
51
+ let saves = 0;
52
+ let timer: ReturnType<typeof setTimeout> | undefined;
53
+ async function save(next: boolean) {
54
+ clearTimeout(timer);
55
+ status.value = "loading";
56
+ statusText.value = "Saving…";
57
+ await new Promise((resolve) => setTimeout(resolve, 900));
58
+ if (++saves % 3 === 0) {
59
+ value.value = !next;
60
+ status.value = "error";
61
+ statusText.value = "Couldn't save. Try again.";
62
+ return;
63
+ }
64
+ status.value = "success";
65
+ statusText.value = "Saved";
66
+ // The confirmation goes once it's been seen.
67
+ timer = setTimeout(() => (statusText.value = status.value = undefined), 2000);
68
+ }
69
+ return { args, value, status, statusText, save };
70
+ },
71
+ template:
72
+ '<Switch v-bind="args" v-model="value" :status="status" :status-text="statusText" @update:model-value="save" />',
73
+ }),
74
+ };
75
+
76
+ /** A list of settings, each with its own switch. */
77
+ export const SettingsList: Story = {
78
+ render: () => ({
79
+ components: { Switch },
80
+ setup: () => ({
81
+ settings: ref([
82
+ { label: "New applications", description: "As soon as one is submitted.", on: true },
83
+ { label: "Interview reminders", description: "The day before, at 8am.", on: true },
84
+ { label: "Offers accepted", description: "", on: false },
85
+ ]),
86
+ }),
87
+ template: `
88
+ <div class="flex flex-col gap-4">
89
+ <Switch
90
+ v-for="setting in settings"
91
+ :key="setting.label"
92
+ v-model="setting.on"
93
+ :label="setting.label"
94
+ :description="setting.description || undefined"
95
+ />
96
+ </div>`,
97
+ }),
98
+ };
99
+
100
+ export const Disabled: Story = { args: { disabled: true } };