@thekestongroup/ui 0.2.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (207) hide show
  1. package/README.md +90 -32
  2. package/dist/components/Age/Age.vue.d.ts +19 -0
  3. package/dist/components/AppShell/AppShell.vue.d.ts +108 -0
  4. package/dist/components/Avatar/Avatar.vue.d.ts +34 -0
  5. package/dist/components/AvatarGroup/AvatarGroup.vue.d.ts +25 -0
  6. package/dist/components/Badge/Badge.vue.d.ts +41 -0
  7. package/dist/components/Breadcrumb/Breadcrumb.vue.d.ts +39 -0
  8. package/dist/components/Button/Button.vue.d.ts +69 -0
  9. package/dist/components/Calendar/Calendar.vue.d.ts +34 -0
  10. package/dist/components/Card/Card.vue.d.ts +56 -0
  11. package/dist/components/Checkbox/Checkbox.vue.d.ts +40 -0
  12. package/dist/components/Checklist/Checklist.vue.d.ts +18 -0
  13. package/dist/components/Chip/Chip.vue.d.ts +44 -0
  14. package/dist/components/Divider/Divider.vue.d.ts +36 -0
  15. package/dist/components/{ToastItem.vue.d.ts → FormField/FieldMessage.vue.d.ts} +10 -2
  16. package/dist/components/FormField/FormField.vue.d.ts +61 -0
  17. package/dist/components/Header/Header.vue.d.ts +104 -0
  18. package/dist/components/InfoTip/InfoTip.vue.d.ts +20 -0
  19. package/dist/components/Input/Input.vue.d.ts +56 -0
  20. package/dist/components/InputCode/InputCode.vue.d.ts +53 -0
  21. package/dist/components/InputDate/InputDate.vue.d.ts +49 -0
  22. package/dist/components/InputNumber/InputNumber.vue.d.ts +44 -0
  23. package/dist/components/InputPassword/InputPassword.vue.d.ts +51 -0
  24. package/dist/components/InputRichText/InputRichText.vue.d.ts +44 -0
  25. package/dist/components/Link/Link.vue.d.ts +39 -0
  26. package/dist/components/Notification/Notification.vue.d.ts +62 -0
  27. package/dist/components/Notification/NotificationPane.vue.d.ts +38 -0
  28. package/dist/components/Notification/Toaster.vue.d.ts +51 -0
  29. package/dist/components/Notification/notification.samples.d.ts +3 -0
  30. package/dist/components/Notification/notifications.d.ts +115 -0
  31. package/dist/components/PageHeader/PageHeader.vue.d.ts +43 -0
  32. package/dist/components/Popover/Popover.vue.d.ts +83 -0
  33. package/dist/components/Popover/popover.d.ts +16 -0
  34. package/dist/components/Progress/Progress.vue.d.ts +26 -0
  35. package/dist/components/RadioGroup/RadioGroup.vue.d.ts +45 -0
  36. package/dist/components/RelativeTime/RelativeTime.vue.d.ts +22 -0
  37. package/dist/components/Select/Select.vue.d.ts +110 -0
  38. package/dist/components/Sidebar/Sidebar.vue.d.ts +106 -0
  39. package/dist/components/Sidebar/sidebar.d.ts +10 -0
  40. package/dist/components/Slideover/Slideover.vue.d.ts +125 -0
  41. package/dist/components/Spinner/Spinner.vue.d.ts +30 -0
  42. package/dist/components/StatTile/StatTile.vue.d.ts +46 -0
  43. package/dist/components/SummaryList/SummaryList.vue.d.ts +62 -0
  44. package/dist/components/Switch/Switch.vue.d.ts +39 -0
  45. package/dist/components/Table/Table.vue.d.ts +82 -0
  46. package/dist/components/Table/table.d.ts +36 -0
  47. package/dist/components/Tooltip/Tooltip.vue.d.ts +46 -0
  48. package/dist/index.d.ts +89 -25
  49. package/dist/keston-ui.js +4963 -14785
  50. package/dist/lib/cn.d.ts +4 -0
  51. package/dist/lib/dates.d.ts +27 -0
  52. package/dist/lib/initials.d.ts +2 -0
  53. package/dist/lib/parseDate.d.ts +44 -0
  54. package/dist/lib/useNow.d.ts +3 -0
  55. package/package.json +53 -24
  56. package/src/components/.gitkeep +0 -0
  57. package/src/components/Age/Age.stories.ts +24 -0
  58. package/src/components/Age/Age.vue +56 -0
  59. package/src/components/AppShell/AppShell.stories.ts +124 -0
  60. package/src/components/AppShell/AppShell.vue +212 -0
  61. package/src/components/Avatar/Avatar.stories.ts +56 -0
  62. package/src/components/Avatar/Avatar.vue +118 -0
  63. package/src/components/AvatarGroup/AvatarGroup.stories.ts +47 -0
  64. package/src/components/AvatarGroup/AvatarGroup.vue +97 -0
  65. package/src/components/Badge/Badge.stories.ts +92 -0
  66. package/src/components/Badge/Badge.vue +67 -0
  67. package/src/components/Breadcrumb/Breadcrumb.stories.ts +58 -0
  68. package/src/components/Breadcrumb/Breadcrumb.vue +109 -0
  69. package/src/components/Button/Button.mdx +79 -0
  70. package/src/components/Button/Button.stories.ts +207 -0
  71. package/src/components/Button/Button.vue +266 -0
  72. package/src/components/Calendar/Calendar.stories.ts +51 -0
  73. package/src/components/Calendar/Calendar.vue +364 -0
  74. package/src/components/Card/Card.stories.ts +109 -0
  75. package/src/components/Card/Card.vue +115 -0
  76. package/src/components/Checkbox/Checkbox.stories.ts +102 -0
  77. package/src/components/Checkbox/Checkbox.vue +102 -0
  78. package/src/components/Checklist/Checklist.stories.ts +67 -0
  79. package/src/components/Checklist/Checklist.vue +38 -0
  80. package/src/components/Chip/Chip.stories.ts +71 -0
  81. package/src/components/Chip/Chip.vue +86 -0
  82. package/src/components/Divider/Divider.stories.ts +57 -0
  83. package/src/components/Divider/Divider.vue +58 -0
  84. package/src/components/FormField/FieldMessage.vue +81 -0
  85. package/src/components/FormField/FormField.stories.ts +55 -0
  86. package/src/components/FormField/FormField.vue +160 -0
  87. package/src/components/Header/Header.stories.ts +168 -0
  88. package/src/components/Header/Header.vue +232 -0
  89. package/src/components/InfoTip/InfoTip.stories.ts +63 -0
  90. package/src/components/InfoTip/InfoTip.vue +50 -0
  91. package/src/components/Input/Input.stories.ts +206 -0
  92. package/src/components/Input/Input.vue +90 -0
  93. package/src/components/InputCode/InputCode.stories.ts +85 -0
  94. package/src/components/InputCode/InputCode.vue +145 -0
  95. package/src/components/InputDate/InputDate.stories.ts +58 -0
  96. package/src/components/InputDate/InputDate.vue +258 -0
  97. package/src/components/InputNumber/InputNumber.stories.ts +63 -0
  98. package/src/components/InputNumber/InputNumber.vue +109 -0
  99. package/src/components/InputPassword/InputPassword.stories.ts +105 -0
  100. package/src/components/InputPassword/InputPassword.vue +132 -0
  101. package/src/components/InputRichText/InputRichText.stories.ts +100 -0
  102. package/src/components/InputRichText/InputRichText.vue +194 -0
  103. package/src/components/Link/Link.stories.ts +73 -0
  104. package/src/components/Link/Link.vue +56 -0
  105. package/src/components/Notification/Notification.stories.ts +196 -0
  106. package/src/components/Notification/Notification.vue +136 -0
  107. package/src/components/Notification/NotificationPane.vue +187 -0
  108. package/src/components/Notification/Toaster.vue +446 -0
  109. package/src/components/Notification/notification.samples.ts +45 -0
  110. package/src/components/Notification/notifications.test.ts +99 -0
  111. package/src/components/Notification/notifications.ts +172 -0
  112. package/src/components/PageHeader/PageHeader.stories.ts +79 -0
  113. package/src/components/PageHeader/PageHeader.vue +66 -0
  114. package/src/components/Popover/Popover.stories.ts +135 -0
  115. package/src/components/Popover/Popover.vue +192 -0
  116. package/src/components/Popover/popover.ts +20 -0
  117. package/src/components/Progress/Progress.stories.ts +74 -0
  118. package/src/components/Progress/Progress.vue +75 -0
  119. package/src/components/RadioGroup/RadioGroup.stories.ts +90 -0
  120. package/src/components/RadioGroup/RadioGroup.vue +132 -0
  121. package/src/components/RelativeTime/RelativeTime.stories.ts +74 -0
  122. package/src/components/RelativeTime/RelativeTime.vue +51 -0
  123. package/src/components/Select/Select.mdx +202 -0
  124. package/src/components/Select/Select.stories.ts +223 -0
  125. package/src/components/Select/Select.vue +630 -0
  126. package/src/components/Sidebar/Sidebar.stories.ts +192 -0
  127. package/src/components/Sidebar/Sidebar.vue +382 -0
  128. package/src/components/Sidebar/sidebar.ts +20 -0
  129. package/src/components/Slideover/Slideover.stories.ts +225 -0
  130. package/src/components/Slideover/Slideover.vue +365 -0
  131. package/src/components/Spinner/Spinner.stories.ts +79 -0
  132. package/src/components/Spinner/Spinner.vue +97 -0
  133. package/src/components/StatTile/StatTile.stories.ts +75 -0
  134. package/src/components/StatTile/StatTile.vue +89 -0
  135. package/src/components/SummaryList/SummaryList.stories.ts +103 -0
  136. package/src/components/SummaryList/SummaryList.vue +127 -0
  137. package/src/components/Switch/Switch.stories.ts +100 -0
  138. package/src/components/Switch/Switch.vue +96 -0
  139. package/src/components/Table/Table.stories.ts +206 -0
  140. package/src/components/Table/Table.vue +220 -0
  141. package/src/components/Table/table.test.ts +65 -0
  142. package/src/components/Table/table.ts +70 -0
  143. package/src/components/Tooltip/Tooltip.stories.ts +57 -0
  144. package/src/components/Tooltip/Tooltip.vue +86 -0
  145. package/src/examples/AppPages.stories.ts +500 -0
  146. package/src/examples/FormLayout.stories.ts +185 -0
  147. package/src/examples/KestonIdPages.stories.ts +415 -0
  148. package/src/examples/SchoolPages.stories.ts +665 -0
  149. package/src/index.ts +114 -36
  150. package/src/lib/cn.ts +4 -0
  151. package/src/lib/dates.test.ts +68 -0
  152. package/src/lib/dates.ts +86 -0
  153. package/src/lib/initials.ts +8 -0
  154. package/src/lib/parseDate.test.ts +331 -0
  155. package/src/lib/parseDate.ts +561 -0
  156. package/src/lib/useNow.ts +20 -0
  157. package/src/styles/theme.css +101 -0
  158. package/dist/components/AppLauncher.vue.d.ts +0 -10
  159. package/dist/components/Avatar.vue.d.ts +0 -16
  160. package/dist/components/Button.vue.d.ts +0 -27
  161. package/dist/components/Checkbox.vue.d.ts +0 -18
  162. package/dist/components/CloseButton.vue.d.ts +0 -6
  163. package/dist/components/Dialog.vue.d.ts +0 -23
  164. package/dist/components/Drawer.vue.d.ts +0 -34
  165. package/dist/components/DropdownMenu.vue.d.ts +0 -21
  166. package/dist/components/DropdownMenuItem.vue.d.ts +0 -19
  167. package/dist/components/DropdownMenuSeparator.vue.d.ts +0 -6
  168. package/dist/components/Input.vue.d.ts +0 -14
  169. package/dist/components/Label.vue.d.ts +0 -16
  170. package/dist/components/NotificationsMenu.vue.d.ts +0 -3
  171. package/dist/components/Popover.vue.d.ts +0 -23
  172. package/dist/components/ProfileSwitcher.vue.d.ts +0 -24
  173. package/dist/components/Select.vue.d.ts +0 -28
  174. package/dist/components/Separator.vue.d.ts +0 -11
  175. package/dist/components/ToastRenderer.vue.d.ts +0 -3
  176. package/dist/components/Toaster.vue.d.ts +0 -3
  177. package/dist/components/Tooltip.vue.d.ts +0 -23
  178. package/dist/components/TopBar.vue.d.ts +0 -34
  179. package/dist/favicon-old.svg +0 -1
  180. package/dist/favicon.svg +0 -1
  181. package/dist/keston-ui.cjs +0 -15
  182. package/dist/lib/toast.d.ts +0 -29
  183. package/dist/lib/types.d.ts +0 -5
  184. package/src/components/AppLauncher.vue +0 -63
  185. package/src/components/Avatar.vue +0 -51
  186. package/src/components/Button.vue +0 -54
  187. package/src/components/Checkbox.vue +0 -47
  188. package/src/components/CloseButton.vue +0 -24
  189. package/src/components/Dialog.vue +0 -65
  190. package/src/components/Drawer.vue +0 -202
  191. package/src/components/DropdownMenu.vue +0 -41
  192. package/src/components/DropdownMenuItem.vue +0 -28
  193. package/src/components/DropdownMenuSeparator.vue +0 -12
  194. package/src/components/Input.vue +0 -21
  195. package/src/components/Label.vue +0 -15
  196. package/src/components/NotificationsMenu.vue +0 -115
  197. package/src/components/Popover.vue +0 -46
  198. package/src/components/ProfileSwitcher.vue +0 -113
  199. package/src/components/Select.vue +0 -97
  200. package/src/components/Separator.vue +0 -30
  201. package/src/components/ToastItem.vue +0 -158
  202. package/src/components/ToastRenderer.vue +0 -113
  203. package/src/components/Toaster.vue +0 -11
  204. package/src/components/Tooltip.vue +0 -48
  205. package/src/components/TopBar.vue +0 -52
  206. package/src/lib/toast.ts +0 -95
  207. package/src/lib/types.ts +0 -5
@@ -0,0 +1,100 @@
1
+ import type { Meta, StoryObj } from "@storybook/vue3-vite";
2
+ import { ref, watch } from "vue";
3
+ import InputRichText, { type InputRichTextProps } from "./InputRichText.vue";
4
+
5
+ const meta = {
6
+ title: "Components/Form/InputRichText",
7
+ component: InputRichText,
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
+ placeholder: "Add a note…",
16
+ helper: "",
17
+ helperPlacement: "below",
18
+ disabled: false,
19
+ },
20
+ decorators: [() => ({ template: '<div class="max-w-120"><story /></div>' })],
21
+ render: (args) => ({
22
+ components: { InputRichText },
23
+ setup: () => ({ args, value: ref("") }),
24
+ template: `
25
+ <InputRichText v-bind="args" v-model="value" />
26
+ <pre class="mt-4 text-xs whitespace-pre-wrap text-black/65">{{ value || '(empty)' }}</pre>`,
27
+ }),
28
+ } satisfies Meta<typeof InputRichText>;
29
+
30
+ export default meta;
31
+ type Story = StoryObj<typeof meta>;
32
+
33
+ /**
34
+ * Playground. Select text and press **B**, *I* or U, or use ⌘B / ⌘I / ⌘U
35
+ * (Ctrl on Windows). The HTML it produces shows underneath.
36
+ */
37
+ export const Default: Story = {};
38
+
39
+ export const WithText: Story = {
40
+ args: { label: "Notes on Ada Okafor" },
41
+ render: (args) => ({
42
+ components: { InputRichText },
43
+ setup: () => ({
44
+ args,
45
+ value: ref(
46
+ "<p>Settled in well. <strong>Allergic to nuts</strong>: kitchen told on 2 September.</p><p>Mum prefers calls after 3pm; <em>not</em> on Fridays. <u>Check the medical form is signed</u> before the trip.</p>",
47
+ ),
48
+ }),
49
+ template: '<InputRichText v-bind="args" v-model="value" />',
50
+ }),
51
+ };
52
+
53
+ export const HelperBehindIcon: Story = {
54
+ args: { helper: "Seen by staff only, not by parents.", helperPlacement: "icon" },
55
+ };
56
+
57
+ /** Long notes grow the field to 15 lines, then it scrolls. */
58
+ export const LongNotes: Story = {
59
+ render: (args) => ({
60
+ components: { InputRichText },
61
+ setup: () => ({
62
+ args,
63
+ value: ref(
64
+ Array.from({ length: 12 }, (_, i) => `<p>Week ${i + 1}: attended every session, homework handed in.</p>`).join(""),
65
+ ),
66
+ }),
67
+ template: '<InputRichText v-bind="args" v-model="value" />',
68
+ }),
69
+ };
70
+
71
+ /**
72
+ * Saving as you type: "Saving…" while the note saves (faked here with a
73
+ * delay after typing pauses), then "Saved".
74
+ */
75
+ export const AutoSave: Story = {
76
+ render: (args) => ({
77
+ components: { InputRichText },
78
+ setup() {
79
+ const value = ref("");
80
+ const status = ref<InputRichTextProps["status"]>();
81
+ const statusText = ref<string>();
82
+ let timer: ReturnType<typeof setTimeout> | undefined;
83
+ watch(value, () => {
84
+ clearTimeout(timer);
85
+ status.value = "loading";
86
+ statusText.value = "Saving…";
87
+ timer = setTimeout(() => {
88
+ status.value = "success";
89
+ statusText.value = "Saved";
90
+ }, 1000);
91
+ });
92
+ return { args, value, status, statusText };
93
+ },
94
+ template: '<InputRichText v-bind="args" v-model="value" :status="status" :status-text="statusText" />',
95
+ }),
96
+ };
97
+
98
+ export const WithErrorText: Story = { args: { errorText: "Add a note before saving" } };
99
+
100
+ export const Disabled: Story = { args: { disabled: true } };
@@ -0,0 +1,194 @@
1
+ <script setup lang="ts">
2
+ import { defineComponent, onBeforeUnmount, ref, watch, watchEffect, type HTMLAttributes, type PropType } from 'vue'
3
+ import { EditorContent, useEditor } from '@tiptap/vue-3'
4
+ import type { Editor } from '@tiptap/core'
5
+ import Document from '@tiptap/extension-document'
6
+ import Paragraph from '@tiptap/extension-paragraph'
7
+ import Text from '@tiptap/extension-text'
8
+ import HardBreak from '@tiptap/extension-hard-break'
9
+ import Bold from '@tiptap/extension-bold'
10
+ import Italic from '@tiptap/extension-italic'
11
+ import Underline from '@tiptap/extension-underline'
12
+ import { Placeholder, UndoRedo } from '@tiptap/extensions'
13
+ import { Bold as BoldIcon, Italic as ItalicIcon, Underline as UnderlineIcon } from '@lucide/vue'
14
+ import { cn } from '../../lib/cn'
15
+ import FormField, { type FormFieldStatus } from '../FormField/FormField.vue'
16
+ import Button from '../Button/Button.vue'
17
+ import Tooltip from '../Tooltip/Tooltip.vue'
18
+
19
+ /**
20
+ * Several lines of text with bold, italic and underline, e.g. notes on a
21
+ * student or an application. Only those three: no headings, lists, links or
22
+ * colours, so notes look the same everywhere. Pasted text keeps its bold,
23
+ * italic and underline and loses everything else.
24
+ *
25
+ * The value is HTML using only <p>, <br>, <strong>, <em> and <u>. Sanitise
26
+ * it on the server like any HTML from a browser before showing it elsewhere.
27
+ */
28
+ export interface InputRichTextProps {
29
+ /** Visible label. Always set it: it is also the editor's accessible name. */
30
+ label: string
31
+ /** Extra guidance about what to write. */
32
+ helper?: string
33
+ /** Show helper text under the label, or behind a `?` icon next to it. */
34
+ helperPlacement?: 'below' | 'icon'
35
+ /** Error message, e.g. from a Zod schema. Overrides `status` / `statusText`. */
36
+ errorText?: string
37
+ /** Colours the field and the status text, e.g. 'loading' while it saves. */
38
+ status?: FormFieldStatus
39
+ /** Message under the field. */
40
+ statusText?: string
41
+ /** Shown in the empty editor, e.g. "Add a note…". */
42
+ placeholder?: string
43
+ disabled?: boolean
44
+ class?: HTMLAttributes['class']
45
+ }
46
+
47
+ const props = withDefaults(defineProps<InputRichTextProps>(), {
48
+ helperPlacement: 'below'
49
+ })
50
+
51
+ /** The text as HTML; an empty string when there's nothing in it. */
52
+ const model = defineModel<string>({ default: '' })
53
+
54
+ // An empty editor still holds an empty paragraph; report that as ''.
55
+ const html = () => (editor.value?.isEmpty ? '' : (editor.value?.getHTML() ?? ''))
56
+
57
+ const editor = useEditor({
58
+ content: model.value,
59
+ editable: !props.disabled,
60
+ extensions: [
61
+ Document,
62
+ Paragraph,
63
+ Text,
64
+ HardBreak,
65
+ Bold,
66
+ Italic,
67
+ Underline,
68
+ UndoRedo,
69
+ Placeholder.configure({ placeholder: () => props.placeholder ?? '' })
70
+ ],
71
+ onUpdate: () => {
72
+ model.value = html()
73
+ },
74
+ // Every change, including moving the cursor, updates the toolbar.
75
+ onCreate: ({ editor }) => updateActive(editor),
76
+ onTransaction: ({ editor }) => updateActive(editor)
77
+ })
78
+
79
+ // Which formats are on at the cursor (or for the next text typed), for the
80
+ // toolbar's pressed state. Tiptap's isActive() isn't reactive by itself.
81
+ type Mark = 'bold' | 'italic' | 'underline'
82
+ const active = ref<Record<Mark, boolean>>({ bold: false, italic: false, underline: false })
83
+ function updateActive(e: Editor) {
84
+ active.value = { bold: e.isActive('bold'), italic: e.isActive('italic'), underline: e.isActive('underline') }
85
+ }
86
+
87
+ // A value set from outside (e.g. a form reset) replaces the text; the
88
+ // editor's own updates come back unchanged and are skipped.
89
+ watch(model, (value) => {
90
+ if (editor.value && value !== html()) editor.value.commands.setContent(value, { emitUpdate: false })
91
+ })
92
+
93
+ watch(
94
+ () => props.disabled,
95
+ (disabled) => editor.value?.setEditable(!disabled)
96
+ )
97
+
98
+ onBeforeUnmount(() => editor.value?.destroy())
99
+
100
+ // The editable area gets the id and ARIA values FormField hands out. It's a
101
+ // contenteditable <div>, so it needs the textbox role and the label by id.
102
+ // A render-less child, so the values (only known inside FormField's slot)
103
+ // are applied in a watcher rather than while rendering.
104
+ type FieldIds = { id: string; labelId: string; describedBy?: string; invalid?: true }
105
+ const EditorAttributes = defineComponent({
106
+ props: { ids: { type: Object as PropType<FieldIds>, required: true } },
107
+ setup(attrs) {
108
+ watchEffect(() => {
109
+ const { id, labelId, describedBy, invalid } = attrs.ids
110
+ editor.value?.setOptions({
111
+ editorProps: {
112
+ attributes: {
113
+ id,
114
+ role: 'textbox',
115
+ 'aria-multiline': 'true',
116
+ 'aria-labelledby': labelId,
117
+ ...(describedBy ? { 'aria-describedby': describedBy } : {}),
118
+ ...(invalid ? { 'aria-invalid': 'true' } : {}),
119
+ class: editable
120
+ }
121
+ }
122
+ })
123
+ })
124
+ return () => null
125
+ }
126
+ })
127
+
128
+ const isMac = typeof navigator !== 'undefined' && /Mac|iPhone|iPad/.test(navigator.platform)
129
+ const mod = isMac ? '⌘' : 'Ctrl+'
130
+
131
+ const marks = [
132
+ { name: 'bold', label: 'Bold', icon: BoldIcon, key: 'B', toggle: () => editor.value?.chain().focus().toggleBold().run() },
133
+ { name: 'italic', label: 'Italic', icon: ItalicIcon, key: 'I', toggle: () => editor.value?.chain().focus().toggleItalic().run() },
134
+ { name: 'underline', label: 'Underline', icon: UnderlineIcon, key: 'U', toggle: () => editor.value?.chain().focus().toggleUnderline().run() }
135
+ ] as const
136
+
137
+ // The text area: at least 4 lines, then it grows to 15 lines and scrolls.
138
+ // Paragraphs are 8px apart. The placeholder is drawn by Tiptap's Placeholder
139
+ // extension on the first empty paragraph.
140
+ const editable = [
141
+ // 16px on touch screens, so iPhone doesn't zoom in when it's tapped.
142
+ 'min-h-24 max-h-80 overflow-y-auto px-3 py-2 text-sm pointer-coarse:text-base outline-none cursor-text',
143
+ '[&_p+p]:mt-2',
144
+ '[&_p.is-editor-empty:first-child]:before:pointer-events-none [&_p.is-editor-empty:first-child]:before:float-left',
145
+ '[&_p.is-editor-empty:first-child]:before:h-0 [&_p.is-editor-empty:first-child]:before:text-black/55',
146
+ '[&_p.is-editor-empty:first-child]:before:content-[attr(data-placeholder)]'
147
+ ].join(' ')
148
+ </script>
149
+
150
+ <template>
151
+ <FormField
152
+ :label="label"
153
+ :helper="helper"
154
+ :helper-placement="helperPlacement"
155
+ :error-text="errorText"
156
+ :status="status"
157
+ :status-text="statusText"
158
+ :disabled="disabled"
159
+ :class="props.class"
160
+ >
161
+ <template #default="slot">
162
+ <!-- Fills FormField's box: negative margins cancel its padding, so the
163
+ toolbar's line and the text area run to the edges. -->
164
+ <div class="-mx-3 -my-2 flex min-w-0 flex-1 flex-col self-stretch">
165
+ <!-- Pressing a button keeps focus (and the selection) in the text. -->
166
+ <div
167
+ role="toolbar"
168
+ :aria-label="`Formatting for ${label}`"
169
+ :aria-controls="slot.id"
170
+ class="flex items-center gap-0.5 border-b border-black/15 px-1.5 py-1 [&_svg]:opacity-100!"
171
+ @mousedown.prevent
172
+ >
173
+ <Tooltip v-for="mark in marks" :key="mark.name" :text="`${mark.label} (${mod}${mark.key})`" :disabled="disabled">
174
+ <Button
175
+ variant="ghost"
176
+ size="sm"
177
+ square
178
+ :aria-label="mark.label"
179
+ :aria-pressed="active[mark.name]"
180
+ :aria-keyshortcuts="`${isMac ? 'Meta' : 'Control'}+${mark.key}`"
181
+ :disabled="disabled"
182
+ class="aria-pressed:bg-black/15"
183
+ @click="mark.toggle()"
184
+ >
185
+ <component :is="mark.icon" />
186
+ </Button>
187
+ </Tooltip>
188
+ </div>
189
+ <EditorAttributes :ids="slot" />
190
+ <EditorContent :editor="editor" :class="cn('min-w-0', disabled && 'cursor-not-allowed [&_*]:cursor-not-allowed')" />
191
+ </div>
192
+ </template>
193
+ </FormField>
194
+ </template>
@@ -0,0 +1,73 @@
1
+ import type { Meta, StoryObj } from "@storybook/vue3-vite";
2
+ import Link, { type LinkProps } from "./Link.vue";
3
+
4
+ type LinkStoryArgs = LinkProps & { text: string };
5
+
6
+ const meta = {
7
+ title: "Components/Navigation/Link",
8
+ component: Link,
9
+ tags: ["autodocs"],
10
+ argTypes: {
11
+ text: { control: "text", table: { category: "Content" } },
12
+ },
13
+ args: { href: "#", text: "Privacy policy", newTab: false, icon: true },
14
+ render: (args) => ({
15
+ components: { Link },
16
+ setup: () => ({ args }),
17
+ template: `<p class="text-sm text-black"><Link :href="args.href" :new-tab="args.newTab" :icon="args.icon">{{ args.text }}</Link></p>`,
18
+ }),
19
+ } satisfies Meta<LinkStoryArgs>;
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
+ /** Opens in a new tab: the small external-page icon shows it, and screen readers hear "(opens in a new tab)". */
28
+ export const NewTab: Story = { args: { newTab: true } };
29
+
30
+ /** Opens in a new tab without the icon (`:icon="false"`). Screen readers still hear "(opens in a new tab)". */
31
+ export const NewTabWithoutIcon: Story = { args: { newTab: true, icon: false } };
32
+
33
+ /** In a sentence it takes the text's size and colour. */
34
+ export const InASentence: Story = {
35
+ render: () => ({
36
+ components: { Link },
37
+ template: `
38
+ <p class="max-w-100 text-xs text-black/65">
39
+ Make sure you trust Keston Admissions: read its
40
+ <Link href="#" new-tab>privacy policy</Link> and <Link href="#" new-tab>terms</Link>.
41
+ You can remove its access at any time in your <Link href="#">Keston account</Link>.
42
+ </p>`,
43
+ }),
44
+ };
45
+
46
+ /** A row of footer links, muted until hovered. */
47
+ export const Footer: Story = {
48
+ render: () => ({
49
+ components: { Link },
50
+ template: `
51
+ <nav aria-label="Legal and help" class="flex items-center gap-2 text-xs text-black/65">
52
+ <Link href="#" new-tab>Privacy</Link>
53
+ <span aria-hidden="true">·</span>
54
+ <Link href="#" new-tab>Terms</Link>
55
+ <span aria-hidden="true">·</span>
56
+ <Link href="#" new-tab>Help</Link>
57
+ </nav>`,
58
+ }),
59
+ };
60
+
61
+ /** Larger text: the icon grows with it. */
62
+ export const Sizes: Story = {
63
+ render: () => ({
64
+ components: { Link },
65
+ template: `
66
+ <div class="flex flex-col gap-2 text-black">
67
+ <p class="text-xs"><Link href="#" new-tab>Extra small</Link></p>
68
+ <p class="text-sm"><Link href="#" new-tab>Small</Link></p>
69
+ <p class="text-base"><Link href="#" new-tab>Base</Link></p>
70
+ <p class="text-xl"><Link href="#" new-tab>Extra large</Link></p>
71
+ </div>`,
72
+ }),
73
+ };
@@ -0,0 +1,56 @@
1
+ <script setup lang="ts">
2
+ import type { HTMLAttributes } from 'vue'
3
+ import { Primitive, type PrimitiveProps } from 'reka-ui'
4
+ import { ExternalLink } from '@lucide/vue'
5
+ import { cn } from '../../lib/cn'
6
+
7
+ /**
8
+ * A text link: underlined, in the colour and size of the text around it, so
9
+ * it fits in a sentence, a footer or a tooltip alike. With `newTab` it opens
10
+ * in a new tab and shows a small external-page icon (and tells screen
11
+ * readers it opens in a new tab).
12
+ *
13
+ * For a router, pass its link component as `as`, e.g.
14
+ * `<Link :as="RouterLink" to="/help">`.
15
+ */
16
+ export interface LinkProps {
17
+ href?: string
18
+ /** Open in a new tab, with the external-page icon. Use it for pages outside the current flow (policies, help) so people don't lose their place. */
19
+ newTab?: boolean
20
+ /** With `newTab`, show the external-page icon. Turn it off where it would clutter, e.g. a row of footer links. Screen readers still hear "(opens in a new tab)". */
21
+ icon?: boolean
22
+ /** Element or component to render, e.g. RouterLink. */
23
+ as?: PrimitiveProps['as']
24
+ class?: HTMLAttributes['class']
25
+ }
26
+
27
+ const props = withDefaults(defineProps<LinkProps>(), {
28
+ as: 'a',
29
+ icon: true
30
+ })
31
+
32
+ // Underlined in the text's own colour; hovering darkens it to black and
33
+ // thickens the line. Keyboard focus gets the usual focus ring.
34
+ const base = [
35
+ 'cursor-pointer rounded-xs underline underline-offset-2 transition-colors',
36
+ 'hover:text-black hover:decoration-2',
37
+ 'outline-2 outline-offset-2 outline-transparent focus-visible:outline-focus'
38
+ ]
39
+ </script>
40
+
41
+ <template>
42
+ <Primitive
43
+ :as="as"
44
+ :href="href"
45
+ :target="newTab ? '_blank' : undefined"
46
+ :rel="newTab ? 'noopener noreferrer' : undefined"
47
+ :class="cn(base, props.class)"
48
+ >
49
+ <slot />
50
+ <template v-if="newTab">
51
+ <!-- Sized to the text (em), sitting on its baseline, after a thin gap. -->
52
+ <ExternalLink v-if="icon" class="ms-0.5 inline size-[0.9em] align-[-0.1em]" aria-hidden="true" />
53
+ <span class="sr-only"> (opens in a new tab)</span>
54
+ </template>
55
+ </Primitive>
56
+ </template>
@@ -0,0 +1,196 @@
1
+ import type { Meta, StoryObj } from "@storybook/vue3-vite";
2
+ import { h, ref } from "vue";
3
+ import Button from "../Button/Button.vue";
4
+ import Header from "../Header/Header.vue";
5
+ import Notification from "./Notification.vue";
6
+ import NotificationPane from "./NotificationPane.vue";
7
+ import Toaster from "./Toaster.vue";
8
+ import { createNotifications, type NotificationInput } from "./notifications";
9
+ import { passwordExpiry, sampleNotifications } from "./notification.samples";
10
+
11
+ // Cards and rows on the page background, at a toast's width. Header stories
12
+ // use their own (full width), so this is per story rather than in meta.
13
+ const narrow = () => ({ template: '<div class="bg-background p-6"><div class="max-w-sm"><story /></div></div>' });
14
+
15
+ const meta = {
16
+ title: "Components/Overlay/Notification",
17
+ component: Notification,
18
+ tags: ["autodocs"],
19
+ parameters: { backgrounds: { disable: true } },
20
+ argTypes: {
21
+ type: { options: ["info", "success", "warning", "error"], control: { type: "inline-radio" } },
22
+ appearance: { options: ["card", "row"], control: { type: "inline-radio" } },
23
+ description: { control: "text" },
24
+ },
25
+ args: {
26
+ type: "warning",
27
+ title: "Password Expiry",
28
+ description: passwordExpiry.description,
29
+ action: passwordExpiry.action,
30
+ appearance: "card",
31
+ dismissible: true,
32
+ },
33
+ } satisfies Meta<typeof Notification>;
34
+
35
+ export default meta;
36
+ type Story = StoryObj<typeof meta>;
37
+
38
+ /** One notification. The description is a render function, so "7 days" can be bold. */
39
+ export const Default: Story = { decorators: [narrow] };
40
+
41
+ /** Each type: its icon and colour. Screen readers hear the type before the title ("Warning: …"). */
42
+ export const Types: Story = {
43
+ decorators: [narrow],
44
+ render: () => ({
45
+ components: { Notification },
46
+ template: `
47
+ <div class="flex flex-col gap-3">
48
+ <Notification type="info" title="New application" description="Amelia Clarke applied for Year 7." />
49
+ <Notification type="success" title="Timetable published" description="Staff and students can now see it." />
50
+ <Notification type="warning" title="Password Expiry" description="Your password expires in 7 days." :action="{ label: 'Change password' }" />
51
+ <Notification type="error" title="Census upload failed" description="The file has 3 errors." :action="{ label: 'View errors' }" />
52
+ </div>`,
53
+ }),
54
+ };
55
+
56
+ /**
57
+ * compact: one line, for quick confirmations. The action (e.g. Undo) sits on
58
+ * the right, before the ×. As a toast it's the same width as the others,
59
+ * just shorter; with an action it stays 10 seconds.
60
+ */
61
+ export const Compact: Story = {
62
+ decorators: [narrow],
63
+ render: () => ({
64
+ components: { Notification },
65
+ template: `
66
+ <div class="flex flex-col gap-3">
67
+ <Notification compact type="success" title="Student disabled" :action="{ label: 'Undo' }" />
68
+ <Notification compact type="success" title="Changes saved" />
69
+ <Notification compact type="info" title="Link copied" :dismissible="false" />
70
+ <Notification compact type="error" title="Couldn't save" :action="{ label: 'Retry' }" />
71
+ </div>`,
72
+ }),
73
+ };
74
+
75
+ /** The row appearance, as in the pane: the time, and a dot when unread. */
76
+ export const Rows: Story = {
77
+ decorators: [narrow],
78
+ render: () => ({
79
+ components: { Notification },
80
+ setup: () => ({ items: createNotifications(sampleNotifications()).items }),
81
+ template: `
82
+ <ul class="rounded border border-black/15 bg-white">
83
+ <li v-for="item in items" :key="item.id" class="border-b border-black/15 last:border-b-0">
84
+ <Notification appearance="row" v-bind="item" :created-at="item.createdAt" :unread="!item.read" />
85
+ </li>
86
+ </ul>`,
87
+ }),
88
+ };
89
+
90
+ /**
91
+ * The bell in the Header. Open it to see past notifications: × removes one,
92
+ * Clear all removes them all, and closing it marks them read.
93
+ */
94
+ export const Pane: Story = {
95
+ parameters: { layout: "fullscreen" },
96
+ decorators: [() => ({ template: '<div class="min-h-dvh bg-background"><story /></div>' })],
97
+ render: () => ({
98
+ components: { Header, NotificationPane },
99
+ setup: () => ({ notifications: createNotifications(sampleNotifications()) }),
100
+ template: `
101
+ <Header title="Keston School Admin" :user="{ name: 'Ben Smith', email: 'ben.smith@keston.school' }">
102
+ <template #trailing><NotificationPane :notifications="notifications" /></template>
103
+ </Header>`,
104
+ }),
105
+ };
106
+
107
+ /** Nothing to show. */
108
+ export const PaneEmpty: Story = {
109
+ ...Pane,
110
+ render: () => ({
111
+ components: { Header, NotificationPane },
112
+ setup: () => ({ notifications: createNotifications(), open: ref(true) }),
113
+ template: `
114
+ <Header title="Keston School Admin">
115
+ <template #trailing><NotificationPane v-model:open="open" :notifications="notifications" /></template>
116
+ </Header>`,
117
+ }),
118
+ };
119
+
120
+ /**
121
+ * Try notifications: each button calls notify(). They slide up from the
122
+ * bottom right, pushing the others up, and go into the pane. Past 320px tall
123
+ * the older ones collapse into a stack; hover the toasts (or press F8) to
124
+ * spread them out. If there are more than fit on the screen, "+N more" at
125
+ * the end opens the pane (try Error, then Five at once, twice).
126
+ * Info and success close after 6 seconds; ones with an action, and errors,
127
+ * stay until closed. Hover to pause. Swipe right to close. F8 jumps to them.
128
+ */
129
+ export const Playground: Story = {
130
+ parameters: { layout: "fullscreen" },
131
+ decorators: [() => ({ template: '<div class="min-h-dvh bg-background"><story /></div>' })],
132
+ render: () => ({
133
+ components: { Button, Header, NotificationPane, Toaster },
134
+ setup() {
135
+ const notifications = createNotifications(sampleNotifications());
136
+ const samples: Record<string, NotificationInput> = {
137
+ info: { type: "info", title: "New application", description: "Noah Patel applied for Year 9." },
138
+ success: { type: "success", title: "Changes saved", description: "Term dates for 2027–28 are updated." },
139
+ warning: passwordExpiry,
140
+ error: {
141
+ type: "error",
142
+ title: "Couldn't send the newsletter",
143
+ description: () => ["The mail server didn't respond. ", h("b", "Nothing was sent"), "."],
144
+ action: { label: "Try again" },
145
+ },
146
+ };
147
+ let n = 0;
148
+ const burst = () =>
149
+ ["Year 7", "Year 8", "Year 9", "Year 10", "Year 11"].forEach((year, i) =>
150
+ setTimeout(() => notifications.notify({ type: "success", title: `${year} reports sent`, description: `${28 + i} reports emailed to parents.` }), i * 150),
151
+ );
152
+ const quiet = () => notifications.notify({ title: `Background sync ${++n} finished` }, { toast: false });
153
+ const disable = () => {
154
+ const id = notifications.notify({
155
+ type: "success",
156
+ title: "Student disabled",
157
+ compact: true,
158
+ action: {
159
+ label: "Undo",
160
+ onSelect: () => {
161
+ notifications.dismiss(id);
162
+ notifications.notify({ type: "info", title: "Student enabled again", compact: true });
163
+ },
164
+ },
165
+ });
166
+ };
167
+ return { notifications, samples, burst, quiet, disable };
168
+ },
169
+ template: `
170
+ <Header title="Keston School Admin" :user="{ name: 'Ben Smith', email: 'ben.smith@keston.school' }">
171
+ <template #trailing><NotificationPane :notifications="notifications" /></template>
172
+ </Header>
173
+ <div class="flex flex-col gap-4 p-6">
174
+ <p class="max-w-prose text-sm text-black/65">Each button sends a notification. It pops up as a toast and is added to the bell.</p>
175
+ <div class="flex flex-wrap gap-2">
176
+ <Button @click="notifications.notify(samples.info)">Info</Button>
177
+ <Button @click="notifications.notify(samples.success)">Success</Button>
178
+ <Button @click="notifications.notify(samples.warning)">Warning (Password Expiry)</Button>
179
+ <Button @click="notifications.notify(samples.error)">Error</Button>
180
+ <Button @click="burst">Five at once</Button>
181
+ <Button @click="disable">Compact with Undo</Button>
182
+ <Button @click="quiet">Pane only (no toast)</Button>
183
+ </div>
184
+ </div>
185
+ <Toaster :notifications="notifications" />`,
186
+ }),
187
+ };
188
+
189
+ /** Toasts can also sit top right, under the Header. */
190
+ export const ToasterTopRight: Story = {
191
+ ...Playground,
192
+ render: (args, context) => {
193
+ const story = (Playground.render as (a: typeof args, c: typeof context) => { template: string })(args, context);
194
+ return { ...story, template: story.template.replace("<Toaster ", '<Toaster position="top-right" ') };
195
+ },
196
+ };