@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,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,99 @@
1
+ import type { Meta, StoryObj } from "@storybook/vue3-vite";
2
+ import { AppWindow, BellOff, Inbox, SearchX, Users } from "@lucide/vue";
3
+ import Button from "../Button/Button.vue";
4
+ import Card from "../Card/Card.vue";
5
+ import EmptyState from "./EmptyState.vue";
6
+
7
+ const meta = {
8
+ title: "Components/Data/EmptyState",
9
+ component: EmptyState,
10
+ tags: ["autodocs"],
11
+ argTypes: {
12
+ size: { options: ["sm", "md"], control: { type: "inline-radio" } },
13
+ headingLevel: { options: [undefined, 2, 3, 4], control: { type: "select" } },
14
+ icon: { control: false },
15
+ },
16
+ args: {
17
+ title: "No connected apps",
18
+ description: "When you sign in to an app with your Keston account, it'll show here and you can remove its access.",
19
+ icon: AppWindow,
20
+ size: "md",
21
+ },
22
+ render: (args) => ({
23
+ components: { EmptyState, Card },
24
+ setup: () => ({ args }),
25
+ template: `<Card><EmptyState v-bind="args" /></Card>`,
26
+ }),
27
+ } satisfies Meta<typeof EmptyState>;
28
+
29
+ export default meta;
30
+ type Story = StoryObj<typeof meta>;
31
+
32
+ /** Playground: use the controls below. In a Card, as on a page with nothing in it yet. */
33
+ export const Default: Story = {};
34
+
35
+ /** With what to do next, in the actions slot. */
36
+ export const WithAction: Story = {
37
+ args: {
38
+ title: "No students in this class",
39
+ description: "Add students one by one, or import them from a spreadsheet.",
40
+ icon: Users,
41
+ },
42
+ render: (args) => ({
43
+ components: { EmptyState, Card, Button },
44
+ setup: () => ({ args }),
45
+ template: `
46
+ <Card>
47
+ <EmptyState v-bind="args">
48
+ <template #actions>
49
+ <Button>Import</Button>
50
+ <Button variant="primary">Add a student</Button>
51
+ </template>
52
+ </EmptyState>
53
+ </Card>`,
54
+ }),
55
+ };
56
+
57
+ /** Nothing matched a search or filter: say so, and offer a way back. */
58
+ export const NoResults: Story = {
59
+ args: {
60
+ title: "No results for “Smyth”",
61
+ description: "Check the spelling, or search by student number instead.",
62
+ icon: SearchX,
63
+ },
64
+ render: (args) => ({
65
+ components: { EmptyState, Card, Button },
66
+ setup: () => ({ args }),
67
+ template: `
68
+ <Card>
69
+ <EmptyState v-bind="args">
70
+ <template #actions><Button>Clear search</Button></template>
71
+ </EmptyState>
72
+ </Card>`,
73
+ }),
74
+ };
75
+
76
+ /** Both sizes: md for a Card or page, sm for panels, popovers and tables. */
77
+ export const Sizes: Story = {
78
+ render: () => ({
79
+ components: { EmptyState, Card },
80
+ setup: () => ({ Inbox, BellOff }),
81
+ template: `
82
+ <div class="grid gap-4 sm:grid-cols-2">
83
+ <Card title="md">
84
+ <EmptyState :icon="Inbox" title="No messages" description="Messages from families show here." />
85
+ </Card>
86
+ <Card title="sm">
87
+ <EmptyState size="sm" :icon="BellOff" description="You're all caught up." />
88
+ </Card>
89
+ </div>`,
90
+ }),
91
+ };
92
+
93
+ /**
94
+ * Filling a page's main area: give the title a heading level so it's in the
95
+ * page outline (screen readers can jump to it).
96
+ */
97
+ export const AsHeading: Story = {
98
+ args: { headingLevel: 2 },
99
+ };
@@ -0,0 +1,87 @@
1
+ <script setup lang="ts">
2
+ import type { Component, HTMLAttributes } from 'vue'
3
+ import { cn } from '../../lib/cn'
4
+
5
+ /**
6
+ * What to show where a list, table or panel has nothing in it yet: an icon,
7
+ * a short title, a line of explanation, and optionally what to do about it
8
+ * (e.g. a Button). "No connected apps", "You're all caught up", "No
9
+ * applications yet".
10
+ *
11
+ * Slots: title, description, actions (under the text, e.g. a Button),
12
+ * default (anything else, under the description). To animate the icon, pass
13
+ * classes in `ui.icon`.
14
+ */
15
+ export interface EmptyStateProps {
16
+ /** Short and specific, e.g. "No connected apps". */
17
+ title?: string
18
+ /** What this space is for, or what to do next. */
19
+ description?: string
20
+ /** A Lucide (or any) icon component, shown above the title. */
21
+ icon?: Component
22
+ /**
23
+ * Make the title a heading, at this level, to fit the page outline (e.g. 2
24
+ * when it fills a page's main area). Without it the title is plain text,
25
+ * as in a panel or table that already has a heading.
26
+ */
27
+ headingLevel?: 2 | 3 | 4
28
+ /**
29
+ * - sm: compact, for panels, popovers and tables.
30
+ * - md (default): for a Card or a page's main area.
31
+ */
32
+ size?: 'sm' | 'md'
33
+ class?: HTMLAttributes['class']
34
+ /** Extra classes for the parts. */
35
+ ui?: {
36
+ icon?: HTMLAttributes['class']
37
+ title?: HTMLAttributes['class']
38
+ description?: HTMLAttributes['class']
39
+ actions?: HTMLAttributes['class']
40
+ }
41
+ }
42
+
43
+ const props = withDefaults(defineProps<EmptyStateProps>(), {
44
+ size: 'md'
45
+ })
46
+
47
+ defineSlots<{
48
+ default?(): unknown
49
+ title?(): unknown
50
+ description?(): unknown
51
+ actions?(): unknown
52
+ }>()
53
+
54
+ const sizes = {
55
+ sm: { root: 'gap-2 px-4 py-10', icon: 'size-6', title: 'text-sm', description: 'text-sm' },
56
+ md: { root: 'gap-2 px-4 py-12', icon: 'size-8', title: 'text-base', description: 'text-sm' }
57
+ } as const
58
+ </script>
59
+
60
+ <template>
61
+ <div :class="cn('flex flex-col items-center text-center', sizes[size].root, props.class)">
62
+ <div v-if="icon" :class="cn('flex text-black/45', size === 'md' && 'mb-1', ui?.icon)" aria-hidden="true">
63
+ <component :is="icon" :class="sizes[size].icon" />
64
+ </div>
65
+
66
+ <component
67
+ :is="headingLevel ? `h${headingLevel}` : 'p'"
68
+ v-if="$slots.title || title"
69
+ :class="cn('font-bold text-black', sizes[size].title, ui?.title)"
70
+ >
71
+ <slot name="title">{{ title }}</slot>
72
+ </component>
73
+
74
+ <p
75
+ v-if="$slots.description || description"
76
+ :class="cn('max-w-sm text-black/65', sizes[size].description, ui?.description)"
77
+ >
78
+ <slot name="description">{{ description }}</slot>
79
+ </p>
80
+
81
+ <slot />
82
+
83
+ <div v-if="$slots.actions" :class="cn('mt-2 flex flex-wrap justify-center gap-2', ui?.actions)">
84
+ <slot name="actions" />
85
+ </div>
86
+ </div>
87
+ </template>