@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
package/dist/lib/cn.d.ts CHANGED
@@ -1,2 +1,6 @@
1
1
  import { ClassValue } from 'clsx';
2
+ /**
3
+ * Join class names and resolve Tailwind conflicts, so a class passed in by
4
+ * the app (e.g. `class="px-8"`) overrides the component's own `px-4`.
5
+ */
2
6
  export declare function cn(...inputs: ClassValue[]): string;
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Date wording shared by components. UK English throughout.
3
+ *
4
+ * The pattern: show the short, human version ("3 hours ago", "13"), and the
5
+ * exact one ("Wednesday 11 November 2026 at 09:52", "Born 14 March 2013") on
6
+ * hover or focus. See RelativeTime and Age.
7
+ */
8
+ export type DateInput = Date | string | number;
9
+ /**
10
+ * A Date from a Date, a timestamp or a string. Date-only strings
11
+ * ("2013-03-14") are read as that day here: JavaScript would read them as
12
+ * midnight UTC, which is the day before in places behind UTC.
13
+ */
14
+ export declare function toDate(value: DateInput): Date;
15
+ /** "Just now", "5 minutes ago", "Yesterday", "3 weeks ago", "In 2 days". */
16
+ export declare function relativeTime(date: DateInput, now?: Date): string;
17
+ /** "Wednesday 11 November 2026 at 09:52". */
18
+ export declare function formatDateTime(date: DateInput): string;
19
+ /** "14 March 2013". */
20
+ export declare function formatDate(date: DateInput): string;
21
+ /**
22
+ * Whole years since `birth`, as people count birthdays. Someone born on
23
+ * 29 February turns a year older on 1 March in other years (UK law).
24
+ */
25
+ export declare function age(birth: DateInput, now?: Date): number;
26
+ /** Days until the next birthday (0 on the day). */
27
+ export declare function daysToBirthday(birth: DateInput, now?: Date): number;
@@ -0,0 +1,2 @@
1
+ /** "Ben Smith" → "BS", "Ben" → "B", "Mary Jane Watson" → "MW". Empty for an empty name. */
2
+ export declare function initials(name: string): string;
@@ -0,0 +1,44 @@
1
+ import { CalendarDate } from '@internationalized/date';
2
+ /**
3
+ * Reads a date typed in almost any English form and returns it as a
4
+ * CalendarDate, or undefined if it can't be understood.
5
+ *
6
+ * The text is read as a starting day plus any adjustments, in any order:
7
+ *
8
+ * Written dates 26/01/2009 · 26-01-2009 · 26.01.2009 · 26012009 · 2009-01-26
9
+ * 26 jan 2009 · 26th of January 2009 · jan 26 2009 · 2009 jan 26
10
+ * twelfth of may · 5/12 · 5th december · the 5th · march
11
+ * Relative days today · now · tonight · tomorrow / tmrw · yesterday
12
+ * the day after tomorrow · the day before yesterday
13
+ * Weekdays tuesday · next tuesday · this friday · last tuesday
14
+ * tuesday next week · last week friday · tuesday after next
15
+ * monday week · a week on friday · a month on friday
16
+ * Parts of time end of the month · start of next week · mid december
17
+ * end of the year · eow / eom / eoy
18
+ * first monday of next month · last friday of december
19
+ * this weekend · next weekend
20
+ * Holidays christmas · christmas eve · boxing day · new year's day / eve
21
+ * easter · good friday · easter monday · valentine's day
22
+ * halloween · bonfire night · mother's day · father's day …
23
+ * Adjustments next / last week, month, year · in 3 days · 3 days ago
24
+ * 2 weeks from now · a week from tomorrow · in a couple of days
25
+ * in 1 year 2 months · a week today
26
+ * Times ignored: "5th december at 3pm", "tomorrow morning"
27
+ *
28
+ * Weeks run Monday to Sunday. Dates that don't say which year, month or week
29
+ * ("5th march", "the 5th", "tuesday", "christmas") are resolved by `prefer`.
30
+ */
31
+ export type DatePart = 'day' | 'month' | 'year';
32
+ export type DatePreference = 'future' | 'past' | 'nearest';
33
+ export interface ParseDateOptions {
34
+ /** The date to count from. */
35
+ today: CalendarDate;
36
+ /** Order of day / month / year in numeric dates. Default day, month, year. */
37
+ order?: DatePart[];
38
+ /**
39
+ * How to resolve dates that don't say which year, month or week:
40
+ * 'future' (default) picks the next one, 'past' the last one, 'nearest' the closest.
41
+ */
42
+ prefer?: DatePreference;
43
+ }
44
+ export declare function parseDateText(input: string, options: ParseDateOptions): CalendarDate | undefined;
@@ -0,0 +1,3 @@
1
+ import { Ref } from 'vue';
2
+ /** The current time, updated every 30 seconds while any component uses it. */
3
+ export declare function useNow(): Readonly<Ref<Date>>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thekestongroup/ui",
3
- "version": "0.2.1",
3
+ "version": "0.4.0",
4
4
  "description": "Keston UI — Vue 3 + Reka UI + Tailwind CSS component library",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "repository": {
@@ -8,48 +8,81 @@
8
8
  "url": "git+https://github.com/thekestongroup/ui.git"
9
9
  },
10
10
  "type": "module",
11
+ "sideEffects": [
12
+ "**/*.css"
13
+ ],
11
14
  "files": [
12
15
  "dist",
13
16
  "src"
14
17
  ],
15
- "main": "./dist/keston-ui.cjs",
16
18
  "module": "./dist/keston-ui.js",
17
19
  "types": "./dist/index.d.ts",
18
20
  "exports": {
19
21
  ".": {
20
22
  "types": "./dist/index.d.ts",
21
- "import": "./dist/keston-ui.js",
22
- "require": "./dist/keston-ui.cjs"
23
- }
23
+ "import": "./dist/keston-ui.js"
24
+ },
25
+ "./theme.css": "./src/styles/theme.css"
24
26
  },
25
27
  "scripts": {
26
- "dev": "vite",
27
- "build": "vite build",
28
+ "dev": "storybook dev -p 6006",
29
+ "build": "vue-tsc -p tsconfig.app.json --noEmit && vite build",
28
30
  "typecheck": "vue-tsc -b",
29
- "preview": "vite preview"
31
+ "build-storybook": "storybook build",
32
+ "docs:dev": "vitepress dev site",
33
+ "docs:build": "vitepress build site && storybook build --quiet -o site/.vitepress/dist/storybook",
34
+ "docs:preview": "vitepress preview site",
35
+ "new": "node scripts/new-component.mjs",
36
+ "changeset": "changeset",
37
+ "test": "vitest run",
38
+ "test:watch": "vitest"
30
39
  },
31
40
  "peerDependencies": {
32
41
  "vue": "^3.5.0"
33
42
  },
43
+ "packageManager": "pnpm@11.6.0",
44
+ "publishConfig": {
45
+ "access": "public",
46
+ "registry": "https://registry.npmjs.org/"
47
+ },
48
+ "dependencies": {
49
+ "@fontsource/lato": "^5.3.0",
50
+ "@internationalized/date": "^3.12.4",
51
+ "@lucide/vue": "^1.68.0",
52
+ "@tiptap/core": "^3.33.1",
53
+ "@tiptap/extension-bold": "^3.33.1",
54
+ "@tiptap/extension-document": "^3.33.1",
55
+ "@tiptap/extension-hard-break": "^3.33.1",
56
+ "@tiptap/extension-italic": "^3.33.1",
57
+ "@tiptap/extension-paragraph": "^3.33.1",
58
+ "@tiptap/extension-text": "^3.33.1",
59
+ "@tiptap/extension-underline": "^3.33.1",
60
+ "@tiptap/extensions": "^3.33.1",
61
+ "@tiptap/pm": "^3.33.1",
62
+ "@tiptap/vue-3": "^3.33.1",
63
+ "clsx": "^2.1.1",
64
+ "reka-ui": "^2.11.0",
65
+ "tailwind-merge": "^3.7.0"
66
+ },
34
67
  "devDependencies": {
35
- "@lucide/vue": "^1.61.0",
36
- "@tailwindcss/vite": "^4.3.3",
37
- "@types/node": "^24.13.3",
68
+ "@changesets/cli": "^3.0.3",
69
+ "@storybook/addon-a11y": "^10.6.5",
70
+ "@storybook/addon-docs": "^10.6.5",
71
+ "@storybook/builder-vite": "^10.6.5",
72
+ "@storybook/vue3-vite": "^10.6.5",
73
+ "@tailwindcss/vite": "^4.3.4",
74
+ "@types/node": "^26.6.6",
38
75
  "@vitejs/plugin-vue": "^6.0.10",
39
76
  "@vue/tsconfig": "^0.9.1",
40
- "clsx": "^2.1.1",
41
- "reka-ui": "^2.11.0",
42
- "tailwind-merge": "^3.7.0",
43
- "tailwindcss": "^4.3.3",
44
- "typescript": "~6.0.2",
45
- "vite": "^7.0.0",
46
- "vite-plugin-css-injected-by-js": "4.0.1",
77
+ "remark-gfm": "^4.0.1",
78
+ "storybook": "^10.6.5",
79
+ "tailwindcss": "^4.3.4",
80
+ "typescript": "^6.0.3",
81
+ "vite": "^8.3.5",
47
82
  "vite-plugin-dts": "^5.1.2",
48
- "vue": "^3.5.42",
49
- "vue-tsc": "^3.3.13"
50
- },
51
- "publishConfig": {
52
- "access": "public",
53
- "registry": "https://registry.npmjs.org/"
83
+ "vitepress": "1.6.4",
84
+ "vitest": "^5.1.0",
85
+ "vue": "^3.5.44",
86
+ "vue-tsc": "^3.3.14"
54
87
  }
55
88
  }
File without changes
@@ -0,0 +1,24 @@
1
+ import type { Meta, StoryObj } from "@storybook/vue3-vite";
2
+ import Age from "./Age.vue";
3
+
4
+ const meta = {
5
+ title: "Components/Data/Age",
6
+ component: Age,
7
+ tags: ["autodocs"],
8
+ args: { birthDate: "2013-03-14", suffix: "years" },
9
+ decorators: [() => ({ template: '<div class="p-12 text-sm"><story /></div>' })],
10
+ } satisfies Meta<typeof Age>;
11
+
12
+ export default meta;
13
+ type Story = StoryObj<typeof meta>;
14
+
15
+ /** Hover or tab to it: "Born 14 March 2013". */
16
+ export const Default: Story = {};
17
+
18
+ /** Within a week of their birthday, the tooltip says so. */
19
+ export const BirthdaySoon: Story = {
20
+ args: { birthDate: "2013-11-14", now: new Date(2026, 10, 11) },
21
+ };
22
+
23
+ /** Just the number, e.g. in an "Age" column. */
24
+ export const NumberOnly: Story = { args: { suffix: undefined } };
@@ -0,0 +1,56 @@
1
+ <script setup lang="ts">
2
+ import { computed, type HTMLAttributes } from 'vue'
3
+ import { cn } from '../../lib/cn'
4
+ import { age, daysToBirthday, formatDate, toDate, type DateInput } from '../../lib/dates'
5
+ import { useNow } from '../../lib/useNow'
6
+ import Tooltip from '../Tooltip/Tooltip.vue'
7
+
8
+ /**
9
+ * Someone's age, "13", with their date of birth in a tooltip on hover or
10
+ * focus: "Born 14 March 2013", plus "Birthday today" or "Birthday in 3 days"
11
+ * when it's within a week (handy for teachers).
12
+ */
13
+ export interface AgeProps {
14
+ /** Date of birth: a Date, an ISO string ("2013-03-14"), or a timestamp. */
15
+ birthDate: DateInput
16
+ /** Text after the number: "years" gives "13 years". Leave out for just "13" (e.g. in an "Age" column). */
17
+ suffix?: string
18
+ /** What "today" is, e.g. for tests. Default the live date. */
19
+ now?: Date
20
+ class?: HTMLAttributes['class']
21
+ }
22
+
23
+ const props = defineProps<AgeProps>()
24
+
25
+ const liveNow = useNow()
26
+ const born = computed(() => toDate(props.birthDate))
27
+ const today = computed(() => props.now ?? liveNow.value)
28
+ const years = computed(() => age(born.value, today.value))
29
+ const tooltip = computed(() => {
30
+ const days = daysToBirthday(born.value, today.value)
31
+ const soon = days === 0 ? ' · Birthday today' : days === 1 ? ' · Birthday tomorrow' : days <= 7 ? ` · Birthday in ${days} days` : ''
32
+ return `Born ${formatDate(born.value)}${soon}`
33
+ })
34
+ const iso = computed(() => {
35
+ const d = born.value
36
+ return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`
37
+ })
38
+ </script>
39
+
40
+ <template>
41
+ <Tooltip :text="tooltip">
42
+ <span
43
+ tabindex="0"
44
+ :data-birth-date="iso"
45
+ :class="
46
+ cn(
47
+ 'cursor-default rounded-sm tabular-nums underline decoration-current/40 decoration-dotted underline-offset-2',
48
+ 'outline-2 outline-offset-1 outline-transparent focus-visible:outline-focus forced-colors:not-focus-visible:outline-0',
49
+ props.class
50
+ )
51
+ "
52
+ >
53
+ {{ years }}<template v-if="suffix">&nbsp;{{ suffix }}</template>
54
+ </span>
55
+ </Tooltip>
56
+ </template>
@@ -0,0 +1,124 @@
1
+ import type { Meta, StoryObj } from "@storybook/vue3-vite";
2
+ import { Bell, Building2, CalendarCog, CalendarDays, GraduationCap, House, Layers, MessageSquare, Settings, Users } from "@lucide/vue";
3
+ import { computed, ref } from "vue";
4
+ import Breadcrumb from "../Breadcrumb/Breadcrumb.vue";
5
+ import Button from "../Button/Button.vue";
6
+ import { sidebarTrail } from "../Sidebar/sidebar";
7
+ import type { SidebarItem } from "../Sidebar/Sidebar.vue";
8
+ import AppShell from "./AppShell.vue";
9
+
10
+ const pages: SidebarItem[] = [
11
+ { label: "Home", icon: House },
12
+ { label: "Students", icon: Users },
13
+ { label: "Timetable", icon: CalendarDays },
14
+ { label: "Messages", icon: MessageSquare, badge: 3 },
15
+ { label: "Settings", icon: Settings },
16
+ ];
17
+
18
+ const meta = {
19
+ title: "Components/Layout/AppShell",
20
+ component: AppShell,
21
+ tags: ["autodocs"],
22
+ parameters: { layout: "fullscreen" },
23
+ args: {
24
+ title: "Keston Admissions",
25
+ collapsible: true,
26
+ user: { name: "Ben Smith", email: "ben.smith@keston.school", organisation: "The Keston School" },
27
+ },
28
+ render: (args) => ({
29
+ components: { AppShell, Button, Bell },
30
+ setup() {
31
+ const current = ref("Home");
32
+ const items = computed<SidebarItem[]>(() =>
33
+ pages.map((page) => ({
34
+ ...page,
35
+ active: page.label === current.value,
36
+ onSelect: () => (current.value = page.label),
37
+ })),
38
+ );
39
+ return { args, items, current };
40
+ },
41
+ template: `
42
+ <AppShell v-bind="args" :items="items" :ui="{ main: 'p-6' }">
43
+ <template #header-trailing>
44
+ <Button variant="ghost" square aria-label="Notifications"><Bell /></Button>
45
+ </template>
46
+ <h1 class="text-2xl font-bold">{{ current }}</h1>
47
+ <p v-for="n in 40" :key="n" class="mt-3 text-sm text-black/65">
48
+ Line {{ n }}. Scroll: the header stays at the top and the sidebar stays beside the page.
49
+ </p>
50
+ </AppShell>`,
51
+ }),
52
+ } satisfies Meta<typeof AppShell>;
53
+
54
+ export default meta;
55
+ type Story = StoryObj<typeof meta>;
56
+
57
+ /**
58
+ * Playground. Narrow the preview (or use the viewport menu) to see the
59
+ * sidebar move into the menu.
60
+ */
61
+ export const Default: Story = {};
62
+
63
+ /** Starts with the sidebar collapsed to icons. */
64
+ export const Collapsed: Story = {
65
+ args: { collapsed: true },
66
+ };
67
+
68
+ /** Opens on a phone-sized screen, where the sidebar is in the menu. */
69
+ export const Mobile: Story = {
70
+ globals: { viewport: { value: "mobile1", isRotated: false } },
71
+ };
72
+
73
+ /**
74
+ * A nested sidebar with a Breadcrumb above the page that follows it:
75
+ * School › School Structure › New School Year Setup. `sidebarTrail(items)`
76
+ * gives the path to the current page. "School" is a group, not a page, so
77
+ * it's plain text; "School Structure" also opens a level, so here it's text
78
+ * too.
79
+ */
80
+ export const WithBreadcrumb: Story = {
81
+ render: (args) => ({
82
+ components: { AppShell, Breadcrumb },
83
+ setup() {
84
+ const current = ref("New School Year Setup");
85
+ const page = (label: string, icon?: SidebarItem["icon"]): SidebarItem => ({
86
+ label,
87
+ icon,
88
+ active: label === current.value,
89
+ onSelect: () => (current.value = label),
90
+ });
91
+ const items = computed<SidebarItem[]>(() => [
92
+ page("Home", House),
93
+ page("Students", Users),
94
+ {
95
+ label: "School",
96
+ icon: Building2,
97
+ children: [
98
+ page("Overview", House),
99
+ {
100
+ label: "School Structure",
101
+ icon: Layers,
102
+ children: [
103
+ page("New School Year Setup", CalendarCog),
104
+ page("Year Groups", GraduationCap),
105
+ page("Houses", Users),
106
+ ],
107
+ },
108
+ page("Term Dates", CalendarDays),
109
+ ],
110
+ },
111
+ page("Messages", MessageSquare),
112
+ page("Settings", Settings),
113
+ ]);
114
+ const trail = computed(() => sidebarTrail(items.value));
115
+ return { args, items, trail, current };
116
+ },
117
+ template: `
118
+ <AppShell v-bind="args" :items="items" :ui="{ main: 'p-6' }">
119
+ <Breadcrumb :items="trail" />
120
+ <h1 class="mt-2 text-2xl font-bold">{{ current }}</h1>
121
+ <p class="mt-3 text-sm text-black/65">Choose pages in the sidebar: the breadcrumb follows.</p>
122
+ </AppShell>`,
123
+ }),
124
+ };
@@ -0,0 +1,221 @@
1
+ <script setup lang="ts">
2
+ import { onBeforeUnmount, onMounted, useId, type HTMLAttributes } from 'vue'
3
+ import { Menu } from '@lucide/vue'
4
+ import { TooltipProvider } from 'reka-ui'
5
+ import { cn } from '../../lib/cn'
6
+ import Button from '../Button/Button.vue'
7
+ import Header, { type HeaderProps, type HeaderUser, type HeaderUserAction } from '../Header/Header.vue'
8
+ import Sidebar, { type SidebarItem, type SidebarProps } from '../Sidebar/Sidebar.vue'
9
+ import Slideover from '../Slideover/Slideover.vue'
10
+
11
+ /**
12
+ * The layout of a whole app page: the Header across the top, the app's
13
+ * Sidebar down the left, and the page in the middle. Every app uses this, so
14
+ * the header looks and behaves the same everywhere; only the sidebar's items
15
+ * and the page change.
16
+ *
17
+ * - Wide screens (lg and up): the sidebar sits beside the page, and the
18
+ * header's menu button collapses it to icons and back (unless
19
+ * `collapsible` is false).
20
+ * - Narrow screens: the sidebar is hidden and the menu button opens it in a
21
+ * Slideover from the left, whose title bar is the header's height. Choosing
22
+ * an item, or the screen becoming wide, closes it.
23
+ * - The page itself scrolls (not an inner box), so the header stays at the
24
+ * top (sticky), the sidebar stays put below it, and mobile browsers can
25
+ * hide their address bar while scrolling.
26
+ *
27
+ * The account menu (top right) is the Header's: pass `user` and listen for
28
+ * account-settings, switch-account, log-out (and sign-in when signed out).
29
+ *
30
+ * Slots: default (the page), header-leading, header-middle, header-trailing,
31
+ * account, account-menu (passed to Header), sidebar-header and sidebar-footer (passed to Sidebar;
32
+ * sidebar-header is only shown on wide screens, as the Slideover has its own
33
+ * title).
34
+ */
35
+ export interface AppShellProps {
36
+ /** Name of the app, shown in the header and as the mobile menu's title. */
37
+ title?: string
38
+ /** The signed-in user, for the account menu. Without it, Sign in is shown. */
39
+ user?: HeaderUser
40
+ /** Which actions the account menu offers. Default all three. */
41
+ userActions?: HeaderUserAction[]
42
+ /** Show Sign in when there is no user. */
43
+ signIn?: boolean
44
+ /** Sidebar items in a single section. */
45
+ items?: SidebarItem[]
46
+ /** Sidebar items in labelled sections. */
47
+ sections?: SidebarProps['sections']
48
+ /** Wide screens: show the header's menu button, which collapses the sidebar to icons. */
49
+ collapsible?: boolean
50
+ /** Component used for sidebar items with `to`, e.g. RouterLink. */
51
+ linkComponent?: SidebarProps['linkComponent']
52
+ /** Other Header props, e.g. `{ ui: { title: '…' } }`. */
53
+ header?: Omit<HeaderProps, 'title' | 'menu' | 'menuOpen' | 'sticky' | 'user' | 'userActions' | 'signIn'>
54
+ /** Other Sidebar props, e.g. `{ label: 'Admissions' }`. */
55
+ sidebar?: Omit<SidebarProps, 'items' | 'sections' | 'collapsible' | 'linkComponent'>
56
+ class?: HTMLAttributes['class']
57
+ /** Extra classes for the parts. */
58
+ ui?: {
59
+ main?: HTMLAttributes['class']
60
+ }
61
+ }
62
+
63
+ const props = withDefaults(defineProps<AppShellProps>(), {
64
+ items: () => [],
65
+ sections: () => [],
66
+ userActions: undefined,
67
+ signIn: true,
68
+ collapsible: true
69
+ })
70
+
71
+ const emit = defineEmits<{
72
+ 'account-settings': []
73
+ 'switch-account': []
74
+ 'log-out': []
75
+ 'sign-in': []
76
+ }>()
77
+
78
+ defineSlots<{
79
+ default?(): unknown
80
+ 'header-leading'?(): unknown
81
+ 'header-middle'?(): unknown
82
+ 'header-trailing'?(): unknown
83
+ account?(): unknown
84
+ 'account-menu'?(props: { close: () => void }): unknown
85
+ 'sidebar-header'?(props: { collapsed: boolean }): unknown
86
+ 'sidebar-footer'?(props: { collapsed: boolean; mobile: boolean }): unknown
87
+ }>()
88
+
89
+ /** Sidebar collapsed to icons (wide screens). Use v-model:collapsed to keep it, e.g. in localStorage. */
90
+ const collapsed = defineModel<boolean>('collapsed', { default: false })
91
+
92
+ /** Mobile menu open. Optional: use v-model:menu-open to control it. */
93
+ const menuOpen = defineModel<boolean>('menuOpen', { default: false })
94
+
95
+ // Close the mobile menu once the inline sidebar is showing instead.
96
+ // Matches Tailwind's lg breakpoint, used in the template.
97
+ let wide: MediaQueryList | undefined
98
+ const onWide = () => {
99
+ if (wide?.matches) menuOpen.value = false
100
+ }
101
+ onMounted(() => {
102
+ wide = window.matchMedia('(min-width: 64rem)')
103
+ wide.addEventListener('change', onWide)
104
+ })
105
+ onBeforeUnmount(() => wide?.removeEventListener('change', onWide))
106
+
107
+ // "Skip to content" target. Unique, in case two shells are on one page (e.g. Storybook docs).
108
+ const uid = useId()
109
+ const mainId = `${uid}-main`
110
+ const sidebarId = `${uid}-sidebar`
111
+ </script>
112
+
113
+ <template>
114
+ <!-- One provider for every Tooltip in the app, so moving from one to the
115
+ next shows it without waiting again. -->
116
+ <TooltipProvider :delay-duration="400" :skip-delay-duration="300">
117
+ <div :class="cn('flex min-h-dvh flex-col bg-background text-black', props.class)">
118
+ <!-- First thing keyboard users reach: jumps past the header and sidebar. -->
119
+ <a
120
+ :href="`#${mainId}`"
121
+ class="sr-only z-50 rounded bg-white px-4 py-2 text-sm focus:not-sr-only focus:fixed focus:top-2 focus:left-2 focus:outline-2 focus:outline-focus"
122
+ >
123
+ Skip to content
124
+ </a>
125
+
126
+ <Header
127
+ v-bind="header"
128
+ :title="title"
129
+ menu
130
+ sticky
131
+ :menu-open="menuOpen"
132
+ :user="user"
133
+ :user-actions="userActions"
134
+ :sign-in="signIn"
135
+ :ui="{ ...header?.ui, menu: cn('lg:hidden', header?.ui?.menu) }"
136
+ @menu="menuOpen = true"
137
+ @account-settings="emit('account-settings')"
138
+ @switch-account="emit('switch-account')"
139
+ @log-out="emit('log-out')"
140
+ @sign-in="emit('sign-in')"
141
+ >
142
+ <template #leading>
143
+ <!-- Wide screens: in place of the menu button (same look and spot),
144
+ collapses the sidebar beside the page to icons and back. -->
145
+ <Button
146
+ v-if="collapsible"
147
+ variant="ghost"
148
+ square
149
+ :aria-label="collapsed ? 'Expand sidebar' : 'Collapse sidebar'"
150
+ :aria-expanded="!collapsed"
151
+ :aria-controls="sidebarId"
152
+ class="-ml-2.5 max-lg:hidden"
153
+ @click="collapsed = !collapsed"
154
+ >
155
+ <Menu />
156
+ </Button>
157
+ <slot name="header-leading" />
158
+ </template>
159
+ <slot name="header-middle" />
160
+ <template v-if="$slots['header-trailing']" #trailing><slot name="header-trailing" /></template>
161
+ <template v-if="$slots.account" #account><slot name="account" /></template>
162
+ <template v-if="$slots['account-menu']" #account-menu="slotProps"><slot name="account-menu" v-bind="slotProps" /></template>
163
+ </Header>
164
+
165
+ <div class="flex flex-1">
166
+ <!-- Wide screens: beside the page, held below the header while the page scrolls. -->
167
+ <div class="sticky top-12 hidden h-[calc(100dvh-var(--spacing)*12)] shrink-0 self-start lg:flex">
168
+ <Sidebar
169
+ v-bind="sidebar"
170
+ :id="sidebarId"
171
+ v-model:collapsed="collapsed"
172
+ :items="items"
173
+ :sections="sections"
174
+ :link-component="linkComponent"
175
+ >
176
+ <template v-if="$slots['sidebar-header']" #header="slotProps"><slot name="sidebar-header" v-bind="slotProps" /></template>
177
+ <template v-if="$slots['sidebar-footer']" #footer="slotProps">
178
+ <slot name="sidebar-footer" v-bind="slotProps" :mobile="false" />
179
+ </template>
180
+ </Sidebar>
181
+ </div>
182
+
183
+ <!-- Narrow screens: in a Slideover opened by the header's menu button. -->
184
+ <Slideover
185
+ v-model:open="menuOpen"
186
+ side="left"
187
+ :title="title || 'Menu'"
188
+ :ui="{
189
+ content: 'max-w-72',
190
+ // The header is a column (it also holds a Progress for steps), so
191
+ // justify-center centres the title row vertically in the 48px bar,
192
+ // and the row keeps the full width: title left, × right. 20px in,
193
+ // so the title lines up with the menu items' icons below it.
194
+ header: 'h-12 justify-center px-5 py-0',
195
+ title: 'text-base font-bold',
196
+ body: 'flex p-0'
197
+ }"
198
+ >
199
+ <template #body>
200
+ <Sidebar
201
+ v-bind="sidebar"
202
+ :items="items"
203
+ :sections="sections"
204
+ :link-component="linkComponent"
205
+ class="h-auto min-h-full w-full border-r-0"
206
+ @select="menuOpen = false"
207
+ >
208
+ <template v-if="$slots['sidebar-footer']" #footer="slotProps">
209
+ <slot name="sidebar-footer" v-bind="slotProps" :mobile="true" />
210
+ </template>
211
+ </Sidebar>
212
+ </template>
213
+ </Slideover>
214
+
215
+ <main :id="mainId" tabindex="-1" :class="cn('min-w-0 flex-1 outline-none', ui?.main)">
216
+ <slot />
217
+ </main>
218
+ </div>
219
+ </div>
220
+ </TooltipProvider>
221
+ </template>