@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.
- package/README.md +98 -31
- 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/EmptyState/EmptyState.vue.d.ts +55 -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 +91 -25
- package/dist/keston-ui.js +5030 -14786
- 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 +57 -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 +221 -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/EmptyState/EmptyState.stories.ts +99 -0
- package/src/components/EmptyState/EmptyState.vue +87 -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 +186 -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 +212 -0
- package/src/components/Table/Table.vue +223 -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 +116 -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
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from "@storybook/vue3-vite";
|
|
2
|
+
import { getLocalTimeZone, today } from "@internationalized/date";
|
|
3
|
+
import { AtSign, IdCard } from "@lucide/vue";
|
|
4
|
+
import { computed, nextTick, reactive, ref } from "vue";
|
|
5
|
+
import Button, { type ButtonStatus } from "../components/Button/Button.vue";
|
|
6
|
+
import InputDate from "../components/InputDate/InputDate.vue";
|
|
7
|
+
import Input from "../components/Input/Input.vue";
|
|
8
|
+
import InputNumber from "../components/InputNumber/InputNumber.vue";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* A full form built from the library, to see how fields grow and shrink as
|
|
12
|
+
* errors appear and clear. Not part of the library itself.
|
|
13
|
+
*
|
|
14
|
+
* - Each field is checked when you leave it, then again as you type once it
|
|
15
|
+
* shows an error (so the error clears as soon as it's fixed).
|
|
16
|
+
* - "Create student" checks every field at once, shows all errors and moves
|
|
17
|
+
* focus to the first one. When everything is valid it loads, then succeeds.
|
|
18
|
+
*/
|
|
19
|
+
const meta = {
|
|
20
|
+
title: "Examples/Form layout",
|
|
21
|
+
parameters: { layout: "padded" },
|
|
22
|
+
} satisfies Meta;
|
|
23
|
+
|
|
24
|
+
export default meta;
|
|
25
|
+
type Story = StoryObj<typeof meta>;
|
|
26
|
+
|
|
27
|
+
type FieldName = "firstName" | "lastName" | "email" | "dateOfBirth" | "yearGroup" | "studentId";
|
|
28
|
+
|
|
29
|
+
export const AddStudent: Story = {
|
|
30
|
+
render: () => ({
|
|
31
|
+
components: { Button, InputDate, Input, InputNumber, AtSign, IdCard },
|
|
32
|
+
setup() {
|
|
33
|
+
const form = reactive({
|
|
34
|
+
firstName: "",
|
|
35
|
+
lastName: "",
|
|
36
|
+
email: "",
|
|
37
|
+
dateOfBirth: undefined as string | undefined,
|
|
38
|
+
yearGroup: undefined as number | undefined,
|
|
39
|
+
studentId: "",
|
|
40
|
+
});
|
|
41
|
+
const errors = reactive<Partial<Record<FieldName, string>>>({});
|
|
42
|
+
const status = ref<ButtonStatus>("idle");
|
|
43
|
+
const formEl = ref<HTMLFormElement>();
|
|
44
|
+
const todayIso = today(getLocalTimeZone()).toString();
|
|
45
|
+
|
|
46
|
+
// Stand-ins for a schema (e.g. Zod): a message, or undefined when valid.
|
|
47
|
+
const rules: Record<FieldName, () => string | undefined> = {
|
|
48
|
+
firstName: () => (form.firstName.trim() ? undefined : "Enter a first name"),
|
|
49
|
+
lastName: () => (form.lastName.trim() ? undefined : "Enter a last name"),
|
|
50
|
+
email: () =>
|
|
51
|
+
!form.email.trim()
|
|
52
|
+
? "Enter an email address"
|
|
53
|
+
: /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(form.email)
|
|
54
|
+
? undefined
|
|
55
|
+
: "Enter a valid email address, like name@school.org",
|
|
56
|
+
dateOfBirth: () => (form.dateOfBirth ? undefined : "Enter a date of birth"),
|
|
57
|
+
yearGroup: () =>
|
|
58
|
+
form.yearGroup === undefined
|
|
59
|
+
? "Choose a year group"
|
|
60
|
+
: form.yearGroup < 7 || form.yearGroup > 13
|
|
61
|
+
? "Year group must be from 7 to 13"
|
|
62
|
+
: undefined,
|
|
63
|
+
studentId: () =>
|
|
64
|
+
!form.studentId || /^KS-\d{5}$/i.test(form.studentId)
|
|
65
|
+
? undefined
|
|
66
|
+
: "Student IDs look like KS-20491",
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const check = (field: FieldName) => {
|
|
70
|
+
errors[field] = rules[field]();
|
|
71
|
+
};
|
|
72
|
+
// After an error shows, re-check while typing so it clears when fixed.
|
|
73
|
+
const recheck = (field: FieldName) => {
|
|
74
|
+
if (errors[field]) check(field);
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const errorCount = computed(() => Object.values(errors).filter(Boolean).length);
|
|
78
|
+
|
|
79
|
+
async function submit() {
|
|
80
|
+
(Object.keys(rules) as FieldName[]).forEach(check);
|
|
81
|
+
if (errorCount.value) {
|
|
82
|
+
status.value = "error";
|
|
83
|
+
await nextTick();
|
|
84
|
+
formEl.value?.querySelector<HTMLElement>('[aria-invalid="true"]')?.focus();
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
status.value = "loading";
|
|
88
|
+
setTimeout(() => (status.value = "success"), 1000);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function reset() {
|
|
92
|
+
Object.assign(form, { firstName: "", lastName: "", email: "", dateOfBirth: undefined, yearGroup: undefined, studentId: "" });
|
|
93
|
+
(Object.keys(errors) as FieldName[]).forEach((key) => delete errors[key]);
|
|
94
|
+
status.value = "idle";
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return { form, errors, errorCount, status, formEl, todayIso, check, recheck, submit, reset };
|
|
98
|
+
},
|
|
99
|
+
template: `
|
|
100
|
+
<form ref="formEl" novalidate class="flex max-w-md flex-col gap-5 text-black" @submit.prevent="submit">
|
|
101
|
+
<div>
|
|
102
|
+
<h2 class="text-lg">Add student</h2>
|
|
103
|
+
<p class="text-sm text-black/65">Fields check themselves when you leave them. Try "Create student" with the form empty.</p>
|
|
104
|
+
</div>
|
|
105
|
+
|
|
106
|
+
<div class="grid grid-cols-2 items-start gap-3">
|
|
107
|
+
<Input
|
|
108
|
+
v-model="form.firstName"
|
|
109
|
+
label="First name"
|
|
110
|
+
autocomplete="given-name"
|
|
111
|
+
:error-text="errors.firstName"
|
|
112
|
+
@blur="check('firstName')"
|
|
113
|
+
@input="recheck('firstName')"
|
|
114
|
+
/>
|
|
115
|
+
<Input
|
|
116
|
+
v-model="form.lastName"
|
|
117
|
+
label="Last name"
|
|
118
|
+
autocomplete="family-name"
|
|
119
|
+
:error-text="errors.lastName"
|
|
120
|
+
@blur="check('lastName')"
|
|
121
|
+
@input="recheck('lastName')"
|
|
122
|
+
/>
|
|
123
|
+
</div>
|
|
124
|
+
|
|
125
|
+
<Input
|
|
126
|
+
v-model="form.email"
|
|
127
|
+
label="Email"
|
|
128
|
+
type="email"
|
|
129
|
+
placeholder="name@school.org"
|
|
130
|
+
autocomplete="email"
|
|
131
|
+
:error-text="errors.email"
|
|
132
|
+
@blur="check('email')"
|
|
133
|
+
@input="recheck('email')"
|
|
134
|
+
>
|
|
135
|
+
<template #leading><AtSign /></template>
|
|
136
|
+
</Input>
|
|
137
|
+
|
|
138
|
+
<div class="grid grid-cols-2 items-start gap-3">
|
|
139
|
+
<InputDate
|
|
140
|
+
v-model="form.dateOfBirth"
|
|
141
|
+
label="Date of birth"
|
|
142
|
+
prefer="past"
|
|
143
|
+
:max="todayIso"
|
|
144
|
+
:error-text="errors.dateOfBirth"
|
|
145
|
+
@update:model-value="recheck('dateOfBirth')"
|
|
146
|
+
/>
|
|
147
|
+
<InputNumber
|
|
148
|
+
v-model="form.yearGroup"
|
|
149
|
+
label="Year group"
|
|
150
|
+
:min="7"
|
|
151
|
+
:max="13"
|
|
152
|
+
:error-text="errors.yearGroup"
|
|
153
|
+
@update:model-value="recheck('yearGroup')"
|
|
154
|
+
/>
|
|
155
|
+
</div>
|
|
156
|
+
|
|
157
|
+
<Input
|
|
158
|
+
v-model="form.studentId"
|
|
159
|
+
label="Student ID"
|
|
160
|
+
helper="Optional. Found on the enrolment letter, e.g. KS-20491."
|
|
161
|
+
helper-placement="icon"
|
|
162
|
+
placeholder="KS-00000"
|
|
163
|
+
:error-text="errors.studentId"
|
|
164
|
+
@blur="check('studentId')"
|
|
165
|
+
@input="recheck('studentId')"
|
|
166
|
+
>
|
|
167
|
+
<template #leading><IdCard /></template>
|
|
168
|
+
</Input>
|
|
169
|
+
|
|
170
|
+
<div class="flex justify-end gap-2 border-t border-black/15 pt-4">
|
|
171
|
+
<Button @click="reset">Reset</Button>
|
|
172
|
+
<Button
|
|
173
|
+
v-model:status="status"
|
|
174
|
+
type="submit"
|
|
175
|
+
variant="primary"
|
|
176
|
+
loading-text="Creating…"
|
|
177
|
+
success-text="Student created"
|
|
178
|
+
:error-text="errorCount === 1 ? '1 problem' : errorCount + ' problems'"
|
|
179
|
+
>
|
|
180
|
+
Create student
|
|
181
|
+
</Button>
|
|
182
|
+
</div>
|
|
183
|
+
</form>`,
|
|
184
|
+
}),
|
|
185
|
+
};
|
|
@@ -0,0 +1,415 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from "@storybook/vue3-vite";
|
|
2
|
+
import { ArrowLeftRight, BadgeCheck, BookOpen, Lock, Mail, RefreshCw, ShieldCheck, User } from "@lucide/vue";
|
|
3
|
+
import { computed, nextTick, reactive, ref } from "vue";
|
|
4
|
+
import Avatar from "../components/Avatar/Avatar.vue";
|
|
5
|
+
import Button, { type ButtonStatus } from "../components/Button/Button.vue";
|
|
6
|
+
import Card from "../components/Card/Card.vue";
|
|
7
|
+
import Checkbox from "../components/Checkbox/Checkbox.vue";
|
|
8
|
+
import Divider from "../components/Divider/Divider.vue";
|
|
9
|
+
import Input from "../components/Input/Input.vue";
|
|
10
|
+
import InputCode, { type InputCodeProps } from "../components/InputCode/InputCode.vue";
|
|
11
|
+
import InputPassword from "../components/InputPassword/InputPassword.vue";
|
|
12
|
+
import Link from "../components/Link/Link.vue";
|
|
13
|
+
import Popover from "../components/Popover/Popover.vue";
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Keston ID, the identity provider: signing in to an app (which then asks for
|
|
17
|
+
* consent), the two-step code, and the OAuth 2.0 consent prompt an app shows
|
|
18
|
+
* before it gets access to someone's account. Built only from library
|
|
19
|
+
* components; not part of the library itself.
|
|
20
|
+
*/
|
|
21
|
+
const meta = {
|
|
22
|
+
title: "Examples/Keston ID",
|
|
23
|
+
parameters: { layout: "fullscreen" },
|
|
24
|
+
} satisfies Meta;
|
|
25
|
+
|
|
26
|
+
export default meta;
|
|
27
|
+
type Story = StoryObj<typeof meta>;
|
|
28
|
+
|
|
29
|
+
const user = { name: "Ben Smith", email: "ben.smith@keston.school", organisation: "The Keston School" };
|
|
30
|
+
|
|
31
|
+
// ── The app asking ──────────────────────────────────────────────────────────
|
|
32
|
+
|
|
33
|
+
interface Scope {
|
|
34
|
+
/** OAuth scope, e.g. "students:read". Shown to developers only. */
|
|
35
|
+
id: string;
|
|
36
|
+
label: string;
|
|
37
|
+
description: string;
|
|
38
|
+
icon: unknown;
|
|
39
|
+
/** The app can't work without it, so it isn't a choice. */
|
|
40
|
+
required?: boolean;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const client = {
|
|
44
|
+
name: "Keston Admissions",
|
|
45
|
+
publisher: "The Keston Group",
|
|
46
|
+
/**
|
|
47
|
+
* The mark by its name: "owned" (the organisation's own app), "verified"
|
|
48
|
+
* (checked by the organisation) or "none".
|
|
49
|
+
*/
|
|
50
|
+
verification: "owned" as "owned" | "verified" | "none",
|
|
51
|
+
redirectHost: "admissions.keston.school",
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
// What the mark by the app's name says, on hover, click or Enter. Owned apps
|
|
55
|
+
// get a Keston blue tick; verified ones the brighter blue.
|
|
56
|
+
const verificationMarks = {
|
|
57
|
+
owned: { label: "Verified by The Keston Group." },
|
|
58
|
+
verified: { label: "Verified by The Keston Group." },
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const scopes: Scope[] = [
|
|
62
|
+
{
|
|
63
|
+
id: "openid profile",
|
|
64
|
+
label: "View your name and profile picture",
|
|
65
|
+
description: "To show who's signed in.",
|
|
66
|
+
icon: User,
|
|
67
|
+
required: true,
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
id: "email",
|
|
71
|
+
label: "View your email address",
|
|
72
|
+
description: "ben.smith@keston.school",
|
|
73
|
+
icon: Mail,
|
|
74
|
+
required: true,
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
id: "students:read",
|
|
78
|
+
label: "View student records at The Keston School",
|
|
79
|
+
description: "Names, year groups and contact details. It can't change them.",
|
|
80
|
+
icon: BookOpen,
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
id: "offline_access",
|
|
84
|
+
label: "Stay connected when you're not using it",
|
|
85
|
+
description: "So it can sync applications overnight. You can disconnect it at any time.",
|
|
86
|
+
icon: RefreshCw,
|
|
87
|
+
},
|
|
88
|
+
];
|
|
89
|
+
|
|
90
|
+
/** What the shared templates below need from setup(). */
|
|
91
|
+
const appState = () => ({
|
|
92
|
+
user,
|
|
93
|
+
client,
|
|
94
|
+
app: { name: client.name },
|
|
95
|
+
mark: client.verification === "none" ? undefined : verificationMarks[client.verification],
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
// ── Shared page parts ───────────────────────────────────────────────────────
|
|
99
|
+
|
|
100
|
+
// Branding above the card. Pages show the organisation's logo (for now always
|
|
101
|
+
// The Keston Group) or Keston ID's own. The TKG square stands in for the real
|
|
102
|
+
// logo: swap it for the SVG when there is one.
|
|
103
|
+
const brands = {
|
|
104
|
+
tkg: `
|
|
105
|
+
<div class="flex items-center justify-center gap-2 text-primary">
|
|
106
|
+
<span class="flex size-8 items-center justify-center rounded bg-primary text-xs font-bold text-white" aria-hidden="true">TKG</span>
|
|
107
|
+
<span class="text-lg font-bold">The Keston Group</span>
|
|
108
|
+
</div>`,
|
|
109
|
+
kestonId: `
|
|
110
|
+
<div class="flex items-center justify-center gap-2 text-primary">
|
|
111
|
+
<ShieldCheck class="size-6" aria-hidden="true" />
|
|
112
|
+
<span class="text-lg font-bold">Keston ID</span>
|
|
113
|
+
</div>`,
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
// Every Keston ID page: a narrow column centred on the grey background, with
|
|
117
|
+
// the branding above the card.
|
|
118
|
+
const page = (body: string, brand: keyof typeof brands = "kestonId") => `
|
|
119
|
+
<div class="flex min-h-screen flex-col items-center bg-background px-4 py-12 text-black">
|
|
120
|
+
<div class="flex w-full max-w-100 flex-col gap-6">
|
|
121
|
+
${brands[brand]}
|
|
122
|
+
${body}
|
|
123
|
+
<nav aria-label="Legal and help" class="flex items-center justify-center gap-2 text-xs text-black/65">
|
|
124
|
+
<Link href="#" new-tab class="py-1">Privacy</Link>
|
|
125
|
+
<span aria-hidden="true">·</span>
|
|
126
|
+
<Link href="#" new-tab class="py-1">Terms</Link>
|
|
127
|
+
<span aria-hidden="true">·</span>
|
|
128
|
+
<Link href="#" new-tab class="py-1">Help</Link>
|
|
129
|
+
</nav>
|
|
130
|
+
</div>
|
|
131
|
+
</div>`;
|
|
132
|
+
|
|
133
|
+
// The app's name as the page heading, with its verification mark beside it
|
|
134
|
+
// (outside the heading, so the mark's "More info" link isn't part of it).
|
|
135
|
+
// The mark's panel is rendered in place, so Tab goes from the mark straight
|
|
136
|
+
// to "More info" once it's open. Used by sign-in and consent alike.
|
|
137
|
+
const appName = (headingId: string) => `
|
|
138
|
+
<div class="flex items-center justify-center gap-1.5">
|
|
139
|
+
<h1 id="${headingId}" tabindex="-1" class="text-xl font-bold outline-none">{{ client.name }}</h1>
|
|
140
|
+
<Popover
|
|
141
|
+
v-if="mark"
|
|
142
|
+
mode="hover"
|
|
143
|
+
:portal="false"
|
|
144
|
+
:open-delay="200"
|
|
145
|
+
:close-delay="150"
|
|
146
|
+
arrow
|
|
147
|
+
:content="{ side: 'top', sideOffset: 6 }"
|
|
148
|
+
:ui="{ content: 'w-max px-3 py-2' }"
|
|
149
|
+
>
|
|
150
|
+
<button
|
|
151
|
+
type="button"
|
|
152
|
+
:aria-label="mark.label"
|
|
153
|
+
:class="client.verification === 'owned' ? 'text-kblue' : 'text-blue'"
|
|
154
|
+
class="flex cursor-pointer rounded-full outline-2 outline-offset-1 outline-transparent focus-visible:outline-focus"
|
|
155
|
+
>
|
|
156
|
+
<BadgeCheck class="size-5" aria-hidden="true" />
|
|
157
|
+
</button>
|
|
158
|
+
<template #content>
|
|
159
|
+
<!-- One line, as narrow as its text. -->
|
|
160
|
+
<div class="flex items-center gap-2 whitespace-nowrap text-sm">
|
|
161
|
+
<p class="font-bold">{{ mark.label }}</p>
|
|
162
|
+
<Link href="#" new-tab>More info<span class="sr-only"> about verification marks</span></Link>
|
|
163
|
+
</div>
|
|
164
|
+
</template>
|
|
165
|
+
</Popover>
|
|
166
|
+
</div>`;
|
|
167
|
+
|
|
168
|
+
const appComponents = { Avatar, BadgeCheck, Link, Popover };
|
|
169
|
+
|
|
170
|
+
// ── OAuth consent card ──────────────────────────────────────────────────────
|
|
171
|
+
|
|
172
|
+
/** State for the consent card. */
|
|
173
|
+
function useConsent() {
|
|
174
|
+
const optional = reactive(Object.fromEntries(scopes.filter((s) => !s.required).map((s) => [s.id, true])));
|
|
175
|
+
const granted = computed(() => scopes.filter((s) => s.required || optional[s.id]).map((s) => s.id).join(" "));
|
|
176
|
+
const allowStatus = ref<ButtonStatus>("idle");
|
|
177
|
+
const result = ref<string>();
|
|
178
|
+
async function allow() {
|
|
179
|
+
allowStatus.value = "loading";
|
|
180
|
+
await new Promise((resolve) => setTimeout(resolve, 700));
|
|
181
|
+
allowStatus.value = "success";
|
|
182
|
+
result.value = `Redirecting to https://${client.redirectHost}/callback?code=…&scope=${encodeURIComponent(granted.value)}`;
|
|
183
|
+
}
|
|
184
|
+
function cancel() {
|
|
185
|
+
result.value = `Redirecting to https://${client.redirectHost}/callback?error=access_denied`;
|
|
186
|
+
}
|
|
187
|
+
return {
|
|
188
|
+
required: scopes.filter((s) => s.required),
|
|
189
|
+
optionalScopes: scopes.filter((s) => !s.required),
|
|
190
|
+
optional,
|
|
191
|
+
allowStatus,
|
|
192
|
+
result,
|
|
193
|
+
allow,
|
|
194
|
+
cancel,
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
const consentComponents = { ...appComponents, Button, Card, Checkbox, Divider, ArrowLeftRight };
|
|
199
|
+
|
|
200
|
+
const consentCard = `
|
|
201
|
+
<Card :heading-level="1" padding="md">
|
|
202
|
+
<div class="flex flex-col gap-6">
|
|
203
|
+
<div class="flex items-center justify-center gap-3" aria-hidden="true">
|
|
204
|
+
<Avatar :user="app" size="lg" decorative />
|
|
205
|
+
<ArrowLeftRight class="size-5 text-black/55" />
|
|
206
|
+
<Avatar :user="user" size="lg" decorative />
|
|
207
|
+
</div>
|
|
208
|
+
|
|
209
|
+
<div class="flex flex-col gap-1 text-center">
|
|
210
|
+
${appName("consent-heading")}
|
|
211
|
+
<p class="text-base">wants to access your Keston account</p>
|
|
212
|
+
<p class="text-sm text-black/65">An app by {{ client.publisher }}</p>
|
|
213
|
+
</div>
|
|
214
|
+
|
|
215
|
+
<!-- Who's signed in, as a small Card in a row. -->
|
|
216
|
+
<Card as="div" padding="sm" :ui="{ body: 'flex-row items-center justify-between gap-3 p-3' }">
|
|
217
|
+
<div class="flex min-w-0 items-center gap-2">
|
|
218
|
+
<Avatar :user="user" size="sm" decorative />
|
|
219
|
+
<div class="flex min-w-0 flex-col">
|
|
220
|
+
<span class="truncate text-sm font-bold">{{ user.name }}</span>
|
|
221
|
+
<span class="truncate text-xs text-black/65">{{ user.email }}</span>
|
|
222
|
+
</div>
|
|
223
|
+
</div>
|
|
224
|
+
<Button size="sm" class="shrink-0">Switch account</Button>
|
|
225
|
+
</Card>
|
|
226
|
+
|
|
227
|
+
<div class="flex flex-col gap-3">
|
|
228
|
+
<h2 class="text-sm font-bold">This will let {{ client.name }}:</h2>
|
|
229
|
+
<ul class="flex flex-col gap-3">
|
|
230
|
+
<li v-for="scope in required" :key="scope.id" class="flex items-start gap-3">
|
|
231
|
+
<component :is="scope.icon" class="mt-0.5 size-4 shrink-0 text-black/65" aria-hidden="true" />
|
|
232
|
+
<div class="flex flex-col gap-0.5">
|
|
233
|
+
<span class="text-sm">{{ scope.label }}</span>
|
|
234
|
+
<span class="text-xs text-black/65">{{ scope.description }}</span>
|
|
235
|
+
</div>
|
|
236
|
+
</li>
|
|
237
|
+
</ul>
|
|
238
|
+
</div>
|
|
239
|
+
|
|
240
|
+
<div class="flex flex-col gap-3">
|
|
241
|
+
<h2 class="text-sm font-bold">You can choose whether it can also:</h2>
|
|
242
|
+
<Checkbox
|
|
243
|
+
v-for="scope in optionalScopes"
|
|
244
|
+
:key="scope.id"
|
|
245
|
+
v-model="optional[scope.id]"
|
|
246
|
+
:label="scope.label"
|
|
247
|
+
:description="scope.description"
|
|
248
|
+
/>
|
|
249
|
+
</div>
|
|
250
|
+
|
|
251
|
+
<Divider />
|
|
252
|
+
|
|
253
|
+
<p class="text-xs text-black/65">
|
|
254
|
+
You'll be sent to <span class="font-bold text-black">{{ client.redirectHost }}</span>.
|
|
255
|
+
Make sure you trust {{ client.name }}: read its
|
|
256
|
+
<Link href="#" new-tab>privacy policy</Link>
|
|
257
|
+
and
|
|
258
|
+
<Link href="#" new-tab>terms</Link>.
|
|
259
|
+
You can remove its access at any time in your Keston account.
|
|
260
|
+
</p>
|
|
261
|
+
|
|
262
|
+
<div class="flex flex-col-reverse gap-2 sm:flex-row sm:justify-end">
|
|
263
|
+
<Button :disabled="allowStatus !== 'idle'" @click="cancel">Cancel</Button>
|
|
264
|
+
<Button variant="primary" :status="allowStatus" loading-text="Allowing" success-text="Allowed" @click="allow">
|
|
265
|
+
Allow
|
|
266
|
+
</Button>
|
|
267
|
+
</div>
|
|
268
|
+
|
|
269
|
+
<p v-if="result" class="break-all rounded bg-surface px-3 py-2 font-mono text-xs" role="status">{{ result }}</p>
|
|
270
|
+
</div>
|
|
271
|
+
</Card>`;
|
|
272
|
+
|
|
273
|
+
// ── Stories ─────────────────────────────────────────────────────────────────
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* Signing in to an app: its name and verification mark at the top, email and
|
|
277
|
+
* password, and the terms people agree to by signing in. Signing in goes on
|
|
278
|
+
* to the consent prompt, as it would after a real sign-in. Try the password
|
|
279
|
+
* "correct horse".
|
|
280
|
+
*/
|
|
281
|
+
export const SignIn: Story = {
|
|
282
|
+
render: () => ({
|
|
283
|
+
components: { ...consentComponents, Input, InputPassword, ShieldCheck, Mail, Lock },
|
|
284
|
+
setup() {
|
|
285
|
+
const form = reactive({ email: "", password: "" });
|
|
286
|
+
const error = ref<string>();
|
|
287
|
+
const status = ref<ButtonStatus>("idle");
|
|
288
|
+
const stage = ref<"signIn" | "consent">("signIn");
|
|
289
|
+
async function signIn() {
|
|
290
|
+
error.value = undefined;
|
|
291
|
+
status.value = "loading";
|
|
292
|
+
await new Promise((resolve) => setTimeout(resolve, 800));
|
|
293
|
+
if (form.password !== "correct horse") {
|
|
294
|
+
status.value = "idle";
|
|
295
|
+
error.value = "Incorrect email or password";
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
298
|
+
status.value = "success";
|
|
299
|
+
await new Promise((resolve) => setTimeout(resolve, 600));
|
|
300
|
+
// A new page in a real app. Here, focus its heading so screen readers
|
|
301
|
+
// start reading from the top of the consent prompt.
|
|
302
|
+
stage.value = "consent";
|
|
303
|
+
await nextTick();
|
|
304
|
+
document.getElementById("consent-heading")?.focus();
|
|
305
|
+
}
|
|
306
|
+
return { ...appState(), ...useConsent(), form, error, status, stage, signIn };
|
|
307
|
+
},
|
|
308
|
+
template: page(`
|
|
309
|
+
<Card v-if="stage === 'signIn'" :heading-level="1" padding="md" :ui="{ footer: 'justify-center' }">
|
|
310
|
+
<div class="flex flex-col gap-6">
|
|
311
|
+
<div class="flex justify-center" aria-hidden="true">
|
|
312
|
+
<Avatar :user="app" size="lg" decorative />
|
|
313
|
+
</div>
|
|
314
|
+
|
|
315
|
+
<div class="flex flex-col gap-1 text-center">
|
|
316
|
+
${appName("sign-in-heading")}
|
|
317
|
+
<p class="text-base">Sign in with your Keston account</p>
|
|
318
|
+
<p class="text-sm text-black/65">An app by {{ client.publisher }}</p>
|
|
319
|
+
</div>
|
|
320
|
+
|
|
321
|
+
<form class="flex flex-col gap-4" @submit.prevent="signIn">
|
|
322
|
+
<Input v-model="form.email" label="Email" type="email" autocomplete="username">
|
|
323
|
+
<template #leading><Mail /></template>
|
|
324
|
+
</Input>
|
|
325
|
+
<!-- Forgot password? shows by the label but is reached by Tab after
|
|
326
|
+
the field, so people typing their password aren't sent to it. -->
|
|
327
|
+
<InputPassword v-model="form.password" label="Password" :error-text="error">
|
|
328
|
+
<template #leading><Lock /></template>
|
|
329
|
+
<template #label-trailing>
|
|
330
|
+
<Link href="#" class="text-black/65">Forgot password?</Link>
|
|
331
|
+
</template>
|
|
332
|
+
</InputPassword>
|
|
333
|
+
<Button type="submit" variant="primary" :status="status" loading-text="Signing in" success-text="Signed in">
|
|
334
|
+
Sign in
|
|
335
|
+
</Button>
|
|
336
|
+
</form>
|
|
337
|
+
<Divider label="or" />
|
|
338
|
+
<Button>Sign in with a passkey</Button>
|
|
339
|
+
</div>
|
|
340
|
+
<template #footer>
|
|
341
|
+
<p class="text-center text-xs text-black/65">
|
|
342
|
+
By signing in, you agree to our <Link href="#" new-tab>terms</Link>
|
|
343
|
+
and <Link href="#" new-tab>privacy policy</Link>.
|
|
344
|
+
</p>
|
|
345
|
+
</template>
|
|
346
|
+
</Card>
|
|
347
|
+
<template v-else>${consentCard}</template>`, "tkg"),
|
|
348
|
+
}),
|
|
349
|
+
};
|
|
350
|
+
|
|
351
|
+
/** The second step: a code from an authenticator app. Try 123456. */
|
|
352
|
+
export const TwoStepCode: Story = {
|
|
353
|
+
render: () => ({
|
|
354
|
+
components: { Button, Card, InputCode, Link, ShieldCheck },
|
|
355
|
+
setup() {
|
|
356
|
+
const code = ref("");
|
|
357
|
+
const status = ref<InputCodeProps["status"]>();
|
|
358
|
+
const statusText = ref<string>();
|
|
359
|
+
async function check(value = code.value) {
|
|
360
|
+
if (value.length < 6) {
|
|
361
|
+
status.value = "error";
|
|
362
|
+
statusText.value = "Enter all 6 digits";
|
|
363
|
+
return;
|
|
364
|
+
}
|
|
365
|
+
status.value = "loading";
|
|
366
|
+
statusText.value = "Checking code…";
|
|
367
|
+
await new Promise((resolve) => setTimeout(resolve, 900));
|
|
368
|
+
const ok = value === "123456";
|
|
369
|
+
status.value = ok ? "success" : "error";
|
|
370
|
+
statusText.value = ok ? "Code accepted" : "That code didn't work. Check it and try again.";
|
|
371
|
+
if (!ok) code.value = "";
|
|
372
|
+
}
|
|
373
|
+
return { code, status, statusText, check };
|
|
374
|
+
},
|
|
375
|
+
template: page(`
|
|
376
|
+
<Card
|
|
377
|
+
title="Check it's you"
|
|
378
|
+
description="Open your authenticator app and enter the code for The Keston Group."
|
|
379
|
+
:heading-level="1"
|
|
380
|
+
:ui="{ footer: 'justify-evenly' }"
|
|
381
|
+
>
|
|
382
|
+
<form class="flex flex-col gap-4" @submit.prevent="check()">
|
|
383
|
+
<InputCode
|
|
384
|
+
v-model="code"
|
|
385
|
+
label="Code from your authenticator app"
|
|
386
|
+
:status="status"
|
|
387
|
+
:status-text="statusText"
|
|
388
|
+
:disabled="status === 'loading'"
|
|
389
|
+
class="items-center"
|
|
390
|
+
@complete="check"
|
|
391
|
+
/>
|
|
392
|
+
<Button type="submit" variant="primary" :disabled="status === 'loading'">Continue</Button>
|
|
393
|
+
</form>
|
|
394
|
+
<template #footer>
|
|
395
|
+
<Link href="#" class="py-1 text-xs text-black/65">Use a backup code</Link>
|
|
396
|
+
<Link href="#" class="py-1 text-xs text-black/65">Email me a code</Link>
|
|
397
|
+
</template>
|
|
398
|
+
</Card>`, "tkg"),
|
|
399
|
+
}),
|
|
400
|
+
};
|
|
401
|
+
|
|
402
|
+
/**
|
|
403
|
+
* The OAuth 2.0 consent prompt: which app is asking, who's signed in, what it
|
|
404
|
+
* will get, and Allow / Cancel. Scopes the app needs are listed; the others
|
|
405
|
+
* can be unticked before allowing. Allow sends the person back to the app's
|
|
406
|
+
* redirect address with a code; Cancel sends them back with
|
|
407
|
+
* `error=access_denied`.
|
|
408
|
+
*/
|
|
409
|
+
export const OAuthConsent: Story = {
|
|
410
|
+
render: () => ({
|
|
411
|
+
components: { ...consentComponents, ShieldCheck },
|
|
412
|
+
setup: () => ({ ...appState(), ...useConsent() }),
|
|
413
|
+
template: page(consentCard, "tkg"),
|
|
414
|
+
}),
|
|
415
|
+
};
|