@thekestongroup/ui 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (207) hide show
  1. package/README.md +90 -32
  2. package/dist/components/Age/Age.vue.d.ts +19 -0
  3. package/dist/components/AppShell/AppShell.vue.d.ts +108 -0
  4. package/dist/components/Avatar/Avatar.vue.d.ts +34 -0
  5. package/dist/components/AvatarGroup/AvatarGroup.vue.d.ts +25 -0
  6. package/dist/components/Badge/Badge.vue.d.ts +41 -0
  7. package/dist/components/Breadcrumb/Breadcrumb.vue.d.ts +39 -0
  8. package/dist/components/Button/Button.vue.d.ts +69 -0
  9. package/dist/components/Calendar/Calendar.vue.d.ts +34 -0
  10. package/dist/components/Card/Card.vue.d.ts +56 -0
  11. package/dist/components/Checkbox/Checkbox.vue.d.ts +40 -0
  12. package/dist/components/Checklist/Checklist.vue.d.ts +18 -0
  13. package/dist/components/Chip/Chip.vue.d.ts +44 -0
  14. package/dist/components/Divider/Divider.vue.d.ts +36 -0
  15. package/dist/components/{ToastItem.vue.d.ts → FormField/FieldMessage.vue.d.ts} +10 -2
  16. package/dist/components/FormField/FormField.vue.d.ts +61 -0
  17. package/dist/components/Header/Header.vue.d.ts +104 -0
  18. package/dist/components/InfoTip/InfoTip.vue.d.ts +20 -0
  19. package/dist/components/Input/Input.vue.d.ts +56 -0
  20. package/dist/components/InputCode/InputCode.vue.d.ts +53 -0
  21. package/dist/components/InputDate/InputDate.vue.d.ts +49 -0
  22. package/dist/components/InputNumber/InputNumber.vue.d.ts +44 -0
  23. package/dist/components/InputPassword/InputPassword.vue.d.ts +51 -0
  24. package/dist/components/InputRichText/InputRichText.vue.d.ts +44 -0
  25. package/dist/components/Link/Link.vue.d.ts +39 -0
  26. package/dist/components/Notification/Notification.vue.d.ts +62 -0
  27. package/dist/components/Notification/NotificationPane.vue.d.ts +38 -0
  28. package/dist/components/Notification/Toaster.vue.d.ts +51 -0
  29. package/dist/components/Notification/notification.samples.d.ts +3 -0
  30. package/dist/components/Notification/notifications.d.ts +115 -0
  31. package/dist/components/PageHeader/PageHeader.vue.d.ts +43 -0
  32. package/dist/components/Popover/Popover.vue.d.ts +83 -0
  33. package/dist/components/Popover/popover.d.ts +16 -0
  34. package/dist/components/Progress/Progress.vue.d.ts +26 -0
  35. package/dist/components/RadioGroup/RadioGroup.vue.d.ts +45 -0
  36. package/dist/components/RelativeTime/RelativeTime.vue.d.ts +22 -0
  37. package/dist/components/Select/Select.vue.d.ts +110 -0
  38. package/dist/components/Sidebar/Sidebar.vue.d.ts +106 -0
  39. package/dist/components/Sidebar/sidebar.d.ts +10 -0
  40. package/dist/components/Slideover/Slideover.vue.d.ts +125 -0
  41. package/dist/components/Spinner/Spinner.vue.d.ts +30 -0
  42. package/dist/components/StatTile/StatTile.vue.d.ts +46 -0
  43. package/dist/components/SummaryList/SummaryList.vue.d.ts +62 -0
  44. package/dist/components/Switch/Switch.vue.d.ts +39 -0
  45. package/dist/components/Table/Table.vue.d.ts +82 -0
  46. package/dist/components/Table/table.d.ts +36 -0
  47. package/dist/components/Tooltip/Tooltip.vue.d.ts +46 -0
  48. package/dist/index.d.ts +89 -25
  49. package/dist/keston-ui.js +4963 -14785
  50. package/dist/lib/cn.d.ts +4 -0
  51. package/dist/lib/dates.d.ts +27 -0
  52. package/dist/lib/initials.d.ts +2 -0
  53. package/dist/lib/parseDate.d.ts +44 -0
  54. package/dist/lib/useNow.d.ts +3 -0
  55. package/package.json +53 -24
  56. package/src/components/.gitkeep +0 -0
  57. package/src/components/Age/Age.stories.ts +24 -0
  58. package/src/components/Age/Age.vue +56 -0
  59. package/src/components/AppShell/AppShell.stories.ts +124 -0
  60. package/src/components/AppShell/AppShell.vue +212 -0
  61. package/src/components/Avatar/Avatar.stories.ts +56 -0
  62. package/src/components/Avatar/Avatar.vue +118 -0
  63. package/src/components/AvatarGroup/AvatarGroup.stories.ts +47 -0
  64. package/src/components/AvatarGroup/AvatarGroup.vue +97 -0
  65. package/src/components/Badge/Badge.stories.ts +92 -0
  66. package/src/components/Badge/Badge.vue +67 -0
  67. package/src/components/Breadcrumb/Breadcrumb.stories.ts +58 -0
  68. package/src/components/Breadcrumb/Breadcrumb.vue +109 -0
  69. package/src/components/Button/Button.mdx +79 -0
  70. package/src/components/Button/Button.stories.ts +207 -0
  71. package/src/components/Button/Button.vue +266 -0
  72. package/src/components/Calendar/Calendar.stories.ts +51 -0
  73. package/src/components/Calendar/Calendar.vue +364 -0
  74. package/src/components/Card/Card.stories.ts +109 -0
  75. package/src/components/Card/Card.vue +115 -0
  76. package/src/components/Checkbox/Checkbox.stories.ts +102 -0
  77. package/src/components/Checkbox/Checkbox.vue +102 -0
  78. package/src/components/Checklist/Checklist.stories.ts +67 -0
  79. package/src/components/Checklist/Checklist.vue +38 -0
  80. package/src/components/Chip/Chip.stories.ts +71 -0
  81. package/src/components/Chip/Chip.vue +86 -0
  82. package/src/components/Divider/Divider.stories.ts +57 -0
  83. package/src/components/Divider/Divider.vue +58 -0
  84. package/src/components/FormField/FieldMessage.vue +81 -0
  85. package/src/components/FormField/FormField.stories.ts +55 -0
  86. package/src/components/FormField/FormField.vue +160 -0
  87. package/src/components/Header/Header.stories.ts +168 -0
  88. package/src/components/Header/Header.vue +232 -0
  89. package/src/components/InfoTip/InfoTip.stories.ts +63 -0
  90. package/src/components/InfoTip/InfoTip.vue +50 -0
  91. package/src/components/Input/Input.stories.ts +206 -0
  92. package/src/components/Input/Input.vue +90 -0
  93. package/src/components/InputCode/InputCode.stories.ts +85 -0
  94. package/src/components/InputCode/InputCode.vue +145 -0
  95. package/src/components/InputDate/InputDate.stories.ts +58 -0
  96. package/src/components/InputDate/InputDate.vue +258 -0
  97. package/src/components/InputNumber/InputNumber.stories.ts +63 -0
  98. package/src/components/InputNumber/InputNumber.vue +109 -0
  99. package/src/components/InputPassword/InputPassword.stories.ts +105 -0
  100. package/src/components/InputPassword/InputPassword.vue +132 -0
  101. package/src/components/InputRichText/InputRichText.stories.ts +100 -0
  102. package/src/components/InputRichText/InputRichText.vue +194 -0
  103. package/src/components/Link/Link.stories.ts +73 -0
  104. package/src/components/Link/Link.vue +56 -0
  105. package/src/components/Notification/Notification.stories.ts +196 -0
  106. package/src/components/Notification/Notification.vue +136 -0
  107. package/src/components/Notification/NotificationPane.vue +187 -0
  108. package/src/components/Notification/Toaster.vue +446 -0
  109. package/src/components/Notification/notification.samples.ts +45 -0
  110. package/src/components/Notification/notifications.test.ts +99 -0
  111. package/src/components/Notification/notifications.ts +172 -0
  112. package/src/components/PageHeader/PageHeader.stories.ts +79 -0
  113. package/src/components/PageHeader/PageHeader.vue +66 -0
  114. package/src/components/Popover/Popover.stories.ts +135 -0
  115. package/src/components/Popover/Popover.vue +192 -0
  116. package/src/components/Popover/popover.ts +20 -0
  117. package/src/components/Progress/Progress.stories.ts +74 -0
  118. package/src/components/Progress/Progress.vue +75 -0
  119. package/src/components/RadioGroup/RadioGroup.stories.ts +90 -0
  120. package/src/components/RadioGroup/RadioGroup.vue +132 -0
  121. package/src/components/RelativeTime/RelativeTime.stories.ts +74 -0
  122. package/src/components/RelativeTime/RelativeTime.vue +51 -0
  123. package/src/components/Select/Select.mdx +202 -0
  124. package/src/components/Select/Select.stories.ts +223 -0
  125. package/src/components/Select/Select.vue +630 -0
  126. package/src/components/Sidebar/Sidebar.stories.ts +192 -0
  127. package/src/components/Sidebar/Sidebar.vue +382 -0
  128. package/src/components/Sidebar/sidebar.ts +20 -0
  129. package/src/components/Slideover/Slideover.stories.ts +225 -0
  130. package/src/components/Slideover/Slideover.vue +365 -0
  131. package/src/components/Spinner/Spinner.stories.ts +79 -0
  132. package/src/components/Spinner/Spinner.vue +97 -0
  133. package/src/components/StatTile/StatTile.stories.ts +75 -0
  134. package/src/components/StatTile/StatTile.vue +89 -0
  135. package/src/components/SummaryList/SummaryList.stories.ts +103 -0
  136. package/src/components/SummaryList/SummaryList.vue +127 -0
  137. package/src/components/Switch/Switch.stories.ts +100 -0
  138. package/src/components/Switch/Switch.vue +96 -0
  139. package/src/components/Table/Table.stories.ts +206 -0
  140. package/src/components/Table/Table.vue +220 -0
  141. package/src/components/Table/table.test.ts +65 -0
  142. package/src/components/Table/table.ts +70 -0
  143. package/src/components/Tooltip/Tooltip.stories.ts +57 -0
  144. package/src/components/Tooltip/Tooltip.vue +86 -0
  145. package/src/examples/AppPages.stories.ts +500 -0
  146. package/src/examples/FormLayout.stories.ts +185 -0
  147. package/src/examples/KestonIdPages.stories.ts +415 -0
  148. package/src/examples/SchoolPages.stories.ts +665 -0
  149. package/src/index.ts +114 -36
  150. package/src/lib/cn.ts +4 -0
  151. package/src/lib/dates.test.ts +68 -0
  152. package/src/lib/dates.ts +86 -0
  153. package/src/lib/initials.ts +8 -0
  154. package/src/lib/parseDate.test.ts +331 -0
  155. package/src/lib/parseDate.ts +561 -0
  156. package/src/lib/useNow.ts +20 -0
  157. package/src/styles/theme.css +101 -0
  158. package/dist/components/AppLauncher.vue.d.ts +0 -10
  159. package/dist/components/Avatar.vue.d.ts +0 -16
  160. package/dist/components/Button.vue.d.ts +0 -27
  161. package/dist/components/Checkbox.vue.d.ts +0 -18
  162. package/dist/components/CloseButton.vue.d.ts +0 -6
  163. package/dist/components/Dialog.vue.d.ts +0 -23
  164. package/dist/components/Drawer.vue.d.ts +0 -34
  165. package/dist/components/DropdownMenu.vue.d.ts +0 -21
  166. package/dist/components/DropdownMenuItem.vue.d.ts +0 -19
  167. package/dist/components/DropdownMenuSeparator.vue.d.ts +0 -6
  168. package/dist/components/Input.vue.d.ts +0 -14
  169. package/dist/components/Label.vue.d.ts +0 -16
  170. package/dist/components/NotificationsMenu.vue.d.ts +0 -3
  171. package/dist/components/Popover.vue.d.ts +0 -23
  172. package/dist/components/ProfileSwitcher.vue.d.ts +0 -24
  173. package/dist/components/Select.vue.d.ts +0 -28
  174. package/dist/components/Separator.vue.d.ts +0 -11
  175. package/dist/components/ToastRenderer.vue.d.ts +0 -3
  176. package/dist/components/Toaster.vue.d.ts +0 -3
  177. package/dist/components/Tooltip.vue.d.ts +0 -23
  178. package/dist/components/TopBar.vue.d.ts +0 -34
  179. package/dist/favicon-old.svg +0 -1
  180. package/dist/favicon.svg +0 -1
  181. package/dist/keston-ui.cjs +0 -15
  182. package/dist/lib/toast.d.ts +0 -29
  183. package/dist/lib/types.d.ts +0 -5
  184. package/src/components/AppLauncher.vue +0 -63
  185. package/src/components/Avatar.vue +0 -51
  186. package/src/components/Button.vue +0 -54
  187. package/src/components/Checkbox.vue +0 -47
  188. package/src/components/CloseButton.vue +0 -24
  189. package/src/components/Dialog.vue +0 -65
  190. package/src/components/Drawer.vue +0 -202
  191. package/src/components/DropdownMenu.vue +0 -41
  192. package/src/components/DropdownMenuItem.vue +0 -28
  193. package/src/components/DropdownMenuSeparator.vue +0 -12
  194. package/src/components/Input.vue +0 -21
  195. package/src/components/Label.vue +0 -15
  196. package/src/components/NotificationsMenu.vue +0 -115
  197. package/src/components/Popover.vue +0 -46
  198. package/src/components/ProfileSwitcher.vue +0 -113
  199. package/src/components/Select.vue +0 -97
  200. package/src/components/Separator.vue +0 -30
  201. package/src/components/ToastItem.vue +0 -158
  202. package/src/components/ToastRenderer.vue +0 -113
  203. package/src/components/Toaster.vue +0 -11
  204. package/src/components/Tooltip.vue +0 -48
  205. package/src/components/TopBar.vue +0 -52
  206. package/src/lib/toast.ts +0 -95
  207. package/src/lib/types.ts +0 -5
@@ -0,0 +1,79 @@
1
+ import { Canvas, Controls, Meta, Primary } from '@storybook/addon-docs/blocks'
2
+ import * as ButtonStories from './Button.stories'
3
+
4
+ <Meta of={ButtonStories} />
5
+
6
+ # Button
7
+
8
+ Starts an action: saving, cancelling, opening a panel, deleting. For going to another page, use a link (or `as-child` with a router link). The full platform-neutral spec is in `specs/button.md`; the values here are measured from the rendered component.
9
+
10
+ <Primary />
11
+
12
+ <Controls />
13
+
14
+ ## Variants
15
+
16
+ <Canvas of={ButtonStories.AllVariants} />
17
+
18
+ | Variant | Background | Text | Border | Use for |
19
+ |---|---|---|---|---|
20
+ | primary | primary `#023750` | white `#FAFAFA` | black 15% | The main action, one per area: Save, Continue |
21
+ | basic (default) | white `#FAFAFA` | black `#050505` | black 15% | Most actions: Cancel, Export |
22
+ | ghost | none | black `#050505` | transparent | Low emphasis: toolbars, icon buttons, × on panels |
23
+ | danger | red `#D2042D` | white `#FAFAFA` | black 15% | Destructive actions: Delete |
24
+
25
+ ## Sizes
26
+
27
+ <Canvas of={ButtonStories.WithIconButtons} />
28
+
29
+ Every size has a **1px border** and **4px radius** (`rounded`). Height is padding + one line of text + border. Icons are Lucide at a 2px stroke.
30
+
31
+ | Size | Height | Padding (y / x) | Gap | Icon | Icon-only (`square`) |
32
+ |---|---|---|---|---|---|
33
+ | `sm` | **26px** | 4px / 8px | 4px | 14px | 26 × 26px |
34
+ | `md` (default) | **38px** | 8px / 16px | 8px | 16px | 38 × 38px |
35
+ | `lg` | **50px** | 12px / 24px | 12px | 20px | 50 × 50px |
36
+
37
+ In an icon-only button the icon is centred, with 5 / 10 / 14px of space on every side inside the border.
38
+
39
+ ## Typography
40
+
41
+ **Lato**, regular weight, sentence case, no letter spacing. Labels never wrap.
42
+
43
+ | Size | Font size | Line height | Weight | Tailwind |
44
+ |---|---|---|---|---|
45
+ | `sm` | **12px** | 16px | 400 (regular) | `text-xs` |
46
+ | `md` | **14px** | 20px | 400 (regular) | `text-sm` |
47
+ | `lg` | **16px** | 24px | 400 (regular) | `text-base` |
48
+
49
+ Status text (`loadingText`, `successText`, `errorText`) uses the same style, with an 8px gap to its icon at every size.
50
+
51
+ ## States
52
+
53
+ <Canvas of={ButtonStories.Disabled} />
54
+
55
+ | State | Appearance |
56
+ |---|---|
57
+ | Hovered | Filled variants: 90% brightness (white becomes about `#E1E1E1`). Ghost: black 10% fill. 150ms ease-in-out. |
58
+ | Pressed | Filled variants: 80% brightness. Ghost: black 15% fill. |
59
+ | Focused | 2px outline in focus `#007FC9`, 1px outside the border. Keyboard focus only. |
60
+ | Disabled | 40% opacity, not-allowed cursor, no hover or press. |
61
+ | Loading | Spinner (icon-sized) and optional text in place of the content. Stays focusable; clicks are blocked. |
62
+ | Success / error | Green / red background with ✓ / × and optional text, for `statusDuration` (2s), then back to idle. |
63
+
64
+ Click the button below to see loading, then success or error:
65
+
66
+ <Canvas of={ButtonStories.StatusDemo} />
67
+
68
+ ## Layout
69
+
70
+ - Buttons in a row sit 8px apart (`gap-2`), with the main action last (right): Cancel, then Save.
71
+ - `md` is 38px tall. On touch-first screens use `lg` (50px), or leave space around smaller buttons so the tap area reaches 44px.
72
+ - Ghost icon buttons at the edge of a bar use a negative margin, so their icon lines up with the bar's padding (see Header and Slideover).
73
+
74
+ ## Accessibility
75
+
76
+ - A native `<button>` (`type="button"` by default): focus, Enter and Space work without extra code.
77
+ - Icon-only buttons need an `aria-label`. If the button shows text, the label must include it.
78
+ - While busy the button is `aria-disabled` (and `aria-busy` while loading) but stays focusable. The status is announced through a live region.
79
+ - Contrast: basic 19.5:1, primary 12.1:1, danger 5.3:1, success status 5.3:1, ghost 19.5:1 on white and 15.6:1 on the page background. All meet WCAG AA. The focus ring is 4.1:1 against white (the minimum is 3:1).
@@ -0,0 +1,207 @@
1
+ import type { Meta, StoryObj } from "@storybook/vue3-vite";
2
+ import {
3
+ ArrowLeft,
4
+ ArrowRight,
5
+ Check,
6
+ ChevronDown,
7
+ Copy,
8
+ Download,
9
+ Pencil,
10
+ Plus,
11
+ RotateCcw,
12
+ Save,
13
+ Search,
14
+ Star,
15
+ Trash2,
16
+ X,
17
+ } from "@lucide/vue";
18
+ import { computed, ref } from "vue";
19
+ import Button, { type ButtonProps, type ButtonStatus } from "./Button.vue";
20
+
21
+ // Icons offered in the Controls panel. Add any Lucide icon here.
22
+ const icons = {
23
+ None: null,
24
+ Star,
25
+ Plus,
26
+ Check,
27
+ X,
28
+ Pencil,
29
+ Trash2,
30
+ Copy,
31
+ Save,
32
+ Download,
33
+ Search,
34
+ RotateCcw,
35
+ ArrowLeft,
36
+ ArrowRight,
37
+ ChevronDown,
38
+ };
39
+ type IconName = keyof typeof icons;
40
+
41
+ // Story-only controls on top of the real props.
42
+ type ButtonStoryArgs = ButtonProps & {
43
+ label: string;
44
+ leadingIcon: IconName;
45
+ trailingIcon: IconName;
46
+ };
47
+
48
+ const iconControl = {
49
+ options: Object.keys(icons),
50
+ control: { type: "select" },
51
+ table: { category: "Content" },
52
+ } as const;
53
+
54
+ // Splits the story-only args from the real props and resolves the icons.
55
+ function useStoryButton(args: ButtonStoryArgs) {
56
+ const buttonProps = computed(() => {
57
+ const {
58
+ label: _label,
59
+ leadingIcon: _leading,
60
+ trailingIcon: _trailing,
61
+ ...rest
62
+ } = args;
63
+ return rest;
64
+ });
65
+ const leading = computed(() => icons[args.leadingIcon]);
66
+ const trailing = computed(() => icons[args.trailingIcon]);
67
+ return { args, buttonProps, leading, trailing };
68
+ }
69
+
70
+ const buttonContent = `
71
+ <template v-if="leading" #leading><component :is="leading" /></template>
72
+ {{ args.label }}
73
+ <template v-if="trailing" #trailing><component :is="trailing" /></template>`;
74
+
75
+ const meta = {
76
+ title: "Components/Element/Button",
77
+ component: Button,
78
+ // The docs page is Button.mdx (sizes, typography, states), not autodocs.
79
+ argTypes: {
80
+ label: { control: "text", table: { category: "Content" } },
81
+ leadingIcon: iconControl,
82
+ trailingIcon: iconControl,
83
+ status: {
84
+ options: ["idle", "loading", "success", "error"],
85
+ control: { type: "inline-radio" },
86
+ },
87
+ },
88
+ args: {
89
+ label: "Button",
90
+ leadingIcon: "None",
91
+ trailingIcon: "None",
92
+ variant: "basic",
93
+ size: "md",
94
+ disabled: false,
95
+ square: false,
96
+ status: "idle",
97
+ },
98
+ render: (args) => ({
99
+ components: { Button },
100
+ setup: () => useStoryButton(args),
101
+ template: `<Button v-bind="buttonProps">${buttonContent}</Button>`,
102
+ }),
103
+ } satisfies Meta<ButtonStoryArgs>;
104
+
105
+ export default meta;
106
+ type Story = StoryObj<typeof meta>;
107
+
108
+ /** Playground: use the controls below. */
109
+ export const Default: Story = {};
110
+
111
+ export const Primary: Story = { args: { variant: "primary" } };
112
+
113
+ /** Low-emphasis actions: toolbars, icon buttons, × on panels. */
114
+ export const Ghost: Story = { args: { variant: "ghost", label: "Export", leadingIcon: "Download" } };
115
+
116
+ /** Every variant side by side, in the order of emphasis. */
117
+ export const AllVariants: Story = {
118
+ render: () => ({
119
+ components: { Button },
120
+ template: `
121
+ <div class="flex flex-wrap items-center gap-2">
122
+ <Button variant="primary">Primary</Button>
123
+ <Button variant="basic">Basic</Button>
124
+ <Button variant="ghost">Ghost</Button>
125
+ <Button variant="danger">Danger</Button>
126
+ </div>`,
127
+ }),
128
+ };
129
+
130
+ /**
131
+ * Text and icon-only (square) buttons side by side, at each size. Icon buttons
132
+ * are exactly as tall as the text buttons next to them, and just as wide.
133
+ */
134
+ export const WithIconButtons: Story = {
135
+ render: () => ({
136
+ components: { Button, Save, Pencil, Trash2, Copy, Plus },
137
+ template: `
138
+ <div class="flex flex-col gap-4">
139
+ <div v-for="size in ['sm', 'md', 'lg']" :key="size" class="flex items-center gap-2">
140
+ <Button variant="primary" :size="size"><template #leading><Save /></template>Save</Button>
141
+ <Button variant="ghost" :size="size">Cancel</Button>
142
+ <Button variant="ghost" :size="size" square aria-label="Edit"><Pencil /></Button>
143
+ <Button :size="size" square aria-label="Copy"><Copy /></Button>
144
+ <Button variant="primary" :size="size" square aria-label="Add"><Plus /></Button>
145
+ <Button variant="danger" :size="size" square aria-label="Delete"><Trash2 /></Button>
146
+ </div>
147
+ </div>`,
148
+ }),
149
+ };
150
+
151
+ export const Danger: Story = {
152
+ args: { variant: "danger", label: "Delete", leadingIcon: "Trash2" },
153
+ };
154
+
155
+ export const Previous: Story = {
156
+ args: { label: "Previous", leadingIcon: "ArrowLeft" },
157
+ };
158
+
159
+ export const Next: Story = {
160
+ args: { label: "Next", trailingIcon: "ArrowRight" },
161
+ };
162
+
163
+ export const Disabled: Story = { args: { disabled: true } };
164
+
165
+ /**
166
+ * Click the button: it loads for a second, then randomly succeeds, fails, or
167
+ * goes straight back to idle. Success and error return to idle on their own
168
+ * after `statusDuration`.
169
+ */
170
+ export const StatusDemo: Story = {
171
+ name: "Status (click me)",
172
+ args: {
173
+ variant: "primary",
174
+ label: "Save",
175
+ leadingIcon: "Save",
176
+ loadingText: "",
177
+ successText: "",
178
+ errorText: "",
179
+ },
180
+ argTypes: { status: { table: { disable: true } } },
181
+ render: (args) => ({
182
+ components: { Button },
183
+ setup() {
184
+ const status = ref<ButtonStatus>("idle");
185
+ const lastResult = ref<ButtonStatus | null>(null);
186
+ const outcomes: ButtonStatus[] = ["success", "error", "idle"];
187
+
188
+ function run() {
189
+ status.value = "loading";
190
+ setTimeout(() => {
191
+ const result = outcomes[Math.floor(Math.random() * outcomes.length)];
192
+ status.value = result;
193
+ lastResult.value = result;
194
+ }, 1000);
195
+ }
196
+
197
+ return { ...useStoryButton(args), status, lastResult, run };
198
+ },
199
+ template: `
200
+ <div class="flex flex-col items-start gap-3">
201
+ <Button v-bind="buttonProps" v-model:status="status" @click="run">${buttonContent}</Button>
202
+ <small class="text-xs text-black/60">
203
+ Last result: {{ lastResult ?? "—" }}
204
+ </small>
205
+ </div>`,
206
+ }),
207
+ };
@@ -0,0 +1,266 @@
1
+ <script setup lang="ts">
2
+ import { computed, nextTick, onBeforeUnmount, ref, watch, type HTMLAttributes } from 'vue'
3
+ import { Primitive, type PrimitiveProps } from 'reka-ui';
4
+ import { Check, X } from '@lucide/vue'
5
+ import { cn } from '../../lib/cn'
6
+ import Spinner from '../Spinner/Spinner.vue'
7
+
8
+ export type ButtonStatus = 'idle' | 'loading' | 'success' | 'error'
9
+
10
+ export interface ButtonProps extends PrimitiveProps {
11
+ /**
12
+ * What the button is for:
13
+ * - primary: the main action (one per area), e.g. Save
14
+ * - basic: other actions, e.g. Cancel, Export
15
+ * - ghost: low-emphasis actions, e.g. toolbar and icon buttons, × on panels
16
+ * - danger: destructive actions, e.g. Delete
17
+ */
18
+ variant?: 'basic' | 'primary' | 'ghost' | 'danger'
19
+ size?: 'sm' | 'md' | 'lg'
20
+ /**
21
+ * Icon-only button: as tall as a normal button of the same size and just as
22
+ * wide, so the icon has equal space on every side. Give it an `aria-label`
23
+ * (e.g. "Close"), as there is no text to name it.
24
+ */
25
+ square?: boolean
26
+ disabled?: boolean
27
+ type?: 'button' | 'submit' | 'reset'
28
+ /**
29
+ * Progress of the action this button starts. The parent sets it; use
30
+ * `v-model:status` so the button can return itself to `idle` after showing
31
+ * success or error. Not supported with `asChild`.
32
+ */
33
+ status?: ButtonStatus
34
+ /** Text shown next to the spinner while loading. Icon only if not set. */
35
+ loadingText?: string
36
+ /** Text shown next to the check on success. Icon only if not set. */
37
+ successText?: string
38
+ /** Text shown next to the cross on error. Icon only if not set. */
39
+ errorText?: string
40
+ /** How long success / error is shown before returning to idle, in ms. */
41
+ statusDuration?: number
42
+ class?: HTMLAttributes['class']
43
+ }
44
+
45
+ const props = withDefaults(defineProps<ButtonProps>(), {
46
+ as: 'button',
47
+ variant: 'basic',
48
+ size: 'md',
49
+ type: 'button',
50
+ status: 'idle',
51
+ statusDuration: 2000
52
+ })
53
+
54
+ const emit = defineEmits<{ 'update:status': [status: ButtonStatus] }>()
55
+
56
+ const busy = computed(() => props.status !== 'idle' && !props.asChild)
57
+
58
+ // ── Status timing ───────────────────────────────────────────────────────────
59
+ // When a status goes away, the colour and width change together, and the
60
+ // text hands over without the old and new text ever overlapping (no ghosting):
61
+ // 0–300ms button colour and width change to the idle ones
62
+ // 0–150ms status text and icon fade out (anchored to the button, so they
63
+ // stay centred while it resizes)
64
+ // 150–300ms the normal label fades in
65
+ // When one status replaces another (spinner → ✓), the new one waits 100ms so
66
+ // the two icons don't overlap.
67
+
68
+ // How long the colour change back to idle takes, in ms.
69
+ const SETTLE_MS = 300
70
+
71
+ // After success / error, ask the parent to go back to idle.
72
+ let resetTimer: ReturnType<typeof setTimeout> | undefined
73
+ // True briefly while fading back to idle, so the colour change is slower
74
+ // than a normal hover.
75
+ const settling = ref(false)
76
+ let settleTimer: ReturnType<typeof setTimeout> | undefined
77
+
78
+ watch(
79
+ () => props.status,
80
+ (status, previous) => {
81
+ clearTimeout(resetTimer)
82
+ clearTimeout(settleTimer)
83
+ settling.value = status === 'idle' && (previous === 'success' || previous === 'error')
84
+ if (settling.value) {
85
+ settleTimer = setTimeout(() => (settling.value = false), SETTLE_MS)
86
+ }
87
+ if (status === 'success' || status === 'error') {
88
+ resetTimer = setTimeout(() => emit('update:status', 'idle'), props.statusDuration)
89
+ }
90
+ },
91
+ { immediate: true }
92
+ )
93
+ onBeforeUnmount(() => {
94
+ clearTimeout(resetTimer)
95
+ clearTimeout(settleTimer)
96
+ })
97
+
98
+ // Block clicks (and form submits) while busy, without using `disabled`,
99
+ // so keyboard focus stays on the button.
100
+ function blockWhileBusy(event: MouseEvent) {
101
+ if (!busy.value) return
102
+ event.preventDefault()
103
+ event.stopImmediatePropagation()
104
+ }
105
+
106
+ // Loading uses the shared Spinner (see template); these are the result icons.
107
+ const statusIcon = { success: Check, error: X } as const
108
+
109
+ const visibleText = computed(() => {
110
+ switch (props.status) {
111
+ case 'loading': return props.loadingText
112
+ case 'success': return props.successText
113
+ case 'error': return props.errorText
114
+ default: return undefined
115
+ }
116
+ })
117
+
118
+ // ── Smooth width ────────────────────────────────────────────────────────────
119
+ // Status text can make the button wider or narrower ("Save" → "Saving…").
120
+ // CSS can't animate an automatic width, so: measure the width before the
121
+ // change, let the new content render, measure again, and animate between the
122
+ // two. The animation leaves no inline width behind, so the button goes back to
123
+ // sizing itself. Skipped with reduced motion.
124
+ const rootRef = ref<{ $el?: unknown }>()
125
+ let widthAnimation: Animation | undefined
126
+
127
+ watch(
128
+ () => [busy.value, props.status, visibleText.value],
129
+ async () => {
130
+ const el = rootRef.value?.$el
131
+ if (!(el instanceof HTMLElement)) return
132
+ // Mid-animation, this is the current animated width.
133
+ const from = el.getBoundingClientRect().width
134
+ await nextTick()
135
+ widthAnimation?.cancel()
136
+ const to = el.getBoundingClientRect().width
137
+ if (Math.abs(to - from) < 0.5 || window.matchMedia('(prefers-reduced-motion: reduce)').matches) return
138
+ // Same length as the colour change (see Status timing).
139
+ widthAnimation = el.animate([{ width: `${from}px` }, { width: `${to}px` }], {
140
+ duration: SETTLE_MS,
141
+ easing: 'cubic-bezier(0, 0, 0.2, 1)' // Tailwind's ease-out
142
+ })
143
+ },
144
+ { flush: 'pre' }
145
+ )
146
+
147
+ // Announced to screen readers; falls back to a generic word if no text is set.
148
+ const announcement = computed(() => {
149
+ if (!busy.value) return ''
150
+ const fallback = { loading: 'Loading', success: 'Done', error: 'Failed' } as const
151
+ return visibleText.value || fallback[props.status as keyof typeof fallback]
152
+ })
153
+
154
+ const base = [
155
+ // overflow-hidden: content briefly wider than the button while its width animates is clipped
156
+ 'relative inline-flex shrink-0 items-center justify-center whitespace-nowrap select-none overflow-hidden',
157
+ 'border border-black/15 cursor-pointer transition',
158
+ 'disabled:cursor-not-allowed disabled:opacity-40',
159
+ 'aria-busy:cursor-progress',
160
+ 'outline-2 outline-offset-1 outline-transparent forced-colors:not-focus-visible:outline-0',
161
+ 'focus-visible:outline-focus'
162
+ ]
163
+
164
+ // Hover / pressed only apply when the button is usable.
165
+ const interactive = 'not-disabled:not-aria-disabled:hover:brightness-90 not-disabled:not-aria-disabled:active:brightness-80'
166
+
167
+ // Ghost has no fill to darken, so hover / press tint it with black instead
168
+ // (10% / 15%, matching the other variants' 90% / 80% brightness). The border
169
+ // stays (transparent) so it lines up with the other variants.
170
+ const ghostInteractive = 'not-disabled:not-aria-disabled:hover:bg-black/10 not-disabled:not-aria-disabled:active:bg-black/15'
171
+
172
+ const variants: Record<NonNullable<ButtonProps['variant']>, string> = {
173
+ basic: `bg-white text-black ${interactive}`,
174
+ primary: `bg-primary text-white ${interactive}`,
175
+ ghost: `bg-transparent text-black border-transparent ${ghostInteractive}`,
176
+ danger: `bg-red text-white ${interactive}`
177
+ }
178
+
179
+ // Applied on top of the variant, so success / error recolour any variant.
180
+ // The colours are the same tokens, rewritten as oklch() so the browser blends
181
+ // them in OKLab rather than RGB when fading back. In RGB, red → navy loses
182
+ // most of its red in the first half, so error looked faster than success.
183
+ const statuses: Record<ButtonStatus, string> = {
184
+ idle: '',
185
+ loading: '',
186
+ success: 'bg-[oklch(from_var(--color-green)_l_c_h)] text-white cursor-default',
187
+ error: 'bg-[oklch(from_var(--color-red)_l_c_h)] text-white cursor-default'
188
+ }
189
+
190
+ // Corners: 4px for small and medium (matching form fields), 6px for large.
191
+ const sizes: Record<NonNullable<ButtonProps['size']>, string> = {
192
+ sm: 'px-2 py-1 text-xs [&_svg]:size-3.5 gap-1 rounded',
193
+ md: 'px-4 py-2 text-sm [&_svg]:size-4 gap-2 rounded',
194
+ lg: 'px-6 py-3 text-base [&_svg]:size-5 gap-3 rounded-md'
195
+ }
196
+
197
+ // Icon-only: the same height as a normal button of that size (padding + one
198
+ // line of text + border: 26 / 38 / 50px), and the same width. The icon is
199
+ // centred, so the space around it is equal on all four sides.
200
+ const squareSizes: Record<NonNullable<ButtonProps['size']>, string> = {
201
+ sm: 'size-6.5 p-0',
202
+ md: 'size-9.5 p-0',
203
+ lg: 'size-12.5 p-0'
204
+ }
205
+ </script>
206
+
207
+ <template>
208
+ <Primitive
209
+ ref="rootRef"
210
+ :as="as"
211
+ :as-child="asChild"
212
+ :type="as === 'button' && !asChild ? type : undefined"
213
+ :disabled="disabled || undefined"
214
+ :aria-disabled="disabled || busy || undefined"
215
+ :aria-busy="(busy && status === 'loading') || undefined"
216
+ :data-status="busy ? status : undefined"
217
+ :class="cn(base, variants[variant], busy && statuses[status], settling && 'duration-300', sizes[size], square && squareSizes[size], props.class)"
218
+ @click.capture="blockWhileBusy"
219
+ >
220
+ <template v-if="asChild">
221
+ <slot />
222
+ </template>
223
+ <!--
224
+ Content and status sit in the same grid cell, so the button is as wide
225
+ as whichever is wider (the width change is animated, see Smooth width).
226
+ A status that is leaving is taken out of the layout (absolute) while it
227
+ fades, so the button can start resizing straight away. It is positioned
228
+ against the button itself (not this wrapper, which snaps to the new
229
+ width), so it stays centred while the button resizes.
230
+ -->
231
+ <span v-else class="inline-grid place-items-center gap-[inherit]">
232
+ <span
233
+ class="col-start-1 row-start-1 inline-flex items-center gap-[inherit] transition-[opacity,visibility]"
234
+ :class="busy ? 'invisible opacity-0 duration-150' : 'delay-150 duration-150'"
235
+ >
236
+ <slot name="leading" />
237
+ <slot />
238
+ <slot name="trailing" />
239
+ </span>
240
+ <Transition
241
+ enter-active-class="transition delay-100 duration-200 ease-out motion-reduce:transition-opacity"
242
+ enter-from-class="opacity-0 scale-50 motion-reduce:scale-100"
243
+ leave-active-class="absolute inset-0 justify-center transition duration-150 ease-out [&_svg]:transition-transform [&_svg]:duration-150 [&_svg]:ease-in"
244
+ leave-to-class="opacity-0 [&_svg]:scale-50 motion-reduce:[&_svg]:scale-100"
245
+ >
246
+ <span
247
+ v-if="busy"
248
+ :key="status"
249
+ aria-hidden="true"
250
+ class="col-start-1 row-start-1 inline-flex items-center gap-2"
251
+ >
252
+ <!--
253
+ The shared Spinner. size-auto lets the button's icon
254
+ size (14 / 16 / 20px by button size) set its size, like an icon.
255
+ The button announces the status itself, so this layer is hidden
256
+ from screen readers.
257
+ -->
258
+ <Spinner v-if="status === 'loading'" class="size-auto" />
259
+ <component :is="statusIcon[status as keyof typeof statusIcon]" v-else />
260
+ <span v-if="visibleText">{{ visibleText }}</span>
261
+ </span>
262
+ </Transition>
263
+ <span class="sr-only" role="status">{{ announcement }}</span>
264
+ </span>
265
+ </Primitive>
266
+ </template>
@@ -0,0 +1,51 @@
1
+ import type { Meta, StoryObj } from "@storybook/vue3-vite";
2
+ import { ref } from "vue";
3
+ import Card from "../Card/Card.vue";
4
+ import Calendar from "./Calendar.vue";
5
+
6
+ const meta = {
7
+ title: "Components/Form/Calendar",
8
+ component: Calendar,
9
+ tags: ["autodocs"],
10
+ args: { locale: "en-GB", disabled: false },
11
+ render: (args) => ({
12
+ components: { Calendar, Card },
13
+ setup: () => ({ args, value: ref<string>() }),
14
+ template: `
15
+ <Card class="w-fit">
16
+ <Calendar v-bind="args" v-model="value" />
17
+ </Card>
18
+ <p class="mt-3 text-sm text-black/65">Chosen: {{ value ?? 'nothing yet' }}</p>`,
19
+ }),
20
+ } satisfies Meta<typeof Calendar>;
21
+
22
+ export default meta;
23
+ type Story = StoryObj<typeof meta>;
24
+
25
+ /**
26
+ * Playground. Press the month or year in the heading to jump; the arrow keys
27
+ * move between days once one has focus.
28
+ */
29
+ export const Default: Story = {};
30
+
31
+ /** Only dates in the autumn term can be chosen. Months and years outside it are greyed out too. */
32
+ export const WithMinAndMax: Story = {
33
+ args: { min: "2026-09-02", max: "2026-12-18" },
34
+ };
35
+
36
+ /** Beside the day's details: choosing an interview day. */
37
+ export const InterviewDay: Story = {
38
+ render: (args) => ({
39
+ components: { Calendar, Card },
40
+ setup: () => ({ args, value: ref("2026-11-18") }),
41
+ template: `
42
+ <div class="flex flex-wrap items-start gap-4">
43
+ <Card class="w-fit"><Calendar v-bind="args" v-model="value" /></Card>
44
+ <Card :title="'Interviews on ' + new Date(value).toLocaleDateString('en-GB', { dateStyle: 'long' })" class="min-w-64 flex-1">
45
+ <p class="text-sm text-black/65">3 interviews booked, 2 slots free.</p>
46
+ </Card>
47
+ </div>`,
48
+ }),
49
+ };
50
+
51
+ export const Disabled: Story = { args: { disabled: true } };