@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,102 @@
1
+ <script setup lang="ts">
2
+ import { computed, useId, type HTMLAttributes } from 'vue'
3
+ import { CheckboxIndicator, CheckboxRoot } from 'reka-ui'
4
+ import { Check, Minus } from '@lucide/vue'
5
+ import { cn } from '../../lib/cn'
6
+ import FieldMessage from '../FormField/FieldMessage.vue'
7
+
8
+ /**
9
+ * A yes / no answer that's sent with the form, e.g. "Has a sibling at the
10
+ * school" or agreeing to terms. For a setting that takes effect straight
11
+ * away, use Switch; for one choice from a few, use RadioGroup.
12
+ */
13
+ export interface CheckboxProps {
14
+ /** Visible label, beside the box. Pressing it ticks the box too. */
15
+ label: string
16
+ /** More detail, in smaller text under the label. */
17
+ description?: string
18
+ /**
19
+ * Error message, e.g. "Agree to the terms to continue". When set (and not
20
+ * empty) the box shows as an error with this text.
21
+ */
22
+ errorText?: string
23
+ /** Name for native form submission. */
24
+ name?: string
25
+ /** Value sent with the form when ticked. Default "on". */
26
+ value?: string
27
+ required?: boolean
28
+ disabled?: boolean
29
+ class?: HTMLAttributes['class']
30
+ }
31
+
32
+ const props = defineProps<CheckboxProps>()
33
+
34
+ /**
35
+ * Ticked or not. 'indeterminate' shows a dash: for a "select all" box when
36
+ * only some of its items are ticked. Pressing it then ticks it.
37
+ */
38
+ const model = defineModel<boolean | 'indeterminate'>({ default: false })
39
+
40
+ const id = useId()
41
+ const controlId = `${id}-control`
42
+ const descriptionId = `${id}-description`
43
+ const statusId = `${id}-status`
44
+
45
+ const describedBy = computed(
46
+ () => [props.description && descriptionId, props.errorText && statusId].filter(Boolean).join(' ') || undefined
47
+ )
48
+
49
+ // Pressing anywhere in the text (the description, or the gap between it and
50
+ // the label) acts like pressing the label. The description isn't inside the
51
+ // <label>, which would make it part of the accessible name; it stays the
52
+ // description (aria-describedby). The label already presses the control
53
+ // itself, so it's skipped here. Keyboard use is unchanged.
54
+ function pressControl(event: MouseEvent, id: string) {
55
+ if ((event.target as Element).closest('label')) return
56
+ document.getElementById(id)?.click()
57
+ }
58
+
59
+ // 16px box, level with the first line of the label (20px line: 2px above).
60
+ // The border is darker than a text box's so the box itself is easy to see.
61
+ const box = [
62
+ 'mt-0.5 flex size-4 shrink-0 cursor-pointer items-center justify-center rounded-sm border bg-white text-white transition',
63
+ 'not-disabled:hover:border-black disabled:cursor-not-allowed',
64
+ 'data-[state=checked]:border-primary data-[state=checked]:bg-primary data-[state=checked]:hover:border-primary',
65
+ 'data-[state=indeterminate]:border-primary data-[state=indeterminate]:bg-primary data-[state=indeterminate]:hover:border-primary',
66
+ 'outline-2 outline-offset-2 outline-transparent focus-visible:outline-focus',
67
+ '[&_svg]:size-3.5 [&_svg]:stroke-3'
68
+ ]
69
+ </script>
70
+
71
+ <template>
72
+ <div :class="cn('flex flex-col gap-1.5 text-black', disabled && 'opacity-40', props.class)">
73
+ <div class="flex items-start gap-2">
74
+ <CheckboxRoot
75
+ :id="controlId"
76
+ v-model="model"
77
+ :name="name"
78
+ :value="value"
79
+ :required="required"
80
+ :disabled="disabled"
81
+ :aria-invalid="errorText ? true : undefined"
82
+ :aria-describedby="describedBy"
83
+ :class="cn(box, errorText ? 'border-red' : 'border-black/55')"
84
+ >
85
+ <CheckboxIndicator class="flex">
86
+ <Minus v-if="model === 'indeterminate'" aria-hidden="true" />
87
+ <Check v-else aria-hidden="true" />
88
+ </CheckboxIndicator>
89
+ </CheckboxRoot>
90
+ <div
91
+ :class="cn('flex min-w-0 flex-col gap-0.5', disabled ? 'cursor-not-allowed' : 'cursor-pointer')"
92
+ @click="pressControl($event, controlId)"
93
+ >
94
+ <label :for="controlId" :class="cn('text-sm', disabled ? 'cursor-not-allowed' : 'cursor-pointer')">{{ label }}</label>
95
+ <p v-if="description" :id="descriptionId" class="text-xs text-black/65">
96
+ {{ description }}
97
+ </p>
98
+ </div>
99
+ </div>
100
+ <FieldMessage :id="statusId" :status="errorText ? 'error' : undefined" :text="errorText" />
101
+ </div>
102
+ </template>
@@ -0,0 +1,67 @@
1
+ import type { Meta, StoryObj } from "@storybook/vue3-vite";
2
+ import { computed, ref } from "vue";
3
+ import Card from "../Card/Card.vue";
4
+ import Checkbox from "../Checkbox/Checkbox.vue";
5
+ import Checklist from "./Checklist.vue";
6
+
7
+ const meta = {
8
+ title: "Components/Data/Checklist",
9
+ component: Checklist,
10
+ tags: ["autodocs"],
11
+ args: {
12
+ items: [
13
+ { label: "Academic year", done: true },
14
+ { label: "Term dates", done: true },
15
+ { label: "Year groups", done: false },
16
+ { label: "Copy from last year", done: false },
17
+ ],
18
+ },
19
+ } satisfies Meta<typeof Checklist>;
20
+
21
+ export default meta;
22
+ type Story = StoryObj<typeof meta>;
23
+
24
+ export const Default: Story = {
25
+ decorators: [() => ({ template: '<div class="max-w-72"><story /></div>' })],
26
+ };
27
+
28
+ /** Long steps wrap; the icon stays level with the first line. */
29
+ export const LongItems: Story = {
30
+ decorators: [() => ({ template: '<div class="max-w-72"><story /></div>' })],
31
+ args: {
32
+ items: [
33
+ { label: "Upload proof of address dated within the last three months", done: true },
34
+ { label: "Upload the student's most recent school report", done: false },
35
+ ],
36
+ },
37
+ };
38
+
39
+ /** Following a form: each step ticks itself off as its part is filled in. */
40
+ export const FollowingAForm: Story = {
41
+ render: () => ({
42
+ components: { Card, Checkbox, Checklist },
43
+ setup() {
44
+ const form = ref({ address: false, report: false, medical: false });
45
+ const items = computed(() => [
46
+ { label: "Proof of address", done: form.value.address },
47
+ { label: "School report", done: form.value.report },
48
+ { label: "Medical form", done: form.value.medical },
49
+ ]);
50
+ return { form, items };
51
+ },
52
+ template: `
53
+ <!-- Laid out by the space it has (container query), not the window. -->
54
+ <div class="@container max-w-160">
55
+ <div class="grid grid-cols-1 items-start gap-4 @lg:grid-cols-[minmax(0,1fr)_14rem]">
56
+ <Card title="Documents">
57
+ <Checkbox v-model="form.address" label="Proof of address received" />
58
+ <Checkbox v-model="form.report" label="School report received" />
59
+ <Checkbox v-model="form.medical" label="Medical form received" />
60
+ </Card>
61
+ <Card as="aside" title="Before submitting" padding="sm">
62
+ <Checklist :items="items" />
63
+ </Card>
64
+ </div>
65
+ </div>`,
66
+ }),
67
+ };
@@ -0,0 +1,38 @@
1
+ <script setup lang="ts">
2
+ import type { HTMLAttributes } from 'vue'
3
+ import { Circle, CircleCheck } from '@lucide/vue'
4
+ import { cn } from '../../lib/cn'
5
+
6
+ /**
7
+ * Steps towards something, ticked off as they're done: what's left before a
8
+ * form can be submitted, or setting up a new school year. It shows progress;
9
+ * people don't tick it themselves (use Checkbox for that).
10
+ */
11
+ export interface ChecklistItem {
12
+ /** What needs doing, e.g. "Term dates". */
13
+ label: string
14
+ done: boolean
15
+ }
16
+
17
+ export interface ChecklistProps {
18
+ items: ChecklistItem[]
19
+ class?: HTMLAttributes['class']
20
+ }
21
+
22
+ const props = defineProps<ChecklistProps>()
23
+ </script>
24
+
25
+ <template>
26
+ <ul :class="cn('flex flex-col gap-2 text-sm', props.class)">
27
+ <li v-for="item in items" :key="item.label" class="flex items-start gap-2">
28
+ <!-- h-5 keeps the icon level with the first line of a label that wraps. -->
29
+ <span class="flex h-5 shrink-0 items-center">
30
+ <CircleCheck v-if="item.done" class="size-4 text-green" aria-hidden="true" />
31
+ <Circle v-else class="size-4 text-black/40" aria-hidden="true" />
32
+ </span>
33
+ <span :class="item.done ? 'text-black' : 'text-black/65'">
34
+ {{ item.label }}<span class="sr-only">{{ item.done ? ' (done)' : ' (to do)' }}</span>
35
+ </span>
36
+ </li>
37
+ </ul>
38
+ </template>
@@ -0,0 +1,71 @@
1
+ import type { Meta, StoryObj } from "@storybook/vue3-vite";
2
+ import { BookOpen, Calculator, FlaskConical, User } from "@lucide/vue";
3
+ import { ref } from "vue";
4
+ import Chip from "./Chip.vue";
5
+
6
+ const meta = {
7
+ title: "Components/Element/Chip",
8
+ component: Chip,
9
+ tags: ["autodocs"],
10
+ argTypes: {
11
+ size: { options: ["sm", "md"], control: { type: "inline-radio" } },
12
+ },
13
+ args: { size: "md", removable: false, disabled: false },
14
+ render: (args) => ({
15
+ components: { Chip },
16
+ setup: () => ({ args }),
17
+ template: `<Chip v-bind="args">Ben Blissett</Chip>`,
18
+ }),
19
+ } satisfies Meta<typeof Chip>;
20
+
21
+ export default meta;
22
+ type Story = StoryObj<typeof meta>;
23
+
24
+ /** Playground: use the controls below. */
25
+ export const Default: Story = {};
26
+
27
+ /** Both sizes, with and without an icon and a ×. */
28
+ export const Sizes: Story = {
29
+ render: () => ({
30
+ components: { Chip, User },
31
+ template: `
32
+ <div class="flex flex-col gap-3">
33
+ <div v-for="size in ['sm', 'md']" :key="size" class="flex flex-wrap items-center gap-1">
34
+ <Chip :size="size">Ben Blissett</Chip>
35
+ <Chip :size="size"><template #leading><User /></template>Ben Blissett</Chip>
36
+ <Chip :size="size" removable remove-label="Remove Ben Blissett">Ben Blissett</Chip>
37
+ <Chip :size="size" removable remove-label="Remove Ben Blissett"><template #leading><User /></template>Ben Blissett</Chip>
38
+ </div>
39
+ </div>`,
40
+ }),
41
+ };
42
+
43
+ /** Chosen items with × to remove them, wrapping onto more lines. */
44
+ export const Removable: Story = {
45
+ render: () => ({
46
+ components: { Chip },
47
+ setup() {
48
+ const subjects = ref([
49
+ { label: "English", icon: BookOpen },
50
+ { label: "Maths", icon: Calculator },
51
+ { label: "Science", icon: FlaskConical },
52
+ ]);
53
+ const remove = (label: string) => (subjects.value = subjects.value.filter((s) => s.label !== label));
54
+ return { subjects, remove };
55
+ },
56
+ template: `
57
+ <div class="flex max-w-64 flex-wrap gap-1">
58
+ <Chip
59
+ v-for="subject in subjects"
60
+ :key="subject.label"
61
+ removable
62
+ :remove-label="'Remove ' + subject.label"
63
+ @remove="remove(subject.label)"
64
+ >
65
+ <template #leading><component :is="subject.icon" /></template>
66
+ {{ subject.label }}
67
+ </Chip>
68
+ <span v-if="!subjects.length" class="text-sm text-black/65">All removed</span>
69
+ </div>`,
70
+ }),
71
+ };
@@ -0,0 +1,86 @@
1
+ <script setup lang="ts">
2
+ import type { HTMLAttributes } from 'vue'
3
+ import { X } from '@lucide/vue'
4
+ import { cn } from '../../lib/cn'
5
+
6
+ /**
7
+ * A small item someone has chosen or entered, e.g. a recipient or a filter,
8
+ * usually shown in a row that wraps. Unlike Badge (a fully rounded status
9
+ * label), a chip has the same 4px corners as Button and Input, and can have a
10
+ * × to remove it.
11
+ *
12
+ * Slots: default (the text), leading (e.g. an icon).
13
+ */
14
+ export interface ChipProps {
15
+ size?: 'sm' | 'md'
16
+ /** Show a × that emits `remove`. */
17
+ removable?: boolean
18
+ /** Accessible name of the ×, e.g. "Remove Ben Blissett". Default "Remove". */
19
+ removeLabel?: string
20
+ /**
21
+ * Let keyboard users Tab to the ×. Off when something else offers a
22
+ * keyboard way to remove it (e.g. Backspace in Select's search box).
23
+ */
24
+ removeFocusable?: boolean
25
+ disabled?: boolean
26
+ class?: HTMLAttributes['class']
27
+ }
28
+
29
+ const props = withDefaults(defineProps<ChipProps>(), {
30
+ size: 'md',
31
+ removeLabel: 'Remove',
32
+ removeFocusable: true
33
+ })
34
+
35
+ const emit = defineEmits<{ remove: [] }>()
36
+
37
+ defineSlots<{
38
+ default?(): unknown
39
+ leading?(): unknown
40
+ }>()
41
+
42
+ // Light grey fill and the shared border, so it reads as a chosen item on a
43
+ // white field without competing with buttons.
44
+ const base = [
45
+ 'inline-flex max-w-full shrink-0 items-center whitespace-nowrap rounded border border-black/15 bg-black/5 text-black',
46
+ '[&_svg]:shrink-0'
47
+ ]
48
+
49
+ // Heights 20 / 24px, including the border. With a ×, the right padding
50
+ // shrinks so the × sits close to the edge.
51
+ const sizes: Record<NonNullable<ChipProps['size']>, string> = {
52
+ sm: 'h-5 gap-1 px-1.5 text-xs [&_svg]:size-3',
53
+ md: 'h-6 gap-1 px-2 text-sm [&_svg]:size-3.5'
54
+ }
55
+ const removableSizes: Record<NonNullable<ChipProps['size']>, string> = {
56
+ sm: 'pr-0.5',
57
+ md: 'pr-1'
58
+ }
59
+ const removeSizes: Record<NonNullable<ChipProps['size']>, string> = {
60
+ sm: 'size-4',
61
+ md: 'size-5'
62
+ }
63
+ </script>
64
+
65
+ <template>
66
+ <span :class="cn(base, sizes[size], removable && removableSizes[size], disabled && 'opacity-40', props.class)">
67
+ <slot name="leading" />
68
+ <span class="min-w-0 truncate"><slot /></span>
69
+ <button
70
+ v-if="removable"
71
+ type="button"
72
+ :tabindex="removeFocusable ? undefined : -1"
73
+ :aria-label="removeLabel"
74
+ :disabled="disabled"
75
+ :class="cn(
76
+ 'flex shrink-0 cursor-pointer items-center justify-center rounded-sm transition',
77
+ 'not-disabled:hover:bg-black/10 not-disabled:active:bg-black/15 disabled:cursor-not-allowed',
78
+ 'outline-2 outline-offset-0 outline-transparent focus-visible:outline-focus',
79
+ removeSizes[size]
80
+ )"
81
+ @click="emit('remove')"
82
+ >
83
+ <X aria-hidden="true" />
84
+ </button>
85
+ </span>
86
+ </template>
@@ -0,0 +1,57 @@
1
+ import type { Meta, StoryObj } from "@storybook/vue3-vite";
2
+ import { Bold, Italic, Underline } from "@lucide/vue";
3
+ import Button from "../Button/Button.vue";
4
+ import Divider from "./Divider.vue";
5
+
6
+ const meta = {
7
+ title: "Components/Element/Divider",
8
+ component: Divider,
9
+ tags: ["autodocs"],
10
+ argTypes: {
11
+ orientation: { options: ["horizontal", "vertical"], control: { type: "inline-radio" } },
12
+ },
13
+ args: { orientation: "horizontal", decorative: true },
14
+ render: (args) => ({
15
+ components: { Divider },
16
+ setup: () => ({ args }),
17
+ template: `
18
+ <div class="flex max-w-sm flex-col gap-4 text-sm">
19
+ <p>Above the line.</p>
20
+ <Divider v-bind="args" />
21
+ <p>Below the line.</p>
22
+ </div>`,
23
+ }),
24
+ } satisfies Meta<typeof Divider>;
25
+
26
+ export default meta;
27
+ type Story = StoryObj<typeof meta>;
28
+
29
+ /** Between stacked content. */
30
+ export const Default: Story = {};
31
+
32
+ /** A short label in the middle, e.g. between two ways of doing something. */
33
+ export const WithLabel: Story = {
34
+ render: () => ({
35
+ components: { Divider, Button },
36
+ template: `
37
+ <div class="flex max-w-sm flex-col gap-4">
38
+ <Button variant="primary">Sign in with Microsoft</Button>
39
+ <Divider label="or" />
40
+ <Button>Sign in with email</Button>
41
+ </div>`,
42
+ }),
43
+ };
44
+
45
+ /** Vertical, between groups of buttons in a row. */
46
+ export const Vertical: Story = {
47
+ render: () => ({
48
+ components: { Divider, Button, Bold, Italic, Underline },
49
+ template: `
50
+ <div class="flex h-9.5 items-center gap-1">
51
+ <Button variant="ghost" square aria-label="Bold"><Bold /></Button>
52
+ <Button variant="ghost" square aria-label="Italic"><Italic /></Button>
53
+ <Divider orientation="vertical" class="mx-1 my-2" />
54
+ <Button variant="ghost" square aria-label="Underline"><Underline /></Button>
55
+ </div>`,
56
+ }),
57
+ };
@@ -0,0 +1,58 @@
1
+ <script setup lang="ts">
2
+ import type { HTMLAttributes } from 'vue'
3
+ import { Separator } from 'reka-ui'
4
+ import { cn } from '../../lib/cn'
5
+
6
+ /**
7
+ * A thin line between groups of content, in the same black 15% as every
8
+ * border. Horizontal (between stacked content) or vertical (between items in
9
+ * a row, e.g. toolbar buttons). Optionally with a short label in the middle,
10
+ * e.g. "or".
11
+ *
12
+ * Decorative by default (hidden from screen readers), as the content either
13
+ * side usually has headings. Set `decorative` to false when the split itself
14
+ * carries meaning.
15
+ *
16
+ * Slots: default (the label, instead of the `label` prop).
17
+ */
18
+ export interface DividerProps {
19
+ orientation?: 'horizontal' | 'vertical'
20
+ /** Short text in the middle of a horizontal divider, e.g. "or". */
21
+ label?: string
22
+ /** Hidden from screen readers (the default). False: announced as a separator. */
23
+ decorative?: boolean
24
+ class?: HTMLAttributes['class']
25
+ }
26
+
27
+ const props = withDefaults(defineProps<DividerProps>(), {
28
+ orientation: 'horizontal',
29
+ decorative: true
30
+ })
31
+
32
+ defineSlots<{ default?(): unknown }>()
33
+ </script>
34
+
35
+ <template>
36
+ <!-- With a label: a line either side of the text. -->
37
+ <div
38
+ v-if="orientation === 'horizontal' && (label || $slots.default)"
39
+ :role="decorative ? 'presentation' : 'separator'"
40
+ :aria-label="decorative ? undefined : label"
41
+ :class="cn('flex w-full items-center gap-3 text-xs text-black/65', props.class)"
42
+ >
43
+ <span aria-hidden="true" class="h-px flex-1 bg-black/15" />
44
+ <span class="shrink-0"><slot>{{ label }}</slot></span>
45
+ <span aria-hidden="true" class="h-px flex-1 bg-black/15" />
46
+ </div>
47
+
48
+ <Separator
49
+ v-else
50
+ :orientation="orientation"
51
+ :decorative="decorative"
52
+ :class="cn(
53
+ 'shrink-0 bg-black/15',
54
+ orientation === 'horizontal' ? 'h-px w-full' : 'w-px self-stretch',
55
+ props.class
56
+ )"
57
+ />
58
+ </template>
@@ -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 } };