@trackunit/react-date-and-time-components 1.3.221 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (27) hide show
  1. package/index.cjs.js +419 -73
  2. package/index.esm.js +417 -75
  3. package/package.json +13 -12
  4. package/src/DayPicker/DayRangePicker.d.ts +7 -14
  5. package/src/DayPicker/DayRangePicker.stories.d.ts +0 -1
  6. package/src/DayPicker/index.d.ts +0 -1
  7. package/src/DayRangeSelect/DayRangeSelect.d.ts +56 -0
  8. package/src/DayRangeSelect/DayRangeSelect.stories.d.ts +10 -0
  9. package/src/DayRangeSelect/DayRangeSelect.variants.d.ts +3 -0
  10. package/src/DayRangeSelect/components/DayRangeSelectOptions.d.ts +11 -0
  11. package/src/DayRangeSelect/hooks/useCalculateCustomDateRangeDisabledDays/useCalculateCustomDateRangeDisabledDays.d.ts +11 -0
  12. package/src/DayRangeSelect/hooks/useCalculateDateRange/useCalculateDateRange.d.ts +9 -0
  13. package/src/DayRangeSelect/hooks/useFilterTemporalPeriodsInRange/useFilterTemporalPeriodsInRange.d.ts +18 -0
  14. package/src/DayRangeSelect/hooks/useFormatTemporalPeriodLabel/useFormatTemporalPeriodLabel.d.ts +9 -0
  15. package/src/DayRangeSelect/hooks/useParseTemporalPeriodFromText/hooks/useFindTemporalDirection.d.ts +5 -0
  16. package/src/DayRangeSelect/hooks/useParseTemporalPeriodFromText/hooks/useFindTemporalUnit.d.ts +5 -0
  17. package/src/DayRangeSelect/hooks/useParseTemporalPeriodFromText/useParseTemporalPeriodFromText.d.ts +10 -0
  18. package/src/DayRangeSelect/index.d.ts +6 -0
  19. package/src/DayRangeSelect/types.d.ts +16 -0
  20. package/src/DayRangeSelect/utils/createTemporalPeriodCombinations/createTemporalPeriodCombinations.d.ts +12 -0
  21. package/src/DayRangeSelect/utils/formatCustomDateRangeLabel/formatCustomDateRangeLabel.d.ts +8 -0
  22. package/src/DayRangeSelect/utils/isTemporalPeriod/isTemporalPeriod.d.ts +8 -0
  23. package/src/DayRangeSelect/utils/temporalUnitMappings.d.ts +3 -0
  24. package/src/index.d.ts +1 -0
  25. package/src/translation.d.ts +2 -2
  26. package/src/DayPicker/DayRangePickerPopover.d.ts +0 -45
  27. package/src/DayPicker/DayRangePickerPopover.stories.d.ts +0 -10
@@ -8,4 +8,3 @@ export declare const packageName: () => import("react/jsx-runtime").JSX.Element;
8
8
  export declare const DefaultSDA: () => import("react/jsx-runtime").JSX.Element;
9
9
  export declare const VariantWithMax: () => import("react/jsx-runtime").JSX.Element;
10
10
  export declare const VariantWithDisabledDays: () => import("react/jsx-runtime").JSX.Element;
11
- export declare const VariantWithQuickButtons: () => import("react/jsx-runtime").JSX.Element;
@@ -18,4 +18,3 @@ export interface TimeZone {
18
18
  }
19
19
  export * from "./DayPicker";
20
20
  export * from "./DayRangePicker";
21
- export * from "./DayRangePickerPopover";
@@ -0,0 +1,56 @@
1
+ import { CommonProps } from "@trackunit/react-components";
2
+ import { Size } from "@trackunit/shared-utils";
3
+ import { DayRangePickerProps } from "../DayPicker/DayRangePicker";
4
+ import { DateRange, SelectedDateRange, TemporalDirection, TemporalPeriod } from "./types";
5
+ export type DayRangeSelectProps = CommonProps & {
6
+ /**
7
+ * Whether the component is disabled.
8
+ */
9
+ disabled?: boolean;
10
+ /**
11
+ * The selected date range.
12
+ * When a temporal period is provided, the date range will be calculated and rendered as if a options was selected.
13
+ * When a date range is provided, it will be rendered as a custom date range.
14
+ */
15
+ selectedDateRange?: DateRange | TemporalPeriod;
16
+ /**
17
+ * If initialDateRangeOptions is provided, it will be used instead of the components default options.
18
+ */
19
+ initialDateRangeOptions?: Array<TemporalPeriod>;
20
+ /**
21
+ * Callback function that is called when a date range is selected.
22
+ */
23
+ onRangeSelect: (params?: SelectedDateRange) => void;
24
+ /**
25
+ * The direction of the date range to allow. If not provided, both 'last' and 'next' directions are allowed.
26
+ */
27
+ allowedDirection?: TemporalDirection;
28
+ /**
29
+ * Whether to show the date range search input.
30
+ */
31
+ showDateRangeSearch?: boolean;
32
+ /**
33
+ * Whether to show the custom date range option with a calendar picker.
34
+ */
35
+ showCustomDateRangeOption?: boolean;
36
+ /**
37
+ * The timezone for the date range picker.
38
+ */
39
+ timezone?: DayRangePickerProps["timezone"];
40
+ /**
41
+ * The maximum amount of days that can be selected
42
+ */
43
+ maxDaysInRange?: number;
44
+ /**
45
+ * The size of the button.
46
+ */
47
+ size?: Size;
48
+ /**
49
+ * Whether the trigger button is full width.
50
+ */
51
+ fullWidth?: boolean;
52
+ };
53
+ /**
54
+ * Day range select component.
55
+ */
56
+ export declare const DayRangeSelect: ({ className, dataTestId, disabled, selectedDateRange, onRangeSelect, allowedDirection, initialDateRangeOptions, showDateRangeSearch, showCustomDateRangeOption, timezone, maxDaysInRange, size, fullWidth, }: DayRangeSelectProps) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,10 @@
1
+ import { Meta, StoryObj } from "@storybook/react";
2
+ import { DayRangeSelect } from "./DayRangeSelect";
3
+ type Story = StoryObj<typeof DayRangeSelect>;
4
+ declare const meta: Meta<typeof DayRangeSelect>;
5
+ export default meta;
6
+ export declare const Default: Story;
7
+ export declare const packageName: () => import("react/jsx-runtime").JSX.Element;
8
+ export declare const VariantWithoutCustomDateRangeOptionAndSearch: Story;
9
+ export declare const VariantWithAllowedDirectionSet: Story;
10
+ export declare const VariantWithInitialDateRangeOptionsSet: Story;
@@ -0,0 +1,3 @@
1
+ export declare const cvaTriggerButton: (props?: ({
2
+ active?: boolean | null | undefined;
3
+ } & import("class-variance-authority/dist/types").ClassProp) | undefined) => string;
@@ -0,0 +1,11 @@
1
+ import { CommonProps } from "@trackunit/react-components";
2
+ import { SelectedDateRange, TemporalPeriod } from "../types";
3
+ export type DayRangeSelectOptionsProps = CommonProps & {
4
+ temporalPeriods: Array<TemporalPeriod>;
5
+ onSelect: (option: SelectedDateRange) => void;
6
+ selectedDateRange: SelectedDateRange | undefined;
7
+ };
8
+ /**
9
+ * Renders a list of options for the DayRangeSelect component.
10
+ */
11
+ export declare const DayRangeSelectOptions: ({ dataTestId, temporalPeriods, selectedDateRange, onSelect, }: DayRangeSelectOptionsProps) => import("react/jsx-runtime").JSX.Element | import("react/jsx-runtime").JSX.Element[];
@@ -0,0 +1,11 @@
1
+ import { DayRangePickerProps } from "../../../DayPicker";
2
+ import { TemporalDirection } from "../../types";
3
+ export type CalculateCustomDateRangeDisabledDaysProps = {
4
+ maxDaysInRange: number | undefined;
5
+ allowedDirection: TemporalDirection | undefined;
6
+ };
7
+ /**
8
+ * Calculate the disabled days for the custom date range picker based on the maxDaysInRange and allowedDirection.
9
+ * The range is inclusive of both start and end dates, so we subtract 1 from maxDaysInRange to get the correct number of days.
10
+ */
11
+ export declare const useCalculateCustomDateRangeDisabledDays: () => ({ maxDaysInRange, allowedDirection, }: CalculateCustomDateRangeDisabledDaysProps) => DayRangePickerProps["disabledDays"] | undefined;
@@ -0,0 +1,9 @@
1
+ import { DateRange, TemporalPeriod } from "../../types";
2
+ /**
3
+ * Calculate a date range based on a temporal period.
4
+ *
5
+ * @example
6
+ * getDataRange({ direction: "next", count: 1, unit: "month" }); // { from: 2025-06-01, to: 2025-07-01 }
7
+ * getDataRange({ direction: "last", count: 2, unit: "weeks" }); // { from: 2025-05-24, to: 2025-06-01 }
8
+ */
9
+ export declare const useCalculateDateRange: () => ({ direction, count, unit }: TemporalPeriod) => DateRange;
@@ -0,0 +1,18 @@
1
+ import { TemporalPeriod } from "../../types";
2
+ /**
3
+ * Filter temporal periods to only include those within a max day count.
4
+ *
5
+ * @example
6
+ * getTemporalPeriodsInRange({
7
+ * temporalPeriods: [
8
+ * { direction: "next", count: 1, unit: "week" },
9
+ * { direction: "next", count: 1, unit: "month" },
10
+ * ],
11
+ * maxDaysInRange: 7,
12
+ * });
13
+ * ); // [{ direction: "next", count: 1, unit: "week" }]
14
+ */
15
+ export declare const useFilterTemporalPeriodsInRange: () => ({ temporalPeriods, maxDaysInRange, }: {
16
+ temporalPeriods: Array<TemporalPeriod>;
17
+ maxDaysInRange: number | undefined;
18
+ }) => Array<TemporalPeriod>;
@@ -0,0 +1,9 @@
1
+ import { TemporalPeriod } from "../../types";
2
+ /**
3
+ * Format a temporal period into a label.
4
+ *
5
+ * @example
6
+ * formatTemporalPeriodLabel({ direction: "last", count: 2, unit: "days" }); // Last 2 days
7
+ * formatTemporalPeriodLabel({ direction: "next", count: 1, unit: "week" }); // Next week
8
+ */
9
+ export declare const useFormatTemporalPeriodLabel: () => (option: TemporalPeriod) => string;
@@ -0,0 +1,5 @@
1
+ import { TemporalDirection } from "../../../types";
2
+ /**
3
+ * Find the TemporalDirection type matching the value.
4
+ */
5
+ export declare const useFindTemporalDirection: () => (value: string | undefined) => TemporalDirection | undefined;
@@ -0,0 +1,5 @@
1
+ import { TemporalUnit } from "../../../types";
2
+ /**
3
+ * Find the TemporalUnit type matching the value.
4
+ */
5
+ export declare const useFindTemporalUnit: () => (value: string | undefined) => TemporalUnit | undefined;
@@ -0,0 +1,10 @@
1
+ import { TemporalPeriod } from "../../types";
2
+ /**
3
+ * Parse a text string into a temporal period object.
4
+ *
5
+ * @example
6
+ * parseTemporalPeriodFromText("Last 2 days"); // { direction: "last", count: 2, unit: "days" }
7
+ * parseTemporalPeriodFromText("next 3"); // { direction: "next", count: 3 }
8
+ * parseTemporalPeriodFromText("1 month"); // {count: 1, unit: "month" }
9
+ */
10
+ export declare const useParseTemporalPeriodFromText: () => (value: string) => Partial<TemporalPeriod>;
@@ -0,0 +1,6 @@
1
+ export * from "./DayRangeSelect";
2
+ export * from "./hooks/useCalculateDateRange/useCalculateDateRange";
3
+ export * from "./hooks/useFormatTemporalPeriodLabel/useFormatTemporalPeriodLabel";
4
+ export * from "./types";
5
+ export * from "./utils/formatCustomDateRangeLabel/formatCustomDateRangeLabel";
6
+ export * from "./utils/isTemporalPeriod/isTemporalPeriod";
@@ -0,0 +1,16 @@
1
+ import { TemporalArithmeticType, TemporalSameType } from "@trackunit/react-date-and-time-hooks";
2
+ export type DateRange = {
3
+ from: Date;
4
+ to: Date;
5
+ };
6
+ export type TemporalUnit = Exclude<TemporalArithmeticType | TemporalSameType, "year" | "hours" | "minutes" | "years">;
7
+ export type TemporalDirection = "next" | "last";
8
+ export type TemporalPeriod = {
9
+ direction: TemporalDirection;
10
+ count: number;
11
+ unit: TemporalUnit;
12
+ };
13
+ export type SelectedDateRange = {
14
+ dateRange: DateRange;
15
+ temporalPeriod: TemporalPeriod | undefined;
16
+ };
@@ -0,0 +1,12 @@
1
+ import { TemporalPeriod } from "../../types";
2
+ /**
3
+ * Generate all possible temporal period combinations for a given temporal period.
4
+ * If direction is not provided, both "last" and "next" directions are used.
5
+ * If count is not provided, the count defaults to 1.
6
+ * If unit is not provided, both "day", "week", and "month" are used in plural or singular form depending on the count.
7
+ *
8
+ * @example
9
+ * createTemporalPeriodCombinations({ direction: "last", count: 2, unit: "days" }); // [{ direction: "last", count: 2, unit: "days" }]
10
+ * createTemporalPeriodCombinations({ direction: "next", count: 1 }); // [{ direction: "next", count: 1, unit: "day" }, { direction: "next", count: 1, unit: "week" }, { direction: "next", count: 1, unit: "month" }]
11
+ */
12
+ export declare const createTemporalPeriodCombinations: ({ direction, count, unit, }: Partial<TemporalPeriod>) => Array<TemporalPeriod>;
@@ -0,0 +1,8 @@
1
+ import { DateRange } from "../../types";
2
+ /**
3
+ * Format a label representing the provided date range.
4
+ *
5
+ * @example
6
+ * formatCustomDateRangeLabel({ from: new Date("2025-06-16"), to: new Date("2025-06-17") }); // "June 16, 2025 - June 17, 2025"
7
+ */
8
+ export declare const formatCustomDateRangeLabel: (dateRange: DateRange) => string;
@@ -0,0 +1,8 @@
1
+ import { DateRange, TemporalPeriod } from "../../types";
2
+ /**
3
+ * Check if a value is a temporal period.
4
+ *
5
+ * @param value - The value to check.
6
+ * @returns {boolean} - Whether the value is a temporal period.
7
+ */
8
+ export declare const isTemporalPeriod: (value: DateRange | TemporalPeriod | undefined) => value is TemporalPeriod;
@@ -0,0 +1,3 @@
1
+ import { TemporalArithmeticType } from "@trackunit/react-date-and-time-hooks";
2
+ import { TemporalUnit } from "../types";
3
+ export declare const temporalArithmeticTypeMapping: Record<TemporalUnit, TemporalArithmeticType>;
package/src/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from "./dateTime";
2
2
  export * from "./DayPicker";
3
+ export * from "./DayRangeSelect";
3
4
  export * from "./Timeline";
@@ -14,8 +14,8 @@ export declare const translations: TranslationResource<TranslationKeys>;
14
14
  /**
15
15
  * Local useTranslation for this specific library
16
16
  */
17
- export declare const useTranslation: () => [TransForLibs<"dateTime.instant.now" | "dayRangePickerPopover.icon.tooltip.calendar" | "layout.actions.apply" | "layout.actions.cancel" | "layout.actions.clear" | "shared.timePeriods.days" | "shared.timePeriods.days_plural" | "shared.timePeriods.hours" | "shared.timePeriods.hours_plural" | "shared.timePeriods.months" | "shared.timePeriods.months_plural" | "shared.timePeriods.today" | "shared.timePeriods.weeks" | "shared.timePeriods.weeks_plural" | "timeline.loadMore">, import("i18next").i18n, boolean] & {
18
- t: TransForLibs<"dateTime.instant.now" | "dayRangePickerPopover.icon.tooltip.calendar" | "layout.actions.apply" | "layout.actions.cancel" | "layout.actions.clear" | "shared.timePeriods.days" | "shared.timePeriods.days_plural" | "shared.timePeriods.hours" | "shared.timePeriods.hours_plural" | "shared.timePeriods.months" | "shared.timePeriods.months_plural" | "shared.timePeriods.today" | "shared.timePeriods.weeks" | "shared.timePeriods.weeks_plural" | "timeline.loadMore">;
17
+ export declare const useTranslation: () => [TransForLibs<"dateTime.instant.now" | "input.combined" | "input.direction.last" | "input.direction.next" | "input.icon.tooltip.calendar" | "input.noOptions" | "input.placeholder.customRange.last" | "input.placeholder.customRange.next" | "input.today" | "input.unit.day" | "input.unit.days" | "input.unit.month" | "input.unit.months" | "input.unit.week" | "input.unit.weeks" | "layout.actions.apply" | "layout.actions.back" | "layout.actions.cancel" | "layout.actions.clear" | "layout.actions.reset" | "shared.timePeriods.days" | "shared.timePeriods.days_plural" | "shared.timePeriods.hours" | "shared.timePeriods.hours_plural" | "shared.timePeriods.months" | "shared.timePeriods.months_plural" | "shared.timePeriods.today" | "shared.timePeriods.weeks" | "shared.timePeriods.weeks_plural" | "timeline.loadMore" | "trigger.customRange" | "trigger.selectDateRange">, import("i18next").i18n, boolean] & {
18
+ t: TransForLibs<"dateTime.instant.now" | "input.combined" | "input.direction.last" | "input.direction.next" | "input.icon.tooltip.calendar" | "input.noOptions" | "input.placeholder.customRange.last" | "input.placeholder.customRange.next" | "input.today" | "input.unit.day" | "input.unit.days" | "input.unit.month" | "input.unit.months" | "input.unit.week" | "input.unit.weeks" | "layout.actions.apply" | "layout.actions.back" | "layout.actions.cancel" | "layout.actions.clear" | "layout.actions.reset" | "shared.timePeriods.days" | "shared.timePeriods.days_plural" | "shared.timePeriods.hours" | "shared.timePeriods.hours_plural" | "shared.timePeriods.months" | "shared.timePeriods.months_plural" | "shared.timePeriods.today" | "shared.timePeriods.weeks" | "shared.timePeriods.weeks_plural" | "timeline.loadMore" | "trigger.customRange" | "trigger.selectDateRange">;
19
19
  i18n: import("i18next").i18n;
20
20
  ready: boolean;
21
21
  };
@@ -1,45 +0,0 @@
1
- import { ButtonVariant, CommonProps, PopoverPlacement, Size } from "@trackunit/react-components";
2
- import { ReactElement } from "react";
3
- import { Matcher } from "react-day-picker";
4
- import { IDateRange, ShowQuickOption } from "./DayRangePicker";
5
- import { TimeZone } from "./index";
6
- export interface DayRangePickerPopoverProps extends CommonProps {
7
- interval: IDateRange;
8
- showQuickOptions?: ShowQuickOption;
9
- disabledDays?: Matcher | Array<Matcher>;
10
- onRangeSelect: (range: IDateRange) => void;
11
- placement?: PopoverPlacement;
12
- variant?: Extract<ButtonVariant, "secondary">;
13
- size?: Size;
14
- fullwidth?: boolean;
15
- /**
16
- * Shown time ranges will take timezone into consideration
17
- */
18
- timezone?: TimeZone;
19
- /** An element to use as the portal root for the popover component */
20
- bindTo?: HTMLElement;
21
- buttonContent: ReactElement;
22
- max?: number;
23
- disabled?: boolean;
24
- }
25
- /**
26
- * A popover to select a range of dates. Consider providing quick options.
27
- * quickOptions takes optional "includeExtraDay". This is because customers often want to see 8 days when selecting "week" so they can compare this monday to last weeks monday. Same goes for months. This option will not impact the label of the button.
28
- *
29
- * @param { DayRangePickerPopoverProps} props - The properties for the DayRangePickerPopover component.
30
- * @param props.interval initial date range
31
- * @param props.showQuickOptions display additional buttons for quick date range selection
32
- * @param props.disabledDays disable days from selecting possibility
33
- * @param props.className custom className to be added to the component
34
- * @param props.dataTestId id used for tests
35
- * @param props.onRangeSelect hook function to handle applied date range
36
- * @param props.variant popover button variant
37
- * @param props.size popover button size
38
- * @param props.placement popover button placement
39
- * @param props.timezone timezone for DayRangePicker
40
- * @param props.fullwidth popover button fill width
41
- * @param props.buttonContent popover button content
42
- * @param props.max The maximum amount of days that can be selected
43
- * @param props.disabled disabling popover button
44
- */
45
- export declare const DayRangePickerPopover: ({ interval, showQuickOptions, disabledDays, className, dataTestId, onRangeSelect, variant, size, placement, timezone, fullwidth, bindTo, buttonContent, max, disabled, }: DayRangePickerPopoverProps) => import("react/jsx-runtime").JSX.Element;
@@ -1,10 +0,0 @@
1
- import { Meta, StoryObj } from "@storybook/react";
2
- import { DayRangePickerPopover } from "./DayRangePickerPopover";
3
- type Story = StoryObj<typeof DayRangePickerPopover>;
4
- declare const meta: Meta<typeof DayRangePickerPopover>;
5
- export default meta;
6
- export declare const Default: Story;
7
- export declare const packageName: () => import("react/jsx-runtime").JSX.Element;
8
- export declare const VariantWithMax: () => import("react/jsx-runtime").JSX.Element;
9
- export declare const VariantWithDisabledDays: () => import("react/jsx-runtime").JSX.Element;
10
- export declare const VariantWithQuickButtons: () => import("react/jsx-runtime").JSX.Element;