@thekestongroup/ui 0.2.0 → 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,160 @@
1
+ <script setup lang="ts">
2
+ import { computed, useId, type HTMLAttributes } from 'vue'
3
+ import { cn } from '../../lib/cn'
4
+ import InfoTip from '../InfoTip/InfoTip.vue'
5
+ import FieldMessage, { type FieldStatus } from './FieldMessage.vue'
6
+
7
+ /**
8
+ * Shared shell for form controls: label, helper text (below or behind a `?`),
9
+ * the bordered box styled like a medium basic Button, and the status message
10
+ * that slides out underneath. Input, InputNumber, InputDate and Select use
11
+ * it; use it too for a text control the library doesn't have, so it looks and
12
+ * behaves like the rest. The control goes in the default slot, which receives
13
+ * the id and ARIA values to put on it.
14
+ */
15
+
16
+ export type FormFieldStatus = FieldStatus
17
+
18
+ export interface FormFieldProps {
19
+ /** Visible label. Always set it: it is also the control's accessible name. */
20
+ label: string
21
+ /** Extra guidance about what to enter. */
22
+ helper?: string
23
+ /** Show helper text under the label, or behind a `?` icon next to it. */
24
+ helperPlacement?: 'below' | 'icon'
25
+ /**
26
+ * Error message, e.g. from a Zod / VeeValidate schema. When set (and not
27
+ * empty) the field shows as an error with this text; leave it undefined
28
+ * when the value is valid. Overrides `status` and `statusText`.
29
+ */
30
+ errorText?: string
31
+ /**
32
+ * Colours the field and the status text. `loading` shows a small spinner
33
+ * by the status text while something is checked, e.g. "Checking
34
+ * availability…", and leaves the border as it is.
35
+ */
36
+ status?: FormFieldStatus
37
+ /** Message under the field, e.g. why the value is invalid. */
38
+ statusText?: string
39
+ disabled?: boolean
40
+ class?: HTMLAttributes['class']
41
+ }
42
+
43
+ const props = withDefaults(defineProps<FormFieldProps>(), {
44
+ helperPlacement: 'below'
45
+ })
46
+
47
+ defineSlots<{
48
+ default(props: { id: string; labelId: string; describedBy?: string; invalid?: true }): unknown
49
+ leading?(): unknown
50
+ trailing?(): unknown
51
+ /**
52
+ * At the end of the label row, e.g. a "Forgot password?" link. It comes
53
+ * after the control in the page, so Tab reaches it after the field.
54
+ */
55
+ 'label-trailing'?(): unknown
56
+ }>()
57
+
58
+ const id = useId()
59
+ const controlId = `${id}-control`
60
+ const labelId = `${id}-label`
61
+ const helperId = `${id}-helper`
62
+ const statusId = `${id}-status`
63
+
64
+ // ── Status ──────────────────────────────────────────────────────────────────
65
+ // Priority: errorText, then status / statusText.
66
+ const currentStatus = computed<FormFieldStatus | undefined>(() =>
67
+ props.errorText ? 'error' : props.status
68
+ )
69
+ const currentStatusText = computed(() => props.errorText || props.statusText)
70
+
71
+ const describedBy = computed(() =>
72
+ [props.helper && helperId, currentStatusText.value && statusId].filter(Boolean).join(' ') || undefined
73
+ )
74
+
75
+
76
+ // ── Box ─────────────────────────────────────────────────────────────────────
77
+ // Clicking the box's padding or decorative icons focuses the control. Clicks
78
+ // on the control itself or on buttons inside (e.g. − / +) are left alone.
79
+ const focusable = 'input, textarea, [role="spinbutton"], [contenteditable="true"]'
80
+ function focusControl(event: PointerEvent) {
81
+ const target = event.target as Element
82
+ if (props.disabled || target.closest(`${focusable}, button`)) return
83
+ event.preventDefault()
84
+ ;(event.currentTarget as Element).querySelector<HTMLElement>(focusable)?.focus()
85
+ }
86
+
87
+ // A <label> only focuses form elements. Others, like InputRichText's
88
+ // contenteditable <div>, are focused by hand (they have no `labels` list).
89
+ function focusUnlabelable() {
90
+ const control = document.getElementById(controlId)
91
+ if (control && !('labels' in control) && !props.disabled) control.focus()
92
+ }
93
+
94
+ // Same look as a medium basic Button. The focus ring follows :focus-visible,
95
+ // so it shows for keyboard use only: text boxes always count (you're typing),
96
+ // but buttons inside don't after a click, or when a closing list (Select)
97
+ // hands focus back after the mouse was used.
98
+ //
99
+ // Text is 16px on touch screens: iPhone zooms the page into any field with
100
+ // smaller text when it's tapped. 16px stops that without blocking pinch-zoom.
101
+ const box = [
102
+ 'flex items-center gap-2 px-3 py-2 text-sm pointer-coarse:text-base [&_svg]:size-4 [&_svg]:shrink-0 [&_svg]:opacity-70',
103
+ 'bg-white text-black border border-black/15 rounded cursor-text transition',
104
+ 'outline-2 outline-offset-1 outline-transparent forced-colors:not-has-focus-visible:outline-0',
105
+ 'has-focus-visible:outline-focus',
106
+ // A control can mark itself data-pointer-focus to hide the ring while it
107
+ // holds focus that came from the mouse (Select, after its list closes).
108
+ 'has-[[data-pointer-focus]]:outline-transparent!'
109
+ ]
110
+
111
+ const statusBorder: Record<FormFieldStatus, string> = {
112
+ error: 'border-red',
113
+ success: 'border-green',
114
+ loading: ''
115
+ }
116
+
117
+ </script>
118
+
119
+ <template>
120
+ <div :class="cn('flex flex-col gap-1.5 text-black', props.class)">
121
+ <!-- Label row and box in a grid, so label-trailing can come after the
122
+ box in the page (and the Tab order) but show at the end of the label row. -->
123
+ <div :class="cn('grid grid-cols-[minmax(0,1fr)_auto] gap-y-1.5', $slots['label-trailing'] && 'gap-x-3')">
124
+ <div class="col-start-1 row-start-1 flex flex-col gap-0.5">
125
+ <div class="flex items-center gap-1">
126
+ <label :id="labelId" :for="controlId" class="text-sm" @click="focusUnlabelable">{{ label }}</label>
127
+
128
+ <!-- Screen readers get the helper from the control's aria-describedby
129
+ (the hidden copy below), so the ? is for sighted users. -->
130
+ <InfoTip v-if="helper && helperPlacement === 'icon'" :text="helper" :label="`About ${label}`" />
131
+ </div>
132
+
133
+ <!-- Behind the ?: hidden, but still the control's description. -->
134
+ <p v-if="helper" :id="helperId" :hidden="helperPlacement === 'icon'" class="text-xs text-black/65">
135
+ {{ helper }}
136
+ </p>
137
+ </div>
138
+
139
+ <div
140
+ :class="cn(box, 'col-span-2 row-start-2', currentStatus && statusBorder[currentStatus], disabled && 'opacity-40 cursor-not-allowed')"
141
+ @pointerdown="focusControl"
142
+ >
143
+ <slot name="leading" />
144
+ <slot
145
+ :id="controlId"
146
+ :label-id="labelId"
147
+ :described-by="describedBy"
148
+ :invalid="currentStatus === 'error' || undefined"
149
+ />
150
+ <slot name="trailing" />
151
+ </div>
152
+
153
+ <div v-if="$slots['label-trailing']" class="col-start-2 row-start-1 flex h-5 items-center text-xs">
154
+ <slot name="label-trailing" />
155
+ </div>
156
+ </div>
157
+
158
+ <FieldMessage :id="statusId" :status="currentStatus" :text="currentStatusText" />
159
+ </div>
160
+ </template>
@@ -0,0 +1,168 @@
1
+ import type { Meta, StoryObj } from "@storybook/vue3-vite";
2
+ import { Bell, Building2, ChevronRight } from "@lucide/vue";
3
+ import { ref } from "vue";
4
+ import Button from "../Button/Button.vue";
5
+ import Header, { type HeaderUser } from "./Header.vue";
6
+
7
+ const user: HeaderUser = {
8
+ name: "Ben Smith",
9
+ email: "ben.smith@keston.school",
10
+ organisation: "The Keston School",
11
+ };
12
+
13
+ const meta = {
14
+ title: "Components/Layout/Header",
15
+ component: Header,
16
+ tags: ["autodocs"],
17
+ parameters: { layout: "fullscreen" },
18
+ args: {
19
+ title: "Keston Admissions",
20
+ menu: true,
21
+ sticky: true,
22
+ user,
23
+ signIn: true,
24
+ },
25
+ render: (args) => ({
26
+ components: { Header, Button, Bell },
27
+ setup() {
28
+ const last = ref("");
29
+ return { args, last };
30
+ },
31
+ template: `
32
+ <div>
33
+ <Header
34
+ v-bind="args"
35
+ @account-settings="last = 'account-settings'"
36
+ @switch-account="last = 'switch-account'"
37
+ @log-out="last = 'log-out'"
38
+ @sign-in="last = 'sign-in'"
39
+ >
40
+ <template #trailing>
41
+ <Button variant="ghost" square aria-label="Notifications"><Bell /></Button>
42
+ </template>
43
+ </Header>
44
+ <p class="p-4 text-sm text-black/65">Last event: {{ last || "none" }}</p>
45
+ </div>`,
46
+ }),
47
+ } satisfies Meta<typeof Header>;
48
+
49
+ export default meta;
50
+ type Story = StoryObj<typeof meta>;
51
+
52
+ /**
53
+ * Playground: use the controls below. The avatar on the right opens the
54
+ * account menu; its actions emit account-settings, switch-account and log-out.
55
+ */
56
+ export const Default: Story = {};
57
+
58
+ /** A picture instead of initials. */
59
+ export const WithAvatar: Story = {
60
+ args: {
61
+ user: { ...user, avatar: "https://i.pravatar.cc/96?img=12" },
62
+ },
63
+ };
64
+
65
+ /** Signed out: a Sign in button (emits sign-in) in place of the account menu. */
66
+ export const SignedOut: Story = {
67
+ args: { user: undefined },
68
+ };
69
+
70
+ /** Only some account actions, e.g. an app where people can't switch account. */
71
+ export const FewerActions: Story = {
72
+ args: { userActions: ["account-settings", "log-out"] },
73
+ };
74
+
75
+ /** Extra content in the account menu with the account-menu slot, above the actions. */
76
+ export const CustomUserMenu: Story = {
77
+ render: (args) => ({
78
+ components: { Header, Button, Building2 },
79
+ setup: () => ({ args }),
80
+ template: `
81
+ <Header v-bind="args">
82
+ <template #account-menu="{ close }">
83
+ <div class="flex flex-col gap-1 border-t border-black/15 p-2">
84
+ <p class="px-3 pt-1 text-xs font-bold text-black/65 uppercase">Switch school</p>
85
+ <Button variant="ghost" class="w-full justify-start px-3" @click="close">
86
+ <template #leading><Building2 /></template>Keston Prep
87
+ </Button>
88
+ <Button variant="ghost" class="w-full justify-start px-3" @click="close">
89
+ <template #leading><Building2 /></template>Keston Sixth Form
90
+ </Button>
91
+ </div>
92
+ </template>
93
+ </Header>`,
94
+ }),
95
+ };
96
+
97
+ /** The whole account area replaced with the account slot. */
98
+ export const CustomUser: Story = {
99
+ render: (args) => ({
100
+ components: { Header, Button },
101
+ setup: () => ({ args }),
102
+ template: `
103
+ <Header v-bind="args">
104
+ <template #account><Button size="sm">Help</Button></template>
105
+ </Header>`,
106
+ }),
107
+ };
108
+
109
+ /** Just the title: no menu button, actions or account menu. */
110
+ export const TitleOnly: Story = {
111
+ args: { menu: false, user: undefined, signIn: false },
112
+ render: (args) => ({
113
+ components: { Header },
114
+ setup: () => ({ args }),
115
+ template: `<Header v-bind="args" />`,
116
+ }),
117
+ };
118
+
119
+ /** Content in the middle slot (here, breadcrumbs) fills the space between the title and the actions. */
120
+ export const WithMiddle: Story = {
121
+ render: (args) => ({
122
+ components: { Header, Button, Bell, ChevronRight },
123
+ setup: () => ({ args }),
124
+ template: `
125
+ <Header v-bind="args">
126
+ <nav aria-label="Breadcrumb" class="ml-2 hidden items-center gap-1 text-sm text-black/65 sm:flex [&_svg]:size-4">
127
+ <ChevronRight aria-hidden="true" />
128
+ <a href="#" class="hover:underline">Students</a>
129
+ <ChevronRight aria-hidden="true" />
130
+ <span aria-current="page" class="text-black">Ben Smith</span>
131
+ </nav>
132
+ <template #trailing>
133
+ <Button variant="ghost" square aria-label="Notifications"><Bell /></Button>
134
+ <Button size="sm" variant="primary">New student</Button>
135
+ </template>
136
+ </Header>`,
137
+ }),
138
+ };
139
+
140
+ /** A logo in the leading slot, before the title. */
141
+ export const WithLogo: Story = {
142
+ args: { menu: false },
143
+ render: (args) => ({
144
+ components: { Header },
145
+ setup: () => ({ args }),
146
+ template: `
147
+ <Header v-bind="args">
148
+ <template #leading>
149
+ <span class="flex size-7 items-center justify-center rounded bg-primary text-xs font-bold text-white" aria-hidden="true">K</span>
150
+ </template>
151
+ </Header>`,
152
+ }),
153
+ };
154
+
155
+ /** Stays at the top while the page scrolls (the default). Scroll the box below. */
156
+ export const Sticky: Story = {
157
+ render: (args) => ({
158
+ components: { Header },
159
+ setup: () => ({ args }),
160
+ template: `
161
+ <div class="h-96 overflow-y-auto bg-background">
162
+ <Header v-bind="args" />
163
+ <div class="flex flex-col gap-3 p-4">
164
+ <p v-for="n in 30" :key="n" class="text-sm text-black/65">Row {{ n }}</p>
165
+ </div>
166
+ </div>`,
167
+ }),
168
+ };
@@ -0,0 +1,232 @@
1
+ <script setup lang="ts">
2
+ import { computed, type HTMLAttributes } from 'vue'
3
+ import { ArrowLeftRight, LogOut, Menu, Settings } from '@lucide/vue'
4
+ import { cn } from '../../lib/cn'
5
+ import Avatar from '../Avatar/Avatar.vue'
6
+ import Button from '../Button/Button.vue'
7
+ import { initials as toInitials } from '../../lib/initials'
8
+ import Popover from '../Popover/Popover.vue'
9
+
10
+ export interface HeaderUser {
11
+ name: string
12
+ email?: string
13
+ /** Organisation or school the account belongs to, shown at the top of the account menu. */
14
+ organisation?: string
15
+ /** Picture URL. Initials are shown without one. */
16
+ avatar?: string
17
+ }
18
+
19
+ export type HeaderUserAction = 'account-settings' | 'switch-account' | 'log-out'
20
+
21
+ /**
22
+ * The bar across the top of every Keston app. It is the same in every app:
23
+ * a menu button (to open the Sidebar on small screens), the app's name, an
24
+ * optional middle area, actions, and the signed-in user's account menu on
25
+ * the right (Account settings, Switch account, Log out). Each part can be
26
+ * overridden with a slot.
27
+ *
28
+ * Slots: leading (before the title, e.g. a logo), title, default (the middle,
29
+ * fills the space between title and trailing), trailing (actions before the
30
+ * account menu), account (replaces the account menu, or the Sign in button),
31
+ * account-menu (extra content in the account menu, above Switch account /
32
+ * Log out: `{ close }`).
33
+ */
34
+ export interface HeaderProps {
35
+ /** Name of the app or area, shown next to the menu button. */
36
+ title?: string
37
+ /**
38
+ * Show the menu button, which emits `menu` when pressed. Hide it on wide
39
+ * screens with `ui.menu`, e.g. `{ menu: 'lg:hidden' }`.
40
+ */
41
+ menu?: boolean
42
+ /** Whether what the menu button opens is open, for screen readers (aria-expanded). */
43
+ menuOpen?: boolean
44
+ /** Id of what the menu button opens (aria-controls). */
45
+ menuControls?: string
46
+ /** Accessible name of the menu button. */
47
+ menuLabel?: string
48
+ /**
49
+ * The signed-in user. Shows their picture or initials on the right, which
50
+ * opens the account menu. Without it, a Sign in button is shown instead
51
+ * (see `signIn`).
52
+ */
53
+ user?: HeaderUser
54
+ /**
55
+ * Which actions the account menu offers. Each emits an event of the same
56
+ * name. Account settings sits under the user's name; Switch account and Log
57
+ * out share the bottom row (left and right).
58
+ */
59
+ userActions?: HeaderUserAction[]
60
+ /** Show a Sign in button (emits `sign-in`) when there is no `user`. */
61
+ signIn?: boolean
62
+ /**
63
+ * Stay at the top while the page scrolls (on by default). Turn off when the
64
+ * header isn't inside the element that scrolls.
65
+ */
66
+ sticky?: boolean
67
+ class?: HTMLAttributes['class']
68
+ /** Extra classes for the parts. */
69
+ ui?: {
70
+ menu?: HTMLAttributes['class']
71
+ title?: HTMLAttributes['class']
72
+ middle?: HTMLAttributes['class']
73
+ trailing?: HTMLAttributes['class']
74
+ userMenu?: HTMLAttributes['class']
75
+ }
76
+ }
77
+
78
+ const props = withDefaults(defineProps<HeaderProps>(), {
79
+ menu: false,
80
+ menuOpen: undefined,
81
+ menuLabel: 'Menu',
82
+ userActions: () => ['account-settings', 'switch-account', 'log-out'],
83
+ signIn: true,
84
+ sticky: true
85
+ })
86
+
87
+ const emit = defineEmits<{
88
+ menu: []
89
+ 'account-settings': []
90
+ 'switch-account': []
91
+ 'log-out': []
92
+ 'sign-in': []
93
+ }>()
94
+
95
+ defineSlots<{
96
+ leading?(): unknown
97
+ title?(): unknown
98
+ default?(): unknown
99
+ trailing?(): unknown
100
+ account?(): unknown
101
+ 'account-menu'?(props: { close: () => void }): unknown
102
+ }>()
103
+
104
+ // "Ben Smith" → "BS", "Ben" → "B".
105
+ const initials = computed(() => toInitials(props.user?.name ?? ''))
106
+
107
+ // The avatar button's name. When it shows initials (no picture), they are
108
+ // its visible text, so the name starts with them, for voice control ("click
109
+ // BS"): "BS, account: Ben Smith". Not in brackets: axe doesn't match "(BS)".
110
+ const accountLabel = computed(() => {
111
+ if (!props.user) return ''
112
+ if (props.user.avatar || !initials.value) return `Account: ${props.user.name}`
113
+ return `${initials.value}, account: ${props.user.name}`
114
+ })
115
+
116
+ function runAction(action: HeaderUserAction, close: () => void) {
117
+ close()
118
+ // Vue can't emit a name held in a variable with full typing, so switch.
119
+ if (action === 'account-settings') emit('account-settings')
120
+ else if (action === 'switch-account') emit('switch-account')
121
+ else emit('log-out')
122
+ }
123
+
124
+ </script>
125
+
126
+ <template>
127
+ <header
128
+ :class="cn(
129
+ 'flex h-12 shrink-0 items-center gap-2 border-b border-black/15 bg-white px-4 text-black',
130
+ sticky && 'sticky top-0 z-40',
131
+ props.class
132
+ )"
133
+ >
134
+ <!-- A ghost icon Button; the negative margin lines its icon up with the
135
+ header's padding, as the × does in Slideover. -->
136
+ <Button
137
+ v-if="menu"
138
+ variant="ghost"
139
+ square
140
+ :aria-label="menuLabel"
141
+ :aria-expanded="menuOpen"
142
+ :aria-controls="menuControls"
143
+ :class="cn('-ml-2.5', ui?.menu)"
144
+ @click="emit('menu')"
145
+ >
146
+ <Menu />
147
+ </Button>
148
+
149
+ <slot name="leading" />
150
+
151
+ <span
152
+ v-if="title || $slots.title"
153
+ :class="cn('min-w-0 truncate text-base font-bold', ui?.title)"
154
+ >
155
+ <slot name="title">{{ title }}</slot>
156
+ </span>
157
+
158
+ <div :class="cn('flex min-w-0 flex-1 items-center', ui?.middle)">
159
+ <slot />
160
+ </div>
161
+
162
+ <div
163
+ v-if="$slots.trailing || $slots.account || user || signIn"
164
+ :class="cn('flex shrink-0 items-center gap-1', ui?.trailing)"
165
+ >
166
+ <slot name="trailing" />
167
+
168
+ <slot name="account">
169
+ <!-- Account menu: the user's avatar opens a panel with who is signed
170
+ in and the account actions. -->
171
+ <Popover v-if="user" :content="{ align: 'end' }" :ui="{ content: cn('w-72', ui?.userMenu) }">
172
+ <Button variant="ghost" square :aria-label="accountLabel" class="-mr-1.5 rounded-full">
173
+ <Avatar :user="user" size="sm" decorative />
174
+ </Button>
175
+
176
+ <template #content="{ close }">
177
+ <div class="flex flex-col">
178
+ <p
179
+ v-if="user.organisation"
180
+ class="truncate px-4 pt-3 text-xs font-bold text-black/65 uppercase"
181
+ >
182
+ {{ user.organisation }}
183
+ </p>
184
+ <!-- Two columns: the avatar at the top left, beside the name and
185
+ email; Account settings sits under them in the text column,
186
+ without moving the avatar. -->
187
+ <div class="grid grid-cols-[auto_minmax(0,1fr)] items-start gap-x-3 gap-y-2 px-4 py-3">
188
+ <Avatar :user="user" size="lg" decorative />
189
+ <div class="flex min-w-0 flex-col">
190
+ <span class="truncate font-bold">{{ user.name }}</span>
191
+ <span v-if="user.email" class="truncate text-sm text-black/65">{{ user.email }}</span>
192
+ </div>
193
+ <Button
194
+ v-if="userActions.includes('account-settings')"
195
+ size="sm"
196
+ class="col-start-2 justify-self-start"
197
+ @click="runAction('account-settings', close)"
198
+ >
199
+ <template #leading><Settings /></template>
200
+ Account settings
201
+ </Button>
202
+ </div>
203
+
204
+ <slot name="account-menu" :close="close" />
205
+
206
+ <!-- Switch account on the left, Log out on the right. -->
207
+ <div
208
+ v-if="userActions.includes('switch-account') || userActions.includes('log-out')"
209
+ class="flex items-center gap-2 border-t border-black/15 px-4 py-3"
210
+ >
211
+ <Button v-if="userActions.includes('switch-account')" @click="runAction('switch-account', close)">
212
+ <template #leading><ArrowLeftRight /></template>
213
+ Switch account
214
+ </Button>
215
+ <Button
216
+ v-if="userActions.includes('log-out')"
217
+ class="ml-auto"
218
+ @click="runAction('log-out', close)"
219
+ >
220
+ <template #leading><LogOut /></template>
221
+ Log out
222
+ </Button>
223
+ </div>
224
+ </div>
225
+ </template>
226
+ </Popover>
227
+
228
+ <Button v-else-if="signIn" size="sm" variant="primary" @click="emit('sign-in')">Sign in</Button>
229
+ </slot>
230
+ </div>
231
+ </header>
232
+ </template>
@@ -0,0 +1,63 @@
1
+ import type { Meta, StoryObj } from "@storybook/vue3-vite";
2
+ import StatTile from "../StatTile/StatTile.vue";
3
+ import InfoTip from "./InfoTip.vue";
4
+
5
+ const meta = {
6
+ title: "Components/Overlay/InfoTip",
7
+ component: InfoTip,
8
+ tags: ["autodocs"],
9
+ args: {
10
+ label: "About attendance",
11
+ text: "Sessions attended as a share of possible sessions this term. Authorised absences count against it.",
12
+ },
13
+ decorators: [() => ({ template: '<div class="p-16"><story /></div>' })],
14
+ render: (args) => ({
15
+ components: { InfoTip },
16
+ setup: () => ({ args }),
17
+ template: `
18
+ <span class="inline-flex items-center gap-1 text-sm">Attendance <InfoTip v-bind="args" /></span>`,
19
+ }),
20
+ } satisfies Meta<typeof InfoTip>;
21
+
22
+ export default meta;
23
+ type Story = StoryObj<typeof meta>;
24
+
25
+ /**
26
+ * Hover, click or tab to the `?`. Screen readers hear its label ("About
27
+ * attendance") and the text as its description, without opening it.
28
+ */
29
+ export const Default: Story = {};
30
+
31
+ /** Explaining a column heading. */
32
+ export const InTableHeading: Story = {
33
+ args: { label: "About FSM", text: "Free school meals: eligible at any point in the last six years." },
34
+ render: (args) => ({
35
+ components: { InfoTip },
36
+ setup: () => ({ args }),
37
+ template: `
38
+ <table class="text-sm">
39
+ <thead><tr class="border-b border-black/15">
40
+ <th class="px-3 py-2 text-left font-bold">Student</th>
41
+ <th class="px-3 py-2 text-left font-bold"><span class="inline-flex items-center gap-1">FSM <InfoTip v-bind="args" /></span></th>
42
+ </tr></thead>
43
+ <tbody>
44
+ <tr><td class="px-3 py-2">Ada Okafor</td><td class="px-3 py-2">Yes</td></tr>
45
+ <tr><td class="px-3 py-2">Sam Patel</td><td class="px-3 py-2">No</td></tr>
46
+ </tbody>
47
+ </table>`,
48
+ }),
49
+ };
50
+
51
+ /** Fields have it built in: set `helper-placement="icon"` on Input, Select, RadioGroup and the rest. */
52
+ export const BesideAFigure: Story = {
53
+ decorators: [() => ({ template: '<div class="max-w-64 p-16"><story /></div>' })],
54
+ render: (args) => ({
55
+ components: { InfoTip, StatTile },
56
+ setup: () => ({ args }),
57
+ template: `
58
+ <div class="flex items-start gap-1">
59
+ <StatTile label="Attendance" value="94.2%" class="flex-1" />
60
+ <InfoTip v-bind="args" />
61
+ </div>`,
62
+ }),
63
+ };
@@ -0,0 +1,50 @@
1
+ <script setup lang="ts">
2
+ import { useId, type HTMLAttributes } from 'vue'
3
+ import { CircleHelp } from '@lucide/vue'
4
+ import { cn } from '../../lib/cn'
5
+ import Popover from '../Popover/Popover.vue'
6
+
7
+ /**
8
+ * A `?` that explains the thing beside it: a field's label, a table column,
9
+ * a figure. Opens on hover, and on click / tap (which keeps it open, so it
10
+ * works on touch screens). Focus is never moved, so typing in a nearby
11
+ * control isn't interrupted.
12
+ */
13
+ export interface InfoTipProps {
14
+ /** The explanation. Keep it to a sentence or two. */
15
+ text: string
16
+ /**
17
+ * The button's accessible name: what it explains, e.g. "About Student ID".
18
+ * Screen readers then hear `text` as its description.
19
+ */
20
+ label: string
21
+ class?: HTMLAttributes['class']
22
+ }
23
+
24
+ const props = defineProps<InfoTipProps>()
25
+
26
+ const descriptionId = `${useId()}-description`
27
+ </script>
28
+
29
+ <template>
30
+ <Popover mode="hover" :content="{ side: 'top', sideOffset: 6 }">
31
+ <button
32
+ type="button"
33
+ :aria-label="label"
34
+ :aria-describedby="descriptionId"
35
+ :class="cn(
36
+ 'inline-flex shrink-0 rounded-full p-0.5 align-middle text-black transition hover:bg-black/10 data-[state=open]:bg-black/10',
37
+ 'outline-2 outline-offset-1 outline-transparent focus-visible:outline-focus [&_svg]:size-4',
38
+ props.class
39
+ )"
40
+ >
41
+ <CircleHelp aria-hidden="true" />
42
+ <!-- Hidden, but still read as the button's description (the
43
+ aria-label replaces the button's content as its name). -->
44
+ <span :id="descriptionId" hidden>{{ text }}</span>
45
+ </button>
46
+ <template #content>
47
+ <p class="max-w-64 px-3 py-2 text-xs">{{ text }}</p>
48
+ </template>
49
+ </Popover>
50
+ </template>