@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.
Files changed (210) hide show
  1. package/README.md +98 -31
  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/EmptyState/EmptyState.vue.d.ts +55 -0
  16. package/dist/components/{ToastItem.vue.d.ts → FormField/FieldMessage.vue.d.ts} +10 -2
  17. package/dist/components/FormField/FormField.vue.d.ts +61 -0
  18. package/dist/components/Header/Header.vue.d.ts +104 -0
  19. package/dist/components/InfoTip/InfoTip.vue.d.ts +20 -0
  20. package/dist/components/Input/Input.vue.d.ts +56 -0
  21. package/dist/components/InputCode/InputCode.vue.d.ts +53 -0
  22. package/dist/components/InputDate/InputDate.vue.d.ts +49 -0
  23. package/dist/components/InputNumber/InputNumber.vue.d.ts +44 -0
  24. package/dist/components/InputPassword/InputPassword.vue.d.ts +51 -0
  25. package/dist/components/InputRichText/InputRichText.vue.d.ts +44 -0
  26. package/dist/components/Link/Link.vue.d.ts +39 -0
  27. package/dist/components/Notification/Notification.vue.d.ts +62 -0
  28. package/dist/components/Notification/NotificationPane.vue.d.ts +38 -0
  29. package/dist/components/Notification/Toaster.vue.d.ts +51 -0
  30. package/dist/components/Notification/notification.samples.d.ts +3 -0
  31. package/dist/components/Notification/notifications.d.ts +115 -0
  32. package/dist/components/PageHeader/PageHeader.vue.d.ts +43 -0
  33. package/dist/components/Popover/Popover.vue.d.ts +83 -0
  34. package/dist/components/Popover/popover.d.ts +16 -0
  35. package/dist/components/Progress/Progress.vue.d.ts +26 -0
  36. package/dist/components/RadioGroup/RadioGroup.vue.d.ts +45 -0
  37. package/dist/components/RelativeTime/RelativeTime.vue.d.ts +22 -0
  38. package/dist/components/Select/Select.vue.d.ts +110 -0
  39. package/dist/components/Sidebar/Sidebar.vue.d.ts +106 -0
  40. package/dist/components/Sidebar/sidebar.d.ts +10 -0
  41. package/dist/components/Slideover/Slideover.vue.d.ts +125 -0
  42. package/dist/components/Spinner/Spinner.vue.d.ts +30 -0
  43. package/dist/components/StatTile/StatTile.vue.d.ts +46 -0
  44. package/dist/components/SummaryList/SummaryList.vue.d.ts +62 -0
  45. package/dist/components/Switch/Switch.vue.d.ts +39 -0
  46. package/dist/components/Table/Table.vue.d.ts +82 -0
  47. package/dist/components/Table/table.d.ts +36 -0
  48. package/dist/components/Tooltip/Tooltip.vue.d.ts +46 -0
  49. package/dist/index.d.ts +91 -25
  50. package/dist/keston-ui.js +5030 -14786
  51. package/dist/lib/cn.d.ts +4 -0
  52. package/dist/lib/dates.d.ts +27 -0
  53. package/dist/lib/initials.d.ts +2 -0
  54. package/dist/lib/parseDate.d.ts +44 -0
  55. package/dist/lib/useNow.d.ts +3 -0
  56. package/package.json +57 -24
  57. package/src/components/.gitkeep +0 -0
  58. package/src/components/Age/Age.stories.ts +24 -0
  59. package/src/components/Age/Age.vue +56 -0
  60. package/src/components/AppShell/AppShell.stories.ts +124 -0
  61. package/src/components/AppShell/AppShell.vue +221 -0
  62. package/src/components/Avatar/Avatar.stories.ts +56 -0
  63. package/src/components/Avatar/Avatar.vue +118 -0
  64. package/src/components/AvatarGroup/AvatarGroup.stories.ts +47 -0
  65. package/src/components/AvatarGroup/AvatarGroup.vue +97 -0
  66. package/src/components/Badge/Badge.stories.ts +92 -0
  67. package/src/components/Badge/Badge.vue +67 -0
  68. package/src/components/Breadcrumb/Breadcrumb.stories.ts +58 -0
  69. package/src/components/Breadcrumb/Breadcrumb.vue +109 -0
  70. package/src/components/Button/Button.mdx +79 -0
  71. package/src/components/Button/Button.stories.ts +207 -0
  72. package/src/components/Button/Button.vue +266 -0
  73. package/src/components/Calendar/Calendar.stories.ts +51 -0
  74. package/src/components/Calendar/Calendar.vue +364 -0
  75. package/src/components/Card/Card.stories.ts +109 -0
  76. package/src/components/Card/Card.vue +115 -0
  77. package/src/components/Checkbox/Checkbox.stories.ts +102 -0
  78. package/src/components/Checkbox/Checkbox.vue +102 -0
  79. package/src/components/Checklist/Checklist.stories.ts +67 -0
  80. package/src/components/Checklist/Checklist.vue +38 -0
  81. package/src/components/Chip/Chip.stories.ts +71 -0
  82. package/src/components/Chip/Chip.vue +86 -0
  83. package/src/components/Divider/Divider.stories.ts +57 -0
  84. package/src/components/Divider/Divider.vue +58 -0
  85. package/src/components/EmptyState/EmptyState.stories.ts +99 -0
  86. package/src/components/EmptyState/EmptyState.vue +87 -0
  87. package/src/components/FormField/FieldMessage.vue +81 -0
  88. package/src/components/FormField/FormField.stories.ts +55 -0
  89. package/src/components/FormField/FormField.vue +160 -0
  90. package/src/components/Header/Header.stories.ts +168 -0
  91. package/src/components/Header/Header.vue +232 -0
  92. package/src/components/InfoTip/InfoTip.stories.ts +63 -0
  93. package/src/components/InfoTip/InfoTip.vue +50 -0
  94. package/src/components/Input/Input.stories.ts +206 -0
  95. package/src/components/Input/Input.vue +90 -0
  96. package/src/components/InputCode/InputCode.stories.ts +85 -0
  97. package/src/components/InputCode/InputCode.vue +145 -0
  98. package/src/components/InputDate/InputDate.stories.ts +58 -0
  99. package/src/components/InputDate/InputDate.vue +258 -0
  100. package/src/components/InputNumber/InputNumber.stories.ts +63 -0
  101. package/src/components/InputNumber/InputNumber.vue +109 -0
  102. package/src/components/InputPassword/InputPassword.stories.ts +105 -0
  103. package/src/components/InputPassword/InputPassword.vue +132 -0
  104. package/src/components/InputRichText/InputRichText.stories.ts +100 -0
  105. package/src/components/InputRichText/InputRichText.vue +194 -0
  106. package/src/components/Link/Link.stories.ts +73 -0
  107. package/src/components/Link/Link.vue +56 -0
  108. package/src/components/Notification/Notification.stories.ts +196 -0
  109. package/src/components/Notification/Notification.vue +136 -0
  110. package/src/components/Notification/NotificationPane.vue +186 -0
  111. package/src/components/Notification/Toaster.vue +446 -0
  112. package/src/components/Notification/notification.samples.ts +45 -0
  113. package/src/components/Notification/notifications.test.ts +99 -0
  114. package/src/components/Notification/notifications.ts +172 -0
  115. package/src/components/PageHeader/PageHeader.stories.ts +79 -0
  116. package/src/components/PageHeader/PageHeader.vue +66 -0
  117. package/src/components/Popover/Popover.stories.ts +135 -0
  118. package/src/components/Popover/Popover.vue +192 -0
  119. package/src/components/Popover/popover.ts +20 -0
  120. package/src/components/Progress/Progress.stories.ts +74 -0
  121. package/src/components/Progress/Progress.vue +75 -0
  122. package/src/components/RadioGroup/RadioGroup.stories.ts +90 -0
  123. package/src/components/RadioGroup/RadioGroup.vue +132 -0
  124. package/src/components/RelativeTime/RelativeTime.stories.ts +74 -0
  125. package/src/components/RelativeTime/RelativeTime.vue +51 -0
  126. package/src/components/Select/Select.mdx +202 -0
  127. package/src/components/Select/Select.stories.ts +223 -0
  128. package/src/components/Select/Select.vue +630 -0
  129. package/src/components/Sidebar/Sidebar.stories.ts +192 -0
  130. package/src/components/Sidebar/Sidebar.vue +382 -0
  131. package/src/components/Sidebar/sidebar.ts +20 -0
  132. package/src/components/Slideover/Slideover.stories.ts +225 -0
  133. package/src/components/Slideover/Slideover.vue +365 -0
  134. package/src/components/Spinner/Spinner.stories.ts +79 -0
  135. package/src/components/Spinner/Spinner.vue +97 -0
  136. package/src/components/StatTile/StatTile.stories.ts +75 -0
  137. package/src/components/StatTile/StatTile.vue +89 -0
  138. package/src/components/SummaryList/SummaryList.stories.ts +103 -0
  139. package/src/components/SummaryList/SummaryList.vue +127 -0
  140. package/src/components/Switch/Switch.stories.ts +100 -0
  141. package/src/components/Switch/Switch.vue +96 -0
  142. package/src/components/Table/Table.stories.ts +212 -0
  143. package/src/components/Table/Table.vue +223 -0
  144. package/src/components/Table/table.test.ts +65 -0
  145. package/src/components/Table/table.ts +70 -0
  146. package/src/components/Tooltip/Tooltip.stories.ts +57 -0
  147. package/src/components/Tooltip/Tooltip.vue +86 -0
  148. package/src/examples/AppPages.stories.ts +500 -0
  149. package/src/examples/FormLayout.stories.ts +185 -0
  150. package/src/examples/KestonIdPages.stories.ts +415 -0
  151. package/src/examples/SchoolPages.stories.ts +665 -0
  152. package/src/index.ts +116 -36
  153. package/src/lib/cn.ts +4 -0
  154. package/src/lib/dates.test.ts +68 -0
  155. package/src/lib/dates.ts +86 -0
  156. package/src/lib/initials.ts +8 -0
  157. package/src/lib/parseDate.test.ts +331 -0
  158. package/src/lib/parseDate.ts +561 -0
  159. package/src/lib/useNow.ts +20 -0
  160. package/src/styles/theme.css +101 -0
  161. package/dist/components/AppLauncher.vue.d.ts +0 -10
  162. package/dist/components/Avatar.vue.d.ts +0 -16
  163. package/dist/components/Button.vue.d.ts +0 -27
  164. package/dist/components/Checkbox.vue.d.ts +0 -18
  165. package/dist/components/CloseButton.vue.d.ts +0 -6
  166. package/dist/components/Dialog.vue.d.ts +0 -23
  167. package/dist/components/Drawer.vue.d.ts +0 -34
  168. package/dist/components/DropdownMenu.vue.d.ts +0 -21
  169. package/dist/components/DropdownMenuItem.vue.d.ts +0 -19
  170. package/dist/components/DropdownMenuSeparator.vue.d.ts +0 -6
  171. package/dist/components/Input.vue.d.ts +0 -14
  172. package/dist/components/Label.vue.d.ts +0 -16
  173. package/dist/components/NotificationsMenu.vue.d.ts +0 -3
  174. package/dist/components/Popover.vue.d.ts +0 -23
  175. package/dist/components/ProfileSwitcher.vue.d.ts +0 -24
  176. package/dist/components/Select.vue.d.ts +0 -28
  177. package/dist/components/Separator.vue.d.ts +0 -11
  178. package/dist/components/ToastRenderer.vue.d.ts +0 -3
  179. package/dist/components/Toaster.vue.d.ts +0 -3
  180. package/dist/components/Tooltip.vue.d.ts +0 -23
  181. package/dist/components/TopBar.vue.d.ts +0 -34
  182. package/dist/favicon-old.svg +0 -1
  183. package/dist/favicon.svg +0 -1
  184. package/dist/keston-ui.cjs +0 -15
  185. package/dist/lib/toast.d.ts +0 -29
  186. package/dist/lib/types.d.ts +0 -5
  187. package/src/components/AppLauncher.vue +0 -63
  188. package/src/components/Avatar.vue +0 -51
  189. package/src/components/Button.vue +0 -54
  190. package/src/components/Checkbox.vue +0 -47
  191. package/src/components/CloseButton.vue +0 -24
  192. package/src/components/Dialog.vue +0 -65
  193. package/src/components/Drawer.vue +0 -202
  194. package/src/components/DropdownMenu.vue +0 -41
  195. package/src/components/DropdownMenuItem.vue +0 -28
  196. package/src/components/DropdownMenuSeparator.vue +0 -12
  197. package/src/components/Input.vue +0 -21
  198. package/src/components/Label.vue +0 -15
  199. package/src/components/NotificationsMenu.vue +0 -115
  200. package/src/components/Popover.vue +0 -46
  201. package/src/components/ProfileSwitcher.vue +0 -113
  202. package/src/components/Select.vue +0 -97
  203. package/src/components/Separator.vue +0 -30
  204. package/src/components/ToastItem.vue +0 -158
  205. package/src/components/ToastRenderer.vue +0 -113
  206. package/src/components/Toaster.vue +0 -11
  207. package/src/components/Tooltip.vue +0 -48
  208. package/src/components/TopBar.vue +0 -52
  209. package/src/lib/toast.ts +0 -95
  210. package/src/lib/types.ts +0 -5
package/src/index.ts CHANGED
@@ -1,37 +1,117 @@
1
- export { default as Avatar } from './components/Avatar.vue'
2
- export { default as AppLauncher } from './components/AppLauncher.vue'
3
- export { default as Button } from './components/Button.vue'
4
- export { default as Checkbox } from './components/Checkbox.vue'
5
- export { default as CloseButton } from './components/CloseButton.vue'
6
- export { default as Dialog } from './components/Dialog.vue'
7
- export { default as Drawer } from './components/Drawer.vue'
8
- export { default as DropdownMenu } from './components/DropdownMenu.vue'
9
- export { default as Input } from './components/Input.vue'
10
- export { default as Label } from './components/Label.vue'
11
- export { default as DropdownMenuItem } from './components/DropdownMenuItem.vue'
12
- export { default as DropdownMenuSeparator } from './components/DropdownMenuSeparator.vue'
13
- export { default as NotificationsMenu } from './components/NotificationsMenu.vue'
14
- export { default as Popover } from './components/Popover.vue'
15
- export { default as ProfileSwitcher } from './components/ProfileSwitcher.vue'
16
- export { default as Select } from './components/Select.vue'
17
- export type { SelectOption } from './components/Select.vue'
18
- export { default as Separator } from './components/Separator.vue'
19
- export { default as Tooltip } from './components/Tooltip.vue'
20
- export { default as Toaster } from './components/Toaster.vue'
21
- export { default as TopBar } from './components/TopBar.vue'
22
- export { toast, toastManager } from './lib/toast'
23
- export {
24
- clearNotifications,
25
- markNotificationsRead,
26
- removeNotification,
27
- toastNotifications,
28
- } from './lib/toast'
29
- export type { AppLink } from './lib/types'
1
+ // Public API of @thekestongroup/ui.
2
+ // Components are grouped as in Storybook (Layout, Element, Form, Data,
3
+ // Navigation, Overlay). `pnpm new <Name> <Group>` adds a component's exports
4
+ // at the end of its group.
5
+
6
+ export { cn } from './lib/cn'
7
+
8
+ // Layout
9
+ export { default as AppShell } from './components/AppShell/AppShell.vue'
10
+ export type { AppShellProps } from './components/AppShell/AppShell.vue'
11
+ export { default as Header } from './components/Header/Header.vue'
12
+ export type { HeaderProps, HeaderUser, HeaderUserAction } from './components/Header/Header.vue'
13
+ export { default as PageHeader } from './components/PageHeader/PageHeader.vue'
14
+ export type { PageHeaderProps } from './components/PageHeader/PageHeader.vue'
15
+
16
+ // Element
17
+ export { default as Avatar } from './components/Avatar/Avatar.vue'
18
+ export type { AvatarProps, AvatarUser } from './components/Avatar/Avatar.vue'
19
+ export { default as AvatarGroup } from './components/AvatarGroup/AvatarGroup.vue'
20
+ export type { AvatarGroupProps } from './components/AvatarGroup/AvatarGroup.vue'
21
+ export { default as Badge } from './components/Badge/Badge.vue'
22
+ export type { BadgeProps } from './components/Badge/Badge.vue'
23
+ export { default as Button } from './components/Button/Button.vue'
24
+ export type { ButtonProps, ButtonStatus } from './components/Button/Button.vue'
25
+ export { default as Card } from './components/Card/Card.vue'
26
+ export type { CardProps } from './components/Card/Card.vue'
27
+ export { default as Chip } from './components/Chip/Chip.vue'
28
+ export type { ChipProps } from './components/Chip/Chip.vue'
29
+ export { default as Divider } from './components/Divider/Divider.vue'
30
+ export type { DividerProps } from './components/Divider/Divider.vue'
31
+ export { default as Spinner } from './components/Spinner/Spinner.vue'
32
+ export type { SpinnerProps } from './components/Spinner/Spinner.vue'
33
+ export { default as Progress } from './components/Progress/Progress.vue'
34
+ export type { ProgressProps } from './components/Progress/Progress.vue'
35
+
36
+ // Form
37
+ export { default as FormField } from './components/FormField/FormField.vue'
38
+ export type { FormFieldProps, FormFieldStatus } from './components/FormField/FormField.vue'
39
+ export { default as Input } from './components/Input/Input.vue'
40
+ export type { InputProps } from './components/Input/Input.vue'
41
+ export { default as InputNumber } from './components/InputNumber/InputNumber.vue'
42
+ export type { InputNumberProps } from './components/InputNumber/InputNumber.vue'
43
+ export { default as InputDate } from './components/InputDate/InputDate.vue'
44
+ export type { InputDateProps } from './components/InputDate/InputDate.vue'
45
+ export { default as InputRichText } from './components/InputRichText/InputRichText.vue'
46
+ export type { InputRichTextProps } from './components/InputRichText/InputRichText.vue'
47
+ export { default as InputPassword } from './components/InputPassword/InputPassword.vue'
48
+ export type { InputPasswordProps, InputPasswordStatus } from './components/InputPassword/InputPassword.vue'
49
+ export { default as InputCode } from './components/InputCode/InputCode.vue'
50
+ export type { InputCodeProps, InputCodeStatus } from './components/InputCode/InputCode.vue'
51
+ export { default as Select } from './components/Select/Select.vue'
52
+ export type { SelectProps } from './components/Select/Select.vue'
53
+ export { default as Checkbox } from './components/Checkbox/Checkbox.vue'
54
+ export type { CheckboxProps } from './components/Checkbox/Checkbox.vue'
55
+ export { default as RadioGroup } from './components/RadioGroup/RadioGroup.vue'
56
+ export type { RadioGroupProps, RadioOption, RadioValue } from './components/RadioGroup/RadioGroup.vue'
57
+ export { default as Switch } from './components/Switch/Switch.vue'
58
+ export type { SwitchProps } from './components/Switch/Switch.vue'
59
+ export { default as Calendar } from './components/Calendar/Calendar.vue'
60
+ export type { CalendarProps } from './components/Calendar/Calendar.vue'
61
+
62
+ // Data
63
+ export { default as Table } from './components/Table/Table.vue'
64
+ export type { TableProps } from './components/Table/Table.vue'
65
+ export type { TableColumn, TableSort, SortDirection } from './components/Table/table'
66
+ export { sortRows } from './components/Table/table'
67
+ export { default as StatTile } from './components/StatTile/StatTile.vue'
68
+ export type { StatTileProps } from './components/StatTile/StatTile.vue'
69
+ export { default as SummaryList } from './components/SummaryList/SummaryList.vue'
70
+ export type { SummaryListProps, SummaryListItem } from './components/SummaryList/SummaryList.vue'
71
+ export { default as Checklist } from './components/Checklist/Checklist.vue'
72
+ export type { ChecklistProps, ChecklistItem } from './components/Checklist/Checklist.vue'
73
+ export { default as RelativeTime } from './components/RelativeTime/RelativeTime.vue'
74
+ export type { RelativeTimeProps } from './components/RelativeTime/RelativeTime.vue'
75
+ export { default as Age } from './components/Age/Age.vue'
76
+ export type { AgeProps } from './components/Age/Age.vue'
77
+ export { default as EmptyState } from './components/EmptyState/EmptyState.vue'
78
+ export type { EmptyStateProps } from './components/EmptyState/EmptyState.vue'
79
+
80
+ // Navigation
81
+ export { default as Breadcrumb } from './components/Breadcrumb/Breadcrumb.vue'
82
+ export type { BreadcrumbProps, BreadcrumbItem } from './components/Breadcrumb/Breadcrumb.vue'
83
+ export { default as Sidebar } from './components/Sidebar/Sidebar.vue'
84
+ export type { SidebarProps, SidebarItem, SidebarSection } from './components/Sidebar/Sidebar.vue'
85
+ export { sidebarTrail } from './components/Sidebar/sidebar'
86
+ export { default as Link } from './components/Link/Link.vue'
87
+ export type { LinkProps } from './components/Link/Link.vue'
88
+
89
+ // Overlay
90
+ export { default as Popover } from './components/Popover/Popover.vue'
91
+ export type { PopoverProps } from './components/Popover/Popover.vue'
92
+ export { default as Slideover } from './components/Slideover/Slideover.vue'
93
+ export type { SlideoverProps } from './components/Slideover/Slideover.vue'
94
+ export { default as Tooltip } from './components/Tooltip/Tooltip.vue'
95
+ export type { TooltipProps } from './components/Tooltip/Tooltip.vue'
96
+ export { default as InfoTip } from './components/InfoTip/InfoTip.vue'
97
+ export type { InfoTipProps } from './components/InfoTip/InfoTip.vue'
98
+ export { default as Notification } from './components/Notification/Notification.vue'
99
+ export type { NotificationProps } from './components/Notification/Notification.vue'
100
+ export { default as NotificationPane } from './components/Notification/NotificationPane.vue'
101
+ export type { NotificationPaneProps } from './components/Notification/NotificationPane.vue'
102
+ export { default as Toaster } from './components/Notification/Toaster.vue'
103
+ export type { ToasterProps } from './components/Notification/Toaster.vue'
104
+ export { createNotifications, useNotifications, relativeTime } from './components/Notification/notifications'
30
105
  export type {
31
- ToastStatus,
32
- ToastNotification,
33
- ToastObject,
34
- ToastAddOptions,
35
- ToastUpdateOptions,
36
- ToastPromiseOptions,
37
- } from './lib/toast'
106
+ Notifications,
107
+ NotificationItem,
108
+ NotificationInput,
109
+ NotificationAction,
110
+ NotificationType,
111
+ ToastOptions
112
+ } from './components/Notification/notifications'
113
+
114
+ // Helpers
115
+ export { age, daysToBirthday, formatDate, formatDateTime, toDate } from './lib/dates'
116
+ export type { DateInput } from './lib/dates'
117
+ export { useNow } from './lib/useNow'
package/src/lib/cn.ts CHANGED
@@ -1,6 +1,10 @@
1
1
  import { clsx, type ClassValue } from 'clsx'
2
2
  import { twMerge } from 'tailwind-merge'
3
3
 
4
+ /**
5
+ * Join class names and resolve Tailwind conflicts, so a class passed in by
6
+ * the app (e.g. `class="px-8"`) overrides the component's own `px-4`.
7
+ */
4
8
  export function cn(...inputs: ClassValue[]) {
5
9
  return twMerge(clsx(inputs))
6
10
  }
@@ -0,0 +1,68 @@
1
+ import { describe, expect, it } from 'vitest'
2
+ import { age, daysToBirthday, formatDate, formatDateTime, relativeTime, toDate } from './dates'
3
+
4
+ describe('relativeTime', () => {
5
+ const now = new Date(2026, 10, 11, 12, 0, 0)
6
+ const ago = (seconds: number) => relativeTime(new Date(now.getTime() - seconds * 1000), now)
7
+ it('words the time since', () => {
8
+ expect(ago(10)).toBe('Just now')
9
+ expect(ago(60)).toBe('1 minute ago')
10
+ expect(ago(5 * 60)).toBe('5 minutes ago')
11
+ expect(ago(2 * 3600)).toBe('2 hours ago')
12
+ expect(ago(24 * 3600)).toBe('Yesterday')
13
+ expect(ago(3 * 24 * 3600)).toBe('3 days ago')
14
+ expect(ago(14 * 24 * 3600)).toBe('2 weeks ago')
15
+ expect(ago(400 * 24 * 3600)).toBe('Last year')
16
+ })
17
+ it('words the future, and takes strings', () => {
18
+ expect(ago(-2 * 24 * 3600)).toBe('In 2 days')
19
+ expect(relativeTime(now.toISOString(), now)).toBe('Just now')
20
+ })
21
+ })
22
+
23
+ describe('formatDateTime / formatDate', () => {
24
+ it('writes the date out in full', () => {
25
+ const d = new Date(2026, 10, 11, 9, 52)
26
+ expect(formatDateTime(d)).toBe('Wednesday 11 November 2026 at 09:52')
27
+ expect(formatDate(new Date(2013, 2, 14))).toBe('14 March 2013')
28
+ })
29
+ })
30
+
31
+ describe('age', () => {
32
+ const born = new Date(2013, 2, 14)
33
+ it('counts whole years, going up on the birthday', () => {
34
+ expect(age(born, new Date(2026, 2, 13))).toBe(12)
35
+ expect(age(born, new Date(2026, 2, 14))).toBe(13)
36
+ expect(age(born, new Date(2026, 10, 11))).toBe(13)
37
+ })
38
+ it('29 February birthdays go up on 1 March in other years', () => {
39
+ const leap = new Date(2012, 1, 29)
40
+ expect(age(leap, new Date(2026, 1, 28))).toBe(13)
41
+ expect(age(leap, new Date(2026, 2, 1))).toBe(14)
42
+ })
43
+ })
44
+
45
+ describe('daysToBirthday', () => {
46
+ const born = new Date(2013, 2, 14)
47
+ it('counts days to the next one', () => {
48
+ expect(daysToBirthday(born, new Date(2026, 2, 14, 15))).toBe(0)
49
+ expect(daysToBirthday(born, new Date(2026, 2, 13))).toBe(1)
50
+ expect(daysToBirthday(born, new Date(2026, 2, 15))).toBe(364)
51
+ })
52
+ it('29 February falls on 1 March in other years', () => {
53
+ expect(daysToBirthday(new Date(2012, 1, 29), new Date(2026, 1, 27))).toBe(2)
54
+ })
55
+ })
56
+
57
+ describe('toDate', () => {
58
+ it('reads date-only strings as that local day', () => {
59
+ const d = toDate('2013-03-14')
60
+ expect([d.getFullYear(), d.getMonth(), d.getDate(), d.getHours()]).toEqual([2013, 2, 14, 0])
61
+ })
62
+ it('passes Dates through and reads timestamps and full ISO strings', () => {
63
+ const d = new Date(2026, 0, 1)
64
+ expect(toDate(d)).toBe(d)
65
+ expect(toDate(d.getTime()).getTime()).toBe(d.getTime())
66
+ expect(toDate(d.toISOString()).getTime()).toBe(d.getTime())
67
+ })
68
+ })
@@ -0,0 +1,86 @@
1
+ /**
2
+ * Date wording shared by components. UK English throughout.
3
+ *
4
+ * The pattern: show the short, human version ("3 hours ago", "13"), and the
5
+ * exact one ("Wednesday 11 November 2026 at 09:52", "Born 14 March 2013") on
6
+ * hover or focus. See RelativeTime and Age.
7
+ */
8
+
9
+ export type DateInput = Date | string | number
10
+
11
+ /**
12
+ * A Date from a Date, a timestamp or a string. Date-only strings
13
+ * ("2013-03-14") are read as that day here: JavaScript would read them as
14
+ * midnight UTC, which is the day before in places behind UTC.
15
+ */
16
+ export function toDate(value: DateInput): Date {
17
+ if (value instanceof Date) return value
18
+ if (typeof value === 'string' && /^\d{4}-\d{2}-\d{2}$/.test(value)) {
19
+ const [y, m, d] = value.split('-').map(Number)
20
+ return new Date(y, m - 1, d)
21
+ }
22
+ return new Date(value)
23
+ }
24
+
25
+ const units: [Intl.RelativeTimeFormatUnit, number][] = [
26
+ ['year', 365 * 24 * 60 * 60],
27
+ ['month', 30 * 24 * 60 * 60],
28
+ ['week', 7 * 24 * 60 * 60],
29
+ ['day', 24 * 60 * 60],
30
+ ['hour', 60 * 60],
31
+ ['minute', 60]
32
+ ]
33
+ const relative = new Intl.RelativeTimeFormat('en-GB', { numeric: 'auto' })
34
+
35
+ /** "Just now", "5 minutes ago", "Yesterday", "3 weeks ago", "In 2 days". */
36
+ export function relativeTime(date: DateInput, now: Date = new Date()): string {
37
+ const seconds = Math.round((toDate(date).getTime() - now.getTime()) / 1000)
38
+ if (Math.abs(seconds) < 60) return 'Just now'
39
+ for (const [unit, size] of units) {
40
+ if (Math.abs(seconds) >= size) {
41
+ const text = relative.format(Math.trunc(seconds / size), unit)
42
+ return text.charAt(0).toUpperCase() + text.slice(1)
43
+ }
44
+ }
45
+ return 'Just now'
46
+ }
47
+
48
+ /** "Wednesday 11 November 2026 at 09:52". */
49
+ export function formatDateTime(date: DateInput): string {
50
+ // Built from parts: browsers differ on the comma after the weekday.
51
+ const d = toDate(date)
52
+ const weekday = d.toLocaleDateString('en-GB', { weekday: 'long' })
53
+ const time = d.toLocaleTimeString('en-GB', { hour: '2-digit', minute: '2-digit' })
54
+ return `${weekday} ${formatDate(d)} at ${time}`
55
+ }
56
+
57
+ /** "14 March 2013". */
58
+ export function formatDate(date: DateInput): string {
59
+ return toDate(date).toLocaleDateString('en-GB', { day: 'numeric', month: 'long', year: 'numeric' })
60
+ }
61
+
62
+ /**
63
+ * Whole years since `birth`, as people count birthdays. Someone born on
64
+ * 29 February turns a year older on 1 March in other years (UK law).
65
+ */
66
+ export function age(birth: DateInput, now: Date = new Date()): number {
67
+ const born = toDate(birth)
68
+ let years = now.getFullYear() - born.getFullYear()
69
+ const month = now.getMonth() - born.getMonth()
70
+ if (month < 0 || (month === 0 && now.getDate() < born.getDate())) years--
71
+ return years
72
+ }
73
+
74
+ /** Days until the next birthday (0 on the day). */
75
+ export function daysToBirthday(birth: DateInput, now: Date = new Date()): number {
76
+ const born = toDate(birth)
77
+ const today = new Date(now.getFullYear(), now.getMonth(), now.getDate())
78
+ const next = (year: number) => {
79
+ // 29 February in a non-leap year falls on 1 March.
80
+ const d = new Date(year, born.getMonth(), born.getDate())
81
+ return d.getMonth() === born.getMonth() ? d : new Date(year, 2, 1)
82
+ }
83
+ let birthday = next(today.getFullYear())
84
+ if (birthday < today) birthday = next(today.getFullYear() + 1)
85
+ return Math.round((birthday.getTime() - today.getTime()) / 86_400_000)
86
+ }
@@ -0,0 +1,8 @@
1
+ /** "Ben Smith" → "BS", "Ben" → "B", "Mary Jane Watson" → "MW". Empty for an empty name. */
2
+ export function initials(name: string): string {
3
+ const words = name.trim().split(/\s+/).filter(Boolean)
4
+ if (!words.length) return ''
5
+ const first = words[0]!
6
+ const last = words.length > 1 ? words[words.length - 1]! : ''
7
+ return (first[0]! + (last[0] ?? '')).toUpperCase()
8
+ }
@@ -0,0 +1,331 @@
1
+ import { CalendarDate } from '@internationalized/date'
2
+ import { describe, expect, it } from 'vitest'
3
+ import { parseDateText, type ParseDateOptions } from './parseDate'
4
+
5
+ // Every test counts from Tuesday 10 November 2026 (week: Mon 9 – Sun 15).
6
+ const today = new CalendarDate(2026, 11, 10)
7
+
8
+ function parse(text: string, options: Partial<ParseDateOptions> = {}) {
9
+ return parseDateText(text, { today, ...options })?.toString()
10
+ }
11
+
12
+ function cases(table: Record<string, string | undefined>, options: Partial<ParseDateOptions> = {}) {
13
+ it.each(Object.entries(table))('%s → %s', (text, expected) => {
14
+ expect(parse(text, options)).toBe(expected)
15
+ })
16
+ }
17
+
18
+ describe('numeric dates', () => {
19
+ cases({
20
+ '26/01/2009': '2009-01-26',
21
+ '26-01-2009': '2009-01-26',
22
+ '26.01.2009': '2009-01-26',
23
+ '26 01 2009': '2009-01-26',
24
+ '26/1/2009': '2009-01-26',
25
+ '26/01/09': '2009-01-26',
26
+ '26/01/85': '1985-01-26',
27
+ '26012009': '2009-01-26',
28
+ '2009-01-26': '2009-01-26',
29
+ '2009-1-26': '2009-01-26',
30
+ ' 26/01/2009 ': '2009-01-26',
31
+ '29/02/2028': '2028-02-29'
32
+ })
33
+
34
+ describe('US order', () => {
35
+ cases({ '01/26/2009': '2009-01-26', '26/01/2009': undefined }, { order: ['month', 'day', 'year'] })
36
+ })
37
+ })
38
+
39
+ describe('month names', () => {
40
+ cases({
41
+ '26 jan 2009': '2009-01-26',
42
+ '26 Jan 2009': '2009-01-26',
43
+ '26 JANUARY 2009': '2009-01-26',
44
+ '26-jan-2009': '2009-01-26',
45
+ '26/jan/2009': '2009-01-26',
46
+ 'jan 26 2009': '2009-01-26',
47
+ 'January 26, 2009': '2009-01-26',
48
+ '26th jan 2009': '2009-01-26',
49
+ '26th of January 2009': '2009-01-26',
50
+ 'the 26th of january, 2009': '2009-01-26',
51
+ '26 jan 09': '2009-01-26',
52
+ '2009 jan 26': '2009-01-26',
53
+ '2009 January 26th': '2009-01-26',
54
+ 'tue 26 jan 2009': '2009-01-26',
55
+ 'Monday 26th January 2009': '2009-01-26',
56
+ '1 sept 2026': '2026-09-01',
57
+ '1 sep 2026': '2026-09-01',
58
+ '3rd may 1990': '1990-05-03',
59
+ 'jan 2009': '2009-01-01',
60
+ 'march 2027': '2027-03-01'
61
+ })
62
+
63
+ describe('ordinal words', () => {
64
+ cases({
65
+ 'twelfth of may 2027': '2027-05-12',
66
+ 'the twenty-first of june 2027': '2027-06-21',
67
+ 'twenty first june 2027': '2027-06-21',
68
+ 'first of march 2027': '2027-03-01',
69
+ 'thirty-first december 2026': '2026-12-31'
70
+ })
71
+ })
72
+ })
73
+
74
+ describe('dates without a year (prefer future)', () => {
75
+ cases({
76
+ '5th december': '2026-12-05',
77
+ '5th of december': '2026-12-05',
78
+ 'december 5th': '2026-12-05',
79
+ 'dec 5': '2026-12-05',
80
+ '5 dec': '2026-12-05',
81
+ 'Friday the 5th of December': '2026-12-05',
82
+ '5th march': '2027-03-05',
83
+ '5/12': '2026-12-05',
84
+ '5.12': '2026-12-05',
85
+ '10/11': '2026-11-10',
86
+ '9/11': '2027-11-09',
87
+ 'march': '2027-03-01',
88
+ 'december': '2026-12-01',
89
+ '5th march this year': '2026-03-05',
90
+ '26 jan next year': '2027-01-26',
91
+ 'next year 26 jan': '2027-01-26',
92
+ '29 feb': '2028-02-29'
93
+ })
94
+ })
95
+
96
+ describe('day of the month', () => {
97
+ cases({
98
+ 'the 5th': '2026-12-05',
99
+ 'the 15th': '2026-11-15',
100
+ '15th': '2026-11-15',
101
+ 'the 10th': '2026-11-10',
102
+ 'the 31st': '2026-12-31',
103
+ 'the 12th of next month': '2026-12-12',
104
+ '12th next month': '2026-12-12',
105
+ 'the 5th this month': '2026-11-05',
106
+ 'the 31st of next month': '2026-12-31',
107
+ '31st this month': undefined,
108
+ '32nd': undefined
109
+ })
110
+ })
111
+
112
+ describe('relative days', () => {
113
+ cases({
114
+ 'today': '2026-11-10',
115
+ 'now': '2026-11-10',
116
+ 'tdy': '2026-11-10',
117
+ 'tonight': '2026-11-10',
118
+ 'this evening': '2026-11-10',
119
+ 'eod': '2026-11-10',
120
+ 'tomorrow': '2026-11-11',
121
+ 'tmrw': '2026-11-11',
122
+ 'tmr': '2026-11-11',
123
+ 'TMRW': '2026-11-11',
124
+ 'Tomorrow.': '2026-11-11',
125
+ 'tomorrow morning': '2026-11-11',
126
+ 'yesterday': '2026-11-09',
127
+ 'yday': '2026-11-09',
128
+ 'the day after tomorrow': '2026-11-12',
129
+ 'day before yesterday': '2026-11-08'
130
+ })
131
+ })
132
+
133
+ describe('weekdays', () => {
134
+ cases({
135
+ 'tuesday': '2026-11-17',
136
+ 'tue': '2026-11-17',
137
+ 'tues': '2026-11-17',
138
+ 'on tuesday': '2026-11-17',
139
+ 'wednesday': '2026-11-11',
140
+ 'monday': '2026-11-16',
141
+ 'sun': '2026-11-15',
142
+ 'next tuesday': '2026-11-17',
143
+ 'next week tuesday': '2026-11-17',
144
+ 'tuesday next week': '2026-11-17',
145
+ 'next friday': '2026-11-20',
146
+ 'next monday': '2026-11-16',
147
+ 'this friday': '2026-11-13',
148
+ 'this week friday': '2026-11-13',
149
+ 'friday this week': '2026-11-13',
150
+ 'this monday': '2026-11-09',
151
+ 'last tuesday': '2026-11-03',
152
+ 'last friday': '2026-11-06',
153
+ 'last week friday': '2026-11-06',
154
+ 'friday last week': '2026-11-06',
155
+ 'tuesday after next': '2026-11-24',
156
+ 'the tuesday after next': '2026-11-24',
157
+ 'monday week': '2026-11-23',
158
+ 'friday fortnight': '2026-11-27',
159
+ 'a week on friday': '2026-11-20',
160
+ 'a month on friday': '2026-12-13',
161
+ '2 weeks on monday': '2026-11-30'
162
+ })
163
+ })
164
+
165
+ describe('parts of a week, month or year', () => {
166
+ cases({
167
+ 'end of the month': '2026-11-30',
168
+ 'end of month': '2026-11-30',
169
+ 'eom': '2026-11-30',
170
+ 'end of next month': '2026-12-31',
171
+ 'start of next month': '2026-12-01',
172
+ 'beginning of next month': '2026-12-01',
173
+ 'middle of the month': '2026-11-15',
174
+ 'end of the week': '2026-11-13',
175
+ 'eow': '2026-11-13',
176
+ 'end of next week': '2026-11-20',
177
+ 'start of next week': '2026-11-16',
178
+ 'end of the year': '2026-12-31',
179
+ 'eoy': '2026-12-31',
180
+ 'start of next year': '2027-01-01',
181
+ 'mid december': '2026-12-15',
182
+ 'early march': '2027-03-01',
183
+ 'end of february': '2027-02-28',
184
+ 'end of february 2028': '2028-02-29',
185
+ 'late december': '2026-12-31',
186
+ 'first monday of next month': '2026-12-07',
187
+ 'last friday of the month': '2026-11-27',
188
+ 'last friday of month': '2026-11-27',
189
+ '2nd tuesday of december': '2026-12-08',
190
+ 'third thursday in march 2027': '2027-03-18',
191
+ '5th monday of february': undefined
192
+ })
193
+ })
194
+
195
+ describe('weekends', () => {
196
+ cases({
197
+ 'this weekend': '2026-11-14',
198
+ 'next weekend': '2026-11-21',
199
+ 'last weekend': '2026-11-07',
200
+ 'the weekend': '2026-11-14',
201
+ 'weekend': '2026-11-14',
202
+ 'on the weekend': '2026-11-14'
203
+ })
204
+ })
205
+
206
+ describe('holidays', () => {
207
+ cases({
208
+ 'christmas': '2026-12-25',
209
+ 'xmas': '2026-12-25',
210
+ 'christmas day': '2026-12-25',
211
+ 'christmas eve': '2026-12-24',
212
+ 'boxing day': '2026-12-26',
213
+ "new year's eve": '2026-12-31',
214
+ 'nye': '2026-12-31',
215
+ "new year's day": '2027-01-01',
216
+ 'new years': '2027-01-01',
217
+ "valentine's day": '2027-02-14',
218
+ 'halloween': '2027-10-31',
219
+ 'bonfire night': '2027-11-05',
220
+ 'remembrance day': '2026-11-11',
221
+ 'easter': '2027-03-28',
222
+ 'good friday': '2027-03-26',
223
+ 'easter monday': '2027-03-29',
224
+ "mother's day": '2027-03-07',
225
+ "father's day": '2027-06-20',
226
+ "st patrick's day": '2027-03-17',
227
+ 'christmas next year': '2027-12-25',
228
+ 'christmas 2027': '2027-12-25',
229
+ 'easter next year': '2027-03-28',
230
+ 'easter this year': '2026-04-05',
231
+ 'easter 2028': '2028-04-16'
232
+ })
233
+ })
234
+
235
+ describe('adjustments', () => {
236
+ cases({
237
+ 'next week': '2026-11-17',
238
+ 'next month': '2026-12-10',
239
+ 'next year': '2027-11-10',
240
+ 'next year today': '2027-11-10',
241
+ 'today next year': '2027-11-10',
242
+ 'last week': '2026-11-03',
243
+ 'last month': '2026-10-10',
244
+ 'last year today': '2025-11-10',
245
+ 'in 3 days': '2026-11-13',
246
+ 'in three days': '2026-11-13',
247
+ 'in a couple of days': '2026-11-12',
248
+ 'in a few days': '2026-11-13',
249
+ 'in a fortnight': '2026-11-24',
250
+ 'next fortnight': '2026-11-24',
251
+ 'in 2 weeks': '2026-11-24',
252
+ 'in two weeks': '2026-11-24',
253
+ '2 weeks from now': '2026-11-24',
254
+ '3 days ago': '2026-11-07',
255
+ 'a week ago': '2026-11-03',
256
+ '3 days later': '2026-11-13',
257
+ 'in 1 year 2 months': '2028-01-10',
258
+ 'in 1 week and 3 days': '2026-11-20',
259
+ 'in two weeks and a day': '2026-11-25',
260
+ 'a week from tomorrow': '2026-11-18',
261
+ '2 weeks after next friday': '2026-12-04',
262
+ 'a week today': '2026-11-17',
263
+ 'a fortnight tomorrow': '2026-11-25',
264
+ 'yesterday next month': '2026-12-09',
265
+ 'next month yesterday': '2026-12-09',
266
+ 'tomorrow next week': '2026-11-18',
267
+ 'next tuesday next month': '2026-12-17',
268
+ '26/01/2009 next year': '2010-01-26'
269
+ })
270
+ })
271
+
272
+ describe('times are ignored', () => {
273
+ cases({
274
+ '5th december at 3pm': '2026-12-05',
275
+ '5th december 3pm': '2026-12-05',
276
+ 'tomorrow at 15:30': '2026-11-11',
277
+ 'tomorrow at noon': '2026-11-11',
278
+ 'monday at 9': '2026-11-16',
279
+ 'friday 9am': '2026-11-13',
280
+ 'at 26/01/2009': '2009-01-26'
281
+ })
282
+ })
283
+
284
+ describe('prefer past', () => {
285
+ cases(
286
+ {
287
+ '5th march': '2026-03-05',
288
+ '5th december': '2025-12-05',
289
+ 'tuesday': '2026-11-03',
290
+ 'the 5th': '2026-11-05',
291
+ 'the 15th': '2026-10-15',
292
+ 'christmas': '2025-12-25',
293
+ 'march': '2026-03-01',
294
+ // Explicit phrases ignore prefer
295
+ 'next tuesday': '2026-11-17',
296
+ 'tomorrow': '2026-11-11',
297
+ 'christmas next year': '2027-12-25'
298
+ },
299
+ { prefer: 'past' }
300
+ )
301
+ })
302
+
303
+ describe('prefer nearest', () => {
304
+ cases(
305
+ {
306
+ '5th march': '2027-03-05', // 115 days ahead vs 250 back
307
+ '5th june': '2026-06-05', // 158 days back vs 207 ahead
308
+ 'friday': '2026-11-13', // 3 ahead vs 4 back
309
+ 'saturday': '2026-11-07' // 4 ahead vs 3 back
310
+ },
311
+ { prefer: 'nearest' }
312
+ )
313
+ })
314
+
315
+ describe('not understood', () => {
316
+ cases({
317
+ '': undefined,
318
+ ' ': undefined,
319
+ 'hello': undefined,
320
+ 'next blursday': undefined,
321
+ '31 feb 2009': undefined,
322
+ '26/13/2009': undefined,
323
+ '26 janu 2009': undefined,
324
+ 'tomorrow yesterday': undefined,
325
+ 'tomorrow 26 jan': undefined,
326
+ '2 weeks': undefined,
327
+ 'next': undefined,
328
+ '5': undefined,
329
+ '2009': undefined
330
+ })
331
+ })