@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,225 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from "@storybook/vue3-vite";
|
|
2
|
+
import { reactive, ref } from "vue";
|
|
3
|
+
import Button from "../Button/Button.vue";
|
|
4
|
+
import Input from "../Input/Input.vue";
|
|
5
|
+
import InputDate from "../InputDate/InputDate.vue";
|
|
6
|
+
import InputNumber from "../InputNumber/InputNumber.vue";
|
|
7
|
+
import RadioGroup from "../RadioGroup/RadioGroup.vue";
|
|
8
|
+
import SummaryList from "../SummaryList/SummaryList.vue";
|
|
9
|
+
import Slideover from "./Slideover.vue";
|
|
10
|
+
|
|
11
|
+
const meta = {
|
|
12
|
+
title: "Components/Overlay/Slideover",
|
|
13
|
+
component: Slideover,
|
|
14
|
+
tags: ["autodocs"],
|
|
15
|
+
argTypes: {
|
|
16
|
+
side: { options: ["right", "left", "top", "bottom"], control: { type: "inline-radio" } },
|
|
17
|
+
initialFocus: { options: ["auto", "close", "none"], control: { type: "inline-radio" } },
|
|
18
|
+
},
|
|
19
|
+
args: {
|
|
20
|
+
title: "Notifications",
|
|
21
|
+
description: "Updates from the last 7 days.",
|
|
22
|
+
side: "right",
|
|
23
|
+
overlay: true,
|
|
24
|
+
close: true,
|
|
25
|
+
dismissible: true,
|
|
26
|
+
modal: true,
|
|
27
|
+
},
|
|
28
|
+
render: (args) => ({
|
|
29
|
+
components: { Slideover, Button },
|
|
30
|
+
setup: () => ({ args }),
|
|
31
|
+
template: `
|
|
32
|
+
<Slideover v-bind="args">
|
|
33
|
+
<Button>Open slideover</Button>
|
|
34
|
+
<template #body>
|
|
35
|
+
<p class="text-sm text-black/65">Nothing new.</p>
|
|
36
|
+
</template>
|
|
37
|
+
</Slideover>`,
|
|
38
|
+
}),
|
|
39
|
+
} satisfies Meta<typeof Slideover>;
|
|
40
|
+
|
|
41
|
+
export default meta;
|
|
42
|
+
type Story = StoryObj<typeof meta>;
|
|
43
|
+
|
|
44
|
+
/** Playground: use the controls below. Slides in from the right by default. */
|
|
45
|
+
export const Default: Story = {};
|
|
46
|
+
|
|
47
|
+
/** Editing a record without leaving the page, with Cancel / Save in the footer. */
|
|
48
|
+
export const EditStudent: Story = {
|
|
49
|
+
args: { title: "Edit student", description: "Changes are saved to the register." },
|
|
50
|
+
render: (args) => ({
|
|
51
|
+
components: { Slideover, Button, Input, InputDate, InputNumber },
|
|
52
|
+
setup() {
|
|
53
|
+
const student = ref({ firstName: "Ben", lastName: "Smith", dateOfBirth: "2012-01-26", yearGroup: 9 });
|
|
54
|
+
return { args, student };
|
|
55
|
+
},
|
|
56
|
+
template: `
|
|
57
|
+
<Slideover v-bind="args">
|
|
58
|
+
<Button variant="primary">Edit student</Button>
|
|
59
|
+
<template #body>
|
|
60
|
+
<div class="flex flex-col gap-5">
|
|
61
|
+
<div class="grid grid-cols-2 items-start gap-3">
|
|
62
|
+
<Input v-model="student.firstName" label="First name" />
|
|
63
|
+
<Input v-model="student.lastName" label="Last name" />
|
|
64
|
+
</div>
|
|
65
|
+
<InputDate v-model="student.dateOfBirth" label="Date of birth" prefer="past" />
|
|
66
|
+
<InputNumber v-model="student.yearGroup" label="Year group" :min="7" :max="13" />
|
|
67
|
+
</div>
|
|
68
|
+
</template>
|
|
69
|
+
<template #footer="{ close }">
|
|
70
|
+
<Button @click="close">Cancel</Button>
|
|
71
|
+
<Button variant="primary" @click="close">Save</Button>
|
|
72
|
+
</template>
|
|
73
|
+
</Slideover>`,
|
|
74
|
+
}),
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* A multi-step form: `steps` adds a segment per step at the top, the step's
|
|
79
|
+
* name, and Cancel / Previous and Next / Finish at the bottom. The body slot
|
|
80
|
+
* gets `{ step }` to show that step's fields. `validateStep` keeps you on a
|
|
81
|
+
* step until it's filled in; on the last step it saves (with a spinner)
|
|
82
|
+
* before `finish`. Try Next with the names empty.
|
|
83
|
+
*/
|
|
84
|
+
export const MultiStep: Story = {
|
|
85
|
+
args: { title: "Add a student", description: undefined },
|
|
86
|
+
render: (args) => ({
|
|
87
|
+
components: { Slideover, Button, Input, InputDate, InputNumber, RadioGroup, SummaryList },
|
|
88
|
+
setup() {
|
|
89
|
+
const open = ref(false);
|
|
90
|
+
const student = reactive({
|
|
91
|
+
firstName: "",
|
|
92
|
+
lastName: "",
|
|
93
|
+
dateOfBirth: undefined as string | undefined,
|
|
94
|
+
yearGroup: 7 as number | undefined,
|
|
95
|
+
contact: "email",
|
|
96
|
+
email: "",
|
|
97
|
+
});
|
|
98
|
+
const errors = reactive<Record<string, string | undefined>>({});
|
|
99
|
+
const steps = ["Name", "Date of birth and year", "Contact", "Check and add"];
|
|
100
|
+
|
|
101
|
+
async function validateStep(step: number) {
|
|
102
|
+
if (step === 0) {
|
|
103
|
+
errors.firstName = student.firstName.trim() ? undefined : "Enter a first name";
|
|
104
|
+
errors.lastName = student.lastName.trim() ? undefined : "Enter a last name";
|
|
105
|
+
return !errors.firstName && !errors.lastName;
|
|
106
|
+
}
|
|
107
|
+
if (step === 1) {
|
|
108
|
+
errors.dateOfBirth = student.dateOfBirth ? undefined : "Enter a date of birth";
|
|
109
|
+
return !errors.dateOfBirth;
|
|
110
|
+
}
|
|
111
|
+
if (step === 2) {
|
|
112
|
+
errors.email = student.contact !== "email" || /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(student.email) ? undefined : "Enter a valid email address";
|
|
113
|
+
return !errors.email;
|
|
114
|
+
}
|
|
115
|
+
// Last step: "save", then close.
|
|
116
|
+
await new Promise((resolve) => setTimeout(resolve, 900));
|
|
117
|
+
return true;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const summary = () => [
|
|
121
|
+
{ label: "Name", value: `${student.firstName} ${student.lastName}` },
|
|
122
|
+
{ label: "Date of birth", value: student.dateOfBirth ?? "" },
|
|
123
|
+
{ label: "Year group", value: `Year ${student.yearGroup}` },
|
|
124
|
+
{ label: "Contact", value: student.contact === "email" ? student.email : "By post" },
|
|
125
|
+
];
|
|
126
|
+
|
|
127
|
+
return { args, open, student, errors, steps, validateStep, summary };
|
|
128
|
+
},
|
|
129
|
+
template: `
|
|
130
|
+
<Slideover v-bind="args" v-model:open="open" :steps="steps" :validate-step="validateStep" finish-label="Add student" @finish="open = false">
|
|
131
|
+
<Button variant="primary">Add student</Button>
|
|
132
|
+
<template #body="{ step }">
|
|
133
|
+
<div v-if="step === 0" class="flex flex-col gap-5">
|
|
134
|
+
<Input v-model="student.firstName" label="First name" :error-text="errors.firstName" />
|
|
135
|
+
<Input v-model="student.lastName" label="Last name" :error-text="errors.lastName" />
|
|
136
|
+
</div>
|
|
137
|
+
<div v-else-if="step === 1" class="flex flex-col gap-5">
|
|
138
|
+
<InputDate v-model="student.dateOfBirth" label="Date of birth" prefer="past" :error-text="errors.dateOfBirth" />
|
|
139
|
+
<InputNumber v-model="student.yearGroup" label="Year group" :min="7" :max="13" />
|
|
140
|
+
</div>
|
|
141
|
+
<div v-else-if="step === 2" class="flex flex-col gap-5">
|
|
142
|
+
<RadioGroup
|
|
143
|
+
v-model="student.contact"
|
|
144
|
+
label="How should we contact the family?"
|
|
145
|
+
:options="[{ value: 'email', label: 'Email' }, { value: 'post', label: 'Post' }]"
|
|
146
|
+
/>
|
|
147
|
+
<Input v-if="student.contact === 'email'" v-model="student.email" label="Email" type="email" :error-text="errors.email" />
|
|
148
|
+
</div>
|
|
149
|
+
<SummaryList v-else :items="summary()" />
|
|
150
|
+
</template>
|
|
151
|
+
</Slideover>`,
|
|
152
|
+
}),
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
export const Sides: Story = {
|
|
156
|
+
render: (args) => ({
|
|
157
|
+
components: { Slideover, Button },
|
|
158
|
+
setup: () => ({ args }),
|
|
159
|
+
template: `
|
|
160
|
+
<div class="flex gap-2">
|
|
161
|
+
<Slideover v-for="side in ['right', 'left', 'top', 'bottom']" :key="side" v-bind="args" :side="side" :title="'From the ' + side">
|
|
162
|
+
<Button>{{ side }}</Button>
|
|
163
|
+
<template #body><p class="text-sm text-black/65">Slides in from the {{ side }}.</p></template>
|
|
164
|
+
</Slideover>
|
|
165
|
+
</div>`,
|
|
166
|
+
}),
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
/** The body scrolls; the header and footer stay put. */
|
|
170
|
+
export const LongContent: Story = {
|
|
171
|
+
args: { title: "Behaviour log", description: "This term." },
|
|
172
|
+
render: (args) => ({
|
|
173
|
+
components: { Slideover, Button },
|
|
174
|
+
setup: () => ({ args }),
|
|
175
|
+
template: `
|
|
176
|
+
<Slideover v-bind="args">
|
|
177
|
+
<Button>Open log</Button>
|
|
178
|
+
<template #body>
|
|
179
|
+
<ul class="flex flex-col gap-3 text-sm">
|
|
180
|
+
<li v-for="n in 40" :key="n" class="rounded border border-black/15 p-3">Entry {{ n }}</li>
|
|
181
|
+
</ul>
|
|
182
|
+
</template>
|
|
183
|
+
<template #footer="{ close }"><Button @click="close">Done</Button></template>
|
|
184
|
+
</Slideover>`,
|
|
185
|
+
}),
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
/** Escape and clicking outside don't close it; only the footer button does. */
|
|
189
|
+
export const NotDismissible: Story = {
|
|
190
|
+
args: { title: "Unsaved changes", description: "Save or discard before leaving.", dismissible: false, close: false },
|
|
191
|
+
render: (args) => ({
|
|
192
|
+
components: { Slideover, Button },
|
|
193
|
+
setup() {
|
|
194
|
+
const attempts = ref(0);
|
|
195
|
+
return { args, attempts };
|
|
196
|
+
},
|
|
197
|
+
template: `
|
|
198
|
+
<Slideover v-bind="args" @close:prevent="attempts++">
|
|
199
|
+
<Button>Open</Button>
|
|
200
|
+
<template #body><p class="text-sm text-black/65">Blocked close attempts: {{ attempts }}</p></template>
|
|
201
|
+
<template #footer="{ close }">
|
|
202
|
+
<Button @click="close">Discard</Button>
|
|
203
|
+
<Button variant="primary" @click="close">Save</Button>
|
|
204
|
+
</template>
|
|
205
|
+
</Slideover>`,
|
|
206
|
+
}),
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
/** Opened from code with v-model:open, without a trigger slot. */
|
|
210
|
+
export const Controlled: Story = {
|
|
211
|
+
render: (args) => ({
|
|
212
|
+
components: { Slideover, Button },
|
|
213
|
+
setup() {
|
|
214
|
+
const open = ref(false);
|
|
215
|
+
return { args, open };
|
|
216
|
+
},
|
|
217
|
+
template: `
|
|
218
|
+
<div>
|
|
219
|
+
<Button variant="primary" @click="open = true">Open from code</Button>
|
|
220
|
+
<Slideover v-bind="args" v-model:open="open">
|
|
221
|
+
<template #body><p class="text-sm text-black/65">Opened with v-model:open.</p></template>
|
|
222
|
+
</Slideover>
|
|
223
|
+
</div>`,
|
|
224
|
+
}),
|
|
225
|
+
};
|
|
@@ -0,0 +1,365 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed, nextTick, ref, useId, watch, type HTMLAttributes } from 'vue'
|
|
3
|
+
import {
|
|
4
|
+
DialogClose,
|
|
5
|
+
DialogContent,
|
|
6
|
+
DialogDescription,
|
|
7
|
+
DialogOverlay,
|
|
8
|
+
DialogPortal,
|
|
9
|
+
DialogRoot,
|
|
10
|
+
DialogTitle,
|
|
11
|
+
DialogTrigger,
|
|
12
|
+
type DialogContentProps
|
|
13
|
+
} from 'reka-ui'
|
|
14
|
+
import { ChevronLeft, ChevronRight, X } from '@lucide/vue'
|
|
15
|
+
import { cn } from '../../lib/cn'
|
|
16
|
+
import Button, { type ButtonStatus } from '../Button/Button.vue'
|
|
17
|
+
import Progress from '../Progress/Progress.vue'
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* A full-height panel that slides in from the side of the screen, e.g. to edit
|
|
21
|
+
* a record without leaving the page. Built on Reka UI's Dialog: focus is kept
|
|
22
|
+
* inside while open, Escape and clicking the overlay close it, the page behind
|
|
23
|
+
* doesn't scroll, and it is announced as a dialog.
|
|
24
|
+
*
|
|
25
|
+
* Slots: default (the trigger, e.g. a Button), header (replaces title,
|
|
26
|
+
* description and close), title, description, body (the scrolling middle),
|
|
27
|
+
* footer (e.g. Cancel / Save), content (replaces everything inside the panel).
|
|
28
|
+
* Slots that close it get `{ close }`.
|
|
29
|
+
*
|
|
30
|
+
* Multi-step forms: pass `steps` (one name per step) and show the current
|
|
31
|
+
* step's fields in the body slot, which gets `{ step }`. The header shows a
|
|
32
|
+
* segment per step and "Step 2 of 4: Contact details"; the footer gets
|
|
33
|
+
* Cancel / Previous and Next / Finish, unless you fill the footer slot.
|
|
34
|
+
* Enter in a text field presses Next / Finish.
|
|
35
|
+
*/
|
|
36
|
+
export interface SlideoverProps {
|
|
37
|
+
/** Heading of the panel. Also its accessible name, so always set it (or the title slot). */
|
|
38
|
+
title?: string
|
|
39
|
+
/** Text under the title. */
|
|
40
|
+
description?: string
|
|
41
|
+
/** Edge it slides in from. */
|
|
42
|
+
side?: 'right' | 'left' | 'top' | 'bottom'
|
|
43
|
+
/** Dim the page behind it. */
|
|
44
|
+
overlay?: boolean
|
|
45
|
+
/** Show the × close button in the header. */
|
|
46
|
+
close?: boolean
|
|
47
|
+
/** Close on Escape and on clicking outside. If false, emits close:prevent instead. */
|
|
48
|
+
dismissible?: boolean
|
|
49
|
+
/** Block interaction with the page behind while open. */
|
|
50
|
+
modal?: boolean
|
|
51
|
+
/** Open when first shown. */
|
|
52
|
+
defaultOpen?: boolean
|
|
53
|
+
/**
|
|
54
|
+
* Where focus goes when it opens:
|
|
55
|
+
* - none (default): the panel itself, so screen readers announce the title
|
|
56
|
+
* and description and read from the top. Tab then moves to the first
|
|
57
|
+
* control.
|
|
58
|
+
* - auto: an element marked `autofocus`, else the first form field, else
|
|
59
|
+
* the × button. On touch screens it skips text fields, so the keyboard
|
|
60
|
+
* doesn't pop up before the panel has been seen.
|
|
61
|
+
* - close: the × button (or the first button, if there's no ×).
|
|
62
|
+
*/
|
|
63
|
+
initialFocus?: 'auto' | 'close' | 'none'
|
|
64
|
+
/** Render at the end of the page (true), inside a given element, or in place (false). */
|
|
65
|
+
portal?: boolean | string | HTMLElement
|
|
66
|
+
/** Passed to Reka's DialogContent. */
|
|
67
|
+
content?: Omit<DialogContentProps, 'as' | 'asChild' | 'forceMount'>
|
|
68
|
+
/** Names of the steps, for a multi-step form. Adds the segments, step name and Previous / Next. */
|
|
69
|
+
steps?: string[]
|
|
70
|
+
/**
|
|
71
|
+
* Checks the current step before moving on (Next) or finishing (Finish).
|
|
72
|
+
* Return false to stay, e.g. after showing field errors. Can be async, e.g.
|
|
73
|
+
* to save on the last step; the button shows a spinner meanwhile.
|
|
74
|
+
*/
|
|
75
|
+
validateStep?: (step: number) => boolean | Promise<boolean>
|
|
76
|
+
/** Text of the last step's button. */
|
|
77
|
+
finishLabel?: string
|
|
78
|
+
/** Extra classes for the parts. */
|
|
79
|
+
ui?: {
|
|
80
|
+
overlay?: HTMLAttributes['class']
|
|
81
|
+
content?: HTMLAttributes['class']
|
|
82
|
+
header?: HTMLAttributes['class']
|
|
83
|
+
title?: HTMLAttributes['class']
|
|
84
|
+
body?: HTMLAttributes['class']
|
|
85
|
+
footer?: HTMLAttributes['class']
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const props = withDefaults(defineProps<SlideoverProps>(), {
|
|
90
|
+
side: 'right',
|
|
91
|
+
overlay: true,
|
|
92
|
+
close: true,
|
|
93
|
+
dismissible: true,
|
|
94
|
+
modal: true,
|
|
95
|
+
portal: true,
|
|
96
|
+
initialFocus: 'none',
|
|
97
|
+
finishLabel: 'Finish'
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
const emit = defineEmits<{
|
|
101
|
+
'close:prevent': []
|
|
102
|
+
/** Finish was pressed on the last step and `validateStep` passed. */
|
|
103
|
+
finish: []
|
|
104
|
+
}>()
|
|
105
|
+
|
|
106
|
+
defineSlots<{
|
|
107
|
+
default?(): unknown
|
|
108
|
+
header?(props: { close: () => void }): unknown
|
|
109
|
+
title?(): unknown
|
|
110
|
+
description?(): unknown
|
|
111
|
+
body?(props: { close: () => void; step: number }): unknown
|
|
112
|
+
footer?(props: { close: () => void }): unknown
|
|
113
|
+
content?(props: { close: () => void }): unknown
|
|
114
|
+
}>()
|
|
115
|
+
|
|
116
|
+
/** Whether it is open. Optional: use v-model:open to control it. */
|
|
117
|
+
const openModel = defineModel<boolean | undefined>('open', { default: undefined })
|
|
118
|
+
const isOpen = ref(openModel.value ?? props.defaultOpen ?? false)
|
|
119
|
+
watch(openModel, (value) => {
|
|
120
|
+
if (value !== undefined) isOpen.value = value
|
|
121
|
+
})
|
|
122
|
+
function setOpen(value: boolean) {
|
|
123
|
+
isOpen.value = value
|
|
124
|
+
openModel.value = value
|
|
125
|
+
}
|
|
126
|
+
const closePanel = () => setOpen(false)
|
|
127
|
+
|
|
128
|
+
// ── Steps ───────────────────────────────────────────────────────────────────
|
|
129
|
+
/** Current step, from 0. Optional: use v-model:step to control it. Back to 0 each time it opens. */
|
|
130
|
+
const step = defineModel<number>('step', { default: 0 })
|
|
131
|
+
watch(isOpen, (open) => {
|
|
132
|
+
if (!open || !props.steps) return
|
|
133
|
+
step.value = 0
|
|
134
|
+
announcement.value = ''
|
|
135
|
+
})
|
|
136
|
+
|
|
137
|
+
const stepCount = computed(() => props.steps?.length ?? 0)
|
|
138
|
+
const isLastStep = computed(() => step.value >= stepCount.value - 1)
|
|
139
|
+
const nextStatus = ref<ButtonStatus>('idle')
|
|
140
|
+
|
|
141
|
+
// Screen readers are always told which step they're on:
|
|
142
|
+
// - focus moves into the new step's first field (after Enter): its fields are
|
|
143
|
+
// a group named "Step 3 of 4: Contact", read out with the field;
|
|
144
|
+
// - otherwise (Next / Previous buttons, touch screens): the same words are
|
|
145
|
+
// announced. Never both, so it isn't read twice.
|
|
146
|
+
const stepLabelId = `${useId()}-step`
|
|
147
|
+
const stepText = computed(() => (props.steps ? `Step ${step.value + 1} of ${stepCount.value}: ${props.steps[step.value]}` : ''))
|
|
148
|
+
const announcement = ref('')
|
|
149
|
+
const body = ref<HTMLElement>()
|
|
150
|
+
|
|
151
|
+
async function goTo(index: number) {
|
|
152
|
+
// If focus is in this step's fields (e.g. Enter was pressed in one), they're
|
|
153
|
+
// about to go: carry on in the new step's first control (or the panel, on
|
|
154
|
+
// touch screens, so the keyboard doesn't pop up). Focus on Next / Previous
|
|
155
|
+
// stays where it is.
|
|
156
|
+
const focusInStep = !!body.value?.contains(document.activeElement)
|
|
157
|
+
announcement.value = ''
|
|
158
|
+
step.value = index
|
|
159
|
+
// Start the new step from the top.
|
|
160
|
+
body.value?.scrollTo({ top: 0 })
|
|
161
|
+
await nextTick()
|
|
162
|
+
const touch = window.matchMedia('(pointer: coarse)').matches
|
|
163
|
+
const field = focusInStep && !touch ? body.value?.querySelector<HTMLElement>(stepControlSelector) : null
|
|
164
|
+
if (field) {
|
|
165
|
+
field.focus()
|
|
166
|
+
return
|
|
167
|
+
}
|
|
168
|
+
if (focusInStep) body.value?.closest<HTMLElement>('[role=dialog]')?.focus()
|
|
169
|
+
announcement.value = stepText.value
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
async function next() {
|
|
173
|
+
if (nextStatus.value === 'loading') return
|
|
174
|
+
if (props.validateStep) {
|
|
175
|
+
nextStatus.value = 'loading'
|
|
176
|
+
try {
|
|
177
|
+
if (!(await props.validateStep(step.value))) return
|
|
178
|
+
} finally {
|
|
179
|
+
nextStatus.value = 'idle'
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
if (isLastStep.value) emit('finish')
|
|
183
|
+
else goTo(step.value + 1)
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// Enter in a text field moves on, like submitting a form: Next, or Finish on
|
|
187
|
+
// the last step. Not in multi-line text, buttons, checkboxes or radios, and
|
|
188
|
+
// not when the field used the Enter itself (InputDate's first Enter fills in
|
|
189
|
+
// the date it understood).
|
|
190
|
+
const skipEnter = 'textarea, [contenteditable="true"], input[type=checkbox], input[type=radio], input[type=button], input[type=submit]'
|
|
191
|
+
function onBodyEnter(event: KeyboardEvent) {
|
|
192
|
+
const target = event.target as HTMLElement
|
|
193
|
+
if (!props.steps || event.defaultPrevented || event.isComposing) return
|
|
194
|
+
if (target.tagName !== 'INPUT' || target.closest(skipEnter)) return
|
|
195
|
+
event.preventDefault()
|
|
196
|
+
next()
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// One outside click can be reported twice by Reka (the press, then focus
|
|
200
|
+
// leaving). Both are prevented, but close:prevent is emitted once per attempt.
|
|
201
|
+
let lastPrevented = 0
|
|
202
|
+
function preventDismiss(event: Event) {
|
|
203
|
+
if (props.dismissible) return
|
|
204
|
+
event.preventDefault()
|
|
205
|
+
const now = performance.now()
|
|
206
|
+
if (now - lastPrevented > 50) emit('close:prevent')
|
|
207
|
+
lastPrevented = now
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// ── Initial focus ───────────────────────────────────────────────────────────
|
|
211
|
+
// Reka moves focus to the first focusable element (usually ×) unless this
|
|
212
|
+
// handler prevents it and focuses something else.
|
|
213
|
+
const fieldSelector = [
|
|
214
|
+
'input:not([type=hidden]):not(:disabled)',
|
|
215
|
+
'textarea:not(:disabled)',
|
|
216
|
+
'select:not(:disabled)',
|
|
217
|
+
'[role="spinbutton"]:not([aria-disabled="true"])'
|
|
218
|
+
].join(', ')
|
|
219
|
+
|
|
220
|
+
// The first control of a step: a field, or the selected radio, a checkbox,
|
|
221
|
+
// switch or select. (In a radio group, the selected radio.)
|
|
222
|
+
const stepControlSelector = [
|
|
223
|
+
fieldSelector,
|
|
224
|
+
'[role="radio"][data-state="checked"]:not(:disabled)',
|
|
225
|
+
'[role="checkbox"]:not(:disabled)',
|
|
226
|
+
'[role="switch"]:not(:disabled)',
|
|
227
|
+
'[role="combobox"]:not(:disabled)'
|
|
228
|
+
].join(', ')
|
|
229
|
+
|
|
230
|
+
function onOpenAutoFocus(event: Event) {
|
|
231
|
+
const panel = event.target as HTMLElement
|
|
232
|
+
if (props.initialFocus === 'close') return
|
|
233
|
+
|
|
234
|
+
if (props.initialFocus === 'none') {
|
|
235
|
+
event.preventDefault()
|
|
236
|
+
panel.focus()
|
|
237
|
+
return
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
// auto
|
|
241
|
+
const marked = panel.querySelector<HTMLElement>('[autofocus], [data-autofocus]')
|
|
242
|
+
const touch = window.matchMedia('(pointer: coarse)').matches
|
|
243
|
+
const field = touch ? null : panel.querySelector<HTMLElement>(fieldSelector)
|
|
244
|
+
const target = marked ?? field
|
|
245
|
+
if (!target) return
|
|
246
|
+
event.preventDefault()
|
|
247
|
+
target.focus()
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
const portalTarget = () =>
|
|
251
|
+
typeof props.portal === 'string' || props.portal instanceof HTMLElement ? props.portal : undefined
|
|
252
|
+
|
|
253
|
+
// Position, edge border and slide animation for each side. Full-height on the
|
|
254
|
+
// left / right (full width on small screens, up to max-w-md); full-width at
|
|
255
|
+
// the top / bottom, as tall as its content.
|
|
256
|
+
const sides: Record<NonNullable<SlideoverProps['side']>, string> = {
|
|
257
|
+
right: 'inset-y-0 right-0 w-full max-w-md border-l data-[state=open]:animate-slide-in-right data-[state=closed]:animate-slide-out-right',
|
|
258
|
+
left: 'inset-y-0 left-0 w-full max-w-md border-r data-[state=open]:animate-slide-in-left data-[state=closed]:animate-slide-out-left',
|
|
259
|
+
top: 'inset-x-0 top-0 max-h-full border-b data-[state=open]:animate-slide-in-top data-[state=closed]:animate-slide-out-top',
|
|
260
|
+
bottom: 'inset-x-0 bottom-0 max-h-full border-t data-[state=open]:animate-slide-in-bottom data-[state=closed]:animate-slide-out-bottom'
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
const panel = [
|
|
264
|
+
'fixed z-50 flex flex-col bg-white text-black border-black/15 shadow-xl outline-none',
|
|
265
|
+
// Reduced motion: fade instead of sliding.
|
|
266
|
+
'motion-reduce:data-[state=open]:animate-fade-in motion-reduce:data-[state=closed]:animate-fade-out'
|
|
267
|
+
]
|
|
268
|
+
</script>
|
|
269
|
+
|
|
270
|
+
<template>
|
|
271
|
+
<DialogRoot :open="isOpen" :modal="modal" @update:open="setOpen">
|
|
272
|
+
<DialogTrigger v-if="$slots.default" as-child>
|
|
273
|
+
<slot />
|
|
274
|
+
</DialogTrigger>
|
|
275
|
+
|
|
276
|
+
<DialogPortal :disabled="portal === false" :to="portalTarget()">
|
|
277
|
+
<DialogOverlay
|
|
278
|
+
v-if="overlay"
|
|
279
|
+
:class="cn(
|
|
280
|
+
'fixed inset-0 z-50 bg-black/40 data-[state=open]:animate-fade-in data-[state=closed]:animate-fade-out',
|
|
281
|
+
ui?.overlay
|
|
282
|
+
)"
|
|
283
|
+
/>
|
|
284
|
+
|
|
285
|
+
<DialogContent
|
|
286
|
+
v-bind="content"
|
|
287
|
+
:class="cn(panel, sides[side], ui?.content)"
|
|
288
|
+
@escape-key-down="preventDismiss"
|
|
289
|
+
@interact-outside="preventDismiss"
|
|
290
|
+
@open-auto-focus="onOpenAutoFocus"
|
|
291
|
+
>
|
|
292
|
+
<slot name="content" :close="closePanel">
|
|
293
|
+
<header
|
|
294
|
+
v-if="title || description || close || steps || $slots.header || $slots.title"
|
|
295
|
+
:class="cn('flex flex-col gap-4 border-b border-black/15 px-6 py-4', ui?.header)"
|
|
296
|
+
>
|
|
297
|
+
<Progress v-if="steps" :label="title ?? 'Steps'" segments :value="step + 1" :max="stepCount" />
|
|
298
|
+
<div class="flex items-start gap-4">
|
|
299
|
+
<slot name="header" :close="closePanel">
|
|
300
|
+
<div class="flex min-w-0 flex-1 flex-col gap-1">
|
|
301
|
+
<DialogTitle :class="title || $slots.title ? cn('text-lg', ui?.title) : 'sr-only'">
|
|
302
|
+
<slot name="title">{{ title }}</slot>
|
|
303
|
+
</DialogTitle>
|
|
304
|
+
<!-- The step is part of the description, so it's read out with
|
|
305
|
+
the title when the panel opens. -->
|
|
306
|
+
<DialogDescription
|
|
307
|
+
v-if="description || $slots.description || steps"
|
|
308
|
+
as="div"
|
|
309
|
+
class="flex flex-col gap-1 text-sm text-black/65"
|
|
310
|
+
>
|
|
311
|
+
<p v-if="description || $slots.description"><slot name="description">{{ description }}</slot></p>
|
|
312
|
+
<p v-if="steps" :id="stepLabelId">
|
|
313
|
+
Step {{ step + 1 }} of {{ stepCount }}: <span class="text-black">{{ steps[step] }}</span>
|
|
314
|
+
</p>
|
|
315
|
+
</DialogDescription>
|
|
316
|
+
<p v-if="steps" aria-live="polite" class="sr-only">{{ announcement }}</p>
|
|
317
|
+
</div>
|
|
318
|
+
<!-- A ghost icon Button; the negative margins keep it from making
|
|
319
|
+
the header taller and line its icon up with the panel edge. -->
|
|
320
|
+
<DialogClose v-if="close" as-child>
|
|
321
|
+
<Button variant="ghost" square aria-label="Close" class="-my-1.5 -mr-3 shrink-0">
|
|
322
|
+
<X />
|
|
323
|
+
</Button>
|
|
324
|
+
</DialogClose>
|
|
325
|
+
</slot>
|
|
326
|
+
</div>
|
|
327
|
+
</header>
|
|
328
|
+
|
|
329
|
+
<div
|
|
330
|
+
ref="body"
|
|
331
|
+
:role="steps ? 'group' : undefined"
|
|
332
|
+
:aria-labelledby="steps ? stepLabelId : undefined"
|
|
333
|
+
:class="cn('flex-1 overflow-y-auto px-6 py-4', ui?.body)"
|
|
334
|
+
@keydown.enter="onBodyEnter"
|
|
335
|
+
>
|
|
336
|
+
<slot name="body" :close="closePanel" :step="step" />
|
|
337
|
+
</div>
|
|
338
|
+
|
|
339
|
+
<footer
|
|
340
|
+
v-if="$slots.footer || steps"
|
|
341
|
+
:class="cn('flex justify-end gap-2 border-t border-black/15 px-6 py-4', ui?.footer)"
|
|
342
|
+
>
|
|
343
|
+
<slot name="footer" :close="closePanel">
|
|
344
|
+
<!-- Steps: Cancel or Previous on the left, Next or Finish on the right. -->
|
|
345
|
+
<!-- One button that turns from Previous into Cancel on the first
|
|
346
|
+
step, so keyboard focus stays on it. -->
|
|
347
|
+
<Button
|
|
348
|
+
class="mr-auto"
|
|
349
|
+
:disabled="step > 0 && nextStatus === 'loading'"
|
|
350
|
+
@click="step === 0 ? closePanel() : goTo(step - 1)"
|
|
351
|
+
>
|
|
352
|
+
<template v-if="step > 0" #leading><ChevronLeft /></template>
|
|
353
|
+
{{ step === 0 ? 'Cancel' : 'Previous' }}
|
|
354
|
+
</Button>
|
|
355
|
+
<Button variant="primary" :status="nextStatus" @click="next">
|
|
356
|
+
{{ isLastStep ? finishLabel : 'Next' }}
|
|
357
|
+
<template v-if="!isLastStep" #trailing><ChevronRight /></template>
|
|
358
|
+
</Button>
|
|
359
|
+
</slot>
|
|
360
|
+
</footer>
|
|
361
|
+
</slot>
|
|
362
|
+
</DialogContent>
|
|
363
|
+
</DialogPortal>
|
|
364
|
+
</DialogRoot>
|
|
365
|
+
</template>
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from "@storybook/vue3-vite";
|
|
2
|
+
import { onBeforeUnmount, ref } from "vue";
|
|
3
|
+
import Spinner from "./Spinner.vue";
|
|
4
|
+
|
|
5
|
+
const meta = {
|
|
6
|
+
title: "Components/Element/Spinner",
|
|
7
|
+
component: Spinner,
|
|
8
|
+
tags: ["autodocs"],
|
|
9
|
+
argTypes: {
|
|
10
|
+
value: { control: { type: "range", min: 0, max: 100, step: 1 } },
|
|
11
|
+
size: { options: ["sm", "md", "lg"], control: { type: "inline-radio" } },
|
|
12
|
+
},
|
|
13
|
+
args: { size: "md", label: "Loading", showValue: false },
|
|
14
|
+
render: (args) => ({
|
|
15
|
+
components: { Spinner },
|
|
16
|
+
setup: () => ({ args }),
|
|
17
|
+
template: '<Spinner v-bind="args" class="text-primary" />',
|
|
18
|
+
}),
|
|
19
|
+
} satisfies Meta<typeof Spinner>;
|
|
20
|
+
|
|
21
|
+
export default meta;
|
|
22
|
+
type Story = StoryObj<typeof meta>;
|
|
23
|
+
|
|
24
|
+
/** No value: spins continuously, for waits of unknown length. */
|
|
25
|
+
export const Continuous: Story = {};
|
|
26
|
+
|
|
27
|
+
/** With a value: use the slider in Controls to change it. */
|
|
28
|
+
export const WithValue: Story = { args: { value: 40 } };
|
|
29
|
+
|
|
30
|
+
export const WithPercentage: Story = { args: { value: 65, size: "lg", showValue: true } };
|
|
31
|
+
|
|
32
|
+
/** Counts from 0 to 100 and starts again, to show the fill animation. */
|
|
33
|
+
export const Filling: Story = {
|
|
34
|
+
args: { size: "lg", showValue: true, label: "Uploading report" },
|
|
35
|
+
render: (args) => ({
|
|
36
|
+
components: { Spinner },
|
|
37
|
+
setup() {
|
|
38
|
+
const value = ref(0);
|
|
39
|
+
const timer = setInterval(() => {
|
|
40
|
+
value.value = value.value >= 100 ? 0 : value.value + 5;
|
|
41
|
+
}, 300);
|
|
42
|
+
onBeforeUnmount(() => clearInterval(timer));
|
|
43
|
+
return { args, value };
|
|
44
|
+
},
|
|
45
|
+
template: '<Spinner v-bind="args" :value="value" class="text-primary" />',
|
|
46
|
+
}),
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export const Sizes: Story = {
|
|
50
|
+
render: () => ({
|
|
51
|
+
components: { Spinner },
|
|
52
|
+
template: `
|
|
53
|
+
<div class="flex items-center gap-6 text-primary">
|
|
54
|
+
<Spinner size="sm" />
|
|
55
|
+
<Spinner size="md" />
|
|
56
|
+
<Spinner size="lg" />
|
|
57
|
+
<Spinner size="sm" :value="60" />
|
|
58
|
+
<Spinner size="md" :value="60" />
|
|
59
|
+
<Spinner size="lg" :value="60" show-value />
|
|
60
|
+
</div>`,
|
|
61
|
+
}),
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
/** It takes the surrounding text colour, like an icon. */
|
|
65
|
+
export const Colours: Story = {
|
|
66
|
+
render: () => ({
|
|
67
|
+
components: { Spinner },
|
|
68
|
+
template: `
|
|
69
|
+
<div class="flex items-center gap-6">
|
|
70
|
+
<Spinner class="text-primary" :value="70" />
|
|
71
|
+
<Spinner class="text-green" :value="70" />
|
|
72
|
+
<Spinner class="text-red" :value="70" />
|
|
73
|
+
<Spinner class="text-black" />
|
|
74
|
+
<span class="inline-flex rounded bg-primary p-2 text-white">
|
|
75
|
+
<Spinner />
|
|
76
|
+
</span>
|
|
77
|
+
</div>`,
|
|
78
|
+
}),
|
|
79
|
+
};
|