@slipstream-ui/core 0.12.1 → 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.
- package/dist/index.d.mts +208 -4
- package/dist/index.d.ts +208 -4
- package/dist/index.js +471 -11
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +463 -11
- package/dist/index.mjs.map +1 -1
- package/dist/manifests/accordion.manifest.json +1 -1
- package/dist/manifests/alert.manifest.json +1 -1
- package/dist/manifests/announcement-bar.manifest.json +1 -1
- package/dist/manifests/app-shell.manifest.json +1 -1
- package/dist/manifests/applied-filters.manifest.json +1 -1
- package/dist/manifests/article-card.manifest.json +1 -1
- package/dist/manifests/auth-layout.manifest.json +1 -1
- package/dist/manifests/autocomplete.manifest.json +1 -1
- package/dist/manifests/avatar.manifest.json +1 -1
- package/dist/manifests/badge.manifest.json +1 -1
- package/dist/manifests/block.manifest.json +1 -1
- package/dist/manifests/bottom-nav.manifest.json +1 -1
- package/dist/manifests/breadcrumb.manifest.json +1 -1
- package/dist/manifests/button-group.manifest.json +1 -1
- package/dist/manifests/button.manifest.json +1 -1
- package/dist/manifests/calendar.manifest.json +1 -1
- package/dist/manifests/card.manifest.json +1 -1
- package/dist/manifests/checkbox.manifest.json +1 -1
- package/dist/manifests/comparison-table.manifest.json +1 -1
- package/dist/manifests/confirm-dialog.manifest.json +1 -1
- package/dist/manifests/consent-banner.manifest.json +1 -1
- package/dist/manifests/contact-strip.manifest.json +1 -1
- package/dist/manifests/container.manifest.json +1 -1
- package/dist/manifests/cover-image.manifest.json +1 -1
- package/dist/manifests/cta-section.manifest.json +1 -1
- package/dist/manifests/data-table.manifest.json +1 -1
- package/dist/manifests/date-picker-popover.manifest.json +1 -1
- package/dist/manifests/date-picker.manifest.json +1 -1
- package/dist/manifests/date-range-picker.manifest.json +1 -1
- package/dist/manifests/deal-card.manifest.json +1 -1
- package/dist/manifests/dialog.manifest.json +1 -1
- package/dist/manifests/document-card.manifest.json +1 -1
- package/dist/manifests/drawer.manifest.json +1 -1
- package/dist/manifests/empty-state.manifest.json +1 -1
- package/dist/manifests/entity-card.manifest.json +1 -1
- package/dist/manifests/feature-grid.manifest.json +1 -1
- package/dist/manifests/feature-row.manifest.json +1 -1
- package/dist/manifests/fieldset.manifest.json +1 -1
- package/dist/manifests/figure.manifest.json +105 -0
- package/dist/manifests/file-upload.manifest.json +1 -1
- package/dist/manifests/filter-bar.manifest.json +1 -1
- package/dist/manifests/filter-chips.manifest.json +1 -1
- package/dist/manifests/filter-panel.manifest.json +1 -1
- package/dist/manifests/flex.manifest.json +1 -1
- package/dist/manifests/form-field.manifest.json +1 -1
- package/dist/manifests/form-layout.manifest.json +1 -1
- package/dist/manifests/form.manifest.json +1 -1
- package/dist/manifests/grid.manifest.json +1 -1
- package/dist/manifests/heading.manifest.json +1 -1
- package/dist/manifests/hero.manifest.json +1 -1
- package/dist/manifests/icon-button.manifest.json +101 -0
- package/dist/manifests/icon-tile.manifest.json +107 -0
- package/dist/manifests/icon.manifest.json +119 -0
- package/dist/manifests/image.manifest.json +1 -1
- package/dist/manifests/input-group.manifest.json +1 -1
- package/dist/manifests/input.manifest.json +1 -1
- package/dist/manifests/label.manifest.json +1 -1
- package/dist/manifests/link-tabs.manifest.json +1 -1
- package/dist/manifests/link.manifest.json +1 -1
- package/dist/manifests/list-toolbar.manifest.json +1 -1
- package/dist/manifests/list.manifest.json +1 -1
- package/dist/manifests/load-more.manifest.json +1 -1
- package/dist/manifests/logo-cloud.manifest.json +1 -1
- package/dist/manifests/media-card.manifest.json +1 -1
- package/dist/manifests/media.manifest.json +142 -0
- package/dist/manifests/menu.manifest.json +1 -1
- package/dist/manifests/metric-card.manifest.json +1 -1
- package/dist/manifests/month-schedule.manifest.json +1 -1
- package/dist/manifests/multi-select.manifest.json +1 -1
- package/dist/manifests/newsletter.manifest.json +1 -1
- package/dist/manifests/page-header.manifest.json +1 -1
- package/dist/manifests/pagination.manifest.json +1 -1
- package/dist/manifests/password-input.manifest.json +1 -1
- package/dist/manifests/popover.manifest.json +1 -1
- package/dist/manifests/process-steps.manifest.json +1 -1
- package/dist/manifests/progress.manifest.json +1 -1
- package/dist/manifests/prose.manifest.json +1 -1
- package/dist/manifests/radio.manifest.json +1 -1
- package/dist/manifests/range-slider.manifest.json +1 -1
- package/dist/manifests/search.manifest.json +1 -1
- package/dist/manifests/section-heading.manifest.json +1 -1
- package/dist/manifests/section.manifest.json +1 -1
- package/dist/manifests/segmented-control.manifest.json +1 -1
- package/dist/manifests/select-menu.manifest.json +1 -1
- package/dist/manifests/select.manifest.json +1 -1
- package/dist/manifests/separator.manifest.json +1 -1
- package/dist/manifests/site-footer.manifest.json +1 -1
- package/dist/manifests/site-header.manifest.json +1 -1
- package/dist/manifests/skeleton.manifest.json +1 -1
- package/dist/manifests/social-links.manifest.json +120 -0
- package/dist/manifests/spinner.manifest.json +1 -1
- package/dist/manifests/stat-band.manifest.json +1 -1
- package/dist/manifests/stepper.manifest.json +1 -1
- package/dist/manifests/switch.manifest.json +1 -1
- package/dist/manifests/table-card.manifest.json +1 -1
- package/dist/manifests/table-of-contents.manifest.json +1 -1
- package/dist/manifests/table.manifest.json +1 -1
- package/dist/manifests/tabs.manifest.json +1 -1
- package/dist/manifests/testimonial.manifest.json +1 -1
- package/dist/manifests/text.manifest.json +1 -1
- package/dist/manifests/textarea.manifest.json +1 -1
- package/dist/manifests/theme-toggle.manifest.json +1 -1
- package/dist/manifests/time-picker.manifest.json +49 -6
- package/dist/manifests/timeline.manifest.json +1 -1
- package/dist/manifests/toast.manifest.json +1 -1
- package/dist/manifests/tombstone-card.manifest.json +1 -1
- package/dist/manifests/tooltip.manifest.json +1 -1
- package/dist/src/components/figure/Figure.d.ts +23 -0
- package/dist/src/components/figure/Figure.js +60 -0
- package/dist/src/components/figure/Figure.js.map +1 -0
- package/dist/src/components/figure/Figure.mjs +26 -0
- package/dist/src/components/figure/Figure.mjs.map +1 -0
- package/dist/src/components/figure/index.d.ts +2 -0
- package/dist/src/components/figure/index.js +29 -0
- package/dist/src/components/figure/index.js.map +1 -0
- package/dist/src/components/figure/index.mjs +5 -0
- package/dist/src/components/figure/index.mjs.map +1 -0
- package/dist/src/components/icon/Icon.d.ts +33 -0
- package/dist/src/components/icon/Icon.js +82 -0
- package/dist/src/components/icon/Icon.js.map +1 -0
- package/dist/src/components/icon/Icon.mjs +47 -0
- package/dist/src/components/icon/Icon.mjs.map +1 -0
- package/dist/src/components/icon/index.d.ts +2 -0
- package/dist/src/components/icon/index.js +31 -0
- package/dist/src/components/icon/index.js.map +1 -0
- package/dist/src/components/icon/index.mjs +6 -0
- package/dist/src/components/icon/index.mjs.map +1 -0
- package/dist/src/components/icon-button/IconButton.d.ts +25 -0
- package/dist/src/components/icon-button/IconButton.js +60 -0
- package/dist/src/components/icon-button/IconButton.js.map +1 -0
- package/dist/src/components/icon-button/IconButton.mjs +26 -0
- package/dist/src/components/icon-button/IconButton.mjs.map +1 -0
- package/dist/src/components/icon-button/index.d.ts +2 -0
- package/dist/src/components/icon-button/index.js +29 -0
- package/dist/src/components/icon-button/index.js.map +1 -0
- package/dist/src/components/icon-button/index.mjs +5 -0
- package/dist/src/components/icon-button/index.mjs.map +1 -0
- package/dist/src/components/icon-tile/IconTile.d.ts +23 -0
- package/dist/src/components/icon-tile/IconTile.js +75 -0
- package/dist/src/components/icon-tile/IconTile.js.map +1 -0
- package/dist/src/components/icon-tile/IconTile.mjs +40 -0
- package/dist/src/components/icon-tile/IconTile.mjs.map +1 -0
- package/dist/src/components/icon-tile/index.d.ts +2 -0
- package/dist/src/components/icon-tile/index.js +31 -0
- package/dist/src/components/icon-tile/index.js.map +1 -0
- package/dist/src/components/icon-tile/index.mjs +6 -0
- package/dist/src/components/icon-tile/index.mjs.map +1 -0
- package/dist/src/components/media/Media.d.ts +48 -0
- package/dist/src/components/media/Media.js +97 -0
- package/dist/src/components/media/Media.js.map +1 -0
- package/dist/src/components/media/Media.mjs +63 -0
- package/dist/src/components/media/Media.mjs.map +1 -0
- package/dist/src/components/media/index.d.ts +2 -0
- package/dist/src/components/media/index.js +29 -0
- package/dist/src/components/media/index.js.map +1 -0
- package/dist/src/components/media/index.mjs +5 -0
- package/dist/src/components/media/index.mjs.map +1 -0
- package/dist/src/components/social-links/SocialLinks.d.ts +34 -0
- package/dist/src/components/social-links/SocialLinks.js +69 -0
- package/dist/src/components/social-links/SocialLinks.js.map +1 -0
- package/dist/src/components/social-links/SocialLinks.mjs +35 -0
- package/dist/src/components/social-links/SocialLinks.mjs.map +1 -0
- package/dist/src/components/social-links/index.d.ts +2 -0
- package/dist/src/components/social-links/index.js +29 -0
- package/dist/src/components/social-links/index.js.map +1 -0
- package/dist/src/components/social-links/index.mjs +5 -0
- package/dist/src/components/social-links/index.mjs.map +1 -0
- package/dist/src/components/time-picker/TimePicker.d.ts +31 -2
- package/dist/src/components/time-picker/TimePicker.js +244 -11
- package/dist/src/components/time-picker/TimePicker.js.map +1 -1
- package/dist/src/components/time-picker/TimePicker.mjs +244 -11
- package/dist/src/components/time-picker/TimePicker.mjs.map +1 -1
- package/dist/src/index.d.ts +6 -0
- package/dist/styles-full.css +1 -1
- package/dist/styles.css +1 -1
- package/package.json +4 -4
- package/src/components/figure/Figure.test.tsx +54 -0
- package/src/components/figure/Figure.tsx +38 -0
- package/src/components/figure/index.ts +2 -0
- package/src/components/icon/Icon.test.tsx +70 -0
- package/src/components/icon/Icon.tsx +61 -0
- package/src/components/icon/index.ts +2 -0
- package/src/components/icon-button/IconButton.test.tsx +76 -0
- package/src/components/icon-button/IconButton.tsx +38 -0
- package/src/components/icon-button/index.ts +2 -0
- package/src/components/icon-tile/IconTile.test.tsx +63 -0
- package/src/components/icon-tile/IconTile.tsx +55 -0
- package/src/components/icon-tile/index.ts +2 -0
- package/src/components/media/Media.test.tsx +53 -0
- package/src/components/media/Media.tsx +92 -0
- package/src/components/media/index.ts +2 -0
- package/src/components/social-links/SocialLinks.test.tsx +59 -0
- package/src/components/social-links/SocialLinks.tsx +73 -0
- package/src/components/social-links/index.ts +2 -0
- package/src/components/time-picker/TimePicker.test.tsx +77 -0
- package/src/components/time-picker/TimePicker.tsx +315 -12
- package/src/index.ts +6 -0
- package/src/manifests/accordion.manifest.json +1 -1
- package/src/manifests/alert.manifest.json +1 -1
- package/src/manifests/announcement-bar.manifest.json +1 -1
- package/src/manifests/app-shell.manifest.json +1 -1
- package/src/manifests/applied-filters.manifest.json +1 -1
- package/src/manifests/article-card.manifest.json +1 -1
- package/src/manifests/auth-layout.manifest.json +1 -1
- package/src/manifests/autocomplete.manifest.json +1 -1
- package/src/manifests/avatar.manifest.json +1 -1
- package/src/manifests/badge.manifest.json +1 -1
- package/src/manifests/block.manifest.json +1 -1
- package/src/manifests/bottom-nav.manifest.json +1 -1
- package/src/manifests/breadcrumb.manifest.json +1 -1
- package/src/manifests/button-group.manifest.json +1 -1
- package/src/manifests/button.manifest.json +1 -1
- package/src/manifests/calendar.manifest.json +1 -1
- package/src/manifests/card.manifest.json +1 -1
- package/src/manifests/checkbox.manifest.json +1 -1
- package/src/manifests/comparison-table.manifest.json +1 -1
- package/src/manifests/confirm-dialog.manifest.json +1 -1
- package/src/manifests/consent-banner.manifest.json +1 -1
- package/src/manifests/contact-strip.manifest.json +1 -1
- package/src/manifests/container.manifest.json +1 -1
- package/src/manifests/cover-image.manifest.json +1 -1
- package/src/manifests/cta-section.manifest.json +1 -1
- package/src/manifests/data-table.manifest.json +1 -1
- package/src/manifests/date-picker-popover.manifest.json +1 -1
- package/src/manifests/date-picker.manifest.json +1 -1
- package/src/manifests/date-range-picker.manifest.json +1 -1
- package/src/manifests/deal-card.manifest.json +1 -1
- package/src/manifests/dialog.manifest.json +1 -1
- package/src/manifests/document-card.manifest.json +1 -1
- package/src/manifests/drawer.manifest.json +1 -1
- package/src/manifests/empty-state.manifest.json +1 -1
- package/src/manifests/entity-card.manifest.json +1 -1
- package/src/manifests/feature-grid.manifest.json +1 -1
- package/src/manifests/feature-row.manifest.json +1 -1
- package/src/manifests/fieldset.manifest.json +1 -1
- package/src/manifests/figure.manifest.json +105 -0
- package/src/manifests/file-upload.manifest.json +1 -1
- package/src/manifests/filter-bar.manifest.json +1 -1
- package/src/manifests/filter-chips.manifest.json +1 -1
- package/src/manifests/filter-panel.manifest.json +1 -1
- package/src/manifests/flex.manifest.json +1 -1
- package/src/manifests/form-field.manifest.json +1 -1
- package/src/manifests/form-layout.manifest.json +1 -1
- package/src/manifests/form.manifest.json +1 -1
- package/src/manifests/grid.manifest.json +1 -1
- package/src/manifests/heading.manifest.json +1 -1
- package/src/manifests/hero.manifest.json +1 -1
- package/src/manifests/icon-button.manifest.json +101 -0
- package/src/manifests/icon-tile.manifest.json +107 -0
- package/src/manifests/icon.manifest.json +119 -0
- package/src/manifests/image.manifest.json +1 -1
- package/src/manifests/input-group.manifest.json +1 -1
- package/src/manifests/input.manifest.json +1 -1
- package/src/manifests/label.manifest.json +1 -1
- package/src/manifests/link-tabs.manifest.json +1 -1
- package/src/manifests/link.manifest.json +1 -1
- package/src/manifests/list-toolbar.manifest.json +1 -1
- package/src/manifests/list.manifest.json +1 -1
- package/src/manifests/load-more.manifest.json +1 -1
- package/src/manifests/logo-cloud.manifest.json +1 -1
- package/src/manifests/media-card.manifest.json +1 -1
- package/src/manifests/media.manifest.json +142 -0
- package/src/manifests/menu.manifest.json +1 -1
- package/src/manifests/metric-card.manifest.json +1 -1
- package/src/manifests/month-schedule.manifest.json +1 -1
- package/src/manifests/multi-select.manifest.json +1 -1
- package/src/manifests/newsletter.manifest.json +1 -1
- package/src/manifests/page-header.manifest.json +1 -1
- package/src/manifests/pagination.manifest.json +1 -1
- package/src/manifests/password-input.manifest.json +1 -1
- package/src/manifests/popover.manifest.json +1 -1
- package/src/manifests/process-steps.manifest.json +1 -1
- package/src/manifests/progress.manifest.json +1 -1
- package/src/manifests/prose.manifest.json +1 -1
- package/src/manifests/radio.manifest.json +1 -1
- package/src/manifests/range-slider.manifest.json +1 -1
- package/src/manifests/search.manifest.json +1 -1
- package/src/manifests/section-heading.manifest.json +1 -1
- package/src/manifests/section.manifest.json +1 -1
- package/src/manifests/segmented-control.manifest.json +1 -1
- package/src/manifests/select-menu.manifest.json +1 -1
- package/src/manifests/select.manifest.json +1 -1
- package/src/manifests/separator.manifest.json +1 -1
- package/src/manifests/site-footer.manifest.json +1 -1
- package/src/manifests/site-header.manifest.json +1 -1
- package/src/manifests/skeleton.manifest.json +1 -1
- package/src/manifests/social-links.manifest.json +120 -0
- package/src/manifests/spinner.manifest.json +1 -1
- package/src/manifests/stat-band.manifest.json +1 -1
- package/src/manifests/stepper.manifest.json +1 -1
- package/src/manifests/switch.manifest.json +1 -1
- package/src/manifests/table-card.manifest.json +1 -1
- package/src/manifests/table-of-contents.manifest.json +1 -1
- package/src/manifests/table.manifest.json +1 -1
- package/src/manifests/tabs.manifest.json +1 -1
- package/src/manifests/testimonial.manifest.json +1 -1
- package/src/manifests/text.manifest.json +1 -1
- package/src/manifests/textarea.manifest.json +1 -1
- package/src/manifests/theme-toggle.manifest.json +1 -1
- package/src/manifests/time-picker.manifest.json +49 -6
- package/src/manifests/timeline.manifest.json +1 -1
- package/src/manifests/toast.manifest.json +1 -1
- package/src/manifests/tombstone-card.manifest.json +1 -1
- package/src/manifests/tooltip.manifest.json +1 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { type InputProps } from '../input/Input';
|
|
3
|
+
export type TimePickerFormat = '24h' | '12h';
|
|
3
4
|
export type TimePickerProps = Omit<InputProps, 'type' | 'value' | 'defaultValue'> & {
|
|
4
5
|
/** "HH:MM" (24h) — controlled. */
|
|
5
6
|
value?: string;
|
|
@@ -11,10 +12,24 @@ export type TimePickerProps = Omit<InputProps, 'type' | 'value' | 'defaultValue'
|
|
|
11
12
|
clearable?: boolean;
|
|
12
13
|
/** Accessible label for the clear button. Default 'Clear time'. */
|
|
13
14
|
clearLabel?: string;
|
|
15
|
+
/**
|
|
16
|
+
* Display contract. '24h' (default) renders the native time input.
|
|
17
|
+
* '12h' renders a button trigger with an hour/minute/AM-PM panel because
|
|
18
|
+
* input[type=time] cannot show AM/PM portably. Both emit "HH:MM".
|
|
19
|
+
*/
|
|
20
|
+
format?: TimePickerFormat;
|
|
21
|
+
/** Minute granularity for the panel options and the native input step. Default 1. */
|
|
22
|
+
minuteStep?: number;
|
|
23
|
+
/** Earliest selectable time, "HH:MM" inclusive. */
|
|
24
|
+
min?: string;
|
|
25
|
+
/** Latest selectable time, "HH:MM" inclusive. */
|
|
26
|
+
max?: string;
|
|
27
|
+
/** Text shown before a time is chosen (12h mode). */
|
|
28
|
+
placeholder?: string;
|
|
14
29
|
};
|
|
15
30
|
/**
|
|
16
|
-
*
|
|
17
|
-
*
|
|
31
|
+
* Time field with an "HH:MM" contract. The 24h format is a native time input;
|
|
32
|
+
* the 12h format is a button trigger with an hour/minute/period panel.
|
|
18
33
|
*/
|
|
19
34
|
export declare const TimePicker: React.ForwardRefExoticComponent<Omit<InputProps, "type" | "defaultValue" | "value"> & {
|
|
20
35
|
/** "HH:MM" (24h) — controlled. */
|
|
@@ -27,4 +42,18 @@ export declare const TimePicker: React.ForwardRefExoticComponent<Omit<InputProps
|
|
|
27
42
|
clearable?: boolean;
|
|
28
43
|
/** Accessible label for the clear button. Default 'Clear time'. */
|
|
29
44
|
clearLabel?: string;
|
|
45
|
+
/**
|
|
46
|
+
* Display contract. '24h' (default) renders the native time input.
|
|
47
|
+
* '12h' renders a button trigger with an hour/minute/AM-PM panel because
|
|
48
|
+
* input[type=time] cannot show AM/PM portably. Both emit "HH:MM".
|
|
49
|
+
*/
|
|
50
|
+
format?: TimePickerFormat;
|
|
51
|
+
/** Minute granularity for the panel options and the native input step. Default 1. */
|
|
52
|
+
minuteStep?: number;
|
|
53
|
+
/** Earliest selectable time, "HH:MM" inclusive. */
|
|
54
|
+
min?: string;
|
|
55
|
+
/** Latest selectable time, "HH:MM" inclusive. */
|
|
56
|
+
max?: string;
|
|
57
|
+
/** Text shown before a time is chosen (12h mode). */
|
|
58
|
+
placeholder?: string;
|
|
30
59
|
} & React.RefAttributes<HTMLInputElement>>;
|
|
@@ -36,13 +36,110 @@ var import_jsx_runtime = require("react/jsx-runtime");
|
|
|
36
36
|
var React = __toESM(require("react"));
|
|
37
37
|
var import_cn = require("../../utils/cn.js");
|
|
38
38
|
var import_Input = require("../input/Input.js");
|
|
39
|
-
|
|
39
|
+
var import_popover = require("../popover/index.js");
|
|
40
|
+
var import_select = require("../select/index.js");
|
|
41
|
+
const pad = (n) => String(n).padStart(2, "0");
|
|
42
|
+
function toMinutes(value) {
|
|
43
|
+
if (!value) return null;
|
|
44
|
+
const match = /^(\d{1,2}):(\d{2})/.exec(value.trim());
|
|
45
|
+
if (!match) return null;
|
|
46
|
+
const minutes = Number(match[1]) * 60 + Number(match[2]);
|
|
47
|
+
return minutes >= 0 && minutes <= 1439 ? minutes : null;
|
|
48
|
+
}
|
|
49
|
+
function fromMinutes(total) {
|
|
50
|
+
return `${pad(Math.floor(total / 60))}:${pad(total % 60)}`;
|
|
51
|
+
}
|
|
52
|
+
function minuteChoices(step) {
|
|
53
|
+
const out = [];
|
|
54
|
+
for (let m = 0; m < 60; m += step) out.push(m);
|
|
55
|
+
return out;
|
|
56
|
+
}
|
|
57
|
+
function allowedMinutes(hour24, minBound, maxBound, step) {
|
|
58
|
+
const base = hour24 * 60;
|
|
59
|
+
return minuteChoices(step).filter((m) => {
|
|
60
|
+
const total = base + m;
|
|
61
|
+
return total >= minBound && total <= maxBound;
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
function hourHasValidMinute(hour24, minBound, maxBound, step) {
|
|
65
|
+
return allowedMinutes(hour24, minBound, maxBound, step).length > 0;
|
|
66
|
+
}
|
|
67
|
+
function to12(hour24, minute) {
|
|
68
|
+
const period = hour24 >= 12 ? "PM" : "AM";
|
|
69
|
+
const hour12 = hour24 % 12 === 0 ? 12 : hour24 % 12;
|
|
70
|
+
return { hour12, minute, period };
|
|
71
|
+
}
|
|
72
|
+
function from12(hour12, minute, period) {
|
|
73
|
+
const hour24 = hour12 % 12 + (period === "PM" ? 12 : 0);
|
|
74
|
+
return hour24 * 60 + minute;
|
|
75
|
+
}
|
|
76
|
+
function format12(value) {
|
|
77
|
+
const total = toMinutes(value);
|
|
78
|
+
if (total === null) return "";
|
|
79
|
+
const { hour12, minute, period } = to12(Math.floor(total / 60), total % 60);
|
|
80
|
+
return `${hour12}:${pad(minute)} ${period}`;
|
|
81
|
+
}
|
|
82
|
+
const PERIODS = ["AM", "PM"];
|
|
83
|
+
const TimePicker = React.forwardRef(function TimePicker2({
|
|
84
|
+
value,
|
|
85
|
+
defaultValue,
|
|
86
|
+
onValueChange,
|
|
87
|
+
onChange,
|
|
88
|
+
clearable = false,
|
|
89
|
+
clearLabel = "Clear time",
|
|
90
|
+
format = "24h",
|
|
91
|
+
minuteStep = 1,
|
|
92
|
+
min,
|
|
93
|
+
max,
|
|
94
|
+
placeholder,
|
|
95
|
+
className,
|
|
96
|
+
name,
|
|
97
|
+
id,
|
|
98
|
+
disabled,
|
|
99
|
+
required,
|
|
100
|
+
"aria-label": ariaLabel,
|
|
101
|
+
"aria-describedby": ariaDescribedBy,
|
|
102
|
+
"aria-invalid": ariaInvalid,
|
|
103
|
+
...props
|
|
104
|
+
}, ref) {
|
|
40
105
|
const [internal, setInternal] = React.useState(defaultValue ?? "");
|
|
41
106
|
const current = value ?? internal;
|
|
107
|
+
const step = Math.min(60, Math.max(1, Math.floor(minuteStep)));
|
|
42
108
|
const commit = (next) => {
|
|
43
109
|
if (value === void 0) setInternal(next);
|
|
44
110
|
onValueChange?.(next);
|
|
45
111
|
};
|
|
112
|
+
const clearButton = clearable && current ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
113
|
+
"button",
|
|
114
|
+
{
|
|
115
|
+
type: "button",
|
|
116
|
+
onClick: () => commit(""),
|
|
117
|
+
"aria-label": clearLabel,
|
|
118
|
+
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",
|
|
119
|
+
children: "\u2715"
|
|
120
|
+
}
|
|
121
|
+
) : null;
|
|
122
|
+
if (format === "12h") {
|
|
123
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
124
|
+
TimePicker12h,
|
|
125
|
+
{
|
|
126
|
+
current,
|
|
127
|
+
commit,
|
|
128
|
+
clearButton,
|
|
129
|
+
step,
|
|
130
|
+
min,
|
|
131
|
+
max,
|
|
132
|
+
placeholder: placeholder ?? "Pick a time",
|
|
133
|
+
className,
|
|
134
|
+
name,
|
|
135
|
+
id,
|
|
136
|
+
disabled,
|
|
137
|
+
ariaLabel,
|
|
138
|
+
ariaDescribedBy,
|
|
139
|
+
ariaInvalid
|
|
140
|
+
}
|
|
141
|
+
);
|
|
142
|
+
}
|
|
46
143
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: (0, import_cn.cn)("relative flex items-center", className), children: [
|
|
47
144
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
48
145
|
import_Input.Input,
|
|
@@ -50,6 +147,17 @@ const TimePicker = React.forwardRef(function TimePicker2({ value, defaultValue,
|
|
|
50
147
|
ref,
|
|
51
148
|
type: "time",
|
|
52
149
|
value: current,
|
|
150
|
+
min,
|
|
151
|
+
max,
|
|
152
|
+
step: step * 60,
|
|
153
|
+
placeholder,
|
|
154
|
+
name,
|
|
155
|
+
id,
|
|
156
|
+
disabled,
|
|
157
|
+
required,
|
|
158
|
+
"aria-label": ariaLabel,
|
|
159
|
+
"aria-describedby": ariaDescribedBy,
|
|
160
|
+
"aria-invalid": ariaInvalid,
|
|
53
161
|
onChange: (event) => {
|
|
54
162
|
commit(event.target.value);
|
|
55
163
|
onChange?.(event);
|
|
@@ -58,18 +166,143 @@ const TimePicker = React.forwardRef(function TimePicker2({ value, defaultValue,
|
|
|
58
166
|
...props
|
|
59
167
|
}
|
|
60
168
|
),
|
|
61
|
-
|
|
62
|
-
"button",
|
|
63
|
-
{
|
|
64
|
-
type: "button",
|
|
65
|
-
onClick: () => commit(""),
|
|
66
|
-
"aria-label": clearLabel,
|
|
67
|
-
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",
|
|
68
|
-
children: "\u2715"
|
|
69
|
-
}
|
|
70
|
-
)
|
|
169
|
+
clearButton
|
|
71
170
|
] });
|
|
72
171
|
});
|
|
172
|
+
TimePicker.displayName = "TimePicker";
|
|
173
|
+
function TimePicker12h({
|
|
174
|
+
current,
|
|
175
|
+
commit,
|
|
176
|
+
clearButton,
|
|
177
|
+
step,
|
|
178
|
+
min,
|
|
179
|
+
max,
|
|
180
|
+
placeholder,
|
|
181
|
+
className,
|
|
182
|
+
name,
|
|
183
|
+
id,
|
|
184
|
+
disabled,
|
|
185
|
+
ariaLabel,
|
|
186
|
+
ariaDescribedBy,
|
|
187
|
+
ariaInvalid
|
|
188
|
+
}) {
|
|
189
|
+
const [open, setOpen] = React.useState(false);
|
|
190
|
+
const total = toMinutes(current);
|
|
191
|
+
const minBound = toMinutes(min) ?? 0;
|
|
192
|
+
const maxBound = toMinutes(max) ?? 1439;
|
|
193
|
+
const draft = React.useMemo(() => {
|
|
194
|
+
if (total !== null) {
|
|
195
|
+
const hour242 = Math.floor(total / 60);
|
|
196
|
+
const { hour12: hour122, minute: minute2, period: period2 } = to12(hour242, total % 60);
|
|
197
|
+
return { hour12: hour122, minute: minute2, period: period2 };
|
|
198
|
+
}
|
|
199
|
+
const anchor = minBound;
|
|
200
|
+
const hour24 = Math.floor(anchor / 60);
|
|
201
|
+
const { hour12, minute, period } = to12(hour24, anchor % 60);
|
|
202
|
+
return { hour12, minute, period };
|
|
203
|
+
}, [total, minBound]);
|
|
204
|
+
const minutesFor = (hour12, period) => {
|
|
205
|
+
const hour24 = hour12 % 12 + (period === "PM" ? 12 : 0);
|
|
206
|
+
return allowedMinutes(hour24, minBound, maxBound, step);
|
|
207
|
+
};
|
|
208
|
+
const hours12 = Array.from({ length: 12 }, (_, i) => i + 1);
|
|
209
|
+
const hour24Of = (h12, p) => h12 % 12 + (p === "PM" ? 12 : 0);
|
|
210
|
+
const isHourEnabled = (h12) => minutesFor(h12, draft.period).length > 0;
|
|
211
|
+
const isPeriodEnabled = (p) => hours12.some((h) => hourHasValidMinute(hour24Of(h, p), minBound, maxBound, step));
|
|
212
|
+
const minuteOptions = minutesFor(draft.hour12, draft.period);
|
|
213
|
+
const validMinute = minuteOptions.includes(draft.minute) ? draft.minute : minuteOptions[0];
|
|
214
|
+
const emit = (h12, minute, p) => {
|
|
215
|
+
commit(fromMinutes(from12(h12, minute, p)));
|
|
216
|
+
};
|
|
217
|
+
const onHour = (h12) => {
|
|
218
|
+
const options = minutesFor(h12, draft.period);
|
|
219
|
+
if (options.length === 0) return;
|
|
220
|
+
const minute = options.includes(draft.minute) ? draft.minute : options[0];
|
|
221
|
+
emit(h12, minute, draft.period);
|
|
222
|
+
};
|
|
223
|
+
const onPeriod = (p) => {
|
|
224
|
+
let hour = draft.hour12;
|
|
225
|
+
let options = minutesFor(hour, p);
|
|
226
|
+
if (options.length === 0) {
|
|
227
|
+
hour = hours12.find((h) => minutesFor(h, p).length > 0) ?? hour;
|
|
228
|
+
options = minutesFor(hour, p);
|
|
229
|
+
if (options.length === 0) return;
|
|
230
|
+
}
|
|
231
|
+
const minute = options.includes(draft.minute) ? draft.minute : options[0];
|
|
232
|
+
emit(hour, minute, p);
|
|
233
|
+
};
|
|
234
|
+
const label = total !== null ? format12(current) : placeholder;
|
|
235
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: (0, import_cn.cn)("relative flex items-center", className), children: [
|
|
236
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_popover.Popover, { open, onOpenChange: setOpen, children: [
|
|
237
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
238
|
+
import_popover.PopoverTrigger,
|
|
239
|
+
{
|
|
240
|
+
id,
|
|
241
|
+
type: "button",
|
|
242
|
+
disabled,
|
|
243
|
+
"aria-label": ariaLabel,
|
|
244
|
+
"aria-describedby": ariaDescribedBy,
|
|
245
|
+
"aria-invalid": ariaInvalid,
|
|
246
|
+
className: (0, import_cn.cn)(
|
|
247
|
+
"flex h-10 w-full items-center justify-between rounded-md border border-input bg-background px-3 py-2 text-left text-sm",
|
|
248
|
+
"hover:bg-muted/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50",
|
|
249
|
+
total === null && "text-muted-foreground",
|
|
250
|
+
clearButton && "pr-9"
|
|
251
|
+
),
|
|
252
|
+
children: [
|
|
253
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: label }),
|
|
254
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { "aria-hidden": "true", className: "text-muted-foreground", children: "\u25BE" })
|
|
255
|
+
]
|
|
256
|
+
}
|
|
257
|
+
),
|
|
258
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_popover.PopoverContent, { side: "bottom", align: "start", matchTriggerWidth: true, className: "p-3", children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex items-end gap-2", children: [
|
|
259
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
260
|
+
import_select.Select,
|
|
261
|
+
{
|
|
262
|
+
label: "Hour",
|
|
263
|
+
labelHidden: true,
|
|
264
|
+
className: "flex-1",
|
|
265
|
+
value: String(draft.hour12),
|
|
266
|
+
onValueChange: (v) => onHour(Number(Array.isArray(v) ? v[0] : v)),
|
|
267
|
+
options: hours12.map((h) => ({
|
|
268
|
+
value: String(h),
|
|
269
|
+
label: pad(h),
|
|
270
|
+
disabled: !isHourEnabled(h)
|
|
271
|
+
}))
|
|
272
|
+
}
|
|
273
|
+
),
|
|
274
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
275
|
+
import_select.Select,
|
|
276
|
+
{
|
|
277
|
+
label: "Minute",
|
|
278
|
+
labelHidden: true,
|
|
279
|
+
className: "flex-1",
|
|
280
|
+
value: String(validMinute),
|
|
281
|
+
onValueChange: (v) => emit(draft.hour12, Number(Array.isArray(v) ? v[0] : v), draft.period),
|
|
282
|
+
options: minuteOptions.map((m) => ({ value: String(m), label: pad(m) }))
|
|
283
|
+
}
|
|
284
|
+
),
|
|
285
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
286
|
+
import_select.Select,
|
|
287
|
+
{
|
|
288
|
+
label: "AM or PM",
|
|
289
|
+
labelHidden: true,
|
|
290
|
+
className: "flex-1",
|
|
291
|
+
value: draft.period,
|
|
292
|
+
onValueChange: (v) => onPeriod(Array.isArray(v) ? v[0] : v),
|
|
293
|
+
options: PERIODS.map((p) => ({
|
|
294
|
+
value: p,
|
|
295
|
+
label: p,
|
|
296
|
+
disabled: !isPeriodEnabled(p)
|
|
297
|
+
}))
|
|
298
|
+
}
|
|
299
|
+
)
|
|
300
|
+
] }) })
|
|
301
|
+
] }),
|
|
302
|
+
clearButton,
|
|
303
|
+
name ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("input", { type: "hidden", name, value: current }) : null
|
|
304
|
+
] });
|
|
305
|
+
}
|
|
73
306
|
// Annotate the CommonJS export names for ESM import in node:
|
|
74
307
|
0 && (module.exports = {
|
|
75
308
|
TimePicker
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/components/time-picker/TimePicker.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { cn } from '../../utils/cn';\nimport { Input, type InputProps } from '../input/Input';\n\nexport type TimePickerProps = Omit<InputProps, 'type' | 'value' | 'defaultValue'> & {\n /** \"HH:MM\" (24h) — controlled. */\n value?: string;\n /** \"HH:MM\" — initial value when uncontrolled. */\n defaultValue?: string;\n /** Fired with the time string ('' when cleared). */\n onValueChange?: (value: string) => void;\n /** Show a clear button once a time is selected. */\n clearable?: boolean;\n /** Accessible label for the clear button. Default 'Clear time'. */\n clearLabel?: string;\n};\n\n/**\n * Native time field with an \"HH:MM\" contract. The platform supplies the\n * picker, keyboard editing and locale behavior.\n */\nexport const TimePicker = React.forwardRef<HTMLInputElement, TimePickerProps>(function TimePicker(\n { value, defaultValue, onValueChange, onChange, clearable = false, clearLabel = 'Clear time', className, ...props },\n ref\n) {\n const [internal, setInternal] = React.useState(defaultValue ?? '');\n const current = value ?? internal;\n\n const commit = (next: string) => {\n if (value === undefined) setInternal(next);\n onValueChange?.(next);\n };\n\n return (\n <div className={cn('relative flex items-center', className)}>\n <Input\n ref={ref}\n type=\"time\"\n value={current}\n onChange={(event) => {\n commit(event.target.value);\n onChange?.(event);\n }}\n className={clearable && current ? 'pr-9' : undefined}\n {...props}\n />\n {clearable && current && (\n <button\n type=\"button\"\n onClick={() => commit('')}\n aria-label={clearLabel}\n 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\"\n >\n ✕\n </button>\n )}\n </div>\n );\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAoCI;AAlCJ,YAAuB;AACvB,gBAAmB;AACnB,mBAAuC;AAmBhC,MAAM,aAAa,MAAM,WAA8C,SAASA,YACrF,EAAE,OAAO,cAAc,eAAe,UAAU,YAAY,OAAO,aAAa,cAAc,WAAW,GAAG,MAAM,GAClH,KACA;AACA,QAAM,CAAC,UAAU,WAAW,IAAI,MAAM,SAAS,gBAAgB,EAAE;AACjE,QAAM,UAAU,SAAS;AAEzB,QAAM,SAAS,CAAC,SAAiB;AAC/B,QAAI,UAAU,OAAW,aAAY,IAAI;AACzC,oBAAgB,IAAI;AAAA,EACtB;AAEA,SACE,6CAAC,SAAI,eAAW,cAAG,8BAA8B,SAAS,GACxD;AAAA;AAAA,MAAC;AAAA;AAAA,QACC;AAAA,QACA,MAAK;AAAA,QACL,OAAO;AAAA,QACP,UAAU,CAAC,UAAU;AACnB,iBAAO,MAAM,OAAO,KAAK;AACzB,qBAAW,KAAK;AAAA,QAClB;AAAA,QACA,WAAW,aAAa,UAAU,SAAS;AAAA,QAC1C,GAAG;AAAA;AAAA,IACN;AAAA,IACC,aAAa,WACZ;AAAA,MAAC;AAAA;AAAA,QACC,MAAK;AAAA,QACL,SAAS,MAAM,OAAO,EAAE;AAAA,QACxB,cAAY;AAAA,QACZ,WAAU;AAAA,QACX;AAAA;AAAA,IAED;AAAA,KAEJ;AAEJ,CAAC;","names":["TimePicker"]}
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/time-picker/TimePicker.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { cn } from '../../utils/cn';\nimport { Input, type InputProps } from '../input/Input';\nimport { Popover, PopoverContent, PopoverTrigger } from '../popover';\nimport { Select } from '../select';\n\nexport type TimePickerFormat = '24h' | '12h';\n\nexport type TimePickerProps = Omit<InputProps, 'type' | 'value' | 'defaultValue'> & {\n /** \"HH:MM\" (24h) — controlled. */\n value?: string;\n /** \"HH:MM\" — initial value when uncontrolled. */\n defaultValue?: string;\n /** Fired with the time string ('' when cleared). */\n onValueChange?: (value: string) => void;\n /** Show a clear button once a time is selected. */\n clearable?: boolean;\n /** Accessible label for the clear button. Default 'Clear time'. */\n clearLabel?: string;\n /**\n * Display contract. '24h' (default) renders the native time input.\n * '12h' renders a button trigger with an hour/minute/AM-PM panel because\n * input[type=time] cannot show AM/PM portably. Both emit \"HH:MM\".\n */\n format?: TimePickerFormat;\n /** Minute granularity for the panel options and the native input step. Default 1. */\n minuteStep?: number;\n /** Earliest selectable time, \"HH:MM\" inclusive. */\n min?: string;\n /** Latest selectable time, \"HH:MM\" inclusive. */\n max?: string;\n /** Text shown before a time is chosen (12h mode). */\n placeholder?: string;\n};\n\nconst pad = (n: number) => String(n).padStart(2, '0');\n\n/** \"HH:MM\" -> minutes since midnight, or null when malformed. */\nfunction toMinutes(value: string | undefined): number | null {\n if (!value) return null;\n const match = /^(\\d{1,2}):(\\d{2})/.exec(value.trim());\n if (!match) return null;\n const minutes = Number(match[1]) * 60 + Number(match[2]);\n return minutes >= 0 && minutes <= 1439 ? minutes : null;\n}\n\nfunction fromMinutes(total: number): string {\n return `${pad(Math.floor(total / 60))}:${pad(total % 60)}`;\n}\n\n/** All stepped minute-of-hour values. */\nfunction minuteChoices(step: number): number[] {\n const out: number[] = [];\n for (let m = 0; m < 60; m += step) out.push(m);\n return out;\n}\n\n/**\n * Minutes-of-hour values that keep `hour24:minute` inside [minBound, maxBound].\n * hour24 is the 24-hour hour the candidate belongs to.\n */\nfunction allowedMinutes(hour24: number, minBound: number, maxBound: number, step: number): number[] {\n const base = hour24 * 60;\n return minuteChoices(step).filter((m) => {\n const total = base + m;\n return total >= minBound && total <= maxBound;\n });\n}\n\n/** Whether any stepped minute keeps `hour24` inside the bounds. */\nfunction hourHasValidMinute(hour24: number, minBound: number, maxBound: number, step: number): boolean {\n return allowedMinutes(hour24, minBound, maxBound, step).length > 0;\n}\n\n/** \"HH:MM\" -> { hour12, minute, period } for the 12h panel. */\nfunction to12(hour24: number, minute: number): { hour12: number; minute: number; period: 'AM' | 'PM' } {\n const period = hour24 >= 12 ? 'PM' : 'AM';\n const hour12 = hour24 % 12 === 0 ? 12 : hour24 % 12;\n return { hour12, minute, period };\n}\n\n/** { hour12, minute, period } -> minutes since midnight. */\nfunction from12(hour12: number, minute: number, period: 'AM' | 'PM'): number {\n const hour24 = (hour12 % 12) + (period === 'PM' ? 12 : 0);\n return hour24 * 60 + minute;\n}\n\n/** \"21:30\" -> \"9:30 PM\". */\nfunction format12(value: string): string {\n const total = toMinutes(value);\n if (total === null) return '';\n const { hour12, minute, period } = to12(Math.floor(total / 60), total % 60);\n return `${hour12}:${pad(minute)} ${period}`;\n}\n\nconst PERIODS = ['AM', 'PM'] as const;\n\n/**\n * Time field with an \"HH:MM\" contract. The 24h format is a native time input;\n * the 12h format is a button trigger with an hour/minute/period panel.\n */\nexport const TimePicker = React.forwardRef<HTMLInputElement, TimePickerProps>(function TimePicker(\n {\n value,\n defaultValue,\n onValueChange,\n onChange,\n clearable = false,\n clearLabel = 'Clear time',\n format = '24h',\n minuteStep = 1,\n min,\n max,\n placeholder,\n className,\n name,\n id,\n disabled,\n required,\n 'aria-label': ariaLabel,\n 'aria-describedby': ariaDescribedBy,\n 'aria-invalid': ariaInvalid,\n ...props\n },\n ref\n) {\n const [internal, setInternal] = React.useState(defaultValue ?? '');\n const current = value ?? internal;\n const step = Math.min(60, Math.max(1, Math.floor(minuteStep)));\n\n const commit = (next: string) => {\n if (value === undefined) setInternal(next);\n onValueChange?.(next);\n };\n\n const clearButton = clearable && current ? (\n <button\n type=\"button\"\n onClick={() => commit('')}\n aria-label={clearLabel}\n 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\"\n >\n ✕\n </button>\n ) : null;\n\n if (format === '12h') {\n return (\n <TimePicker12h\n current={current}\n commit={commit}\n clearButton={clearButton}\n step={step}\n min={min}\n max={max}\n placeholder={placeholder ?? 'Pick a time'}\n className={className}\n name={name}\n id={id}\n disabled={disabled}\n ariaLabel={ariaLabel}\n ariaDescribedBy={ariaDescribedBy}\n ariaInvalid={ariaInvalid}\n />\n );\n }\n\n return (\n <div className={cn('relative flex items-center', className)}>\n <Input\n ref={ref}\n type=\"time\"\n value={current}\n min={min}\n max={max}\n step={step * 60}\n placeholder={placeholder}\n name={name}\n id={id}\n disabled={disabled}\n required={required}\n aria-label={ariaLabel}\n aria-describedby={ariaDescribedBy}\n aria-invalid={ariaInvalid}\n onChange={(event) => {\n commit(event.target.value);\n onChange?.(event);\n }}\n className={clearable && current ? 'pr-9' : undefined}\n {...props}\n />\n {clearButton}\n </div>\n );\n});\nTimePicker.displayName = 'TimePicker';\n\ntype TimePicker12hConfig = {\n current: string;\n commit: (value: string) => void;\n clearButton: React.ReactNode;\n step: number;\n min?: string;\n max?: string;\n placeholder: string;\n className?: string;\n name?: string;\n id?: string;\n disabled?: boolean;\n ariaLabel?: string;\n ariaDescribedBy?: string;\n ariaInvalid?: boolean | 'true' | 'false' | 'grammar' | 'spelling';\n};\n\nfunction TimePicker12h({\n current,\n commit,\n clearButton,\n step,\n min,\n max,\n placeholder,\n className,\n name,\n id,\n disabled,\n ariaLabel,\n ariaDescribedBy,\n ariaInvalid,\n}: TimePicker12hConfig) {\n const [open, setOpen] = React.useState(false);\n\n const total = toMinutes(current);\n const minBound = toMinutes(min) ?? 0;\n const maxBound = toMinutes(max) ?? 1439;\n\n // Draft selection derived from the committed value; falls back to the\n // earliest in-range time so the panel always has a coherent selection.\n const draft = React.useMemo(() => {\n if (total !== null) {\n const hour24 = Math.floor(total / 60);\n const { hour12, minute, period } = to12(hour24, total % 60);\n return { hour12, minute, period };\n }\n // No value: anchor the draft at the lower bound so the panel opens on\n // the earliest selectable time.\n const anchor = minBound;\n const hour24 = Math.floor(anchor / 60);\n const { hour12, minute, period } = to12(hour24, anchor % 60);\n return { hour12, minute, period };\n }, [total, minBound]);\n\n const minutesFor = (hour12: number, period: 'AM' | 'PM') => {\n const hour24 = (hour12 % 12) + (period === 'PM' ? 12 : 0);\n return allowedMinutes(hour24, minBound, maxBound, step);\n };\n\n const hours12 = Array.from({ length: 12 }, (_, i) => i + 1);\n\n const hour24Of = (h12: number, p: 'AM' | 'PM') => (h12 % 12) + (p === 'PM' ? 12 : 0);\n\n // An hour is selectable only when it yields valid minutes under the period\n // currently shown, so a disabled-looking choice can never be committed.\n const isHourEnabled = (h12: number) => minutesFor(h12, draft.period).length > 0;\n\n const isPeriodEnabled = (p: 'AM' | 'PM') =>\n hours12.some((h) => hourHasValidMinute(hour24Of(h, p), minBound, maxBound, step));\n\n const minuteOptions = minutesFor(draft.hour12, draft.period);\n const validMinute = minuteOptions.includes(draft.minute) ? draft.minute : minuteOptions[0];\n\n const emit = (h12: number, minute: number, p: 'AM' | 'PM') => {\n commit(fromMinutes(from12(h12, minute, p)));\n };\n\n const onHour = (h12: number) => {\n const options = minutesFor(h12, draft.period);\n if (options.length === 0) return;\n const minute = options.includes(draft.minute) ? draft.minute : options[0];\n emit(h12, minute, draft.period);\n };\n\n const onPeriod = (p: 'AM' | 'PM') => {\n // The current hour may have no valid minutes under the new period (e.g.\n // min=13:00 makes every AM hour invalid); snap to the first valid hour.\n let hour = draft.hour12;\n let options = minutesFor(hour, p);\n if (options.length === 0) {\n hour = hours12.find((h) => minutesFor(h, p).length > 0) ?? hour;\n options = minutesFor(hour, p);\n if (options.length === 0) return;\n }\n const minute = options.includes(draft.minute) ? draft.minute : options[0];\n emit(hour, minute, p);\n };\n\n const label = total !== null ? format12(current) : placeholder;\n\n return (\n <div className={cn('relative flex items-center', className)}>\n <Popover open={open} onOpenChange={setOpen}>\n <PopoverTrigger\n id={id}\n type=\"button\"\n disabled={disabled}\n aria-label={ariaLabel}\n aria-describedby={ariaDescribedBy}\n aria-invalid={ariaInvalid}\n className={cn(\n 'flex h-10 w-full items-center justify-between rounded-md border border-input bg-background px-3 py-2 text-left text-sm',\n 'hover:bg-muted/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50',\n total === null && 'text-muted-foreground',\n clearButton && 'pr-9'\n )}\n >\n <span>{label}</span>\n <span aria-hidden=\"true\" className=\"text-muted-foreground\">\n ▾\n </span>\n </PopoverTrigger>\n <PopoverContent side=\"bottom\" align=\"start\" matchTriggerWidth className=\"p-3\">\n <div className=\"flex items-end gap-2\">\n <Select\n label=\"Hour\"\n labelHidden\n className=\"flex-1\"\n value={String(draft.hour12)}\n onValueChange={(v) => onHour(Number(Array.isArray(v) ? v[0] : v))}\n options={hours12.map((h) => ({\n value: String(h),\n label: pad(h),\n disabled: !isHourEnabled(h),\n }))}\n />\n <Select\n label=\"Minute\"\n labelHidden\n className=\"flex-1\"\n value={String(validMinute)}\n onValueChange={(v) => emit(draft.hour12, Number(Array.isArray(v) ? v[0] : v), draft.period)}\n options={minuteOptions.map((m) => ({ value: String(m), label: pad(m) }))}\n />\n <Select\n label=\"AM or PM\"\n labelHidden\n className=\"flex-1\"\n value={draft.period}\n onValueChange={(v) => onPeriod((Array.isArray(v) ? v[0] : v) as 'AM' | 'PM')}\n options={PERIODS.map((p) => ({\n value: p,\n label: p,\n disabled: !isPeriodEnabled(p),\n }))}\n />\n </div>\n </PopoverContent>\n </Popover>\n {clearButton}\n {name ? <input type=\"hidden\" name={name} value={current} /> : null}\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA0II;AAxIJ,YAAuB;AACvB,gBAAmB;AACnB,mBAAuC;AACvC,qBAAwD;AACxD,oBAAuB;AA+BvB,MAAM,MAAM,CAAC,MAAc,OAAO,CAAC,EAAE,SAAS,GAAG,GAAG;AAGpD,SAAS,UAAU,OAA0C;AAC3D,MAAI,CAAC,MAAO,QAAO;AACnB,QAAM,QAAQ,qBAAqB,KAAK,MAAM,KAAK,CAAC;AACpD,MAAI,CAAC,MAAO,QAAO;AACnB,QAAM,UAAU,OAAO,MAAM,CAAC,CAAC,IAAI,KAAK,OAAO,MAAM,CAAC,CAAC;AACvD,SAAO,WAAW,KAAK,WAAW,OAAO,UAAU;AACrD;AAEA,SAAS,YAAY,OAAuB;AAC1C,SAAO,GAAG,IAAI,KAAK,MAAM,QAAQ,EAAE,CAAC,CAAC,IAAI,IAAI,QAAQ,EAAE,CAAC;AAC1D;AAGA,SAAS,cAAc,MAAwB;AAC7C,QAAM,MAAgB,CAAC;AACvB,WAAS,IAAI,GAAG,IAAI,IAAI,KAAK,KAAM,KAAI,KAAK,CAAC;AAC7C,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AO;AAAA,cACP,OAAO;AAAA,cACP,UAAU,CAAC,gBAAgB,CAAC;AAAA,YAC9B,EAAE;AAAA;AAAA,QACJ;AAAA,SACF,GACF;AAAA,OACF;AAAA,IACC;AAAA,IACA,OAAO,4CAAC,WAAM,MAAK,UAAS,MAAY,OAAO,SAAS,IAAK;AAAA,KAChE;AAEJ;","names":["TimePicker","hour24","hour12","minute","period"]}
|
|
@@ -3,13 +3,110 @@ import { jsx, jsxs } from "react/jsx-runtime";
|
|
|
3
3
|
import * as React from "react";
|
|
4
4
|
import { cn } from "../../utils/cn.mjs";
|
|
5
5
|
import { Input } from "../input/Input.mjs";
|
|
6
|
-
|
|
6
|
+
import { Popover, PopoverContent, PopoverTrigger } from "../popover/index.mjs";
|
|
7
|
+
import { Select } from "../select/index.mjs";
|
|
8
|
+
const pad = (n) => String(n).padStart(2, "0");
|
|
9
|
+
function toMinutes(value) {
|
|
10
|
+
if (!value) return null;
|
|
11
|
+
const match = /^(\d{1,2}):(\d{2})/.exec(value.trim());
|
|
12
|
+
if (!match) return null;
|
|
13
|
+
const minutes = Number(match[1]) * 60 + Number(match[2]);
|
|
14
|
+
return minutes >= 0 && minutes <= 1439 ? minutes : null;
|
|
15
|
+
}
|
|
16
|
+
function fromMinutes(total) {
|
|
17
|
+
return `${pad(Math.floor(total / 60))}:${pad(total % 60)}`;
|
|
18
|
+
}
|
|
19
|
+
function minuteChoices(step) {
|
|
20
|
+
const out = [];
|
|
21
|
+
for (let m = 0; m < 60; m += step) out.push(m);
|
|
22
|
+
return out;
|
|
23
|
+
}
|
|
24
|
+
function allowedMinutes(hour24, minBound, maxBound, step) {
|
|
25
|
+
const base = hour24 * 60;
|
|
26
|
+
return minuteChoices(step).filter((m) => {
|
|
27
|
+
const total = base + m;
|
|
28
|
+
return total >= minBound && total <= maxBound;
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
function hourHasValidMinute(hour24, minBound, maxBound, step) {
|
|
32
|
+
return allowedMinutes(hour24, minBound, maxBound, step).length > 0;
|
|
33
|
+
}
|
|
34
|
+
function to12(hour24, minute) {
|
|
35
|
+
const period = hour24 >= 12 ? "PM" : "AM";
|
|
36
|
+
const hour12 = hour24 % 12 === 0 ? 12 : hour24 % 12;
|
|
37
|
+
return { hour12, minute, period };
|
|
38
|
+
}
|
|
39
|
+
function from12(hour12, minute, period) {
|
|
40
|
+
const hour24 = hour12 % 12 + (period === "PM" ? 12 : 0);
|
|
41
|
+
return hour24 * 60 + minute;
|
|
42
|
+
}
|
|
43
|
+
function format12(value) {
|
|
44
|
+
const total = toMinutes(value);
|
|
45
|
+
if (total === null) return "";
|
|
46
|
+
const { hour12, minute, period } = to12(Math.floor(total / 60), total % 60);
|
|
47
|
+
return `${hour12}:${pad(minute)} ${period}`;
|
|
48
|
+
}
|
|
49
|
+
const PERIODS = ["AM", "PM"];
|
|
50
|
+
const TimePicker = React.forwardRef(function TimePicker2({
|
|
51
|
+
value,
|
|
52
|
+
defaultValue,
|
|
53
|
+
onValueChange,
|
|
54
|
+
onChange,
|
|
55
|
+
clearable = false,
|
|
56
|
+
clearLabel = "Clear time",
|
|
57
|
+
format = "24h",
|
|
58
|
+
minuteStep = 1,
|
|
59
|
+
min,
|
|
60
|
+
max,
|
|
61
|
+
placeholder,
|
|
62
|
+
className,
|
|
63
|
+
name,
|
|
64
|
+
id,
|
|
65
|
+
disabled,
|
|
66
|
+
required,
|
|
67
|
+
"aria-label": ariaLabel,
|
|
68
|
+
"aria-describedby": ariaDescribedBy,
|
|
69
|
+
"aria-invalid": ariaInvalid,
|
|
70
|
+
...props
|
|
71
|
+
}, ref) {
|
|
7
72
|
const [internal, setInternal] = React.useState(defaultValue ?? "");
|
|
8
73
|
const current = value ?? internal;
|
|
74
|
+
const step = Math.min(60, Math.max(1, Math.floor(minuteStep)));
|
|
9
75
|
const commit = (next) => {
|
|
10
76
|
if (value === void 0) setInternal(next);
|
|
11
77
|
onValueChange?.(next);
|
|
12
78
|
};
|
|
79
|
+
const clearButton = clearable && current ? /* @__PURE__ */ jsx(
|
|
80
|
+
"button",
|
|
81
|
+
{
|
|
82
|
+
type: "button",
|
|
83
|
+
onClick: () => commit(""),
|
|
84
|
+
"aria-label": clearLabel,
|
|
85
|
+
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",
|
|
86
|
+
children: "\u2715"
|
|
87
|
+
}
|
|
88
|
+
) : null;
|
|
89
|
+
if (format === "12h") {
|
|
90
|
+
return /* @__PURE__ */ jsx(
|
|
91
|
+
TimePicker12h,
|
|
92
|
+
{
|
|
93
|
+
current,
|
|
94
|
+
commit,
|
|
95
|
+
clearButton,
|
|
96
|
+
step,
|
|
97
|
+
min,
|
|
98
|
+
max,
|
|
99
|
+
placeholder: placeholder ?? "Pick a time",
|
|
100
|
+
className,
|
|
101
|
+
name,
|
|
102
|
+
id,
|
|
103
|
+
disabled,
|
|
104
|
+
ariaLabel,
|
|
105
|
+
ariaDescribedBy,
|
|
106
|
+
ariaInvalid
|
|
107
|
+
}
|
|
108
|
+
);
|
|
109
|
+
}
|
|
13
110
|
return /* @__PURE__ */ jsxs("div", { className: cn("relative flex items-center", className), children: [
|
|
14
111
|
/* @__PURE__ */ jsx(
|
|
15
112
|
Input,
|
|
@@ -17,6 +114,17 @@ const TimePicker = React.forwardRef(function TimePicker2({ value, defaultValue,
|
|
|
17
114
|
ref,
|
|
18
115
|
type: "time",
|
|
19
116
|
value: current,
|
|
117
|
+
min,
|
|
118
|
+
max,
|
|
119
|
+
step: step * 60,
|
|
120
|
+
placeholder,
|
|
121
|
+
name,
|
|
122
|
+
id,
|
|
123
|
+
disabled,
|
|
124
|
+
required,
|
|
125
|
+
"aria-label": ariaLabel,
|
|
126
|
+
"aria-describedby": ariaDescribedBy,
|
|
127
|
+
"aria-invalid": ariaInvalid,
|
|
20
128
|
onChange: (event) => {
|
|
21
129
|
commit(event.target.value);
|
|
22
130
|
onChange?.(event);
|
|
@@ -25,18 +133,143 @@ const TimePicker = React.forwardRef(function TimePicker2({ value, defaultValue,
|
|
|
25
133
|
...props
|
|
26
134
|
}
|
|
27
135
|
),
|
|
28
|
-
|
|
29
|
-
"button",
|
|
30
|
-
{
|
|
31
|
-
type: "button",
|
|
32
|
-
onClick: () => commit(""),
|
|
33
|
-
"aria-label": clearLabel,
|
|
34
|
-
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",
|
|
35
|
-
children: "\u2715"
|
|
36
|
-
}
|
|
37
|
-
)
|
|
136
|
+
clearButton
|
|
38
137
|
] });
|
|
39
138
|
});
|
|
139
|
+
TimePicker.displayName = "TimePicker";
|
|
140
|
+
function TimePicker12h({
|
|
141
|
+
current,
|
|
142
|
+
commit,
|
|
143
|
+
clearButton,
|
|
144
|
+
step,
|
|
145
|
+
min,
|
|
146
|
+
max,
|
|
147
|
+
placeholder,
|
|
148
|
+
className,
|
|
149
|
+
name,
|
|
150
|
+
id,
|
|
151
|
+
disabled,
|
|
152
|
+
ariaLabel,
|
|
153
|
+
ariaDescribedBy,
|
|
154
|
+
ariaInvalid
|
|
155
|
+
}) {
|
|
156
|
+
const [open, setOpen] = React.useState(false);
|
|
157
|
+
const total = toMinutes(current);
|
|
158
|
+
const minBound = toMinutes(min) ?? 0;
|
|
159
|
+
const maxBound = toMinutes(max) ?? 1439;
|
|
160
|
+
const draft = React.useMemo(() => {
|
|
161
|
+
if (total !== null) {
|
|
162
|
+
const hour242 = Math.floor(total / 60);
|
|
163
|
+
const { hour12: hour122, minute: minute2, period: period2 } = to12(hour242, total % 60);
|
|
164
|
+
return { hour12: hour122, minute: minute2, period: period2 };
|
|
165
|
+
}
|
|
166
|
+
const anchor = minBound;
|
|
167
|
+
const hour24 = Math.floor(anchor / 60);
|
|
168
|
+
const { hour12, minute, period } = to12(hour24, anchor % 60);
|
|
169
|
+
return { hour12, minute, period };
|
|
170
|
+
}, [total, minBound]);
|
|
171
|
+
const minutesFor = (hour12, period) => {
|
|
172
|
+
const hour24 = hour12 % 12 + (period === "PM" ? 12 : 0);
|
|
173
|
+
return allowedMinutes(hour24, minBound, maxBound, step);
|
|
174
|
+
};
|
|
175
|
+
const hours12 = Array.from({ length: 12 }, (_, i) => i + 1);
|
|
176
|
+
const hour24Of = (h12, p) => h12 % 12 + (p === "PM" ? 12 : 0);
|
|
177
|
+
const isHourEnabled = (h12) => minutesFor(h12, draft.period).length > 0;
|
|
178
|
+
const isPeriodEnabled = (p) => hours12.some((h) => hourHasValidMinute(hour24Of(h, p), minBound, maxBound, step));
|
|
179
|
+
const minuteOptions = minutesFor(draft.hour12, draft.period);
|
|
180
|
+
const validMinute = minuteOptions.includes(draft.minute) ? draft.minute : minuteOptions[0];
|
|
181
|
+
const emit = (h12, minute, p) => {
|
|
182
|
+
commit(fromMinutes(from12(h12, minute, p)));
|
|
183
|
+
};
|
|
184
|
+
const onHour = (h12) => {
|
|
185
|
+
const options = minutesFor(h12, draft.period);
|
|
186
|
+
if (options.length === 0) return;
|
|
187
|
+
const minute = options.includes(draft.minute) ? draft.minute : options[0];
|
|
188
|
+
emit(h12, minute, draft.period);
|
|
189
|
+
};
|
|
190
|
+
const onPeriod = (p) => {
|
|
191
|
+
let hour = draft.hour12;
|
|
192
|
+
let options = minutesFor(hour, p);
|
|
193
|
+
if (options.length === 0) {
|
|
194
|
+
hour = hours12.find((h) => minutesFor(h, p).length > 0) ?? hour;
|
|
195
|
+
options = minutesFor(hour, p);
|
|
196
|
+
if (options.length === 0) return;
|
|
197
|
+
}
|
|
198
|
+
const minute = options.includes(draft.minute) ? draft.minute : options[0];
|
|
199
|
+
emit(hour, minute, p);
|
|
200
|
+
};
|
|
201
|
+
const label = total !== null ? format12(current) : placeholder;
|
|
202
|
+
return /* @__PURE__ */ jsxs("div", { className: cn("relative flex items-center", className), children: [
|
|
203
|
+
/* @__PURE__ */ jsxs(Popover, { open, onOpenChange: setOpen, children: [
|
|
204
|
+
/* @__PURE__ */ jsxs(
|
|
205
|
+
PopoverTrigger,
|
|
206
|
+
{
|
|
207
|
+
id,
|
|
208
|
+
type: "button",
|
|
209
|
+
disabled,
|
|
210
|
+
"aria-label": ariaLabel,
|
|
211
|
+
"aria-describedby": ariaDescribedBy,
|
|
212
|
+
"aria-invalid": ariaInvalid,
|
|
213
|
+
className: cn(
|
|
214
|
+
"flex h-10 w-full items-center justify-between rounded-md border border-input bg-background px-3 py-2 text-left text-sm",
|
|
215
|
+
"hover:bg-muted/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50",
|
|
216
|
+
total === null && "text-muted-foreground",
|
|
217
|
+
clearButton && "pr-9"
|
|
218
|
+
),
|
|
219
|
+
children: [
|
|
220
|
+
/* @__PURE__ */ jsx("span", { children: label }),
|
|
221
|
+
/* @__PURE__ */ jsx("span", { "aria-hidden": "true", className: "text-muted-foreground", children: "\u25BE" })
|
|
222
|
+
]
|
|
223
|
+
}
|
|
224
|
+
),
|
|
225
|
+
/* @__PURE__ */ jsx(PopoverContent, { side: "bottom", align: "start", matchTriggerWidth: true, className: "p-3", children: /* @__PURE__ */ jsxs("div", { className: "flex items-end gap-2", children: [
|
|
226
|
+
/* @__PURE__ */ jsx(
|
|
227
|
+
Select,
|
|
228
|
+
{
|
|
229
|
+
label: "Hour",
|
|
230
|
+
labelHidden: true,
|
|
231
|
+
className: "flex-1",
|
|
232
|
+
value: String(draft.hour12),
|
|
233
|
+
onValueChange: (v) => onHour(Number(Array.isArray(v) ? v[0] : v)),
|
|
234
|
+
options: hours12.map((h) => ({
|
|
235
|
+
value: String(h),
|
|
236
|
+
label: pad(h),
|
|
237
|
+
disabled: !isHourEnabled(h)
|
|
238
|
+
}))
|
|
239
|
+
}
|
|
240
|
+
),
|
|
241
|
+
/* @__PURE__ */ jsx(
|
|
242
|
+
Select,
|
|
243
|
+
{
|
|
244
|
+
label: "Minute",
|
|
245
|
+
labelHidden: true,
|
|
246
|
+
className: "flex-1",
|
|
247
|
+
value: String(validMinute),
|
|
248
|
+
onValueChange: (v) => emit(draft.hour12, Number(Array.isArray(v) ? v[0] : v), draft.period),
|
|
249
|
+
options: minuteOptions.map((m) => ({ value: String(m), label: pad(m) }))
|
|
250
|
+
}
|
|
251
|
+
),
|
|
252
|
+
/* @__PURE__ */ jsx(
|
|
253
|
+
Select,
|
|
254
|
+
{
|
|
255
|
+
label: "AM or PM",
|
|
256
|
+
labelHidden: true,
|
|
257
|
+
className: "flex-1",
|
|
258
|
+
value: draft.period,
|
|
259
|
+
onValueChange: (v) => onPeriod(Array.isArray(v) ? v[0] : v),
|
|
260
|
+
options: PERIODS.map((p) => ({
|
|
261
|
+
value: p,
|
|
262
|
+
label: p,
|
|
263
|
+
disabled: !isPeriodEnabled(p)
|
|
264
|
+
}))
|
|
265
|
+
}
|
|
266
|
+
)
|
|
267
|
+
] }) })
|
|
268
|
+
] }),
|
|
269
|
+
clearButton,
|
|
270
|
+
name ? /* @__PURE__ */ jsx("input", { type: "hidden", name, value: current }) : null
|
|
271
|
+
] });
|
|
272
|
+
}
|
|
40
273
|
export {
|
|
41
274
|
TimePicker
|
|
42
275
|
};
|