@camunda/design-system 0.78.1 → 0.80.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/README.md +7 -3
- package/dist/files/geist-sans-latin-400-normal.woff +0 -0
- package/dist/files/geist-sans-latin-400-normal.woff2 +0 -0
- package/dist/files/geist-sans-latin-500-normal.woff +0 -0
- package/dist/files/geist-sans-latin-500-normal.woff2 +0 -0
- package/dist/files/geist-sans-latin-600-normal.woff +0 -0
- package/dist/files/geist-sans-latin-600-normal.woff2 +0 -0
- package/dist/files/geist-sans-latin-700-normal.woff +0 -0
- package/dist/files/geist-sans-latin-700-normal.woff2 +0 -0
- package/dist/src/components/ui/alert-dialog.d.ts +10 -1
- package/dist/src/components/ui/alert-dialog.d.ts.map +1 -1
- package/dist/src/components/ui/alert-dialog.js +8 -4
- package/dist/src/components/ui/alert-dialog.js.map +1 -1
- package/dist/src/components/ui/app-sidebar.d.ts +6 -16
- package/dist/src/components/ui/app-sidebar.d.ts.map +1 -1
- package/dist/src/components/ui/app-sidebar.js +35 -33
- package/dist/src/components/ui/app-sidebar.js.map +1 -1
- package/dist/src/components/ui/card.d.ts +293 -2
- package/dist/src/components/ui/card.d.ts.map +1 -1
- package/dist/src/components/ui/card.js +16 -4
- package/dist/src/components/ui/card.js.map +1 -1
- package/dist/src/components/ui/data-table.js +3 -3
- package/dist/src/components/ui/data-table.js.map +1 -1
- package/dist/src/components/ui/date-picker.d.ts +6 -0
- package/dist/src/components/ui/date-picker.d.ts.map +1 -1
- package/dist/src/components/ui/date-picker.js +9 -2
- package/dist/src/components/ui/date-picker.js.map +1 -1
- package/dist/src/components/ui/date-range-picker.d.ts +2 -0
- package/dist/src/components/ui/date-range-picker.d.ts.map +1 -1
- package/dist/src/components/ui/date-range-picker.js +9 -9
- package/dist/src/components/ui/date-range-picker.js.map +1 -1
- package/dist/src/components/ui/date-time-range-picker.d.ts +2 -3
- package/dist/src/components/ui/date-time-range-picker.d.ts.map +1 -1
- package/dist/src/components/ui/date-time-range-picker.js +52 -69
- package/dist/src/components/ui/date-time-range-picker.js.map +1 -1
- package/dist/src/components/ui/dialog.d.ts.map +1 -1
- package/dist/src/components/ui/dialog.js +6 -3
- package/dist/src/components/ui/dialog.js.map +1 -1
- package/dist/src/components/ui/dropdown.d.ts +2 -2
- package/dist/src/components/ui/dropdown.d.ts.map +1 -1
- package/dist/src/components/ui/dropdown.js +29 -5
- package/dist/src/components/ui/dropdown.js.map +1 -1
- package/dist/src/components/ui/filter-bar.d.ts.map +1 -1
- package/dist/src/components/ui/filter-bar.js +16 -6
- package/dist/src/components/ui/filter-bar.js.map +1 -1
- package/dist/src/components/ui/login-screen.d.ts.map +1 -1
- package/dist/src/components/ui/login-screen.js +1 -7
- package/dist/src/components/ui/login-screen.js.map +1 -1
- package/dist/src/components/ui/meter.d.ts.map +1 -1
- package/dist/src/components/ui/meter.js +2 -1
- package/dist/src/components/ui/meter.js.map +1 -1
- package/dist/src/components/ui/multi-select.js +1 -1
- package/dist/src/components/ui/multi-select.js.map +1 -1
- package/dist/src/components/ui/pagination.d.ts.map +1 -1
- package/dist/src/components/ui/pagination.js +2 -2
- package/dist/src/components/ui/pagination.js.map +1 -1
- package/dist/src/components/ui/sheet.js +1 -1
- package/dist/src/components/ui/sidebar-provider.d.ts +1 -1
- package/dist/src/components/ui/sidebar-provider.js +1 -1
- package/dist/src/components/ui/tabs.d.ts.map +1 -1
- package/dist/src/components/ui/tabs.js +1 -1
- package/dist/src/components/ui/tabs.js.map +1 -1
- package/dist/src/components/ui/toast.d.ts.map +1 -1
- package/dist/src/components/ui/toast.js +18 -4
- package/dist/src/components/ui/toast.js.map +1 -1
- package/dist/src/components/ui/user-menu.d.ts +21 -3
- package/dist/src/components/ui/user-menu.d.ts.map +1 -1
- package/dist/src/components/ui/user-menu.js +5 -3
- package/dist/src/components/ui/user-menu.js.map +1 -1
- package/dist/src/examples/access-control/AccessControlPage.d.ts +9 -0
- package/dist/src/examples/access-control/AccessControlPage.d.ts.map +1 -0
- package/dist/src/examples/access-control/AccessControlPage.js +166 -0
- package/dist/src/examples/access-control/AccessControlPage.js.map +1 -0
- package/dist/src/examples/access-control/mock-data.d.ts +43 -0
- package/dist/src/examples/access-control/mock-data.d.ts.map +1 -0
- package/dist/src/examples/access-control/mock-data.js +55 -0
- package/dist/src/examples/access-control/mock-data.js.map +1 -0
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/lib/date-bounds.d.ts +7 -0
- package/dist/src/lib/date-bounds.d.ts.map +1 -0
- package/dist/src/lib/date-bounds.js +13 -0
- package/dist/src/lib/date-bounds.js.map +1 -0
- package/dist/src/lib/i18n/dictionary.d.ts +0 -2
- package/dist/src/lib/i18n/dictionary.d.ts.map +1 -1
- package/dist/src/lib/i18n/dictionary.js +0 -2
- package/dist/src/lib/i18n/dictionary.js.map +1 -1
- package/dist/src/specs/schema.d.ts +9 -0
- package/dist/src/specs/schema.d.ts.map +1 -1
- package/dist/styles.css +43 -12
- package/package.json +19 -19
|
@@ -6,15 +6,22 @@ import { CalendarIcon } from "../../icons/lucide.js";
|
|
|
6
6
|
import { cn } from "../../lib/utils.js";
|
|
7
7
|
import { withRef } from "../../lib/with-ref.js";
|
|
8
8
|
import { useC4Dictionary } from "../../lib/i18n/context.js";
|
|
9
|
+
import { latestSelectableDate } from "../../lib/date-bounds.js";
|
|
9
10
|
import { Button } from "./button.js";
|
|
10
11
|
import { Calendar } from "./calendar.js";
|
|
11
12
|
import { Popover, PopoverContent, PopoverTrigger } from "./popover.js";
|
|
12
|
-
function DatePickerImpl({ ref, value, defaultValue, onChange, placeholder, format = "PP", disabled, id, className, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, "aria-invalid": ariaInvalid, "aria-describedby": ariaDescribedBy, "aria-errormessage": ariaErrorMessage, }) {
|
|
13
|
+
function DatePickerImpl({ ref, value, defaultValue, onChange, placeholder, format = "PP", fromDate, toDate: toDateProp, disableFuture = false, disabled, id, className, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, "aria-invalid": ariaInvalid, "aria-describedby": ariaDescribedBy, "aria-errormessage": ariaErrorMessage, }) {
|
|
13
14
|
const { t } = useC4Dictionary();
|
|
14
15
|
const [internalValue, setInternalValue] = React.useState(defaultValue);
|
|
15
16
|
const [open, setOpen] = React.useState(false);
|
|
16
17
|
const isControlled = value !== undefined;
|
|
17
18
|
const selected = isControlled ? value : internalValue;
|
|
19
|
+
const toDate = latestSelectableDate(toDateProp, disableFuture);
|
|
20
|
+
const disabledMatchers = [];
|
|
21
|
+
if (fromDate)
|
|
22
|
+
disabledMatchers.push({ before: fromDate });
|
|
23
|
+
if (toDate)
|
|
24
|
+
disabledMatchers.push({ after: toDate });
|
|
18
25
|
const handleSelect = (date) => {
|
|
19
26
|
if (!isControlled) {
|
|
20
27
|
setInternalValue(date);
|
|
@@ -24,7 +31,7 @@ function DatePickerImpl({ ref, value, defaultValue, onChange, placeholder, forma
|
|
|
24
31
|
};
|
|
25
32
|
return (_jsxs(Popover, { open: open, onOpenChange: setOpen, children: [_jsx(PopoverTrigger, { asChild: true, children: _jsxs(Button, { ref: ref, id: id, variant: "secondary", disabled: disabled, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, "aria-invalid": ariaInvalid, "aria-describedby": ariaDescribedBy, "aria-errormessage": ariaErrorMessage, className: cn("w-full justify-between font-normal", !selected && "text-neutral-foreground-subtle", className), "data-slot": "date-picker-trigger", children: [_jsx("span", { children: selected
|
|
26
33
|
? formatDate(selected, format)
|
|
27
|
-
: (placeholder ?? t("datePicker.pickDate")) }), _jsx(CalendarIcon, { className: "size-4 opacity-60" })] }) }), _jsx(PopoverContent, { "data-slot": "date-picker-content", className: "w-auto p-0", align: "start", children: _jsx(Calendar, { mode: "single", selected: selected, onSelect: handleSelect, defaultMonth: selected, autoFocus: true }) })] }));
|
|
34
|
+
: (placeholder ?? t("datePicker.pickDate")) }), _jsx(CalendarIcon, { className: "size-4 opacity-60" })] }) }), _jsx(PopoverContent, { "data-slot": "date-picker-content", className: "w-auto p-0", align: "start", children: _jsx(Calendar, { mode: "single", selected: selected, onSelect: handleSelect, defaultMonth: selected, startMonth: fromDate, endMonth: toDate, disabled: disabledMatchers.length > 0 ? disabledMatchers : undefined, autoFocus: true }) })] }));
|
|
28
35
|
}
|
|
29
36
|
const DatePicker = withRef(DatePickerImpl);
|
|
30
37
|
export { DatePicker };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"date-picker.js","sourceRoot":"","sources":["../../../../src/components/ui/date-picker.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,UAAU,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE5C,OAAO,EAAE,EAAE,EAAE,MAAM,WAAW,CAAC;AAC/B,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"date-picker.js","sourceRoot":"","sources":["../../../../src/components/ui/date-picker.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,UAAU,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE5C,OAAO,EAAE,EAAE,EAAE,MAAM,WAAW,CAAC;AAC/B,OAAO,EAAE,OAAO,E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gB,CAAC,CAAC,CAAC,SAAS,EACpE,SAAS,SACT,GACa,IACT,CACX,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,GAAG,OAAO,CAAqC,cAAc,CAAC,CAAC;AAE/E,OAAO,EAAE,UAAU,EAAE,CAAC"}
|
|
@@ -10,6 +10,8 @@ type DateRangePickerProps = {
|
|
|
10
10
|
format?: string;
|
|
11
11
|
fromDate?: Date;
|
|
12
12
|
toDate?: Date;
|
|
13
|
+
/** Disables every day after today. Combines with `toDate`: the earlier of the two wins. */
|
|
14
|
+
disableFuture?: boolean;
|
|
13
15
|
locale?: Locale;
|
|
14
16
|
weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6;
|
|
15
17
|
calendarLayout?: "single-month" | "two-month";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"date-range-picker.d.ts","sourceRoot":"","sources":["../../../../src/components/ui/date-range-picker.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAmC,KAAK,MAAM,EAAE,MAAM,UAAU,CAAC;AACxE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"date-range-picker.d.ts","sourceRoot":"","sources":["../../../../src/components/ui/date-range-picker.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAmC,KAAK,MAAM,EAAE,MAAM,UAAU,CAAC;AACxE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAalD,KAAK,oBAAoB,GAAG;IAC1B,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,YAAY,CAAC,EAAE,SAAS,CAAC;IACzB,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,SAAS,GAAG,SAAS,KAAK,IAAI,CAAC;IAClD,4IAA4I;IAC5I,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,IAAI,CAAC;IAChB,MAAM,CAAC,EAAE,IAAI,CAAC;IACd,2FAA2F;IAC3F,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACzC,cAAc,CAAC,EAAE,cAAc,GAAG,WAAW,CAAC;IAC9C,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,uIAAuI;IACvI,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,cAAc,CAAC,EAAE,KAAK,CAAC,cAAc,CAAC,cAAc,CAAC,CAAC;IACtD,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,GAAG,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;CACpC,CAAC;AA8MF,QAAA,MAAM,eAAe,6GAEpB,CAAC;AAEF,OAAO,EAAE,eAAe,EAAE,CAAC;AAC3B,YAAY,EAAE,oBAAoB,EAAE,SAAS,EAAE,CAAC"}
|
|
@@ -6,18 +6,20 @@ import { CalendarIcon, XIcon } from "../../icons/lucide.js";
|
|
|
6
6
|
import { cn } from "../../lib/utils.js";
|
|
7
7
|
import { withRef } from "../../lib/with-ref.js";
|
|
8
8
|
import { useC4Dictionary } from "../../lib/i18n/context.js";
|
|
9
|
+
import { latestSelectableDate } from "../../lib/date-bounds.js";
|
|
9
10
|
import { useIsTruncated } from "../../hooks/use-is-truncated.js";
|
|
10
11
|
import { Button } from "./button.js";
|
|
11
12
|
import { Calendar } from "./calendar.js";
|
|
12
13
|
import { Popover, PopoverContent, PopoverTrigger } from "./popover.js";
|
|
13
14
|
import { Tooltip, TooltipContent, TooltipTrigger } from "./tooltip.js";
|
|
14
|
-
function DateRangePickerImpl({ ref, value, defaultValue, onChange, placeholder, format = "PP", fromDate, toDate, locale, weekStartsOn = 1, calendarLayout = "two-month", disabled, clearRangeLabel, id, className, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, "aria-invalid": ariaInvalid, "aria-describedby": ariaDescribedBy, "aria-errormessage": ariaErrorMessage, }) {
|
|
15
|
+
function DateRangePickerImpl({ ref, value, defaultValue, onChange, placeholder, format = "PP", fromDate, toDate: toDateProp, disableFuture = false, locale, weekStartsOn = 1, calendarLayout = "two-month", disabled, clearRangeLabel, id, className, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, "aria-invalid": ariaInvalid, "aria-describedby": ariaDescribedBy, "aria-errormessage": ariaErrorMessage, }) {
|
|
15
16
|
const [internalValue, setInternalValue] = React.useState(defaultValue);
|
|
16
17
|
const [open, setOpen] = React.useState(false);
|
|
17
18
|
const { t } = useC4Dictionary();
|
|
18
19
|
const isControlled = value !== undefined;
|
|
19
20
|
const selected = isControlled ? value : internalValue;
|
|
20
21
|
const showClear = Boolean(selected?.from) && !disabled;
|
|
22
|
+
const toDate = latestSelectableDate(toDateProp, disableFuture);
|
|
21
23
|
const handleSelect = (range, triggerDate) => {
|
|
22
24
|
// `min={1}` below makes react-day-picker's `addToRange` clear the whole
|
|
23
25
|
// selection (rather than commit a one-day range) when the second click
|
|
@@ -58,14 +60,12 @@ function DateRangePickerImpl({ ref, value, defaultValue, onChange, placeholder,
|
|
|
58
60
|
// only). Day-level disabling now goes through the `disabled` matcher, so
|
|
59
61
|
// this component's own `fromDate`/`toDate` props are translated into both
|
|
60
62
|
// to preserve the "earliest/latest selectable date" contract in the spec.
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
return matchers.length > 0 ? matchers : undefined;
|
|
68
|
-
}, [fromDate, toDate]);
|
|
63
|
+
const disabledMatchers = [];
|
|
64
|
+
if (fromDate)
|
|
65
|
+
disabledMatchers.push({ before: fromDate });
|
|
66
|
+
if (toDate)
|
|
67
|
+
disabledMatchers.push({ after: toDate });
|
|
68
|
+
const disabledMatcher = disabledMatchers.length > 0 ? disabledMatchers : undefined;
|
|
69
69
|
const triggerLabel = !selected?.from
|
|
70
70
|
? (placeholder ?? t("dateRangePicker.pickDateRange"))
|
|
71
71
|
: selected.to
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"date-range-picker.js","sourceRoot":"","sources":["../../../../src/components/ui/date-range-picker.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,MAAM,IAAI,UAAU,EAAE,SAAS,EAAe,MAAM,UAAU,CAAC;AAExE,OAAO,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAEnD,OAAO,EAAE,EAAE,EAAE,MAAM,WAAW,CAAC;AAC/B,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AACpE,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"date-range-picker.js","sourceRoot":"","sources":["../../../../src/components/ui/date-range-picker.tsx"],"names":[],"mappings":"AAAA,YAAY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ACH,2BAA2B,EACrC,SAAS,EAAC,YAAY,EACtB,KAAK,EAAC,OAAO,YAEb,KAAC,QAAQ,IACP,IAAI,EAAC,OAAO,EACZ,QAAQ,EAAE,QAAQ,EAClB,QAAQ,EAAE,YAAY,EACtB,YAAY,EAAE,QAAQ,EAAE,IAAI,EAC5B,cAAc,EAAE,cAAc,KAAK,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EACtD,UAAU,EAAE,QAAQ,EACpB,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,eAAe,EACzB,MAAM,EAAE,MAAM,EACd,YAAY,EAAE,YAAY;4BAC1B,iEAAiE;4BACjE,+DAA+D;4BAC/D,iEAAiE;4BACjE,+DAA+D;4BAC/D,iEAAiE;4BACjE,8DAA8D;4BAC9D,8DAA8D;4BAC9D,0DAA0D;4BAC1D,gEAAgE;4BAChE,2DAA2D;4BAC3D,GAAG,EAAE,CAAC,EACN,SAAS,SACT,GACa,IACT,EACT,SAAS,IAAI,CACZ,iBACE,IAAI,EAAC,QAAQ,EACb,OAAO,EAAE,WAAW,gBACR,eAAe,IAAI,CAAC,CAAC,4BAA4B,CAAC,EAC9D,SAAS,EAAC,iPAAiP,YAE3P,KAAC,KAAK,IAAC,SAAS,EAAC,QAAQ,iBAAa,MAAM,GAAG,GACxC,CACV,IACG,CACP,CAAC;AACJ,CAAC;AAED,MAAM,eAAe,GAAG,OAAO,CAC7B,mBAAmB,CACpB,CAAC;AAEF,OAAO,EAAE,eAAe,EAAE,CAAC"}
|
|
@@ -25,12 +25,10 @@ type DateTimeRangePickerMessages = {
|
|
|
25
25
|
timeZone: string;
|
|
26
26
|
apply: string;
|
|
27
27
|
cancel: string;
|
|
28
|
-
clear: string;
|
|
29
28
|
clearRange: string;
|
|
30
29
|
selectEndDate: string;
|
|
31
30
|
pickDayFirst: string;
|
|
32
31
|
pickEndDay: string;
|
|
33
|
-
applyNeedsRange: string;
|
|
34
32
|
openCalendar: string;
|
|
35
33
|
startInput: string;
|
|
36
34
|
endInput: string;
|
|
@@ -45,11 +43,12 @@ type DateTimeRangePickerProps = {
|
|
|
45
43
|
presets?: DateTimeRangePreset[];
|
|
46
44
|
showTimeZone?: boolean;
|
|
47
45
|
showTimePickerIcon?: boolean;
|
|
48
|
-
showApplyButton?: boolean;
|
|
49
46
|
showInputs?: boolean;
|
|
50
47
|
showCalendarButton?: boolean;
|
|
51
48
|
fromDate?: Date;
|
|
52
49
|
toDate?: Date;
|
|
50
|
+
/** Disables every day after today. Combines with `toDate`: the earlier of the two wins. */
|
|
51
|
+
disableFuture?: boolean;
|
|
53
52
|
locale?: Locale;
|
|
54
53
|
disabled?: boolean;
|
|
55
54
|
messages?: Partial<DateTimeRangePickerMessages>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"date-time-range-picker.d.ts","sourceRoot":"","sources":["../../../../src/components/ui/date-time-range-picker.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAgBL,KAAK,MAAM,EACZ,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"date-time-range-picker.d.ts","sourceRoot":"","sources":["../../../../src/components/ui/date-time-range-picker.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAgBL,KAAK,MAAM,EACZ,MAAM,UAAU,CAAC;AAuBlB,KAAK,aAAa,GAAG;IAAE,IAAI,CAAC,EAAE,IAAI,CAAC;IAAC,EAAE,CAAC,EAAE,IAAI,CAAA;CAAE,CAAC;AAEhD,KAAK,uBAAuB,GAAG,UAAU,GAAG,OAAO,CAAC;AAEpD,KAAK,uBAAuB,GAAG;IAC7B,iFAAiF;IACjF,OAAO,EAAE,OAAO,CAAC;IACjB,4EAA4E;IAC5E,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,KAAK,mBAAmB,GAAG;IACzB,EAAE,EAAE,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;IAChB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC,2BAA2B,CAAC,CAAC;IAChD,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,GAAG,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;CACpC,CAAC;AAEF,QAAA,MAAM,+BAA+B,EAAE,mBAAmB,EAYzD,CAAC;AA6mCF,QAAA,MAAM,mBAAmB,iHAGC,CAAC;AAE3B,OAAO,EAAE,mBAAmB,EAAE,+BAA+B,EAAE,CAAC;AAChE,YAAY,EACV,aAAa,EACb,uBAAuB,EACvB,2BAA2B,EAC3B,wBAAwB,EACxB,mBAAmB,EACnB,uBAAuB,GACxB,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx as _jsx, jsxs as _jsxs
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import * as React from "react";
|
|
4
4
|
import { endOfDay, format as formatDate, isAfter, isBefore, isSameDay, isSameYear, isValid, parse, parseISO, setSeconds, addMonths, startOfDay, startOfMonth, subMonths, subMinutes, } from "date-fns";
|
|
5
5
|
import { CalendarIcon, XIcon } from "../../icons/lucide.js";
|
|
@@ -8,6 +8,7 @@ import { withRef } from "../../lib/with-ref.js";
|
|
|
8
8
|
import { useIsTruncated } from "../../hooks/use-is-truncated.js";
|
|
9
9
|
import { useMediaQuery } from "../../hooks/use-media-query.js";
|
|
10
10
|
import { useC4Dictionary } from "../../lib/i18n/context.js";
|
|
11
|
+
import { latestSelectableDate } from "../../lib/date-bounds.js";
|
|
11
12
|
import { Button } from "./button.js";
|
|
12
13
|
import { Calendar } from "./calendar.js";
|
|
13
14
|
import { Input } from "./input.js";
|
|
@@ -130,12 +131,16 @@ function TimeField({ id, label, end, date, timeFormat, showTimePickerIcon, local
|
|
|
130
131
|
onCommit(finalize(next, end, hasSeconds));
|
|
131
132
|
};
|
|
132
133
|
return (_jsxs("div", { className: "flex min-w-0 flex-1 flex-col gap-1.5", "data-slot": "date-time-range-picker-time", children: [_jsxs("div", { className: "flex items-baseline justify-between gap-2", children: [_jsx(Label, { htmlFor: id, children: label }), date ? (_jsx(Text, { as: "span", variant: "helper", children: formatDayMonth(date, locale) })) : null] }), _jsx(Input, { id: id, type: "time", autoComplete: "off", step: step, disabled: disabled || !date, className: cn(!showTimePickerIcon &&
|
|
133
|
-
"[&::-webkit-calendar-picker-indicator]:hidden"), value: typed ?? (date ? formatDate(date, inputFormat) : ""), "aria-invalid": error !== undefined, "aria-describedby": [
|
|
134
|
+
"[&::-webkit-calendar-picker-indicator]:hidden"), value: typed ?? (date ? formatDate(date, inputFormat) : ""), "aria-invalid": error !== undefined, "aria-describedby": [
|
|
135
|
+
error ? errorId : undefined,
|
|
136
|
+
date || !emptyHint ? undefined : hintId,
|
|
137
|
+
describedBy,
|
|
138
|
+
]
|
|
134
139
|
.filter(Boolean)
|
|
135
140
|
.join(" ") || undefined, onBlur: () => setTyped(undefined), onChange: (event) => {
|
|
136
141
|
setTyped(event.target.value);
|
|
137
142
|
commit(event.target.value);
|
|
138
|
-
} }), date ? null : (_jsx(Text, { as: "p", id: hintId, variant: "helper", children: emptyHint })), error ? (_jsx(Text, { as: "p", id: errorId, role: "alert", variant: "helper", className: "text-danger-foreground-subtle", children: error })) : null] }));
|
|
143
|
+
} }), date || !emptyHint ? null : (_jsx(Text, { as: "p", id: hintId, variant: "helper", children: emptyHint })), error ? (_jsx(Text, { as: "p", id: errorId, role: "alert", variant: "helper", className: "text-danger-foreground-subtle", children: error })) : null] }));
|
|
139
144
|
}
|
|
140
145
|
const DATE_TIME_LOCAL_PARTS = "yyyy-MM-dd'T'";
|
|
141
146
|
// Browsers omit the seconds from a datetime-local value when they are zero.
|
|
@@ -233,8 +238,9 @@ function mergeRefs(...refs) {
|
|
|
233
238
|
}
|
|
234
239
|
};
|
|
235
240
|
}
|
|
236
|
-
function DateTimeRangePickerImpl({ ref, value, defaultValue, onChange, label, timeFormat = "HH:mm:ss", presets, showTimeZone = true, showTimePickerIcon = false,
|
|
241
|
+
function DateTimeRangePickerImpl({ ref, value, defaultValue, onChange, label, timeFormat = "HH:mm:ss", presets, showTimeZone = true, showTimePickerIcon = false, showInputs = false, showCalendarButton: showCalendarButtonProp = false, fromDate, toDate: toDateProp, disableFuture = false, locale, disabled = false, messages, id, className, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, }) {
|
|
237
242
|
const { t } = useC4Dictionary();
|
|
243
|
+
const toDate = latestSelectableDate(toDateProp, disableFuture);
|
|
238
244
|
const generatedId = React.useId();
|
|
239
245
|
const baseId = id ?? generatedId;
|
|
240
246
|
const headingId = `${baseId}-label`;
|
|
@@ -286,19 +292,14 @@ function DateTimeRangePickerImpl({ ref, value, defaultValue, onChange, label, ti
|
|
|
286
292
|
committed.to?.getTime() === lastPreset.to
|
|
287
293
|
? lastPreset.id
|
|
288
294
|
: undefined;
|
|
289
|
-
//
|
|
290
|
-
const current =
|
|
295
|
+
// The open popover edits a draft; Apply commits it.
|
|
296
|
+
const current = open ? (pending ?? committed) : committed;
|
|
291
297
|
const setDraft = (range, presetId) => {
|
|
292
298
|
setPending(range);
|
|
293
299
|
setPendingPresetId(presetId);
|
|
294
300
|
};
|
|
295
|
-
const update = showApplyButton ? setDraft : emit;
|
|
296
301
|
const draftChanged = pending?.from?.getTime() !== committed?.from?.getTime() ||
|
|
297
302
|
pending?.to?.getTime() !== committed?.to?.getTime();
|
|
298
|
-
// With the apply button, typed inputs always edit the draft (so fields and
|
|
299
|
-
// calendar agree); typing while closed opens the popover so Apply is in view.
|
|
300
|
-
const inputRange = current;
|
|
301
|
-
const inputUpdate = update;
|
|
302
303
|
// Keep the calendar showing the end that was typed.
|
|
303
304
|
const monthCount = isNarrow ? 1 : 2;
|
|
304
305
|
const [rejectedEnds, setRejectedEnds] = React.useState({
|
|
@@ -317,7 +318,7 @@ function DateTimeRangePickerImpl({ ref, value, defaultValue, onChange, label, ti
|
|
|
317
318
|
};
|
|
318
319
|
const updateInputs = (range, end) => {
|
|
319
320
|
const typed = range[end === "from" ? "from" : "to"];
|
|
320
|
-
if (
|
|
321
|
+
if (!open) {
|
|
321
322
|
openerIdRef.current = `${baseId}-${end === "from" ? "start" : "end"}`;
|
|
322
323
|
setKeyboardOpen(false);
|
|
323
324
|
// Opening repositions the calendar on the saved range; place the typed
|
|
@@ -329,7 +330,7 @@ function DateTimeRangePickerImpl({ ref, value, defaultValue, onChange, label, ti
|
|
|
329
330
|
else {
|
|
330
331
|
showInCalendar(typed, end);
|
|
331
332
|
}
|
|
332
|
-
|
|
333
|
+
setDraft(range);
|
|
333
334
|
};
|
|
334
335
|
// Typed text that never reached the draft must not outlive the popover.
|
|
335
336
|
const closePopover = () => {
|
|
@@ -363,7 +364,7 @@ function DateTimeRangePickerImpl({ ref, value, defaultValue, onChange, label, ti
|
|
|
363
364
|
: !range && current?.from && isSameDay(current.from, triggerDate)
|
|
364
365
|
? { from: current.from, to: triggerDate }
|
|
365
366
|
: range;
|
|
366
|
-
|
|
367
|
+
setDraft(toRange(nextRange?.from &&
|
|
367
368
|
withTime(nextRange.from, "from", hasSeconds, current?.from), nextRange?.to && withTime(nextRange.to, "to", hasSeconds, current?.to)));
|
|
368
369
|
};
|
|
369
370
|
const handlePreset = (preset) => {
|
|
@@ -374,13 +375,7 @@ function DateTimeRangePickerImpl({ ref, value, defaultValue, onChange, label, ti
|
|
|
374
375
|
};
|
|
375
376
|
setInputsResetKey((key) => key + 1);
|
|
376
377
|
setMonth(next.from);
|
|
377
|
-
|
|
378
|
-
setDraft(next, preset.id);
|
|
379
|
-
}
|
|
380
|
-
else {
|
|
381
|
-
emit(next, preset.id);
|
|
382
|
-
closePopover();
|
|
383
|
-
}
|
|
378
|
+
setDraft(next, preset.id);
|
|
384
379
|
};
|
|
385
380
|
const timeZone = getTimeZoneLabel(locale);
|
|
386
381
|
const defaults = {
|
|
@@ -392,12 +387,10 @@ function DateTimeRangePickerImpl({ ref, value, defaultValue, onChange, label, ti
|
|
|
392
387
|
timeZone: t("dateTimeRangePicker.timeZone", { timeZone }),
|
|
393
388
|
apply: t("dateTimeRangePicker.apply"),
|
|
394
389
|
cancel: t("dateTimeRangePicker.cancel"),
|
|
395
|
-
clear: t("dateTimeRangePicker.clear"),
|
|
396
390
|
clearRange: t("dateTimeRangePicker.clearRange"),
|
|
397
391
|
selectEndDate: t("dateTimeRangePicker.selectEndDate"),
|
|
398
392
|
pickDayFirst: t("dateTimeRangePicker.pickDayFirst"),
|
|
399
393
|
pickEndDay: t("dateTimeRangePicker.pickEndDay"),
|
|
400
|
-
applyNeedsRange: t("dateTimeRangePicker.applyNeedsRange"),
|
|
401
394
|
openCalendar: t("dateTimeRangePicker.openCalendar"),
|
|
402
395
|
startInput: t("dateTimeRangePicker.startInput"),
|
|
403
396
|
endInput: t("dateTimeRangePicker.endInput"),
|
|
@@ -421,14 +414,12 @@ function DateTimeRangePickerImpl({ ref, value, defaultValue, onChange, label, ti
|
|
|
421
414
|
min: fromDate ? formatBound(fromDate) : "",
|
|
422
415
|
max: toDate ? formatBound(toDate) : "",
|
|
423
416
|
});
|
|
424
|
-
const
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
return matchers.length > 0 ? matchers : undefined;
|
|
431
|
-
}, [fromDate, toDate]);
|
|
417
|
+
const disabledMatchers = [];
|
|
418
|
+
if (fromDate)
|
|
419
|
+
disabledMatchers.push({ before: fromDate });
|
|
420
|
+
if (toDate)
|
|
421
|
+
disabledMatchers.push({ after: toDate });
|
|
422
|
+
const disabledMatcher = disabledMatchers.length > 0 ? disabledMatchers : undefined;
|
|
432
423
|
// Phones get a shorter label (no seconds, year only when not this year) so
|
|
433
424
|
// the end of the range stays visible.
|
|
434
425
|
const formatEnd = (date) => isNarrow
|
|
@@ -446,11 +437,10 @@ function DateTimeRangePickerImpl({ ref, value, defaultValue, onChange, label, ti
|
|
|
446
437
|
const now = new Date();
|
|
447
438
|
const availablePresets = (presets ?? []).filter((preset) => !isOutOfRange(subMinutes(now, preset.minutes), fromDate, toDate) &&
|
|
448
439
|
!isOutOfRange(now, fromDate, toDate));
|
|
449
|
-
const activePresetId =
|
|
440
|
+
const activePresetId = open ? pendingPresetId : committedPresetId;
|
|
450
441
|
const hasPresets = availablePresets.length > 0;
|
|
451
442
|
const contentId = `${baseId}-content`;
|
|
452
443
|
const presetsHeadingId = `${baseId}-presets`;
|
|
453
|
-
const applyHintId = `${baseId}-apply-hint`;
|
|
454
444
|
const timeZoneId = `${baseId}-time-zone`;
|
|
455
445
|
const startLabel = text("startInput");
|
|
456
446
|
const endLabel = text("endInput");
|
|
@@ -461,7 +451,7 @@ function DateTimeRangePickerImpl({ ref, value, defaultValue, onChange, label, ti
|
|
|
461
451
|
const committedReversed = committed?.from !== undefined &&
|
|
462
452
|
committed.to !== undefined &&
|
|
463
453
|
!isAfter(committed.to, committed.from);
|
|
464
|
-
const showClearButton = !disabled &&
|
|
454
|
+
const showClearButton = !disabled && (committed?.from !== undefined || committed?.to !== undefined);
|
|
465
455
|
const reversedId = `${baseId}-reversed`;
|
|
466
456
|
// Fade the right edge of the narrow quick-range row while more remain.
|
|
467
457
|
const updatePresetsFade = () => {
|
|
@@ -477,15 +467,6 @@ function DateTimeRangePickerImpl({ ref, value, defaultValue, onChange, label, ti
|
|
|
477
467
|
const content = contentRef.current;
|
|
478
468
|
(content?.querySelector('[role="grid"] button[tabindex="0"]') ?? content?.querySelector("button:not([disabled])"))?.focus();
|
|
479
469
|
};
|
|
480
|
-
const handleClear = () => {
|
|
481
|
-
setInputsResetKey((key) => key + 1);
|
|
482
|
-
update({});
|
|
483
|
-
// Clear disables itself in apply mode; keep focus inside the popover.
|
|
484
|
-
if (showApplyButton)
|
|
485
|
-
focusCalendarDay();
|
|
486
|
-
if (!showApplyButton)
|
|
487
|
-
closePopover();
|
|
488
|
-
};
|
|
489
470
|
const clearsCommitted = !current?.from &&
|
|
490
471
|
!current?.to &&
|
|
491
472
|
(committed?.from !== undefined || committed?.to !== undefined);
|
|
@@ -520,13 +501,11 @@ function DateTimeRangePickerImpl({ ref, value, defaultValue, onChange, label, ti
|
|
|
520
501
|
handleOpenChange(true);
|
|
521
502
|
}
|
|
522
503
|
: undefined,
|
|
523
|
-
onFocusPopover:
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
}
|
|
529
|
-
: undefined,
|
|
504
|
+
onFocusPopover: (openerId) => {
|
|
505
|
+
openerIdRef.current = openerId;
|
|
506
|
+
setKeyboardOpen(true);
|
|
507
|
+
focusCalendarDay();
|
|
508
|
+
},
|
|
530
509
|
popup: opensFromInputs ? { open, controls: contentId } : undefined,
|
|
531
510
|
};
|
|
532
511
|
const triggerButton = (_jsxs(Button, { ref: ref, onPointerEnter: measureLabel, onFocus: measureLabel, id: triggerId, variant: "secondary", disabled: disabled, "aria-label": labelledBy ? undefined : ariaLabel, "aria-labelledby": labelledBy, "aria-invalid": committedReversed || undefined, "aria-describedby": committedReversed ? reversedId : undefined, className: cn("w-full justify-between font-normal", isNarrow && "h-auto min-h-9 py-1.5", !committed?.from && "text-neutral-foreground-subtle", committedReversed && "border-danger-foreground-subtle"), "data-slot": "date-time-range-picker-trigger", children: [showCalendarButton ? calendarIcon : null, _jsx("span", { ref: labelRef, className: cn("min-w-0 flex-1 text-left", isNarrow ? "break-words whitespace-normal" : "truncate", showClearButton && "pr-8"), children: triggerLabel }), showCalendarButton ? null : calendarIcon] }));
|
|
@@ -536,20 +515,20 @@ function DateTimeRangePickerImpl({ ref, value, defaultValue, onChange, label, ti
|
|
|
536
515
|
const wrappedTrigger = (_jsxs(Tooltip, { children: [_jsx(TooltipTrigger, { asChild: true, children: popoverTrigger }), isLabelTruncated && !isNarrow ? (_jsx(TooltipContent, { children: triggerLabel })) : null] }));
|
|
537
516
|
const control = showInputs ? (_jsx(PopoverAnchor, { asChild: true, children: _jsxs("div", { ref: groupRef, role: "group", "aria-labelledby": label ? headingId : ariaLabelledBy, "aria-label": label || ariaLabelledBy ? undefined : ariaLabel, className: "flex items-start gap-2 max-[22rem]:flex-col", "data-slot": "date-time-range-picker-inputs", children: [showCalendarButton ? (_jsx(Button, { ref: mergeRefs(ref, calendarButtonRef), id: triggerId, type: "button", variant: "secondary", size: "icon", disabled: disabled, "aria-label": text("openCalendar"), title: text("openCalendar"), "aria-haspopup": "dialog", "aria-expanded": open, "aria-controls": open ? contentId : undefined, className: "mt-[1.625rem] max-[22rem]:mt-0", onClick: () => {
|
|
538
517
|
// An unsaved draft must survive this click; otherwise it toggles.
|
|
539
|
-
if (
|
|
518
|
+
if (open && draftChanged)
|
|
540
519
|
focusCalendarDay();
|
|
541
520
|
else
|
|
542
521
|
handleOpenChange(!open);
|
|
543
|
-
}, "data-slot": "date-time-range-picker-trigger", children: calendarIcon })) : null, _jsxs("div", { className: "flex min-w-0 flex-1 flex-col gap-2 max-[22rem]:w-full sm:flex-row", children: [_jsx(RangeInput, { id: `${baseId}-start`, label: startLabel, end: "from", date:
|
|
522
|
+
}, "data-slot": "date-time-range-picker-trigger", children: calendarIcon })) : null, _jsxs("div", { className: "flex min-w-0 flex-1 flex-col gap-2 max-[22rem]:w-full sm:flex-row", children: [_jsx(RangeInput, { id: `${baseId}-start`, label: startLabel, end: "from", date: current?.from, rangeError: isEndBeforeStart, onCommit: (date) => updateInputs(toRange(date, current?.to), "from"), ...inputProps }), _jsx(RangeInput, { id: `${baseId}-end`, tabIntoPopover: open, label: endLabel, end: "to", date: current?.to, rangeError: isEndBeforeStart, rangeErrorText: isEndBeforeStart
|
|
544
523
|
? endBeforeStartText(endLabel, startLabel)
|
|
545
|
-
: undefined, onCommit: (date) => updateInputs(toRange(
|
|
524
|
+
: undefined, onCommit: (date) => updateInputs(toRange(current?.from, date), "to"), ...inputProps })] })] }) })) : (_jsxs("div", { className: "relative", children: [wrappedTrigger, showClearButton ? (_jsx("button", { type: "button", "aria-label": text("clearRange"), onClick: () => {
|
|
546
525
|
emit({});
|
|
547
526
|
closePopover();
|
|
548
527
|
document.getElementById(triggerId)?.focus();
|
|
549
528
|
}, title: text("clearRange"), className: cn("absolute top-1/2 inline-flex size-7 -translate-y-1/2 items-center justify-center rounded-sm text-neutral-foreground-subtle hover:text-neutral-foreground-strong focus-visible:ring-2 focus-visible:ring-ring focus-visible:outline-none", showCalendarButton ? "right-2" : "right-9"), "data-slot": "date-time-range-picker-clear", children: _jsx(XIcon, { className: "size-4", "aria-hidden": "true" }) })) : null] }));
|
|
550
|
-
return (_jsxs("div", { className: cn("flex flex-col gap-1.5", className), "data-slot": "date-time-range-picker", children: [label ? (_jsx(Text, { as: "div", id: headingId, variant: "label-md-strong", className: "text-neutral-foreground-strong", children: label })) : null, _jsxs(Popover, { open: disabled ? false : open, onOpenChange: handleOpenChange, children: [control, committedReversed && !showInputs && !open ? (_jsx(Text, { as: "p", id: reversedId, role: "alert", variant: "helper", className: "text-danger-foreground-subtle", children: endBeforeStartText(endLabel, startLabel) })) : null,
|
|
529
|
+
return (_jsxs("div", { className: cn("flex flex-col gap-1.5", className), "data-slot": "date-time-range-picker", children: [label ? (_jsx(Text, { as: "div", id: headingId, variant: "label-md-strong", className: "text-neutral-foreground-strong", children: label })) : null, _jsxs(Popover, { open: disabled ? false : open, onOpenChange: handleOpenChange, children: [control, committedReversed && !showInputs && !open ? (_jsx(Text, { as: "p", id: reversedId, role: "alert", variant: "helper", className: "text-danger-foreground-subtle", children: endBeforeStartText(endLabel, startLabel) })) : null, _jsxs(PopoverContent, { id: contentId, "aria-labelledby": label ? headingId : ariaLabelledBy, "aria-label": label || ariaLabelledBy
|
|
551
530
|
? undefined
|
|
552
|
-
: (ariaLabel ?? text("placeholder")), "data-slot": "date-time-range-picker-content", className: "max-h-(--radix-popover-content-available-height) w-auto max-w-[calc(100vw-2rem)] overflow-
|
|
531
|
+
: (ariaLabel ?? text("placeholder")), "data-slot": "date-time-range-picker-content", className: "flex max-h-(--radix-popover-content-available-height) w-auto max-w-[calc(100vw-2rem)] flex-col overflow-hidden p-0", align: "start", collisionPadding: 16, ref: contentRef, onOpenAutoFocus: typingOpen || (opensFromInputs && !keyboardOpen)
|
|
553
532
|
? (event) => event.preventDefault()
|
|
554
533
|
: undefined, onCloseAutoFocus: showInputs
|
|
555
534
|
? (event) => {
|
|
@@ -563,7 +542,7 @@ function DateTimeRangePickerImpl({ ref, value, defaultValue, onChange, label, ti
|
|
|
563
542
|
: document.getElementById(openerIdRef.current ?? `${baseId}-start`))?.focus();
|
|
564
543
|
}
|
|
565
544
|
}
|
|
566
|
-
: undefined, onKeyDown:
|
|
545
|
+
: undefined, onKeyDown: showInputs
|
|
567
546
|
? (event) => {
|
|
568
547
|
if (event.key !== "Tab")
|
|
569
548
|
return;
|
|
@@ -582,24 +561,28 @@ function DateTimeRangePickerImpl({ ref, value, defaultValue, onChange, label, ti
|
|
|
582
561
|
const viaFocus = event.detail.originalEvent.type === "focusin";
|
|
583
562
|
if (groupRef.current?.contains(event.target) ||
|
|
584
563
|
// Tabbing away must not discard a draft the user is still typing.
|
|
585
|
-
(
|
|
564
|
+
(showInputs && viaFocus)) {
|
|
586
565
|
event.preventDefault();
|
|
587
566
|
}
|
|
588
567
|
else {
|
|
589
568
|
closedByOutsideRef.current = true;
|
|
590
569
|
}
|
|
591
|
-
}, children: _jsxs("div", { className: "flex flex-col sm:flex-row", children: [hasPresets ? (_jsxs("div", { className: "flex shrink-0 flex-col gap-1 border-b border-border p-2 sm:w-44 sm:border-r sm:border-b-0", "data-slot": "date-time-range-picker-presets", children: [_jsx(Text, { as: "div", id: presetsHeadingId, variant: "label-md-strong", className: "px-2 pt-1 text-neutral-foreground-strong", children: text("quickRanges") }), _jsx("ul", { ref: presetsRef, "aria-labelledby": presetsHeadingId, onScroll: updatePresetsFade, className: cn("flex gap-0.5 overflow-x-auto sm:max-h-[24rem] sm:flex-col sm:overflow-x-visible sm:overflow-y-auto", presetsFade &&
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
570
|
+
}, children: [_jsxs("div", { className: "flex min-h-0 flex-1 flex-col sm:flex-row", children: [hasPresets ? (_jsxs("div", { className: "flex shrink-0 flex-col gap-1 border-b border-border p-2 sm:min-h-0 sm:w-44 sm:border-r sm:border-b-0", "data-slot": "date-time-range-picker-presets", children: [_jsx(Text, { as: "div", id: presetsHeadingId, variant: "label-md-strong", className: "px-2 pt-1 text-neutral-foreground-strong", children: text("quickRanges") }), _jsx("ul", { ref: presetsRef, "aria-labelledby": presetsHeadingId, onScroll: updatePresetsFade, className: cn("flex gap-0.5 overflow-x-auto sm:max-h-[24rem] sm:min-h-0 sm:flex-col sm:overflow-x-visible sm:overflow-y-auto", presetsFade &&
|
|
571
|
+
"mask-[linear-gradient(to_right,black_calc(100%-2.5rem),transparent)] sm:mask-none"), children: availablePresets.map((preset) => (_jsx("li", { className: "shrink-0", children: _jsx(Button, { variant: activePresetId === preset.id ? "secondary" : "ghost", size: "sm", "aria-pressed": activePresetId === preset.id, className: "w-full justify-start font-normal", onClick: () => handlePreset(preset), children: getPresetLabel(preset, t) }) }, preset.id))) })] })) : null, _jsxs("div", { className: "flex min-h-0 min-w-0 flex-1 flex-col overflow-y-auto", children: [_jsx("div", { className: "min-h-32 flex-1 overflow-y-auto", "data-slot": "date-time-range-picker-months", children: _jsx(Calendar, { mode: "range", selected: current?.from
|
|
572
|
+
? isEndBeforeStart && current.to
|
|
573
|
+
? { from: current.to, to: current.from }
|
|
574
|
+
: { from: current.from, to: current.to }
|
|
575
|
+
: undefined, onSelect: handleSelect, month: month ?? current?.from, onMonthChange: setMonth, numberOfMonths: monthCount, startMonth: fromDate, endMonth: toDate, disabled: disabledMatcher, locale: locale, min: 1,
|
|
576
|
+
// Always six week rows; outside days stay hidden, so the extra cells are blank.
|
|
577
|
+
fixedWeeks: true, autoFocus: (!opensFromInputs || keyboardOpen) && !typingOpen }) }), _jsxs("div", { className: "flex gap-4 border-t border-border p-3 max-[22rem]:flex-col", children: [_jsx(TimeField, { id: `${baseId}-from-time`, label: text("fromTime"), end: "from", emptyHint: text("pickDayFirst"), date: current?.from, onCommit: (date) => setDraft(toRange(date, current?.to)), ...timeProps }), _jsx(TimeField, { id: `${baseId}-to-time`, label: text("toTime"), end: "to", emptyHint: current?.from ? text("pickEndDay") : undefined, date: current?.to, error: isEndBeforeStart && !showInputs
|
|
578
|
+
? endBeforeStartText(endLabel, startLabel)
|
|
579
|
+
: undefined, onCommit: (date) => setDraft(toRange(current?.from, date)), ...timeProps })] }), showTimeZone ? (_jsx(Text, { as: "p", id: timeZoneId, variant: "helper", className: "px-3 pb-2", children: text("timeZone").replace("{timeZone}", timeZone) })) : null] })] }), _jsxs("div", { className: "flex shrink-0 justify-end gap-2 border-t border-border p-3", "data-slot": "date-time-range-picker-footer", children: [_jsx(Button, { variant: "secondary", onClick: () => closePopover(), children: text("cancel") }), _jsx(Button, { disabled: needsRange ||
|
|
580
|
+
isEndBeforeStart ||
|
|
581
|
+
draftOutOfBounds ||
|
|
582
|
+
rejectedEnds.from ||
|
|
583
|
+
rejectedEnds.to, "aria-describedby": needsRange
|
|
584
|
+
? `${baseId}-${current?.from ? "to" : "from"}-time-hint`
|
|
585
|
+
: undefined, onClick: apply, children: text("apply") })] })] })] })] }));
|
|
603
586
|
}
|
|
604
587
|
const DateTimeRangePicker = withRef(DateTimeRangePickerImpl);
|
|
605
588
|
export { DateTimeRangePicker, DEFAULT_DATE_TIME_RANGE_PRESETS };
|