@slipstream-ui/core 0.13.0 → 0.14.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 (228) hide show
  1. package/dist/index.d.mts +32 -3
  2. package/dist/index.d.ts +32 -3
  3. package/dist/index.js +242 -11
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.mjs +242 -11
  6. package/dist/index.mjs.map +1 -1
  7. package/dist/manifests/accordion.manifest.json +1 -1
  8. package/dist/manifests/alert.manifest.json +1 -1
  9. package/dist/manifests/announcement-bar.manifest.json +1 -1
  10. package/dist/manifests/app-shell.manifest.json +1 -1
  11. package/dist/manifests/applied-filters.manifest.json +1 -1
  12. package/dist/manifests/article-card.manifest.json +1 -1
  13. package/dist/manifests/auth-layout.manifest.json +1 -1
  14. package/dist/manifests/autocomplete.manifest.json +1 -1
  15. package/dist/manifests/avatar.manifest.json +1 -1
  16. package/dist/manifests/badge.manifest.json +1 -1
  17. package/dist/manifests/block.manifest.json +1 -1
  18. package/dist/manifests/bottom-nav.manifest.json +1 -1
  19. package/dist/manifests/breadcrumb.manifest.json +1 -1
  20. package/dist/manifests/button-group.manifest.json +1 -1
  21. package/dist/manifests/button.manifest.json +1 -1
  22. package/dist/manifests/calendar.manifest.json +1 -1
  23. package/dist/manifests/card.manifest.json +1 -1
  24. package/dist/manifests/checkbox.manifest.json +1 -1
  25. package/dist/manifests/comparison-table.manifest.json +1 -1
  26. package/dist/manifests/confirm-dialog.manifest.json +1 -1
  27. package/dist/manifests/consent-banner.manifest.json +1 -1
  28. package/dist/manifests/contact-strip.manifest.json +1 -1
  29. package/dist/manifests/container.manifest.json +1 -1
  30. package/dist/manifests/cover-image.manifest.json +1 -1
  31. package/dist/manifests/cta-section.manifest.json +1 -1
  32. package/dist/manifests/data-table.manifest.json +1 -1
  33. package/dist/manifests/date-picker-popover.manifest.json +1 -1
  34. package/dist/manifests/date-picker.manifest.json +1 -1
  35. package/dist/manifests/date-range-picker.manifest.json +1 -1
  36. package/dist/manifests/deal-card.manifest.json +1 -1
  37. package/dist/manifests/dialog.manifest.json +1 -1
  38. package/dist/manifests/document-card.manifest.json +1 -1
  39. package/dist/manifests/drawer.manifest.json +1 -1
  40. package/dist/manifests/empty-state.manifest.json +1 -1
  41. package/dist/manifests/entity-card.manifest.json +1 -1
  42. package/dist/manifests/feature-grid.manifest.json +1 -1
  43. package/dist/manifests/feature-row.manifest.json +1 -1
  44. package/dist/manifests/fieldset.manifest.json +1 -1
  45. package/dist/manifests/figure.manifest.json +1 -1
  46. package/dist/manifests/file-upload.manifest.json +1 -1
  47. package/dist/manifests/filter-bar.manifest.json +1 -1
  48. package/dist/manifests/filter-chips.manifest.json +1 -1
  49. package/dist/manifests/filter-panel.manifest.json +1 -1
  50. package/dist/manifests/flex.manifest.json +1 -1
  51. package/dist/manifests/form-field.manifest.json +1 -1
  52. package/dist/manifests/form-layout.manifest.json +1 -1
  53. package/dist/manifests/form.manifest.json +1 -1
  54. package/dist/manifests/grid.manifest.json +1 -1
  55. package/dist/manifests/heading.manifest.json +1 -1
  56. package/dist/manifests/hero.manifest.json +1 -1
  57. package/dist/manifests/icon-button.manifest.json +1 -1
  58. package/dist/manifests/icon-tile.manifest.json +1 -1
  59. package/dist/manifests/icon.manifest.json +1 -1
  60. package/dist/manifests/image.manifest.json +1 -1
  61. package/dist/manifests/input-group.manifest.json +1 -1
  62. package/dist/manifests/input.manifest.json +1 -1
  63. package/dist/manifests/label.manifest.json +1 -1
  64. package/dist/manifests/link-tabs.manifest.json +1 -1
  65. package/dist/manifests/link.manifest.json +1 -1
  66. package/dist/manifests/list-toolbar.manifest.json +1 -1
  67. package/dist/manifests/list.manifest.json +1 -1
  68. package/dist/manifests/load-more.manifest.json +1 -1
  69. package/dist/manifests/logo-cloud.manifest.json +1 -1
  70. package/dist/manifests/media-card.manifest.json +1 -1
  71. package/dist/manifests/media.manifest.json +1 -1
  72. package/dist/manifests/menu.manifest.json +1 -1
  73. package/dist/manifests/metric-card.manifest.json +1 -1
  74. package/dist/manifests/month-schedule.manifest.json +1 -1
  75. package/dist/manifests/multi-select.manifest.json +1 -1
  76. package/dist/manifests/newsletter.manifest.json +1 -1
  77. package/dist/manifests/page-header.manifest.json +1 -1
  78. package/dist/manifests/pagination.manifest.json +1 -1
  79. package/dist/manifests/password-input.manifest.json +1 -1
  80. package/dist/manifests/popover.manifest.json +1 -1
  81. package/dist/manifests/process-steps.manifest.json +1 -1
  82. package/dist/manifests/progress.manifest.json +1 -1
  83. package/dist/manifests/prose.manifest.json +1 -1
  84. package/dist/manifests/radio.manifest.json +1 -1
  85. package/dist/manifests/range-slider.manifest.json +1 -1
  86. package/dist/manifests/search.manifest.json +1 -1
  87. package/dist/manifests/section-heading.manifest.json +1 -1
  88. package/dist/manifests/section.manifest.json +1 -1
  89. package/dist/manifests/segmented-control.manifest.json +1 -1
  90. package/dist/manifests/select-menu.manifest.json +1 -1
  91. package/dist/manifests/select.manifest.json +1 -1
  92. package/dist/manifests/separator.manifest.json +1 -1
  93. package/dist/manifests/site-footer.manifest.json +1 -1
  94. package/dist/manifests/site-header.manifest.json +1 -1
  95. package/dist/manifests/skeleton.manifest.json +1 -1
  96. package/dist/manifests/social-links.manifest.json +1 -1
  97. package/dist/manifests/spinner.manifest.json +1 -1
  98. package/dist/manifests/stat-band.manifest.json +1 -1
  99. package/dist/manifests/stepper.manifest.json +1 -1
  100. package/dist/manifests/switch.manifest.json +1 -1
  101. package/dist/manifests/table-card.manifest.json +1 -1
  102. package/dist/manifests/table-of-contents.manifest.json +1 -1
  103. package/dist/manifests/table.manifest.json +1 -1
  104. package/dist/manifests/tabs.manifest.json +1 -1
  105. package/dist/manifests/testimonial.manifest.json +1 -1
  106. package/dist/manifests/text.manifest.json +1 -1
  107. package/dist/manifests/textarea.manifest.json +1 -1
  108. package/dist/manifests/theme-toggle.manifest.json +1 -1
  109. package/dist/manifests/time-picker.manifest.json +49 -6
  110. package/dist/manifests/timeline.manifest.json +1 -1
  111. package/dist/manifests/toast.manifest.json +1 -1
  112. package/dist/manifests/tombstone-card.manifest.json +1 -1
  113. package/dist/manifests/tooltip.manifest.json +1 -1
  114. package/dist/src/components/time-picker/TimePicker.d.ts +31 -2
  115. package/dist/src/components/time-picker/TimePicker.js +244 -11
  116. package/dist/src/components/time-picker/TimePicker.js.map +1 -1
  117. package/dist/src/components/time-picker/TimePicker.mjs +244 -11
  118. package/dist/src/components/time-picker/TimePicker.mjs.map +1 -1
  119. package/package.json +4 -4
  120. package/src/components/time-picker/TimePicker.test.tsx +77 -0
  121. package/src/components/time-picker/TimePicker.tsx +315 -12
  122. package/src/manifests/accordion.manifest.json +1 -1
  123. package/src/manifests/alert.manifest.json +1 -1
  124. package/src/manifests/announcement-bar.manifest.json +1 -1
  125. package/src/manifests/app-shell.manifest.json +1 -1
  126. package/src/manifests/applied-filters.manifest.json +1 -1
  127. package/src/manifests/article-card.manifest.json +1 -1
  128. package/src/manifests/auth-layout.manifest.json +1 -1
  129. package/src/manifests/autocomplete.manifest.json +1 -1
  130. package/src/manifests/avatar.manifest.json +1 -1
  131. package/src/manifests/badge.manifest.json +1 -1
  132. package/src/manifests/block.manifest.json +1 -1
  133. package/src/manifests/bottom-nav.manifest.json +1 -1
  134. package/src/manifests/breadcrumb.manifest.json +1 -1
  135. package/src/manifests/button-group.manifest.json +1 -1
  136. package/src/manifests/button.manifest.json +1 -1
  137. package/src/manifests/calendar.manifest.json +1 -1
  138. package/src/manifests/card.manifest.json +1 -1
  139. package/src/manifests/checkbox.manifest.json +1 -1
  140. package/src/manifests/comparison-table.manifest.json +1 -1
  141. package/src/manifests/confirm-dialog.manifest.json +1 -1
  142. package/src/manifests/consent-banner.manifest.json +1 -1
  143. package/src/manifests/contact-strip.manifest.json +1 -1
  144. package/src/manifests/container.manifest.json +1 -1
  145. package/src/manifests/cover-image.manifest.json +1 -1
  146. package/src/manifests/cta-section.manifest.json +1 -1
  147. package/src/manifests/data-table.manifest.json +1 -1
  148. package/src/manifests/date-picker-popover.manifest.json +1 -1
  149. package/src/manifests/date-picker.manifest.json +1 -1
  150. package/src/manifests/date-range-picker.manifest.json +1 -1
  151. package/src/manifests/deal-card.manifest.json +1 -1
  152. package/src/manifests/dialog.manifest.json +1 -1
  153. package/src/manifests/document-card.manifest.json +1 -1
  154. package/src/manifests/drawer.manifest.json +1 -1
  155. package/src/manifests/empty-state.manifest.json +1 -1
  156. package/src/manifests/entity-card.manifest.json +1 -1
  157. package/src/manifests/feature-grid.manifest.json +1 -1
  158. package/src/manifests/feature-row.manifest.json +1 -1
  159. package/src/manifests/fieldset.manifest.json +1 -1
  160. package/src/manifests/figure.manifest.json +1 -1
  161. package/src/manifests/file-upload.manifest.json +1 -1
  162. package/src/manifests/filter-bar.manifest.json +1 -1
  163. package/src/manifests/filter-chips.manifest.json +1 -1
  164. package/src/manifests/filter-panel.manifest.json +1 -1
  165. package/src/manifests/flex.manifest.json +1 -1
  166. package/src/manifests/form-field.manifest.json +1 -1
  167. package/src/manifests/form-layout.manifest.json +1 -1
  168. package/src/manifests/form.manifest.json +1 -1
  169. package/src/manifests/grid.manifest.json +1 -1
  170. package/src/manifests/heading.manifest.json +1 -1
  171. package/src/manifests/hero.manifest.json +1 -1
  172. package/src/manifests/icon-button.manifest.json +1 -1
  173. package/src/manifests/icon-tile.manifest.json +1 -1
  174. package/src/manifests/icon.manifest.json +1 -1
  175. package/src/manifests/image.manifest.json +1 -1
  176. package/src/manifests/input-group.manifest.json +1 -1
  177. package/src/manifests/input.manifest.json +1 -1
  178. package/src/manifests/label.manifest.json +1 -1
  179. package/src/manifests/link-tabs.manifest.json +1 -1
  180. package/src/manifests/link.manifest.json +1 -1
  181. package/src/manifests/list-toolbar.manifest.json +1 -1
  182. package/src/manifests/list.manifest.json +1 -1
  183. package/src/manifests/load-more.manifest.json +1 -1
  184. package/src/manifests/logo-cloud.manifest.json +1 -1
  185. package/src/manifests/media-card.manifest.json +1 -1
  186. package/src/manifests/media.manifest.json +1 -1
  187. package/src/manifests/menu.manifest.json +1 -1
  188. package/src/manifests/metric-card.manifest.json +1 -1
  189. package/src/manifests/month-schedule.manifest.json +1 -1
  190. package/src/manifests/multi-select.manifest.json +1 -1
  191. package/src/manifests/newsletter.manifest.json +1 -1
  192. package/src/manifests/page-header.manifest.json +1 -1
  193. package/src/manifests/pagination.manifest.json +1 -1
  194. package/src/manifests/password-input.manifest.json +1 -1
  195. package/src/manifests/popover.manifest.json +1 -1
  196. package/src/manifests/process-steps.manifest.json +1 -1
  197. package/src/manifests/progress.manifest.json +1 -1
  198. package/src/manifests/prose.manifest.json +1 -1
  199. package/src/manifests/radio.manifest.json +1 -1
  200. package/src/manifests/range-slider.manifest.json +1 -1
  201. package/src/manifests/search.manifest.json +1 -1
  202. package/src/manifests/section-heading.manifest.json +1 -1
  203. package/src/manifests/section.manifest.json +1 -1
  204. package/src/manifests/segmented-control.manifest.json +1 -1
  205. package/src/manifests/select-menu.manifest.json +1 -1
  206. package/src/manifests/select.manifest.json +1 -1
  207. package/src/manifests/separator.manifest.json +1 -1
  208. package/src/manifests/site-footer.manifest.json +1 -1
  209. package/src/manifests/site-header.manifest.json +1 -1
  210. package/src/manifests/skeleton.manifest.json +1 -1
  211. package/src/manifests/social-links.manifest.json +1 -1
  212. package/src/manifests/spinner.manifest.json +1 -1
  213. package/src/manifests/stat-band.manifest.json +1 -1
  214. package/src/manifests/stepper.manifest.json +1 -1
  215. package/src/manifests/switch.manifest.json +1 -1
  216. package/src/manifests/table-card.manifest.json +1 -1
  217. package/src/manifests/table-of-contents.manifest.json +1 -1
  218. package/src/manifests/table.manifest.json +1 -1
  219. package/src/manifests/tabs.manifest.json +1 -1
  220. package/src/manifests/testimonial.manifest.json +1 -1
  221. package/src/manifests/text.manifest.json +1 -1
  222. package/src/manifests/textarea.manifest.json +1 -1
  223. package/src/manifests/theme-toggle.manifest.json +1 -1
  224. package/src/manifests/time-picker.manifest.json +49 -6
  225. package/src/manifests/timeline.manifest.json +1 -1
  226. package/src/manifests/toast.manifest.json +1 -1
  227. package/src/manifests/tombstone-card.manifest.json +1 -1
  228. package/src/manifests/tooltip.manifest.json +1 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@slipstream-ui/core",
3
- "version": "0.13.0",
3
+ "version": "0.14.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/michaelmcshinsky/slipstream-ui.git",
@@ -57,10 +57,10 @@
57
57
  "tsup": "^9.0.0",
58
58
  "typescript": "^5.3.3",
59
59
  "vitest": "^5.0.5",
60
- "@slipstream-ui/tailwind-config": "0.0.1",
61
- "@slipstream-ui/vitest-config": "0.0.1",
62
60
  "@slipstream-ui/eslint-config": "0.0.1",
63
- "@slipstream-ui/typescript-config": "0.0.1"
61
+ "@slipstream-ui/tailwind-config": "0.0.1",
62
+ "@slipstream-ui/typescript-config": "0.0.1",
63
+ "@slipstream-ui/vitest-config": "0.0.1"
64
64
  },
65
65
  "peerDependencies": {
66
66
  "react": "^18.0.0 || ^19.0.0",
@@ -35,3 +35,80 @@ describe('localized labels', () => {
35
35
  expect(screen.getByRole('button', { name: "Effacer l'heure" })).toBeInTheDocument();
36
36
  });
37
37
  });
38
+
39
+ describe('12h format', () => {
40
+ it('renders a trigger showing the formatted time', () => {
41
+ render(<TimePicker aria-label="Starts at" format="12h" defaultValue="21:30" />);
42
+ expect(screen.getByRole('button', { name: 'Starts at' })).toHaveTextContent('9:30 PM');
43
+ });
44
+
45
+ it('shows the placeholder when empty', () => {
46
+ render(<TimePicker aria-label="Starts at" format="12h" />);
47
+ expect(screen.getByRole('button', { name: 'Starts at' })).toHaveTextContent('Pick a time');
48
+ });
49
+
50
+ it('commits HH:MM when the period changes', async () => {
51
+ const user = userEvent.setup();
52
+ const onValueChange = vi.fn();
53
+ render(<TimePicker aria-label="Starts at" format="12h" defaultValue="09:30" onValueChange={onValueChange} />);
54
+ await user.click(screen.getByRole('button', { name: 'Starts at' }));
55
+ await user.selectOptions(screen.getByLabelText('AM or PM'), 'PM');
56
+ expect(onValueChange).toHaveBeenCalledWith('21:30');
57
+ });
58
+
59
+ it('commits HH:MM when the hour changes', async () => {
60
+ const user = userEvent.setup();
61
+ const onValueChange = vi.fn();
62
+ render(<TimePicker aria-label="Starts at" format="12h" defaultValue="09:30" onValueChange={onValueChange} />);
63
+ await user.click(screen.getByRole('button', { name: 'Starts at' }));
64
+ await user.selectOptions(screen.getByLabelText('Hour'), '5');
65
+ expect(onValueChange).toHaveBeenCalledWith('05:30');
66
+ });
67
+
68
+ it('limits minute options by minuteStep', async () => {
69
+ const user = userEvent.setup();
70
+ render(<TimePicker aria-label="Starts at" format="12h" defaultValue="09:30" minuteStep={15} />);
71
+ await user.click(screen.getByRole('button', { name: 'Starts at' }));
72
+ const minute = screen.getByLabelText('Minute') as HTMLSelectElement;
73
+ const values = Array.from(minute.options).map((o) => o.value);
74
+ expect(values).toEqual(['0', '15', '30', '45']);
75
+ });
76
+
77
+ it('disables out-of-range hours under min/max', async () => {
78
+ const user = userEvent.setup();
79
+ render(
80
+ <TimePicker aria-label="Starts at" format="12h" min="13:00" max="17:00" defaultValue="14:00" />
81
+ );
82
+ await user.click(screen.getByRole('button', { name: 'Starts at' }));
83
+ const hour = screen.getByLabelText('Hour') as HTMLSelectElement;
84
+ // Draft period is PM (14:00): 9 PM–12 PM? No — hours map 1–12 onto
85
+ // 13:00–23:59. 9 PM (21:00) and 12 PM (12:00) are out of range;
86
+ // 5 PM (17:00, minute 0 only) is the last enabled hour.
87
+ expect(hour.options[8]).toBeDisabled(); // value "9" -> 21:00
88
+ expect(hour.options[11]).toBeDisabled(); // value "12" -> 12:00
89
+ expect(hour.options[4]).not.toBeDisabled(); // value "5" -> 17:00
90
+ expect(hour.options[5]).toBeDisabled(); // value "6" -> 18:00
91
+ });
92
+
93
+ it('clears the value in 12h mode', async () => {
94
+ const user = userEvent.setup();
95
+ const onValueChange = vi.fn();
96
+ render(<TimePicker aria-label="Ends" format="12h" clearable defaultValue="17:00" onValueChange={onValueChange} />);
97
+ await user.click(screen.getByRole('button', { name: 'Clear time' }));
98
+ expect(onValueChange).toHaveBeenCalledWith('');
99
+ });
100
+
101
+ it('renders a hidden input for native forms', () => {
102
+ const { container } = render(
103
+ <TimePicker aria-label="Starts at" format="12h" name="starts_at" defaultValue="21:30" />
104
+ );
105
+ const hidden = container.querySelector('input[type="hidden"]');
106
+ expect(hidden).toHaveAttribute('name', 'starts_at');
107
+ expect(hidden).toHaveValue('21:30');
108
+ });
109
+
110
+ it('has no accessibility violations in 12h mode', async () => {
111
+ const { container } = render(<TimePicker aria-label="Time" format="12h" />);
112
+ expect(await axe(container)).toHaveNoViolations();
113
+ });
114
+ });
@@ -3,6 +3,10 @@
3
3
  import * as React from 'react';
4
4
  import { cn } from '../../utils/cn';
5
5
  import { Input, type InputProps } from '../input/Input';
6
+ import { Popover, PopoverContent, PopoverTrigger } from '../popover';
7
+ import { Select } from '../select';
8
+
9
+ export type TimePickerFormat = '24h' | '12h';
6
10
 
7
11
  export type TimePickerProps = Omit<InputProps, 'type' | 'value' | 'defaultValue'> & {
8
12
  /** "HH:MM" (24h) — controlled. */
@@ -15,30 +19,171 @@ export type TimePickerProps = Omit<InputProps, 'type' | 'value' | 'defaultValue'
15
19
  clearable?: boolean;
16
20
  /** Accessible label for the clear button. Default 'Clear time'. */
17
21
  clearLabel?: string;
22
+ /**
23
+ * Display contract. '24h' (default) renders the native time input.
24
+ * '12h' renders a button trigger with an hour/minute/AM-PM panel because
25
+ * input[type=time] cannot show AM/PM portably. Both emit "HH:MM".
26
+ */
27
+ format?: TimePickerFormat;
28
+ /** Minute granularity for the panel options and the native input step. Default 1. */
29
+ minuteStep?: number;
30
+ /** Earliest selectable time, "HH:MM" inclusive. */
31
+ min?: string;
32
+ /** Latest selectable time, "HH:MM" inclusive. */
33
+ max?: string;
34
+ /** Text shown before a time is chosen (12h mode). */
35
+ placeholder?: string;
18
36
  };
19
37
 
38
+ const pad = (n: number) => String(n).padStart(2, '0');
39
+
40
+ /** "HH:MM" -> minutes since midnight, or null when malformed. */
41
+ function toMinutes(value: string | undefined): number | null {
42
+ if (!value) return null;
43
+ const match = /^(\d{1,2}):(\d{2})/.exec(value.trim());
44
+ if (!match) return null;
45
+ const minutes = Number(match[1]) * 60 + Number(match[2]);
46
+ return minutes >= 0 && minutes <= 1439 ? minutes : null;
47
+ }
48
+
49
+ function fromMinutes(total: number): string {
50
+ return `${pad(Math.floor(total / 60))}:${pad(total % 60)}`;
51
+ }
52
+
53
+ /** All stepped minute-of-hour values. */
54
+ function minuteChoices(step: number): number[] {
55
+ const out: number[] = [];
56
+ for (let m = 0; m < 60; m += step) out.push(m);
57
+ return out;
58
+ }
59
+
20
60
  /**
21
- * Native time field with an "HH:MM" contract. The platform supplies the
22
- * picker, keyboard editing and locale behavior.
61
+ * Minutes-of-hour values that keep `hour24:minute` inside [minBound, maxBound].
62
+ * hour24 is the 24-hour hour the candidate belongs to.
63
+ */
64
+ function allowedMinutes(hour24: number, minBound: number, maxBound: number, step: number): number[] {
65
+ const base = hour24 * 60;
66
+ return minuteChoices(step).filter((m) => {
67
+ const total = base + m;
68
+ return total >= minBound && total <= maxBound;
69
+ });
70
+ }
71
+
72
+ /** Whether any stepped minute keeps `hour24` inside the bounds. */
73
+ function hourHasValidMinute(hour24: number, minBound: number, maxBound: number, step: number): boolean {
74
+ return allowedMinutes(hour24, minBound, maxBound, step).length > 0;
75
+ }
76
+
77
+ /** "HH:MM" -> { hour12, minute, period } for the 12h panel. */
78
+ function to12(hour24: number, minute: number): { hour12: number; minute: number; period: 'AM' | 'PM' } {
79
+ const period = hour24 >= 12 ? 'PM' : 'AM';
80
+ const hour12 = hour24 % 12 === 0 ? 12 : hour24 % 12;
81
+ return { hour12, minute, period };
82
+ }
83
+
84
+ /** { hour12, minute, period } -> minutes since midnight. */
85
+ function from12(hour12: number, minute: number, period: 'AM' | 'PM'): number {
86
+ const hour24 = (hour12 % 12) + (period === 'PM' ? 12 : 0);
87
+ return hour24 * 60 + minute;
88
+ }
89
+
90
+ /** "21:30" -> "9:30 PM". */
91
+ function format12(value: string): string {
92
+ const total = toMinutes(value);
93
+ if (total === null) return '';
94
+ const { hour12, minute, period } = to12(Math.floor(total / 60), total % 60);
95
+ return `${hour12}:${pad(minute)} ${period}`;
96
+ }
97
+
98
+ const PERIODS = ['AM', 'PM'] as const;
99
+
100
+ /**
101
+ * Time field with an "HH:MM" contract. The 24h format is a native time input;
102
+ * the 12h format is a button trigger with an hour/minute/period panel.
23
103
  */
24
104
  export const TimePicker = React.forwardRef<HTMLInputElement, TimePickerProps>(function TimePicker(
25
- { value, defaultValue, onValueChange, onChange, clearable = false, clearLabel = 'Clear time', className, ...props },
105
+ {
106
+ value,
107
+ defaultValue,
108
+ onValueChange,
109
+ onChange,
110
+ clearable = false,
111
+ clearLabel = 'Clear time',
112
+ format = '24h',
113
+ minuteStep = 1,
114
+ min,
115
+ max,
116
+ placeholder,
117
+ className,
118
+ name,
119
+ id,
120
+ disabled,
121
+ required,
122
+ 'aria-label': ariaLabel,
123
+ 'aria-describedby': ariaDescribedBy,
124
+ 'aria-invalid': ariaInvalid,
125
+ ...props
126
+ },
26
127
  ref
27
128
  ) {
28
129
  const [internal, setInternal] = React.useState(defaultValue ?? '');
29
130
  const current = value ?? internal;
131
+ const step = Math.min(60, Math.max(1, Math.floor(minuteStep)));
30
132
 
31
133
  const commit = (next: string) => {
32
134
  if (value === undefined) setInternal(next);
33
135
  onValueChange?.(next);
34
136
  };
35
137
 
138
+ const clearButton = clearable && current ? (
139
+ <button
140
+ type="button"
141
+ onClick={() => commit('')}
142
+ aria-label={clearLabel}
143
+ className="absolute right-1.5 top-1/2 z-10 inline-flex h-6 w-6 -translate-y-1/2 items-center justify-center rounded text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
144
+ >
145
+ ✕
146
+ </button>
147
+ ) : null;
148
+
149
+ if (format === '12h') {
150
+ return (
151
+ <TimePicker12h
152
+ current={current}
153
+ commit={commit}
154
+ clearButton={clearButton}
155
+ step={step}
156
+ min={min}
157
+ max={max}
158
+ placeholder={placeholder ?? 'Pick a time'}
159
+ className={className}
160
+ name={name}
161
+ id={id}
162
+ disabled={disabled}
163
+ ariaLabel={ariaLabel}
164
+ ariaDescribedBy={ariaDescribedBy}
165
+ ariaInvalid={ariaInvalid}
166
+ />
167
+ );
168
+ }
169
+
36
170
  return (
37
171
  <div className={cn('relative flex items-center', className)}>
38
172
  <Input
39
173
  ref={ref}
40
174
  type="time"
41
175
  value={current}
176
+ min={min}
177
+ max={max}
178
+ step={step * 60}
179
+ placeholder={placeholder}
180
+ name={name}
181
+ id={id}
182
+ disabled={disabled}
183
+ required={required}
184
+ aria-label={ariaLabel}
185
+ aria-describedby={ariaDescribedBy}
186
+ aria-invalid={ariaInvalid}
42
187
  onChange={(event) => {
43
188
  commit(event.target.value);
44
189
  onChange?.(event);
@@ -46,16 +191,174 @@ export const TimePicker = React.forwardRef<HTMLInputElement, TimePickerProps>(fu
46
191
  className={clearable && current ? 'pr-9' : undefined}
47
192
  {...props}
48
193
  />
49
- {clearable && current && (
50
- <button
194
+ {clearButton}
195
+ </div>
196
+ );
197
+ });
198
+ TimePicker.displayName = 'TimePicker';
199
+
200
+ type TimePicker12hConfig = {
201
+ current: string;
202
+ commit: (value: string) => void;
203
+ clearButton: React.ReactNode;
204
+ step: number;
205
+ min?: string;
206
+ max?: string;
207
+ placeholder: string;
208
+ className?: string;
209
+ name?: string;
210
+ id?: string;
211
+ disabled?: boolean;
212
+ ariaLabel?: string;
213
+ ariaDescribedBy?: string;
214
+ ariaInvalid?: boolean | 'true' | 'false' | 'grammar' | 'spelling';
215
+ };
216
+
217
+ function TimePicker12h({
218
+ current,
219
+ commit,
220
+ clearButton,
221
+ step,
222
+ min,
223
+ max,
224
+ placeholder,
225
+ className,
226
+ name,
227
+ id,
228
+ disabled,
229
+ ariaLabel,
230
+ ariaDescribedBy,
231
+ ariaInvalid,
232
+ }: TimePicker12hConfig) {
233
+ const [open, setOpen] = React.useState(false);
234
+
235
+ const total = toMinutes(current);
236
+ const minBound = toMinutes(min) ?? 0;
237
+ const maxBound = toMinutes(max) ?? 1439;
238
+
239
+ // Draft selection derived from the committed value; falls back to the
240
+ // earliest in-range time so the panel always has a coherent selection.
241
+ const draft = React.useMemo(() => {
242
+ if (total !== null) {
243
+ const hour24 = Math.floor(total / 60);
244
+ const { hour12, minute, period } = to12(hour24, total % 60);
245
+ return { hour12, minute, period };
246
+ }
247
+ // No value: anchor the draft at the lower bound so the panel opens on
248
+ // the earliest selectable time.
249
+ const anchor = minBound;
250
+ const hour24 = Math.floor(anchor / 60);
251
+ const { hour12, minute, period } = to12(hour24, anchor % 60);
252
+ return { hour12, minute, period };
253
+ }, [total, minBound]);
254
+
255
+ const minutesFor = (hour12: number, period: 'AM' | 'PM') => {
256
+ const hour24 = (hour12 % 12) + (period === 'PM' ? 12 : 0);
257
+ return allowedMinutes(hour24, minBound, maxBound, step);
258
+ };
259
+
260
+ const hours12 = Array.from({ length: 12 }, (_, i) => i + 1);
261
+
262
+ const hour24Of = (h12: number, p: 'AM' | 'PM') => (h12 % 12) + (p === 'PM' ? 12 : 0);
263
+
264
+ // An hour is selectable only when it yields valid minutes under the period
265
+ // currently shown, so a disabled-looking choice can never be committed.
266
+ const isHourEnabled = (h12: number) => minutesFor(h12, draft.period).length > 0;
267
+
268
+ const isPeriodEnabled = (p: 'AM' | 'PM') =>
269
+ hours12.some((h) => hourHasValidMinute(hour24Of(h, p), minBound, maxBound, step));
270
+
271
+ const minuteOptions = minutesFor(draft.hour12, draft.period);
272
+ const validMinute = minuteOptions.includes(draft.minute) ? draft.minute : minuteOptions[0];
273
+
274
+ const emit = (h12: number, minute: number, p: 'AM' | 'PM') => {
275
+ commit(fromMinutes(from12(h12, minute, p)));
276
+ };
277
+
278
+ const onHour = (h12: number) => {
279
+ const options = minutesFor(h12, draft.period);
280
+ if (options.length === 0) return;
281
+ const minute = options.includes(draft.minute) ? draft.minute : options[0];
282
+ emit(h12, minute, draft.period);
283
+ };
284
+
285
+ const onPeriod = (p: 'AM' | 'PM') => {
286
+ // The current hour may have no valid minutes under the new period (e.g.
287
+ // min=13:00 makes every AM hour invalid); snap to the first valid hour.
288
+ let hour = draft.hour12;
289
+ let options = minutesFor(hour, p);
290
+ if (options.length === 0) {
291
+ hour = hours12.find((h) => minutesFor(h, p).length > 0) ?? hour;
292
+ options = minutesFor(hour, p);
293
+ if (options.length === 0) return;
294
+ }
295
+ const minute = options.includes(draft.minute) ? draft.minute : options[0];
296
+ emit(hour, minute, p);
297
+ };
298
+
299
+ const label = total !== null ? format12(current) : placeholder;
300
+
301
+ return (
302
+ <div className={cn('relative flex items-center', className)}>
303
+ <Popover open={open} onOpenChange={setOpen}>
304
+ <PopoverTrigger
305
+ id={id}
51
306
  type="button"
52
- onClick={() => commit('')}
53
- aria-label={clearLabel}
54
- className="absolute right-1.5 inline-flex h-6 w-6 items-center justify-center rounded text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
307
+ disabled={disabled}
308
+ aria-label={ariaLabel}
309
+ aria-describedby={ariaDescribedBy}
310
+ aria-invalid={ariaInvalid}
311
+ className={cn(
312
+ 'flex h-10 w-full items-center justify-between rounded-md border border-input bg-background px-3 py-2 text-left text-sm',
313
+ 'hover:bg-muted/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50',
314
+ total === null && 'text-muted-foreground',
315
+ clearButton && 'pr-9'
316
+ )}
55
317
  >
56
- ✕
57
- </button>
58
- )}
318
+ <span>{label}</span>
319
+ <span aria-hidden="true" className="text-muted-foreground">
320
+ ▾
321
+ </span>
322
+ </PopoverTrigger>
323
+ <PopoverContent side="bottom" align="start" matchTriggerWidth className="p-3">
324
+ <div className="flex items-end gap-2">
325
+ <Select
326
+ label="Hour"
327
+ labelHidden
328
+ className="flex-1"
329
+ value={String(draft.hour12)}
330
+ onValueChange={(v) => onHour(Number(Array.isArray(v) ? v[0] : v))}
331
+ options={hours12.map((h) => ({
332
+ value: String(h),
333
+ label: pad(h),
334
+ disabled: !isHourEnabled(h),
335
+ }))}
336
+ />
337
+ <Select
338
+ label="Minute"
339
+ labelHidden
340
+ className="flex-1"
341
+ value={String(validMinute)}
342
+ onValueChange={(v) => emit(draft.hour12, Number(Array.isArray(v) ? v[0] : v), draft.period)}
343
+ options={minuteOptions.map((m) => ({ value: String(m), label: pad(m) }))}
344
+ />
345
+ <Select
346
+ label="AM or PM"
347
+ labelHidden
348
+ className="flex-1"
349
+ value={draft.period}
350
+ onValueChange={(v) => onPeriod((Array.isArray(v) ? v[0] : v) as 'AM' | 'PM')}
351
+ options={PERIODS.map((p) => ({
352
+ value: p,
353
+ label: p,
354
+ disabled: !isPeriodEnabled(p),
355
+ }))}
356
+ />
357
+ </div>
358
+ </PopoverContent>
359
+ </Popover>
360
+ {clearButton}
361
+ {name ? <input type="hidden" name={name} value={current} /> : null}
59
362
  </div>
60
363
  );
61
- });
364
+ }
@@ -138,7 +138,7 @@
138
138
  ],
139
139
  "package": "@slipstream-ui/core",
140
140
  "importPath": "@slipstream-ui/core",
141
- "version": "0.13.0",
141
+ "version": "0.14.0",
142
142
  "sourceDir": "accordion",
143
143
  "exportName": "Accordion"
144
144
  }
@@ -91,7 +91,7 @@
91
91
  ],
92
92
  "package": "@slipstream-ui/core",
93
93
  "importPath": "@slipstream-ui/core",
94
- "version": "0.13.0",
94
+ "version": "0.14.0",
95
95
  "sourceDir": "alert",
96
96
  "exportName": "Alert"
97
97
  }
@@ -4,7 +4,7 @@
4
4
  "tier": "molecule",
5
5
  "package": "@slipstream-ui/core",
6
6
  "importPath": "@slipstream-ui/core",
7
- "version": "0.13.0",
7
+ "version": "0.14.0",
8
8
  "sourceDir": "announcement-bar",
9
9
  "exportName": "AnnouncementBar",
10
10
  "description": "Dismissible announcement bar with optional action, tone and sticky positioning.",
@@ -225,7 +225,7 @@
225
225
  ],
226
226
  "package": "@slipstream-ui/core",
227
227
  "importPath": "@slipstream-ui/core",
228
- "version": "0.13.0",
228
+ "version": "0.14.0",
229
229
  "sourceDir": "app-shell",
230
230
  "exportName": "AppShell"
231
231
  }
@@ -4,7 +4,7 @@
4
4
  "tier": "molecule",
5
5
  "package": "@slipstream-ui/core",
6
6
  "importPath": "@slipstream-ui/core",
7
- "version": "0.13.0",
7
+ "version": "0.14.0",
8
8
  "sourceDir": "applied-filters",
9
9
  "exportName": "AppliedFilters",
10
10
  "description": "Applied-filter summary with a live count, removable chips and an edit action.",
@@ -4,7 +4,7 @@
4
4
  "tier": "molecule",
5
5
  "package": "@slipstream-ui/core",
6
6
  "importPath": "@slipstream-ui/core",
7
- "version": "0.13.0",
7
+ "version": "0.14.0",
8
8
  "sourceDir": "article-card",
9
9
  "exportName": "ArticleCard",
10
10
  "description": "Linked article or resource card with media, eyebrow, title, summary and metadata.",
@@ -124,7 +124,7 @@
124
124
  ],
125
125
  "package": "@slipstream-ui/core",
126
126
  "importPath": "@slipstream-ui/core",
127
- "version": "0.13.0",
127
+ "version": "0.14.0",
128
128
  "sourceDir": "auth-layout",
129
129
  "exportName": "AuthLayout"
130
130
  }
@@ -194,7 +194,7 @@
194
194
  ],
195
195
  "package": "@slipstream-ui/core",
196
196
  "importPath": "@slipstream-ui/core",
197
- "version": "0.13.0",
197
+ "version": "0.14.0",
198
198
  "sourceDir": "autocomplete",
199
199
  "exportName": "Autocomplete"
200
200
  }
@@ -152,7 +152,7 @@
152
152
  ],
153
153
  "package": "@slipstream-ui/core",
154
154
  "importPath": "@slipstream-ui/core",
155
- "version": "0.13.0",
155
+ "version": "0.14.0",
156
156
  "sourceDir": "avatar",
157
157
  "exportName": "Avatar"
158
158
  }
@@ -217,7 +217,7 @@
217
217
  ],
218
218
  "package": "@slipstream-ui/core",
219
219
  "importPath": "@slipstream-ui/core",
220
- "version": "0.13.0",
220
+ "version": "0.14.0",
221
221
  "sourceDir": "badge",
222
222
  "exportName": "Badge"
223
223
  }
@@ -101,7 +101,7 @@
101
101
  ],
102
102
  "package": "@slipstream-ui/core",
103
103
  "importPath": "@slipstream-ui/core",
104
- "version": "0.13.0",
104
+ "version": "0.14.0",
105
105
  "sourceDir": "block",
106
106
  "exportName": "Block"
107
107
  }
@@ -124,7 +124,7 @@
124
124
  ],
125
125
  "package": "@slipstream-ui/core",
126
126
  "importPath": "@slipstream-ui/core",
127
- "version": "0.13.0",
127
+ "version": "0.14.0",
128
128
  "sourceDir": "bottom-nav",
129
129
  "exportName": "BottomNav"
130
130
  }
@@ -129,7 +129,7 @@
129
129
  ],
130
130
  "package": "@slipstream-ui/core",
131
131
  "importPath": "@slipstream-ui/core",
132
- "version": "0.13.0",
132
+ "version": "0.14.0",
133
133
  "sourceDir": "breadcrumb",
134
134
  "exportName": "Breadcrumb"
135
135
  }
@@ -105,7 +105,7 @@
105
105
  ],
106
106
  "package": "@slipstream-ui/core",
107
107
  "importPath": "@slipstream-ui/core",
108
- "version": "0.13.0",
108
+ "version": "0.14.0",
109
109
  "sourceDir": "button-group",
110
110
  "exportName": "ButtonGroup"
111
111
  }
@@ -255,7 +255,7 @@
255
255
  ],
256
256
  "package": "@slipstream-ui/core",
257
257
  "importPath": "@slipstream-ui/core",
258
- "version": "0.13.0",
258
+ "version": "0.14.0",
259
259
  "sourceDir": "button",
260
260
  "exportName": "Button"
261
261
  }
@@ -169,7 +169,7 @@
169
169
  ],
170
170
  "package": "@slipstream-ui/core",
171
171
  "importPath": "@slipstream-ui/core",
172
- "version": "0.13.0",
172
+ "version": "0.14.0",
173
173
  "sourceDir": "calendar",
174
174
  "exportName": "Calendar"
175
175
  }
@@ -86,7 +86,7 @@
86
86
  ],
87
87
  "package": "@slipstream-ui/core",
88
88
  "importPath": "@slipstream-ui/core",
89
- "version": "0.13.0",
89
+ "version": "0.14.0",
90
90
  "sourceDir": "card",
91
91
  "exportName": "Card"
92
92
  }
@@ -160,7 +160,7 @@
160
160
  ],
161
161
  "package": "@slipstream-ui/core",
162
162
  "importPath": "@slipstream-ui/core",
163
- "version": "0.13.0",
163
+ "version": "0.14.0",
164
164
  "sourceDir": "checkbox",
165
165
  "exportName": "Checkbox"
166
166
  }
@@ -4,7 +4,7 @@
4
4
  "tier": "molecule",
5
5
  "package": "@slipstream-ui/core",
6
6
  "importPath": "@slipstream-ui/core",
7
- "version": "0.13.0",
7
+ "version": "0.14.0",
8
8
  "sourceDir": "comparison-table",
9
9
  "exportName": "ComparisonTable",
10
10
  "description": "Marketing comparison table with check/dash boolean cells, a highlighted column and responsive overflow.",