@thekestongroup/ui 0.2.1 → 0.4.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 (210) hide show
  1. package/README.md +98 -31
  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/EmptyState/EmptyState.vue.d.ts +55 -0
  16. package/dist/components/{ToastItem.vue.d.ts → FormField/FieldMessage.vue.d.ts} +10 -2
  17. package/dist/components/FormField/FormField.vue.d.ts +61 -0
  18. package/dist/components/Header/Header.vue.d.ts +104 -0
  19. package/dist/components/InfoTip/InfoTip.vue.d.ts +20 -0
  20. package/dist/components/Input/Input.vue.d.ts +56 -0
  21. package/dist/components/InputCode/InputCode.vue.d.ts +53 -0
  22. package/dist/components/InputDate/InputDate.vue.d.ts +49 -0
  23. package/dist/components/InputNumber/InputNumber.vue.d.ts +44 -0
  24. package/dist/components/InputPassword/InputPassword.vue.d.ts +51 -0
  25. package/dist/components/InputRichText/InputRichText.vue.d.ts +44 -0
  26. package/dist/components/Link/Link.vue.d.ts +39 -0
  27. package/dist/components/Notification/Notification.vue.d.ts +62 -0
  28. package/dist/components/Notification/NotificationPane.vue.d.ts +38 -0
  29. package/dist/components/Notification/Toaster.vue.d.ts +51 -0
  30. package/dist/components/Notification/notification.samples.d.ts +3 -0
  31. package/dist/components/Notification/notifications.d.ts +115 -0
  32. package/dist/components/PageHeader/PageHeader.vue.d.ts +43 -0
  33. package/dist/components/Popover/Popover.vue.d.ts +83 -0
  34. package/dist/components/Popover/popover.d.ts +16 -0
  35. package/dist/components/Progress/Progress.vue.d.ts +26 -0
  36. package/dist/components/RadioGroup/RadioGroup.vue.d.ts +45 -0
  37. package/dist/components/RelativeTime/RelativeTime.vue.d.ts +22 -0
  38. package/dist/components/Select/Select.vue.d.ts +110 -0
  39. package/dist/components/Sidebar/Sidebar.vue.d.ts +106 -0
  40. package/dist/components/Sidebar/sidebar.d.ts +10 -0
  41. package/dist/components/Slideover/Slideover.vue.d.ts +125 -0
  42. package/dist/components/Spinner/Spinner.vue.d.ts +30 -0
  43. package/dist/components/StatTile/StatTile.vue.d.ts +46 -0
  44. package/dist/components/SummaryList/SummaryList.vue.d.ts +62 -0
  45. package/dist/components/Switch/Switch.vue.d.ts +39 -0
  46. package/dist/components/Table/Table.vue.d.ts +82 -0
  47. package/dist/components/Table/table.d.ts +36 -0
  48. package/dist/components/Tooltip/Tooltip.vue.d.ts +46 -0
  49. package/dist/index.d.ts +91 -25
  50. package/dist/keston-ui.js +5030 -14786
  51. package/dist/lib/cn.d.ts +4 -0
  52. package/dist/lib/dates.d.ts +27 -0
  53. package/dist/lib/initials.d.ts +2 -0
  54. package/dist/lib/parseDate.d.ts +44 -0
  55. package/dist/lib/useNow.d.ts +3 -0
  56. package/package.json +57 -24
  57. package/src/components/.gitkeep +0 -0
  58. package/src/components/Age/Age.stories.ts +24 -0
  59. package/src/components/Age/Age.vue +56 -0
  60. package/src/components/AppShell/AppShell.stories.ts +124 -0
  61. package/src/components/AppShell/AppShell.vue +221 -0
  62. package/src/components/Avatar/Avatar.stories.ts +56 -0
  63. package/src/components/Avatar/Avatar.vue +118 -0
  64. package/src/components/AvatarGroup/AvatarGroup.stories.ts +47 -0
  65. package/src/components/AvatarGroup/AvatarGroup.vue +97 -0
  66. package/src/components/Badge/Badge.stories.ts +92 -0
  67. package/src/components/Badge/Badge.vue +67 -0
  68. package/src/components/Breadcrumb/Breadcrumb.stories.ts +58 -0
  69. package/src/components/Breadcrumb/Breadcrumb.vue +109 -0
  70. package/src/components/Button/Button.mdx +79 -0
  71. package/src/components/Button/Button.stories.ts +207 -0
  72. package/src/components/Button/Button.vue +266 -0
  73. package/src/components/Calendar/Calendar.stories.ts +51 -0
  74. package/src/components/Calendar/Calendar.vue +364 -0
  75. package/src/components/Card/Card.stories.ts +109 -0
  76. package/src/components/Card/Card.vue +115 -0
  77. package/src/components/Checkbox/Checkbox.stories.ts +102 -0
  78. package/src/components/Checkbox/Checkbox.vue +102 -0
  79. package/src/components/Checklist/Checklist.stories.ts +67 -0
  80. package/src/components/Checklist/Checklist.vue +38 -0
  81. package/src/components/Chip/Chip.stories.ts +71 -0
  82. package/src/components/Chip/Chip.vue +86 -0
  83. package/src/components/Divider/Divider.stories.ts +57 -0
  84. package/src/components/Divider/Divider.vue +58 -0
  85. package/src/components/EmptyState/EmptyState.stories.ts +99 -0
  86. package/src/components/EmptyState/EmptyState.vue +87 -0
  87. package/src/components/FormField/FieldMessage.vue +81 -0
  88. package/src/components/FormField/FormField.stories.ts +55 -0
  89. package/src/components/FormField/FormField.vue +160 -0
  90. package/src/components/Header/Header.stories.ts +168 -0
  91. package/src/components/Header/Header.vue +232 -0
  92. package/src/components/InfoTip/InfoTip.stories.ts +63 -0
  93. package/src/components/InfoTip/InfoTip.vue +50 -0
  94. package/src/components/Input/Input.stories.ts +206 -0
  95. package/src/components/Input/Input.vue +90 -0
  96. package/src/components/InputCode/InputCode.stories.ts +85 -0
  97. package/src/components/InputCode/InputCode.vue +145 -0
  98. package/src/components/InputDate/InputDate.stories.ts +58 -0
  99. package/src/components/InputDate/InputDate.vue +258 -0
  100. package/src/components/InputNumber/InputNumber.stories.ts +63 -0
  101. package/src/components/InputNumber/InputNumber.vue +109 -0
  102. package/src/components/InputPassword/InputPassword.stories.ts +105 -0
  103. package/src/components/InputPassword/InputPassword.vue +132 -0
  104. package/src/components/InputRichText/InputRichText.stories.ts +100 -0
  105. package/src/components/InputRichText/InputRichText.vue +194 -0
  106. package/src/components/Link/Link.stories.ts +73 -0
  107. package/src/components/Link/Link.vue +56 -0
  108. package/src/components/Notification/Notification.stories.ts +196 -0
  109. package/src/components/Notification/Notification.vue +136 -0
  110. package/src/components/Notification/NotificationPane.vue +186 -0
  111. package/src/components/Notification/Toaster.vue +446 -0
  112. package/src/components/Notification/notification.samples.ts +45 -0
  113. package/src/components/Notification/notifications.test.ts +99 -0
  114. package/src/components/Notification/notifications.ts +172 -0
  115. package/src/components/PageHeader/PageHeader.stories.ts +79 -0
  116. package/src/components/PageHeader/PageHeader.vue +66 -0
  117. package/src/components/Popover/Popover.stories.ts +135 -0
  118. package/src/components/Popover/Popover.vue +192 -0
  119. package/src/components/Popover/popover.ts +20 -0
  120. package/src/components/Progress/Progress.stories.ts +74 -0
  121. package/src/components/Progress/Progress.vue +75 -0
  122. package/src/components/RadioGroup/RadioGroup.stories.ts +90 -0
  123. package/src/components/RadioGroup/RadioGroup.vue +132 -0
  124. package/src/components/RelativeTime/RelativeTime.stories.ts +74 -0
  125. package/src/components/RelativeTime/RelativeTime.vue +51 -0
  126. package/src/components/Select/Select.mdx +202 -0
  127. package/src/components/Select/Select.stories.ts +223 -0
  128. package/src/components/Select/Select.vue +630 -0
  129. package/src/components/Sidebar/Sidebar.stories.ts +192 -0
  130. package/src/components/Sidebar/Sidebar.vue +382 -0
  131. package/src/components/Sidebar/sidebar.ts +20 -0
  132. package/src/components/Slideover/Slideover.stories.ts +225 -0
  133. package/src/components/Slideover/Slideover.vue +365 -0
  134. package/src/components/Spinner/Spinner.stories.ts +79 -0
  135. package/src/components/Spinner/Spinner.vue +97 -0
  136. package/src/components/StatTile/StatTile.stories.ts +75 -0
  137. package/src/components/StatTile/StatTile.vue +89 -0
  138. package/src/components/SummaryList/SummaryList.stories.ts +103 -0
  139. package/src/components/SummaryList/SummaryList.vue +127 -0
  140. package/src/components/Switch/Switch.stories.ts +100 -0
  141. package/src/components/Switch/Switch.vue +96 -0
  142. package/src/components/Table/Table.stories.ts +212 -0
  143. package/src/components/Table/Table.vue +223 -0
  144. package/src/components/Table/table.test.ts +65 -0
  145. package/src/components/Table/table.ts +70 -0
  146. package/src/components/Tooltip/Tooltip.stories.ts +57 -0
  147. package/src/components/Tooltip/Tooltip.vue +86 -0
  148. package/src/examples/AppPages.stories.ts +500 -0
  149. package/src/examples/FormLayout.stories.ts +185 -0
  150. package/src/examples/KestonIdPages.stories.ts +415 -0
  151. package/src/examples/SchoolPages.stories.ts +665 -0
  152. package/src/index.ts +116 -36
  153. package/src/lib/cn.ts +4 -0
  154. package/src/lib/dates.test.ts +68 -0
  155. package/src/lib/dates.ts +86 -0
  156. package/src/lib/initials.ts +8 -0
  157. package/src/lib/parseDate.test.ts +331 -0
  158. package/src/lib/parseDate.ts +561 -0
  159. package/src/lib/useNow.ts +20 -0
  160. package/src/styles/theme.css +101 -0
  161. package/dist/components/AppLauncher.vue.d.ts +0 -10
  162. package/dist/components/Avatar.vue.d.ts +0 -16
  163. package/dist/components/Button.vue.d.ts +0 -27
  164. package/dist/components/Checkbox.vue.d.ts +0 -18
  165. package/dist/components/CloseButton.vue.d.ts +0 -6
  166. package/dist/components/Dialog.vue.d.ts +0 -23
  167. package/dist/components/Drawer.vue.d.ts +0 -34
  168. package/dist/components/DropdownMenu.vue.d.ts +0 -21
  169. package/dist/components/DropdownMenuItem.vue.d.ts +0 -19
  170. package/dist/components/DropdownMenuSeparator.vue.d.ts +0 -6
  171. package/dist/components/Input.vue.d.ts +0 -14
  172. package/dist/components/Label.vue.d.ts +0 -16
  173. package/dist/components/NotificationsMenu.vue.d.ts +0 -3
  174. package/dist/components/Popover.vue.d.ts +0 -23
  175. package/dist/components/ProfileSwitcher.vue.d.ts +0 -24
  176. package/dist/components/Select.vue.d.ts +0 -28
  177. package/dist/components/Separator.vue.d.ts +0 -11
  178. package/dist/components/ToastRenderer.vue.d.ts +0 -3
  179. package/dist/components/Toaster.vue.d.ts +0 -3
  180. package/dist/components/Tooltip.vue.d.ts +0 -23
  181. package/dist/components/TopBar.vue.d.ts +0 -34
  182. package/dist/favicon-old.svg +0 -1
  183. package/dist/favicon.svg +0 -1
  184. package/dist/keston-ui.cjs +0 -15
  185. package/dist/lib/toast.d.ts +0 -29
  186. package/dist/lib/types.d.ts +0 -5
  187. package/src/components/AppLauncher.vue +0 -63
  188. package/src/components/Avatar.vue +0 -51
  189. package/src/components/Button.vue +0 -54
  190. package/src/components/Checkbox.vue +0 -47
  191. package/src/components/CloseButton.vue +0 -24
  192. package/src/components/Dialog.vue +0 -65
  193. package/src/components/Drawer.vue +0 -202
  194. package/src/components/DropdownMenu.vue +0 -41
  195. package/src/components/DropdownMenuItem.vue +0 -28
  196. package/src/components/DropdownMenuSeparator.vue +0 -12
  197. package/src/components/Input.vue +0 -21
  198. package/src/components/Label.vue +0 -15
  199. package/src/components/NotificationsMenu.vue +0 -115
  200. package/src/components/Popover.vue +0 -46
  201. package/src/components/ProfileSwitcher.vue +0 -113
  202. package/src/components/Select.vue +0 -97
  203. package/src/components/Separator.vue +0 -30
  204. package/src/components/ToastItem.vue +0 -158
  205. package/src/components/ToastRenderer.vue +0 -113
  206. package/src/components/Toaster.vue +0 -11
  207. package/src/components/Tooltip.vue +0 -48
  208. package/src/components/TopBar.vue +0 -52
  209. package/src/lib/toast.ts +0 -95
  210. package/src/lib/types.ts +0 -5
@@ -0,0 +1,81 @@
1
+ <script setup lang="ts">
2
+ import { computed, ref, watch } from 'vue'
3
+ import { CircleAlert, CircleCheck } from '@lucide/vue'
4
+ import { cn } from '../../lib/cn'
5
+ import Spinner from '../Spinner/Spinner.vue'
6
+
7
+ /**
8
+ * Internal (not exported): the status message under a form control, shared
9
+ * by FormField, Checkbox, RadioGroup and Switch so every field's error /
10
+ * success / loading message looks and moves the same.
11
+ */
12
+
13
+ export type FieldStatus = 'error' | 'success' | 'loading'
14
+
15
+ const props = defineProps<{
16
+ /** id of the screen-reader copy, for the control's aria-describedby. */
17
+ id: string
18
+ status?: FieldStatus
19
+ text?: string
20
+ }>()
21
+
22
+ // The message slides open when there is text and closed when it clears. While
23
+ // closing, keep showing the last message so it doesn't vanish mid-slide.
24
+ const open = computed(() => !!props.text)
25
+ const shownText = ref(props.text)
26
+ const shownStatus = ref(props.status)
27
+ watch(
28
+ () => [props.text, props.status] as const,
29
+ ([text, status]) => {
30
+ if (!text) return
31
+ shownText.value = text
32
+ shownStatus.value = status
33
+ }
34
+ )
35
+
36
+ const colour: Record<FieldStatus, string> = {
37
+ error: 'text-red',
38
+ success: 'text-green',
39
+ loading: 'text-black/65'
40
+ }
41
+
42
+ const icon = { error: CircleAlert, success: CircleCheck } as const
43
+ </script>
44
+
45
+ <template>
46
+ <!--
47
+ Visual message. Its row animates from 0 to full height (grid rows
48
+ 0fr → 1fr), so content below moves smoothly instead of jumping.
49
+ -mt-1.5 cancels the parent's gap while closed; pt-1.5 puts it back when open.
50
+
51
+ The two steps run in sequence so the text is never seen clipped:
52
+ opening: the row grows (150ms), then the text fades in and slides
53
+ down 4px (150ms, starting at 100ms)
54
+ closing: the text fades out (100ms), then the row closes (150ms,
55
+ starting at 100ms)
56
+ -->
57
+ <div
58
+ aria-hidden="true"
59
+ :class="cn(
60
+ '-mt-1.5 grid transition-[grid-template-rows,visibility] duration-150 ease-out motion-reduce:transition-none',
61
+ open ? 'grid-rows-[1fr]' : 'invisible grid-rows-[0fr] delay-100'
62
+ )"
63
+ >
64
+ <div class="overflow-hidden">
65
+ <p
66
+ :class="cn(
67
+ 'flex items-center gap-1 pt-1.5 text-xs transition-[translate,opacity,color] ease-out motion-reduce:transition-none [&_svg]:size-3.5 [&_svg]:shrink-0',
68
+ shownStatus && colour[shownStatus],
69
+ open ? 'duration-150 delay-100' : '-translate-y-1 opacity-0 duration-100'
70
+ )"
71
+ >
72
+ <Spinner v-if="shownStatus === 'loading'" size="sm" class="size-3.5" />
73
+ <component :is="icon[shownStatus]" v-else-if="shownStatus" />
74
+ {{ shownText }}
75
+ </p>
76
+ </div>
77
+ </div>
78
+
79
+ <!-- What screen readers hear: linked to the control and announced when it changes. -->
80
+ <p :id="id" aria-live="polite" class="sr-only">{{ text }}</p>
81
+ </template>
@@ -0,0 +1,55 @@
1
+ import type { Meta, StoryObj } from "@storybook/vue3-vite";
2
+ import { ref } from "vue";
3
+ import FormField from "./FormField.vue";
4
+
5
+ const meta = {
6
+ title: "Components/Form/FormField",
7
+ component: FormField,
8
+ tags: ["autodocs"],
9
+ argTypes: {
10
+ helperPlacement: { options: ["below", "icon"], control: { type: "inline-radio" } },
11
+ status: { options: [undefined, "error", "success", "loading"], control: { type: "inline-radio" } },
12
+ },
13
+ args: {
14
+ label: "Notes",
15
+ helper: "Seen by staff only, not by parents.",
16
+ helperPlacement: "below",
17
+ disabled: false,
18
+ },
19
+ decorators: [() => ({ template: '<div class="max-w-80"><story /></div>' })],
20
+ render: (args) => ({
21
+ components: { FormField },
22
+ setup: () => ({ args, value: ref("") }),
23
+ // A control the library doesn't have yet: a native <textarea>. The slot
24
+ // gives it the id and ARIA values; FormField does the rest.
25
+ template: `
26
+ <FormField v-bind="args">
27
+ <template #default="{ id, describedBy, invalid }">
28
+ <textarea
29
+ :id="id"
30
+ v-model="value"
31
+ rows="3"
32
+ :disabled="args.disabled"
33
+ :aria-invalid="invalid"
34
+ :aria-describedby="describedBy"
35
+ class="min-h-5 min-w-0 flex-1 resize-y bg-transparent outline-none placeholder:text-black/55 disabled:cursor-not-allowed"
36
+ />
37
+ </template>
38
+ </FormField>`,
39
+ }),
40
+ } satisfies Meta<typeof FormField>;
41
+
42
+ export default meta;
43
+ type Story = StoryObj<typeof meta>;
44
+
45
+ /**
46
+ * The shell Input, InputNumber, InputDate and Select are built on. Use it
47
+ * for a text control the library doesn't have, so it matches them.
48
+ */
49
+ export const Default: Story = {};
50
+
51
+ export const WithErrorText: Story = { args: { errorText: "Add a note before saving" } };
52
+
53
+ export const Loading: Story = { args: { status: "loading", statusText: "Saving…" } };
54
+
55
+ export const Disabled: Story = { args: { disabled: true } };
@@ -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
+ };