@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.
- package/README.md +90 -32
- package/dist/components/Age/Age.vue.d.ts +19 -0
- package/dist/components/AppShell/AppShell.vue.d.ts +108 -0
- package/dist/components/Avatar/Avatar.vue.d.ts +34 -0
- package/dist/components/AvatarGroup/AvatarGroup.vue.d.ts +25 -0
- package/dist/components/Badge/Badge.vue.d.ts +41 -0
- package/dist/components/Breadcrumb/Breadcrumb.vue.d.ts +39 -0
- package/dist/components/Button/Button.vue.d.ts +69 -0
- package/dist/components/Calendar/Calendar.vue.d.ts +34 -0
- package/dist/components/Card/Card.vue.d.ts +56 -0
- package/dist/components/Checkbox/Checkbox.vue.d.ts +40 -0
- package/dist/components/Checklist/Checklist.vue.d.ts +18 -0
- package/dist/components/Chip/Chip.vue.d.ts +44 -0
- package/dist/components/Divider/Divider.vue.d.ts +36 -0
- package/dist/components/{ToastItem.vue.d.ts → FormField/FieldMessage.vue.d.ts} +10 -2
- package/dist/components/FormField/FormField.vue.d.ts +61 -0
- package/dist/components/Header/Header.vue.d.ts +104 -0
- package/dist/components/InfoTip/InfoTip.vue.d.ts +20 -0
- package/dist/components/Input/Input.vue.d.ts +56 -0
- package/dist/components/InputCode/InputCode.vue.d.ts +53 -0
- package/dist/components/InputDate/InputDate.vue.d.ts +49 -0
- package/dist/components/InputNumber/InputNumber.vue.d.ts +44 -0
- package/dist/components/InputPassword/InputPassword.vue.d.ts +51 -0
- package/dist/components/InputRichText/InputRichText.vue.d.ts +44 -0
- package/dist/components/Link/Link.vue.d.ts +39 -0
- package/dist/components/Notification/Notification.vue.d.ts +62 -0
- package/dist/components/Notification/NotificationPane.vue.d.ts +38 -0
- package/dist/components/Notification/Toaster.vue.d.ts +51 -0
- package/dist/components/Notification/notification.samples.d.ts +3 -0
- package/dist/components/Notification/notifications.d.ts +115 -0
- package/dist/components/PageHeader/PageHeader.vue.d.ts +43 -0
- package/dist/components/Popover/Popover.vue.d.ts +83 -0
- package/dist/components/Popover/popover.d.ts +16 -0
- package/dist/components/Progress/Progress.vue.d.ts +26 -0
- package/dist/components/RadioGroup/RadioGroup.vue.d.ts +45 -0
- package/dist/components/RelativeTime/RelativeTime.vue.d.ts +22 -0
- package/dist/components/Select/Select.vue.d.ts +110 -0
- package/dist/components/Sidebar/Sidebar.vue.d.ts +106 -0
- package/dist/components/Sidebar/sidebar.d.ts +10 -0
- package/dist/components/Slideover/Slideover.vue.d.ts +125 -0
- package/dist/components/Spinner/Spinner.vue.d.ts +30 -0
- package/dist/components/StatTile/StatTile.vue.d.ts +46 -0
- package/dist/components/SummaryList/SummaryList.vue.d.ts +62 -0
- package/dist/components/Switch/Switch.vue.d.ts +39 -0
- package/dist/components/Table/Table.vue.d.ts +82 -0
- package/dist/components/Table/table.d.ts +36 -0
- package/dist/components/Tooltip/Tooltip.vue.d.ts +46 -0
- package/dist/index.d.ts +89 -25
- package/dist/keston-ui.js +4963 -14785
- package/dist/lib/cn.d.ts +4 -0
- package/dist/lib/dates.d.ts +27 -0
- package/dist/lib/initials.d.ts +2 -0
- package/dist/lib/parseDate.d.ts +44 -0
- package/dist/lib/useNow.d.ts +3 -0
- package/package.json +53 -24
- package/src/components/.gitkeep +0 -0
- package/src/components/Age/Age.stories.ts +24 -0
- package/src/components/Age/Age.vue +56 -0
- package/src/components/AppShell/AppShell.stories.ts +124 -0
- package/src/components/AppShell/AppShell.vue +212 -0
- package/src/components/Avatar/Avatar.stories.ts +56 -0
- package/src/components/Avatar/Avatar.vue +118 -0
- package/src/components/AvatarGroup/AvatarGroup.stories.ts +47 -0
- package/src/components/AvatarGroup/AvatarGroup.vue +97 -0
- package/src/components/Badge/Badge.stories.ts +92 -0
- package/src/components/Badge/Badge.vue +67 -0
- package/src/components/Breadcrumb/Breadcrumb.stories.ts +58 -0
- package/src/components/Breadcrumb/Breadcrumb.vue +109 -0
- package/src/components/Button/Button.mdx +79 -0
- package/src/components/Button/Button.stories.ts +207 -0
- package/src/components/Button/Button.vue +266 -0
- package/src/components/Calendar/Calendar.stories.ts +51 -0
- package/src/components/Calendar/Calendar.vue +364 -0
- package/src/components/Card/Card.stories.ts +109 -0
- package/src/components/Card/Card.vue +115 -0
- package/src/components/Checkbox/Checkbox.stories.ts +102 -0
- package/src/components/Checkbox/Checkbox.vue +102 -0
- package/src/components/Checklist/Checklist.stories.ts +67 -0
- package/src/components/Checklist/Checklist.vue +38 -0
- package/src/components/Chip/Chip.stories.ts +71 -0
- package/src/components/Chip/Chip.vue +86 -0
- package/src/components/Divider/Divider.stories.ts +57 -0
- package/src/components/Divider/Divider.vue +58 -0
- package/src/components/FormField/FieldMessage.vue +81 -0
- package/src/components/FormField/FormField.stories.ts +55 -0
- package/src/components/FormField/FormField.vue +160 -0
- package/src/components/Header/Header.stories.ts +168 -0
- package/src/components/Header/Header.vue +232 -0
- package/src/components/InfoTip/InfoTip.stories.ts +63 -0
- package/src/components/InfoTip/InfoTip.vue +50 -0
- package/src/components/Input/Input.stories.ts +206 -0
- package/src/components/Input/Input.vue +90 -0
- package/src/components/InputCode/InputCode.stories.ts +85 -0
- package/src/components/InputCode/InputCode.vue +145 -0
- package/src/components/InputDate/InputDate.stories.ts +58 -0
- package/src/components/InputDate/InputDate.vue +258 -0
- package/src/components/InputNumber/InputNumber.stories.ts +63 -0
- package/src/components/InputNumber/InputNumber.vue +109 -0
- package/src/components/InputPassword/InputPassword.stories.ts +105 -0
- package/src/components/InputPassword/InputPassword.vue +132 -0
- package/src/components/InputRichText/InputRichText.stories.ts +100 -0
- package/src/components/InputRichText/InputRichText.vue +194 -0
- package/src/components/Link/Link.stories.ts +73 -0
- package/src/components/Link/Link.vue +56 -0
- package/src/components/Notification/Notification.stories.ts +196 -0
- package/src/components/Notification/Notification.vue +136 -0
- package/src/components/Notification/NotificationPane.vue +187 -0
- package/src/components/Notification/Toaster.vue +446 -0
- package/src/components/Notification/notification.samples.ts +45 -0
- package/src/components/Notification/notifications.test.ts +99 -0
- package/src/components/Notification/notifications.ts +172 -0
- package/src/components/PageHeader/PageHeader.stories.ts +79 -0
- package/src/components/PageHeader/PageHeader.vue +66 -0
- package/src/components/Popover/Popover.stories.ts +135 -0
- package/src/components/Popover/Popover.vue +192 -0
- package/src/components/Popover/popover.ts +20 -0
- package/src/components/Progress/Progress.stories.ts +74 -0
- package/src/components/Progress/Progress.vue +75 -0
- package/src/components/RadioGroup/RadioGroup.stories.ts +90 -0
- package/src/components/RadioGroup/RadioGroup.vue +132 -0
- package/src/components/RelativeTime/RelativeTime.stories.ts +74 -0
- package/src/components/RelativeTime/RelativeTime.vue +51 -0
- package/src/components/Select/Select.mdx +202 -0
- package/src/components/Select/Select.stories.ts +223 -0
- package/src/components/Select/Select.vue +630 -0
- package/src/components/Sidebar/Sidebar.stories.ts +192 -0
- package/src/components/Sidebar/Sidebar.vue +382 -0
- package/src/components/Sidebar/sidebar.ts +20 -0
- package/src/components/Slideover/Slideover.stories.ts +225 -0
- package/src/components/Slideover/Slideover.vue +365 -0
- package/src/components/Spinner/Spinner.stories.ts +79 -0
- package/src/components/Spinner/Spinner.vue +97 -0
- package/src/components/StatTile/StatTile.stories.ts +75 -0
- package/src/components/StatTile/StatTile.vue +89 -0
- package/src/components/SummaryList/SummaryList.stories.ts +103 -0
- package/src/components/SummaryList/SummaryList.vue +127 -0
- package/src/components/Switch/Switch.stories.ts +100 -0
- package/src/components/Switch/Switch.vue +96 -0
- package/src/components/Table/Table.stories.ts +206 -0
- package/src/components/Table/Table.vue +220 -0
- package/src/components/Table/table.test.ts +65 -0
- package/src/components/Table/table.ts +70 -0
- package/src/components/Tooltip/Tooltip.stories.ts +57 -0
- package/src/components/Tooltip/Tooltip.vue +86 -0
- package/src/examples/AppPages.stories.ts +500 -0
- package/src/examples/FormLayout.stories.ts +185 -0
- package/src/examples/KestonIdPages.stories.ts +415 -0
- package/src/examples/SchoolPages.stories.ts +665 -0
- package/src/index.ts +114 -36
- package/src/lib/cn.ts +4 -0
- package/src/lib/dates.test.ts +68 -0
- package/src/lib/dates.ts +86 -0
- package/src/lib/initials.ts +8 -0
- package/src/lib/parseDate.test.ts +331 -0
- package/src/lib/parseDate.ts +561 -0
- package/src/lib/useNow.ts +20 -0
- package/src/styles/theme.css +101 -0
- package/dist/components/AppLauncher.vue.d.ts +0 -10
- package/dist/components/Avatar.vue.d.ts +0 -16
- package/dist/components/Button.vue.d.ts +0 -27
- package/dist/components/Checkbox.vue.d.ts +0 -18
- package/dist/components/CloseButton.vue.d.ts +0 -6
- package/dist/components/Dialog.vue.d.ts +0 -23
- package/dist/components/Drawer.vue.d.ts +0 -34
- package/dist/components/DropdownMenu.vue.d.ts +0 -21
- package/dist/components/DropdownMenuItem.vue.d.ts +0 -19
- package/dist/components/DropdownMenuSeparator.vue.d.ts +0 -6
- package/dist/components/Input.vue.d.ts +0 -14
- package/dist/components/Label.vue.d.ts +0 -16
- package/dist/components/NotificationsMenu.vue.d.ts +0 -3
- package/dist/components/Popover.vue.d.ts +0 -23
- package/dist/components/ProfileSwitcher.vue.d.ts +0 -24
- package/dist/components/Select.vue.d.ts +0 -28
- package/dist/components/Separator.vue.d.ts +0 -11
- package/dist/components/ToastRenderer.vue.d.ts +0 -3
- package/dist/components/Toaster.vue.d.ts +0 -3
- package/dist/components/Tooltip.vue.d.ts +0 -23
- package/dist/components/TopBar.vue.d.ts +0 -34
- package/dist/favicon-old.svg +0 -1
- package/dist/favicon.svg +0 -1
- package/dist/keston-ui.cjs +0 -15
- package/dist/lib/toast.d.ts +0 -29
- package/dist/lib/types.d.ts +0 -5
- package/src/components/AppLauncher.vue +0 -63
- package/src/components/Avatar.vue +0 -51
- package/src/components/Button.vue +0 -54
- package/src/components/Checkbox.vue +0 -47
- package/src/components/CloseButton.vue +0 -24
- package/src/components/Dialog.vue +0 -65
- package/src/components/Drawer.vue +0 -202
- package/src/components/DropdownMenu.vue +0 -41
- package/src/components/DropdownMenuItem.vue +0 -28
- package/src/components/DropdownMenuSeparator.vue +0 -12
- package/src/components/Input.vue +0 -21
- package/src/components/Label.vue +0 -15
- package/src/components/NotificationsMenu.vue +0 -115
- package/src/components/Popover.vue +0 -46
- package/src/components/ProfileSwitcher.vue +0 -113
- package/src/components/Select.vue +0 -97
- package/src/components/Separator.vue +0 -30
- package/src/components/ToastItem.vue +0 -158
- package/src/components/ToastRenderer.vue +0 -113
- package/src/components/Toaster.vue +0 -11
- package/src/components/Tooltip.vue +0 -48
- package/src/components/TopBar.vue +0 -52
- package/src/lib/toast.ts +0 -95
- package/src/lib/types.ts +0 -5
package/dist/lib/cn.d.ts
CHANGED
|
@@ -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,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;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thekestongroup/ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.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,77 @@
|
|
|
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
|
-
|
|
23
|
-
|
|
23
|
+
"import": "./dist/keston-ui.js"
|
|
24
|
+
},
|
|
25
|
+
"./theme.css": "./src/styles/theme.css"
|
|
24
26
|
},
|
|
25
27
|
"scripts": {
|
|
26
|
-
"dev": "
|
|
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
|
-
"
|
|
31
|
+
"build-storybook": "storybook build",
|
|
32
|
+
"new": "node scripts/new-component.mjs",
|
|
33
|
+
"changeset": "changeset",
|
|
34
|
+
"test": "vitest run",
|
|
35
|
+
"test:watch": "vitest"
|
|
30
36
|
},
|
|
31
37
|
"peerDependencies": {
|
|
32
38
|
"vue": "^3.5.0"
|
|
33
39
|
},
|
|
40
|
+
"packageManager": "pnpm@11.6.0",
|
|
41
|
+
"publishConfig": {
|
|
42
|
+
"access": "public",
|
|
43
|
+
"registry": "https://registry.npmjs.org/"
|
|
44
|
+
},
|
|
45
|
+
"dependencies": {
|
|
46
|
+
"@fontsource/lato": "^5.3.0",
|
|
47
|
+
"@internationalized/date": "^3.12.4",
|
|
48
|
+
"@lucide/vue": "^1.68.0",
|
|
49
|
+
"@tiptap/core": "^3.33.1",
|
|
50
|
+
"@tiptap/extension-bold": "^3.33.1",
|
|
51
|
+
"@tiptap/extension-document": "^3.33.1",
|
|
52
|
+
"@tiptap/extension-hard-break": "^3.33.1",
|
|
53
|
+
"@tiptap/extension-italic": "^3.33.1",
|
|
54
|
+
"@tiptap/extension-paragraph": "^3.33.1",
|
|
55
|
+
"@tiptap/extension-text": "^3.33.1",
|
|
56
|
+
"@tiptap/extension-underline": "^3.33.1",
|
|
57
|
+
"@tiptap/extensions": "^3.33.1",
|
|
58
|
+
"@tiptap/pm": "^3.33.1",
|
|
59
|
+
"@tiptap/vue-3": "^3.33.1",
|
|
60
|
+
"clsx": "^2.1.1",
|
|
61
|
+
"reka-ui": "^2.11.0",
|
|
62
|
+
"tailwind-merge": "^3.7.0"
|
|
63
|
+
},
|
|
34
64
|
"devDependencies": {
|
|
35
|
-
"@
|
|
36
|
-
"@
|
|
37
|
-
"@
|
|
65
|
+
"@changesets/cli": "^3.0.3",
|
|
66
|
+
"@storybook/addon-a11y": "^10.6.5",
|
|
67
|
+
"@storybook/addon-docs": "^10.6.5",
|
|
68
|
+
"@storybook/builder-vite": "^10.6.5",
|
|
69
|
+
"@storybook/vue3-vite": "^10.6.5",
|
|
70
|
+
"@tailwindcss/vite": "^4.3.4",
|
|
71
|
+
"@types/node": "^26.6.6",
|
|
38
72
|
"@vitejs/plugin-vue": "^6.0.10",
|
|
39
73
|
"@vue/tsconfig": "^0.9.1",
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"vite": "^7.0.0",
|
|
46
|
-
"vite-plugin-css-injected-by-js": "4.0.1",
|
|
74
|
+
"remark-gfm": "^4.0.1",
|
|
75
|
+
"storybook": "^10.6.5",
|
|
76
|
+
"tailwindcss": "^4.3.4",
|
|
77
|
+
"typescript": "^6.0.3",
|
|
78
|
+
"vite": "^8.3.5",
|
|
47
79
|
"vite-plugin-dts": "^5.1.2",
|
|
48
|
-
"
|
|
49
|
-
"vue
|
|
50
|
-
|
|
51
|
-
"publishConfig": {
|
|
52
|
-
"access": "public",
|
|
53
|
-
"registry": "https://registry.npmjs.org/"
|
|
80
|
+
"vitest": "^5.1.0",
|
|
81
|
+
"vue": "^3.5.44",
|
|
82
|
+
"vue-tsc": "^3.3.14"
|
|
54
83
|
}
|
|
55
84
|
}
|
|
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"> {{ 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,212 @@
|
|
|
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="{ content: 'max-w-72', header: 'h-12 items-center px-4 py-0', title: 'text-base font-bold', body: 'flex p-0' }"
|
|
189
|
+
>
|
|
190
|
+
<template #body>
|
|
191
|
+
<Sidebar
|
|
192
|
+
v-bind="sidebar"
|
|
193
|
+
:items="items"
|
|
194
|
+
:sections="sections"
|
|
195
|
+
:link-component="linkComponent"
|
|
196
|
+
class="h-auto min-h-full w-full border-r-0"
|
|
197
|
+
@select="menuOpen = false"
|
|
198
|
+
>
|
|
199
|
+
<template v-if="$slots['sidebar-footer']" #footer="slotProps">
|
|
200
|
+
<slot name="sidebar-footer" v-bind="slotProps" :mobile="true" />
|
|
201
|
+
</template>
|
|
202
|
+
</Sidebar>
|
|
203
|
+
</template>
|
|
204
|
+
</Slideover>
|
|
205
|
+
|
|
206
|
+
<main :id="mainId" tabindex="-1" :class="cn('min-w-0 flex-1 outline-none', ui?.main)">
|
|
207
|
+
<slot />
|
|
208
|
+
</main>
|
|
209
|
+
</div>
|
|
210
|
+
</div>
|
|
211
|
+
</TooltipProvider>
|
|
212
|
+
</template>
|