@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,364 @@
1
+ <script setup lang="ts">
2
+ import { computed, ref, shallowRef, watch, type HTMLAttributes } from 'vue'
3
+ import {
4
+ CalendarCell,
5
+ CalendarCellTrigger,
6
+ CalendarGrid,
7
+ CalendarGridBody,
8
+ CalendarGridHead,
9
+ CalendarGridRow,
10
+ CalendarHeadCell,
11
+ CalendarHeader,
12
+ CalendarNext,
13
+ CalendarPrev,
14
+ CalendarRoot
15
+ } from 'reka-ui'
16
+ import {
17
+ CalendarDate,
18
+ getLocalTimeZone,
19
+ isToday,
20
+ parseDate,
21
+ toCalendarDate,
22
+ today,
23
+ type DateValue
24
+ } from '@internationalized/date'
25
+ import { ChevronDown, ChevronLeft, ChevronRight } from '@lucide/vue'
26
+ import { cn } from '../../lib/cn'
27
+ import Button from '../Button/Button.vue'
28
+
29
+ /**
30
+ * A month of days to pick one from, with the month and year in the heading
31
+ * opening grids of months and years. InputDate shows it in a popover; on its
32
+ * own it suits a page where the date is the main thing, e.g. choosing an
33
+ * interview day. It has no frame: put it in a Card.
34
+ */
35
+ export interface CalendarProps {
36
+ /** Earliest allowed date, as `YYYY-MM-DD`. */
37
+ min?: string
38
+ /** Latest allowed date, as `YYYY-MM-DD`. */
39
+ max?: string
40
+ /** Sets the weekday names, month names and the calendar's language. */
41
+ locale?: string
42
+ /** Move focus to the chosen day (or today) when the calendar appears. */
43
+ initialFocus?: boolean
44
+ disabled?: boolean
45
+ class?: HTMLAttributes['class']
46
+ }
47
+
48
+ const props = withDefaults(defineProps<CalendarProps>(), {
49
+ locale: 'en-GB'
50
+ })
51
+
52
+ /** The date as `YYYY-MM-DD`, or undefined when none is chosen. */
53
+ const model = defineModel<string | undefined>()
54
+
55
+ // Reka works with date objects; the component's value is a plain ISO string,
56
+ // like InputDate's.
57
+ function toDate(iso: string | undefined): DateValue | undefined {
58
+ if (!iso) return undefined
59
+ try {
60
+ return parseDate(iso)
61
+ } catch {
62
+ return undefined
63
+ }
64
+ }
65
+
66
+ const dateValue = computed(() => toDate(model.value))
67
+ const minValue = computed(() => toDate(props.min))
68
+ const maxValue = computed(() => toDate(props.max))
69
+
70
+ // Reka passes undefined when the chosen day is pressed again; keep it chosen.
71
+ function setValue(value: DateValue | undefined) {
72
+ if (value) model.value = value.toString()
73
+ }
74
+
75
+ // ── Views ───────────────────────────────────────────────────────────────────
76
+ // The heading's month and year are buttons that act like dropdowns: the month
77
+ // opens a grid of months, the year a grid of years. Picking either goes back
78
+ // to the days.
79
+ // `placeholder` is the month the calendar is showing.
80
+ type View = 'days' | 'months' | 'years'
81
+ const view = ref<View>('days')
82
+ // shallowRef: dates are replaced, never mutated, and a deep ref would strip
83
+ // CalendarDate's private fields from its type.
84
+ const placeholder = shallowRef<CalendarDate>(startingMonth())
85
+
86
+ // Where the calendar opens: the selected date, or today, or (if today is
87
+ // outside min / max) the nearest allowed date, so it never opens on a month
88
+ // where every day is greyed out.
89
+ function startingMonth(): CalendarDate {
90
+ if (dateValue.value) return toCalendarDate(dateValue.value)
91
+ const now = today(getLocalTimeZone())
92
+ if (minValue.value && now.compare(minValue.value) < 0) return toCalendarDate(minValue.value)
93
+ if (maxValue.value && now.compare(maxValue.value) > 0) return toCalendarDate(maxValue.value)
94
+ return now
95
+ }
96
+
97
+ // Follow a date set from elsewhere (e.g. typed into InputDate).
98
+ watch(dateValue, (value) => {
99
+ if (value) placeholder.value = toCalendarDate(value)
100
+ })
101
+
102
+ function onPlaceholderChange(value: DateValue) {
103
+ placeholder.value = toCalendarDate(value)
104
+ }
105
+
106
+ const monthNames = computed(() => {
107
+ const format = new Intl.DateTimeFormat(props.locale, { month: 'short' })
108
+ return Array.from({ length: 12 }, (_, i) => format.format(new Date(2000, i, 1)))
109
+ })
110
+ const monthLongName = computed(() =>
111
+ new Intl.DateTimeFormat(props.locale, { month: 'long' }).format(
112
+ new Date(placeholder.value.year, placeholder.value.month - 1, 1)
113
+ )
114
+ )
115
+
116
+ // Years are shown 12 at a time.
117
+ const yearPageStart = ref(0)
118
+ const years = computed(() => Array.from({ length: 12 }, (_, i) => yearPageStart.value + i))
119
+
120
+ function showMonths() {
121
+ view.value = 'months'
122
+ }
123
+ function showYears() {
124
+ yearPageStart.value = placeholder.value.year - (placeholder.value.year % 12)
125
+ view.value = 'years'
126
+ }
127
+ function pickMonth(month: number) {
128
+ placeholder.value = placeholder.value.set({ month })
129
+ view.value = 'days'
130
+ }
131
+ // Month and year act as separate dropdowns: picking a year keeps the month
132
+ // and goes back to the days. If that month is outside min / max in the new
133
+ // year, move to the nearest allowed month instead.
134
+ function pickYear(year: number) {
135
+ let next = placeholder.value.set({ year })
136
+ const min = minValue.value && toCalendarDate(minValue.value).set({ day: 1 })
137
+ const max = maxValue.value && toCalendarDate(maxValue.value).set({ day: 1 })
138
+ if (min && next.compare(min) < 0) next = next.set({ month: min.month })
139
+ if (max && next.compare(max) > 0) next = next.set({ month: max.month })
140
+ placeholder.value = next
141
+ view.value = 'days'
142
+ }
143
+ // The arrows move by a year in the month view and by 12 years in the year view.
144
+ function page(direction: 1 | -1) {
145
+ if (view.value === 'months') placeholder.value = placeholder.value.add({ years: direction })
146
+ else yearPageStart.value += 12 * direction
147
+ }
148
+
149
+ function monthDisabled(month: number) {
150
+ const start = new CalendarDate(placeholder.value.year, month, 1)
151
+ const end = start.add({ months: 1 }).subtract({ days: 1 })
152
+ return Boolean(
153
+ (minValue.value && end.compare(minValue.value) < 0) ||
154
+ (maxValue.value && start.compare(maxValue.value) > 0)
155
+ )
156
+ }
157
+ function yearDisabled(year: number) {
158
+ return Boolean(
159
+ (minValue.value && year < minValue.value.year) || (maxValue.value && year > maxValue.value.year)
160
+ )
161
+ }
162
+ const pageBackDisabled = computed(() =>
163
+ view.value === 'months'
164
+ ? yearDisabled(placeholder.value.year - 1)
165
+ : yearDisabled(yearPageStart.value - 1)
166
+ )
167
+ const pageForwardDisabled = computed(() =>
168
+ view.value === 'months'
169
+ ? yearDisabled(placeholder.value.year + 1)
170
+ : yearDisabled(yearPageStart.value + 12)
171
+ )
172
+
173
+ const isSelectedMonth = (month: number) =>
174
+ dateValue.value?.year === placeholder.value.year && dateValue.value?.month === month
175
+ const isSelectedYear = (year: number) => dateValue.value?.year === year
176
+
177
+ // Is this month / year the current one? Marks it with aria-current (see todayMark).
178
+ const isCurrentMonth = (month: number) => {
179
+ const now = today(getLocalTimeZone())
180
+ return placeholder.value.year === now.year && month === now.month
181
+ }
182
+ const isCurrentYear = (year: number) => year === today(getLocalTimeZone()).year
183
+
184
+ // "October ▾" / "2026 ▾" in the heading.
185
+ const headingButton = [
186
+ 'inline-flex items-center gap-0.5 rounded px-1.5 py-1 text-sm cursor-pointer transition',
187
+ 'hover:bg-black/10 active:bg-black/15 [&_svg]:size-3.5',
188
+ 'disabled:cursor-not-allowed disabled:hover:bg-transparent',
189
+ 'outline-2 outline-offset-1 outline-transparent focus-visible:outline-focus'
190
+ ]
191
+
192
+ // Today's day, month and year: bold with a small dot underneath. Driven by
193
+ // aria-current="date", which also tells screen readers it is today. The dot
194
+ // uses the text colour, so it turns white on the selected (filled) cell.
195
+ const todayMark = [
196
+ 'relative aria-[current=date]:font-bold',
197
+ 'aria-[current=date]:after:absolute aria-[current=date]:after:left-1/2 aria-[current=date]:after:size-1',
198
+ 'aria-[current=date]:after:-translate-x-1/2 aria-[current=date]:after:rounded-full aria-[current=date]:after:bg-current'
199
+ ]
200
+
201
+ // Month / year cells: 3 columns, sized so the calendar keeps the same width
202
+ // (7 day columns × 32px = 224px) when switching views.
203
+ const pickCell = [
204
+ ...todayMark,
205
+ 'aria-[current=date]:after:bottom-2',
206
+ 'flex h-12 items-center justify-center rounded text-sm tabular-nums cursor-pointer transition',
207
+ 'hover:bg-black/10',
208
+ 'aria-pressed:bg-primary aria-pressed:text-white aria-pressed:hover:bg-primary',
209
+ 'disabled:cursor-not-allowed disabled:text-black/25 disabled:hover:bg-transparent',
210
+ 'outline-2 outline-offset-1 outline-transparent focus-visible:outline-focus'
211
+ ]
212
+
213
+ const day = [
214
+ ...todayMark,
215
+ 'aria-[current=date]:after:bottom-0.5',
216
+ 'flex size-8 items-center justify-center rounded text-sm tabular-nums cursor-pointer transition',
217
+ 'hover:bg-black/10',
218
+ 'data-[outside-view]:text-black/35',
219
+ 'data-[selected]:bg-primary data-[selected]:text-white data-[selected]:hover:bg-primary',
220
+ 'data-[disabled]:cursor-not-allowed data-[disabled]:text-black/25 data-[disabled]:hover:bg-transparent',
221
+ 'data-[unavailable]:line-through',
222
+ 'outline-2 outline-offset-1 outline-transparent focus-visible:outline-focus'
223
+ ]
224
+ </script>
225
+
226
+ <template>
227
+ <CalendarRoot
228
+ v-slot="{ weekDays, grid }"
229
+ :model-value="dateValue"
230
+ :placeholder="placeholder"
231
+ :min-value="minValue"
232
+ :max-value="maxValue"
233
+ :locale="locale"
234
+ :disabled="disabled"
235
+ :initial-focus="initialFocus"
236
+ :week-starts-on="1"
237
+ fixed-weeks
238
+ :class="cn('w-fit text-black', disabled && 'opacity-40', props.class)"
239
+ @update:model-value="setValue"
240
+ @update:placeholder="onPlaceholderChange"
241
+ >
242
+ <CalendarHeader class="flex items-center justify-between gap-1">
243
+ <!-- Days: arrows change month. Months / years: arrows page years. -->
244
+ <CalendarPrev v-if="view === 'days'" as-child>
245
+ <Button variant="ghost" size="sm" square aria-label="Previous month"><ChevronLeft /></Button>
246
+ </CalendarPrev>
247
+ <Button
248
+ v-else
249
+ variant="ghost"
250
+ size="sm"
251
+ square
252
+ :aria-label="view === 'months' ? 'Previous year' : 'Previous years'"
253
+ :disabled="disabled || pageBackDisabled"
254
+ @click="page(-1)"
255
+ >
256
+ <ChevronLeft />
257
+ </Button>
258
+
259
+ <div class="flex items-center">
260
+ <button
261
+ v-if="view === 'days'"
262
+ type="button"
263
+ :class="headingButton"
264
+ aria-label="Choose month"
265
+ :disabled="disabled"
266
+ @click="showMonths"
267
+ >
268
+ {{ monthLongName }} <ChevronDown />
269
+ </button>
270
+ <button
271
+ v-if="view !== 'years'"
272
+ type="button"
273
+ :class="headingButton"
274
+ aria-label="Choose year"
275
+ :disabled="disabled"
276
+ @click="showYears"
277
+ >
278
+ {{ placeholder.year }} <ChevronDown />
279
+ </button>
280
+ <span v-else class="px-1.5 py-1 text-sm tabular-nums">
281
+ {{ years[0] }} – {{ years[years.length - 1] }}
282
+ </span>
283
+ </div>
284
+
285
+ <CalendarNext v-if="view === 'days'" as-child>
286
+ <Button variant="ghost" size="sm" square aria-label="Next month"><ChevronRight /></Button>
287
+ </CalendarNext>
288
+ <Button
289
+ v-else
290
+ variant="ghost"
291
+ size="sm"
292
+ square
293
+ :aria-label="view === 'months' ? 'Next year' : 'Next years'"
294
+ :disabled="disabled || pageForwardDisabled"
295
+ @click="page(1)"
296
+ >
297
+ <ChevronRight />
298
+ </Button>
299
+ </CalendarHeader>
300
+
301
+ <!-- Month picker -->
302
+ <div v-if="view === 'months'" class="mt-3 grid w-56 grid-cols-3 gap-1">
303
+ <button
304
+ v-for="(name, index) in monthNames"
305
+ :key="name"
306
+ type="button"
307
+ :class="pickCell"
308
+ :aria-current="isCurrentMonth(index + 1) ? 'date' : undefined"
309
+ :aria-pressed="isSelectedMonth(index + 1)"
310
+ :disabled="monthDisabled(index + 1)"
311
+ @click="pickMonth(index + 1)"
312
+ >
313
+ {{ name }}
314
+ </button>
315
+ </div>
316
+
317
+ <!-- Year picker -->
318
+ <div v-else-if="view === 'years'" class="mt-3 grid w-56 grid-cols-3 gap-1">
319
+ <button
320
+ v-for="year in years"
321
+ :key="year"
322
+ type="button"
323
+ :class="pickCell"
324
+ :aria-current="isCurrentYear(year) ? 'date' : undefined"
325
+ :aria-pressed="isSelectedYear(year)"
326
+ :disabled="yearDisabled(year)"
327
+ @click="pickYear(year)"
328
+ >
329
+ {{ year }}
330
+ </button>
331
+ </div>
332
+
333
+ <!-- Day grid -->
334
+ <CalendarGrid
335
+ v-for="month in view === 'days' ? grid : []"
336
+ :key="month.value.toString()"
337
+ class="mt-3 border-collapse select-none"
338
+ >
339
+ <CalendarGridHead>
340
+ <CalendarGridRow class="flex">
341
+ <CalendarHeadCell
342
+ v-for="weekDay in weekDays"
343
+ :key="weekDay"
344
+ class="w-8 pb-1 text-xs font-normal text-black/55"
345
+ >
346
+ {{ weekDay }}
347
+ </CalendarHeadCell>
348
+ </CalendarGridRow>
349
+ </CalendarGridHead>
350
+ <CalendarGridBody>
351
+ <CalendarGridRow v-for="(weekDates, index) in month.rows" :key="`week-${index}`" class="flex">
352
+ <CalendarCell v-for="weekDate in weekDates" :key="weekDate.toString()" :date="weekDate">
353
+ <CalendarCellTrigger
354
+ :day="weekDate"
355
+ :month="month.value"
356
+ :aria-current="isToday(weekDate, getLocalTimeZone()) ? 'date' : undefined"
357
+ :class="day"
358
+ />
359
+ </CalendarCell>
360
+ </CalendarGridRow>
361
+ </CalendarGridBody>
362
+ </CalendarGrid>
363
+ </CalendarRoot>
364
+ </template>
@@ -0,0 +1,109 @@
1
+ import type { Meta, StoryObj } from "@storybook/vue3-vite";
2
+ import { Pencil } from "@lucide/vue";
3
+ import Badge from "../Badge/Badge.vue";
4
+ import Button from "../Button/Button.vue";
5
+ import Input from "../Input/Input.vue";
6
+ import Card from "./Card.vue";
7
+
8
+ const meta = {
9
+ title: "Components/Element/Card",
10
+ component: Card,
11
+ tags: ["autodocs"],
12
+ parameters: { backgrounds: { disable: true } },
13
+ argTypes: {
14
+ padding: { options: ["md", "sm", "none"], control: { type: "inline-radio" } },
15
+ headingLevel: { options: [2, 3, 4], control: { type: "inline-radio" } },
16
+ },
17
+ args: {
18
+ title: "Academic year",
19
+ description: "The first and last day students are on roll.",
20
+ padding: "md",
21
+ headingLevel: 2,
22
+ },
23
+ // Cards sit on the grey page background.
24
+ decorators: [() => ({ template: '<div class="bg-background p-6"><div class="max-w-xl"><story /></div></div>' })],
25
+ render: (args) => ({
26
+ components: { Card },
27
+ setup: () => ({ args }),
28
+ template: `<Card v-bind="args"><p class="text-sm">Content goes here.</p></Card>`,
29
+ }),
30
+ } satisfies Meta<typeof Card>;
31
+
32
+ export default meta;
33
+ type Story = StoryObj<typeof meta>;
34
+
35
+ /** Playground: use the controls below. */
36
+ export const Default: Story = {};
37
+
38
+ /** A form section: fields lay out by the card's own width (container queries). */
39
+ export const FormSection: Story = {
40
+ render: (args) => ({
41
+ components: { Card, Input },
42
+ setup: () => ({ args }),
43
+ template: `
44
+ <Card v-bind="args">
45
+ <div class="grid grid-cols-1 gap-4 @md:grid-cols-2">
46
+ <Input label="Name" model-value="2027–28" />
47
+ <Input label="Code" model-value="AY27" />
48
+ </div>
49
+ </Card>`,
50
+ }),
51
+ };
52
+
53
+ /** Actions beside the title, and a footer under a divider. */
54
+ export const WithActionsAndFooter: Story = {
55
+ args: { title: "Contact details", description: "Shown to parents on the portal." },
56
+ render: (args) => ({
57
+ components: { Card, Button, Pencil },
58
+ setup: () => ({ args }),
59
+ template: `
60
+ <Card v-bind="args">
61
+ <template #actions>
62
+ <Button variant="ghost" size="sm"><template #leading><Pencil /></template>Edit</Button>
63
+ </template>
64
+ <dl class="grid grid-cols-[8rem_1fr] gap-y-2 text-sm">
65
+ <dt class="text-black/65">Email</dt><dd>office@keston.school</dd>
66
+ <dt class="text-black/65">Phone</dt><dd>020 7946 0000</dd>
67
+ </dl>
68
+ <template #footer>
69
+ <Button>Cancel</Button>
70
+ <Button variant="primary">Save</Button>
71
+ </template>
72
+ </Card>`,
73
+ }),
74
+ };
75
+
76
+ /** Small cards in a grid, e.g. stats, with padding="sm" and no title. */
77
+ export const Stats: Story = {
78
+ render: () => ({
79
+ components: { Card, Badge },
80
+ template: `
81
+ <div class="grid grid-cols-1 gap-4 sm:grid-cols-3">
82
+ <Card v-for="stat in [['Open applications', '48'], ['Interviews this week', '9'], ['Offers accepted', '31']]" :key="stat[0]" padding="sm" :ui="{ body: 'gap-1' }">
83
+ <span class="text-sm text-black/65">{{ stat[0] }}</span>
84
+ <span class="text-2xl font-bold">{{ stat[1] }}</span>
85
+ </Card>
86
+ </div>`,
87
+ }),
88
+ };
89
+
90
+ /** padding="none": the content (here a table) runs to the edges. */
91
+ export const Table: Story = {
92
+ args: { title: undefined, description: undefined, padding: "none" },
93
+ render: (args) => ({
94
+ components: { Card, Badge },
95
+ setup: () => ({ args }),
96
+ template: `
97
+ <Card v-bind="args" :ui="{ body: 'overflow-x-auto' }">
98
+ <table class="w-full text-left text-sm">
99
+ <thead class="border-b border-black/15 text-black/65">
100
+ <tr><th class="px-4 py-3 font-bold">Applicant</th><th class="px-4 py-3 font-bold">Year</th><th class="px-4 py-3 font-bold">Status</th></tr>
101
+ </thead>
102
+ <tbody>
103
+ <tr class="border-b border-black/15"><td class="px-4 py-3 font-bold">Amelia Clarke</td><td class="px-4 py-3">Year 7</td><td class="px-4 py-3"><Badge size="sm" color="green">Offered</Badge></td></tr>
104
+ <tr><td class="px-4 py-3 font-bold">Noah Patel</td><td class="px-4 py-3">Year 9</td><td class="px-4 py-3"><Badge size="sm" color="blue">Interview</Badge></td></tr>
105
+ </tbody>
106
+ </table>
107
+ </Card>`,
108
+ }),
109
+ };
@@ -0,0 +1,115 @@
1
+ <script setup lang="ts">
2
+ import { computed, useId, type HTMLAttributes } from 'vue'
3
+ import { cn } from '../../lib/cn'
4
+
5
+ /**
6
+ * A white panel that groups related content on a page: a form section, a
7
+ * summary, a stat, a table. Same border, radius and white as Button, Input
8
+ * and Popover, so everything on the grey page background matches.
9
+ *
10
+ * With a `title` it's a labelled region (a `<section>` named by its heading),
11
+ * so screen reader users can jump between cards. It's also a size container:
12
+ * children can lay out by the card's width with `@sm:` / `@lg:` etc.
13
+ *
14
+ * Slots: default (the content), header (replaces title and description),
15
+ * actions (top right, beside the title, e.g. an Edit button), footer (under a
16
+ * divider, right-aligned, e.g. Cancel / Save).
17
+ */
18
+ export interface CardProps {
19
+ /** Heading. Also the card's accessible name. */
20
+ title?: string
21
+ /** Smaller grey text under the title. */
22
+ description?: string
23
+ /** Heading level, to fit the page outline (h1 is the page title). */
24
+ headingLevel?: 2 | 3 | 4
25
+ /**
26
+ * Space inside:
27
+ * - md (default): 16px, 24px from the sm breakpoint. Sections and forms.
28
+ * - sm: 16px. Small cards, e.g. stats in a grid.
29
+ * - none: content touches the edges, e.g. a table.
30
+ */
31
+ padding?: 'none' | 'sm' | 'md'
32
+ /** Element to render. Defaults to section (with a title) or div. */
33
+ as?: 'section' | 'aside' | 'article' | 'div'
34
+ class?: HTMLAttributes['class']
35
+ /** Extra classes for the parts. */
36
+ ui?: {
37
+ header?: HTMLAttributes['class']
38
+ body?: HTMLAttributes['class']
39
+ footer?: HTMLAttributes['class']
40
+ }
41
+ }
42
+
43
+ const props = withDefaults(defineProps<CardProps>(), {
44
+ headingLevel: 2,
45
+ padding: 'md'
46
+ })
47
+
48
+ defineSlots<{
49
+ default?(): unknown
50
+ header?(): unknown
51
+ actions?(): unknown
52
+ footer?(): unknown
53
+ }>()
54
+
55
+ const headingId = `${useId()}-title`
56
+ const tag = computed(() => props.as ?? (props.title ? 'section' : 'div'))
57
+
58
+ const paddings: Record<NonNullable<CardProps['padding']>, string> = {
59
+ none: '',
60
+ sm: 'p-4',
61
+ md: 'p-4 sm:p-6'
62
+ }
63
+
64
+ // The footer lines up with the body's sides; with no padding it keeps 16px.
65
+ const footerPaddings: Record<NonNullable<CardProps['padding']>, string> = {
66
+ none: 'px-4 py-3',
67
+ sm: 'px-4 py-3',
68
+ md: 'px-4 py-3 sm:px-6 sm:py-4'
69
+ }
70
+ </script>
71
+
72
+ <template>
73
+ <component
74
+ :is="tag"
75
+ :aria-labelledby="title ? headingId : undefined"
76
+ :class="
77
+ cn(
78
+ '@container flex flex-col rounded-lg border border-black/15 bg-white text-black',
79
+ // Content that runs to the edges (a table's header, a list's rows) is
80
+ // clipped to the rounded corners. clip, not hidden: it doesn't make a
81
+ // scroll container, so sticky content inside still sticks to the page.
82
+ padding === 'none' && 'overflow-clip',
83
+ props.class
84
+ )
85
+ "
86
+ >
87
+ <div :class="cn('flex min-w-0 flex-1 flex-col gap-4', paddings[padding], ui?.body)">
88
+ <div
89
+ v-if="title || description || $slots.header || $slots.actions"
90
+ :class="cn('flex items-start justify-between gap-3', ui?.header)"
91
+ >
92
+ <slot name="header">
93
+ <div class="flex min-w-0 flex-col gap-1">
94
+ <component :is="`h${headingLevel}`" v-if="title" :id="headingId" class="text-base font-bold">
95
+ {{ title }}
96
+ </component>
97
+ <p v-if="description" class="text-sm text-black/65">{{ description }}</p>
98
+ </div>
99
+ </slot>
100
+ <div v-if="$slots.actions" class="flex shrink-0 items-center gap-2">
101
+ <slot name="actions" />
102
+ </div>
103
+ </div>
104
+
105
+ <slot />
106
+ </div>
107
+
108
+ <div
109
+ v-if="$slots.footer"
110
+ :class="cn('flex flex-wrap justify-end gap-2 border-t border-black/15', footerPaddings[padding], ui?.footer)"
111
+ >
112
+ <slot name="footer" />
113
+ </div>
114
+ </component>
115
+ </template>
@@ -0,0 +1,102 @@
1
+ import type { Meta, StoryObj } from "@storybook/vue3-vite";
2
+ import { computed, ref } from "vue";
3
+ import Button from "../Button/Button.vue";
4
+ import Checkbox from "./Checkbox.vue";
5
+
6
+ const meta = {
7
+ title: "Components/Form/Checkbox",
8
+ component: Checkbox,
9
+ tags: ["autodocs"],
10
+ args: {
11
+ label: "Has a sibling at the school",
12
+ description: "",
13
+ errorText: "",
14
+ disabled: false,
15
+ },
16
+ decorators: [() => ({ template: '<div class="max-w-80"><story /></div>' })],
17
+ render: (args) => ({
18
+ components: { Checkbox },
19
+ setup: () => ({ args, value: ref(false) }),
20
+ template: '<Checkbox v-bind="args" v-model="value" />',
21
+ }),
22
+ } satisfies Meta<typeof Checkbox>;
23
+
24
+ export default meta;
25
+ type Story = StoryObj<typeof meta>;
26
+
27
+ /** Playground: use the controls below. Press the label as well as the box. */
28
+ export const Default: Story = {};
29
+
30
+ export const WithDescription: Story = {
31
+ args: {
32
+ label: "Eligible for free school meals",
33
+ description: "Checked against the local authority's list each term.",
34
+ },
35
+ };
36
+
37
+ /** Long labels wrap; the box stays level with the first line. */
38
+ export const LongLabel: Story = {
39
+ args: {
40
+ label: "I confirm that the information given is correct and that I will tell the school if anything changes",
41
+ },
42
+ };
43
+
44
+ /** Try "Continue" without ticking the box; the error clears once it's ticked. */
45
+ export const Required: Story = {
46
+ args: { label: "I agree to the terms of admission" },
47
+ render: (args) => ({
48
+ components: { Checkbox, Button },
49
+ setup() {
50
+ const value = ref(false);
51
+ const tried = ref(false);
52
+ const error = computed(() => (tried.value && !value.value ? "Agree to the terms to continue" : undefined));
53
+ return { args, value, tried, error };
54
+ },
55
+ template: `
56
+ <div class="flex flex-col items-start gap-4">
57
+ <Checkbox v-bind="args" v-model="value" :error-text="error" required />
58
+ <Button variant="primary" @click="tried = true">Continue</Button>
59
+ </div>`,
60
+ }),
61
+ };
62
+
63
+ /**
64
+ * A "select all" box: a dash while only some are ticked. Pressing it ticks
65
+ * them all; pressing again unticks them all.
66
+ */
67
+ export const SelectAll: Story = {
68
+ render: () => ({
69
+ components: { Checkbox },
70
+ setup() {
71
+ const years = ref([
72
+ { label: "Year 7", on: true },
73
+ { label: "Year 8", on: false },
74
+ { label: "Year 9", on: true },
75
+ ]);
76
+ const all = computed<boolean | "indeterminate">({
77
+ get: () =>
78
+ years.value.every((y) => y.on) ? true : years.value.some((y) => y.on) ? "indeterminate" : false,
79
+ set: (value) => years.value.forEach((y) => (y.on = value === true)),
80
+ });
81
+ return { years, all };
82
+ },
83
+ template: `
84
+ <div class="flex flex-col gap-2">
85
+ <Checkbox v-model="all" label="All year groups" />
86
+ <div class="flex flex-col gap-2 pl-6">
87
+ <Checkbox v-for="year in years" :key="year.label" v-model="year.on" :label="year.label" />
88
+ </div>
89
+ </div>`,
90
+ }),
91
+ };
92
+
93
+ export const Disabled: Story = { args: { disabled: true } };
94
+
95
+ export const DisabledTicked: Story = {
96
+ args: { disabled: true },
97
+ render: (args) => ({
98
+ components: { Checkbox },
99
+ setup: () => ({ args, value: ref(true) }),
100
+ template: '<Checkbox v-bind="args" v-model="value" />',
101
+ }),
102
+ };