@trackunit/react-date-and-time-components 1.16.27 → 1.16.29

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/index.cjs.js CHANGED
@@ -94,17 +94,35 @@ const setupLibraryTranslations = () => {
94
94
 
95
95
  const MS_PER_HOUR = 60 * 60 * 1000;
96
96
  /**
97
- * DateTime component
97
+ * DateTime renders a locale-aware, formatted date and/or time inside a semantic `<time>` element.
98
+ * It supports absolute formatting via `TemporalFormat` presets (e.g., `DateTimeFormat.DATE`, `DateTimeFormat.DATE_LONG_TIME`)
99
+ * and relative "time ago" display via the `fromNow` prop. Timezone-aware formatting is available through the `timezone` prop.
98
100
  *
99
- * @param { DateTimeProps } props - The properties for the DateTime component.
100
- * @param props.value Date | string | number | null | undefined
101
- * @param props.format DateTimeFormat | TemporalFormat | string
102
- * @param props.className string
103
- * @param props.fromNow boolean
104
- * @param props.withTitle boolean
105
- * @param props.titleFormat string
106
- * @param props.timezone TimeZone
107
- * @param props.subtle boolean
101
+ * ### When to use
102
+ * Use DateTime whenever you need to display a date, time, or relative timestamp in the UI — for example, "Last seen 3 hours ago" or "Feb 17, 2026".
103
+ *
104
+ * ### When not to use
105
+ * Do not use DateTime for date input or selection — use `DayRangePicker` or `TimeRangeField`.
106
+ * Do not use for duration formatting (e.g., "2h 30m") — use dedicated duration utilities instead.
107
+ *
108
+ * @example Displaying a formatted date
109
+ * ```tsx
110
+ * import { DateTime } from "@trackunit/react-date-and-time-components";
111
+ * import { DateTimeFormat } from "@trackunit/shared-utils";
112
+ *
113
+ * const AssetLastService = () => (
114
+ * <DateTime value="2026-01-15T10:30:00Z" format={DateTimeFormat.DATE_LONG} />
115
+ * );
116
+ * ```
117
+ * @example Showing relative time
118
+ * ```tsx
119
+ * import { DateTime } from "@trackunit/react-date-and-time-components";
120
+ *
121
+ * const LastSeenLabel = ({ lastSeen }: { lastSeen: Date }) => (
122
+ * <DateTime value={lastSeen} fromNow />
123
+ * );
124
+ * ```
125
+ * @param {DateTimeProps} props - The props for the DateTime component
108
126
  */
109
127
  const DateTime = ({ value, format, className, fromNow = false, withTitle = false, titleFormat, timezone, "data-testid": dataTestId, subtle = false, ref, }) => {
110
128
  const { t } = useTranslation();
@@ -222,8 +240,29 @@ const DayPicker = ({ onDaySelect, disabledDays, selectedDay, language, className
222
240
  };
223
241
 
224
242
  /**
225
- * The DayRangePicker component should be used when the user needs to select a range of dates.
243
+ * DayRangePicker renders an interactive calendar that allows the user to select a start and end date.
244
+ * It supports disabled days, timezone-aware display, locale configuration, and an optional cancel button.
245
+ * The selected range is returned via the `onRangeSelect` callback as a `DateRange` object.
246
+ *
247
+ * ### When to use
248
+ * Use DayRangePicker when the user needs a visual calendar to pick a custom date range — for example,
249
+ * selecting a reporting period or scheduling an event spanning multiple days.
226
250
  *
251
+ * ### When not to use
252
+ * Do not use DayRangePicker for quick preset ranges (e.g., "Last 7 days") — use `DayRangeSelect` which includes preset options and a calendar fallback.
253
+ * Do not use it for time selection — use `TimeRangeField`.
254
+ *
255
+ * @example Selecting a date range
256
+ * ```tsx
257
+ * import { DayRangePicker } from "@trackunit/react-date-and-time-components";
258
+ *
259
+ * const ReportDatePicker = () => (
260
+ * <DayRangePicker
261
+ * language="en"
262
+ * onRangeSelect={(range) => console.log(range)}
263
+ * />
264
+ * );
265
+ * ```
227
266
  * @param {DayRangePickerProps} props - The props for the DayRangePicker component
228
267
  * @returns {ReactElement} DayRangePicker component
229
268
  */
@@ -591,7 +630,29 @@ const isTemporalDirection = (direction) => {
591
630
  };
592
631
 
593
632
  /**
594
- * Day range select component.
633
+ * DayRangeSelect is a popover-based date range picker with preset temporal options (e.g., "Last 7 days", "Next 30 days")
634
+ * and an optional custom calendar picker. Users can search for presets by typing natural language queries like "last 3 months".
635
+ * It supports configurable allowed directions, timezone handling, and max day limits.
636
+ *
637
+ * ### When to use
638
+ * Use DayRangeSelect when users need to choose a date range from predefined presets or a custom calendar — for example,
639
+ * filtering dashboard data by time period or selecting a reporting window.
640
+ *
641
+ * ### When not to use
642
+ * Do not use DayRangeSelect for a standalone calendar without presets — use `DayRangePicker`.
643
+ * Do not use it for time-only selection — use `TimeRangeField`.
644
+ *
645
+ * @example Date range select with default presets
646
+ * ```tsx
647
+ * import { DayRangeSelect } from "@trackunit/react-date-and-time-components";
648
+ *
649
+ * const ReportFilter = () => (
650
+ * <DayRangeSelect
651
+ * onRangeSelect={(selection) => console.log(selection)}
652
+ * />
653
+ * );
654
+ * ```
655
+ * @param {DayRangeSelectProps} props - The props for the DayRangeSelect component
595
656
  */
596
657
  const DayRangeSelect = ({ className, "data-testid": dataTestId, disabled, selectedDateRange, onRangeSelect, allowedDirection = undefined, initialDateRangeOptions, showDateRangeSearch = true, showCustomDateRangeOption = true, timezone, maxDaysInRange, size = "medium", fullWidth = false, actionButton, popoverPlacement = "bottom-start", }) => {
597
658
  const [t] = useTranslation();
package/index.esm.js CHANGED
@@ -92,17 +92,35 @@ const setupLibraryTranslations = () => {
92
92
 
93
93
  const MS_PER_HOUR = 60 * 60 * 1000;
94
94
  /**
95
- * DateTime component
95
+ * DateTime renders a locale-aware, formatted date and/or time inside a semantic `<time>` element.
96
+ * It supports absolute formatting via `TemporalFormat` presets (e.g., `DateTimeFormat.DATE`, `DateTimeFormat.DATE_LONG_TIME`)
97
+ * and relative "time ago" display via the `fromNow` prop. Timezone-aware formatting is available through the `timezone` prop.
96
98
  *
97
- * @param { DateTimeProps } props - The properties for the DateTime component.
98
- * @param props.value Date | string | number | null | undefined
99
- * @param props.format DateTimeFormat | TemporalFormat | string
100
- * @param props.className string
101
- * @param props.fromNow boolean
102
- * @param props.withTitle boolean
103
- * @param props.titleFormat string
104
- * @param props.timezone TimeZone
105
- * @param props.subtle boolean
99
+ * ### When to use
100
+ * Use DateTime whenever you need to display a date, time, or relative timestamp in the UI — for example, "Last seen 3 hours ago" or "Feb 17, 2026".
101
+ *
102
+ * ### When not to use
103
+ * Do not use DateTime for date input or selection — use `DayRangePicker` or `TimeRangeField`.
104
+ * Do not use for duration formatting (e.g., "2h 30m") — use dedicated duration utilities instead.
105
+ *
106
+ * @example Displaying a formatted date
107
+ * ```tsx
108
+ * import { DateTime } from "@trackunit/react-date-and-time-components";
109
+ * import { DateTimeFormat } from "@trackunit/shared-utils";
110
+ *
111
+ * const AssetLastService = () => (
112
+ * <DateTime value="2026-01-15T10:30:00Z" format={DateTimeFormat.DATE_LONG} />
113
+ * );
114
+ * ```
115
+ * @example Showing relative time
116
+ * ```tsx
117
+ * import { DateTime } from "@trackunit/react-date-and-time-components";
118
+ *
119
+ * const LastSeenLabel = ({ lastSeen }: { lastSeen: Date }) => (
120
+ * <DateTime value={lastSeen} fromNow />
121
+ * );
122
+ * ```
123
+ * @param {DateTimeProps} props - The props for the DateTime component
106
124
  */
107
125
  const DateTime = ({ value, format, className, fromNow = false, withTitle = false, titleFormat, timezone, "data-testid": dataTestId, subtle = false, ref, }) => {
108
126
  const { t } = useTranslation();
@@ -220,8 +238,29 @@ const DayPicker = ({ onDaySelect, disabledDays, selectedDay, language, className
220
238
  };
221
239
 
222
240
  /**
223
- * The DayRangePicker component should be used when the user needs to select a range of dates.
241
+ * DayRangePicker renders an interactive calendar that allows the user to select a start and end date.
242
+ * It supports disabled days, timezone-aware display, locale configuration, and an optional cancel button.
243
+ * The selected range is returned via the `onRangeSelect` callback as a `DateRange` object.
244
+ *
245
+ * ### When to use
246
+ * Use DayRangePicker when the user needs a visual calendar to pick a custom date range — for example,
247
+ * selecting a reporting period or scheduling an event spanning multiple days.
224
248
  *
249
+ * ### When not to use
250
+ * Do not use DayRangePicker for quick preset ranges (e.g., "Last 7 days") — use `DayRangeSelect` which includes preset options and a calendar fallback.
251
+ * Do not use it for time selection — use `TimeRangeField`.
252
+ *
253
+ * @example Selecting a date range
254
+ * ```tsx
255
+ * import { DayRangePicker } from "@trackunit/react-date-and-time-components";
256
+ *
257
+ * const ReportDatePicker = () => (
258
+ * <DayRangePicker
259
+ * language="en"
260
+ * onRangeSelect={(range) => console.log(range)}
261
+ * />
262
+ * );
263
+ * ```
225
264
  * @param {DayRangePickerProps} props - The props for the DayRangePicker component
226
265
  * @returns {ReactElement} DayRangePicker component
227
266
  */
@@ -589,7 +628,29 @@ const isTemporalDirection = (direction) => {
589
628
  };
590
629
 
591
630
  /**
592
- * Day range select component.
631
+ * DayRangeSelect is a popover-based date range picker with preset temporal options (e.g., "Last 7 days", "Next 30 days")
632
+ * and an optional custom calendar picker. Users can search for presets by typing natural language queries like "last 3 months".
633
+ * It supports configurable allowed directions, timezone handling, and max day limits.
634
+ *
635
+ * ### When to use
636
+ * Use DayRangeSelect when users need to choose a date range from predefined presets or a custom calendar — for example,
637
+ * filtering dashboard data by time period or selecting a reporting window.
638
+ *
639
+ * ### When not to use
640
+ * Do not use DayRangeSelect for a standalone calendar without presets — use `DayRangePicker`.
641
+ * Do not use it for time-only selection — use `TimeRangeField`.
642
+ *
643
+ * @example Date range select with default presets
644
+ * ```tsx
645
+ * import { DayRangeSelect } from "@trackunit/react-date-and-time-components";
646
+ *
647
+ * const ReportFilter = () => (
648
+ * <DayRangeSelect
649
+ * onRangeSelect={(selection) => console.log(selection)}
650
+ * />
651
+ * );
652
+ * ```
653
+ * @param {DayRangeSelectProps} props - The props for the DayRangeSelect component
593
654
  */
594
655
  const DayRangeSelect = ({ className, "data-testid": dataTestId, disabled, selectedDateRange, onRangeSelect, allowedDirection = undefined, initialDateRangeOptions, showDateRangeSearch = true, showCustomDateRangeOption = true, timezone, maxDaysInRange, size = "medium", fullWidth = false, actionButton, popoverPlacement = "bottom-start", }) => {
595
656
  const [t] = useTranslation();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/react-date-and-time-components",
3
- "version": "1.16.27",
3
+ "version": "1.16.29",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "engines": {
@@ -8,14 +8,14 @@
8
8
  },
9
9
  "dependencies": {
10
10
  "react": "19.0.0",
11
- "@trackunit/react-components": "1.17.22",
11
+ "@trackunit/react-components": "1.17.23",
12
12
  "@trackunit/date-and-time-utils": "1.11.44",
13
- "@trackunit/react-date-and-time-hooks": "1.13.27",
13
+ "@trackunit/react-date-and-time-hooks": "1.13.29",
14
14
  "@trackunit/css-class-variance-utilities": "1.11.43",
15
15
  "@trackunit/ui-icons": "1.11.42",
16
16
  "@trackunit/shared-utils": "1.13.43",
17
- "@trackunit/i18n-library-translation": "1.12.27",
18
- "@trackunit/react-form-components": "1.14.24",
17
+ "@trackunit/i18n-library-translation": "1.12.28",
18
+ "@trackunit/react-form-components": "1.14.26",
19
19
  "string-ts": "^2.0.0",
20
20
  "tailwind-merge": "^2.0.0",
21
21
  "react-calendar": "^6.0.0"
@@ -38,8 +38,29 @@ export interface DayRangePickerProps extends CommonProps, Refable<HTMLDivElement
38
38
  classNameCalendar?: string;
39
39
  }
40
40
  /**
41
- * The DayRangePicker component should be used when the user needs to select a range of dates.
41
+ * DayRangePicker renders an interactive calendar that allows the user to select a start and end date.
42
+ * It supports disabled days, timezone-aware display, locale configuration, and an optional cancel button.
43
+ * The selected range is returned via the `onRangeSelect` callback as a `DateRange` object.
42
44
  *
45
+ * ### When to use
46
+ * Use DayRangePicker when the user needs a visual calendar to pick a custom date range — for example,
47
+ * selecting a reporting period or scheduling an event spanning multiple days.
48
+ *
49
+ * ### When not to use
50
+ * Do not use DayRangePicker for quick preset ranges (e.g., "Last 7 days") — use `DayRangeSelect` which includes preset options and a calendar fallback.
51
+ * Do not use it for time selection — use `TimeRangeField`.
52
+ *
53
+ * @example Selecting a date range
54
+ * ```tsx
55
+ * import { DayRangePicker } from "@trackunit/react-date-and-time-components";
56
+ *
57
+ * const ReportDatePicker = () => (
58
+ * <DayRangePicker
59
+ * language="en"
60
+ * onRangeSelect={(range) => console.log(range)}
61
+ * />
62
+ * );
63
+ * ```
43
64
  * @param {DayRangePickerProps} props - The props for the DayRangePicker component
44
65
  * @returns {ReactElement} DayRangePicker component
45
66
  */
@@ -64,6 +64,28 @@ export type DayRangeSelectProps = CommonProps & {
64
64
  popoverPlacement?: PopoverPlacement;
65
65
  };
66
66
  /**
67
- * Day range select component.
67
+ * DayRangeSelect is a popover-based date range picker with preset temporal options (e.g., "Last 7 days", "Next 30 days")
68
+ * and an optional custom calendar picker. Users can search for presets by typing natural language queries like "last 3 months".
69
+ * It supports configurable allowed directions, timezone handling, and max day limits.
70
+ *
71
+ * ### When to use
72
+ * Use DayRangeSelect when users need to choose a date range from predefined presets or a custom calendar — for example,
73
+ * filtering dashboard data by time period or selecting a reporting window.
74
+ *
75
+ * ### When not to use
76
+ * Do not use DayRangeSelect for a standalone calendar without presets — use `DayRangePicker`.
77
+ * Do not use it for time-only selection — use `TimeRangeField`.
78
+ *
79
+ * @example Date range select with default presets
80
+ * ```tsx
81
+ * import { DayRangeSelect } from "@trackunit/react-date-and-time-components";
82
+ *
83
+ * const ReportFilter = () => (
84
+ * <DayRangeSelect
85
+ * onRangeSelect={(selection) => console.log(selection)}
86
+ * />
87
+ * );
88
+ * ```
89
+ * @param {DayRangeSelectProps} props - The props for the DayRangeSelect component
68
90
  */
69
91
  export declare const DayRangeSelect: ({ className, "data-testid": dataTestId, disabled, selectedDateRange, onRangeSelect, allowedDirection, initialDateRangeOptions, showDateRangeSearch, showCustomDateRangeOption, timezone, maxDaysInRange, size, fullWidth, actionButton, popoverPlacement, }: DayRangeSelectProps) => import("react/jsx-runtime").JSX.Element;
@@ -2,26 +2,73 @@ import { TemporalFormat } from "@trackunit/date-and-time-utils";
2
2
  import { CommonProps, Refable } from "@trackunit/react-components";
3
3
  import { TimeZone } from "../index";
4
4
  export interface DateTimeProps extends CommonProps, Refable<HTMLTimeElement> {
5
+ /**
6
+ * The date/time value to display. Accepts a `Date` object, an ISO 8601 string, or a Unix timestamp in milliseconds.
7
+ * When `null` or `undefined`, the current date/time is used.
8
+ */
5
9
  value: Date | string | number | null | undefined;
10
+ /**
11
+ * Display format using a `TemporalFormat` configuration object. Use presets from `DateTimeFormat`
12
+ * (e.g., `DateTimeFormat.DATE`, `DateTimeFormat.DATE_LONG_TIME`, `DateTimeFormat.TIME_SHORT`).
13
+ */
6
14
  format?: TemporalFormat;
15
+ /**
16
+ * When true, displays a relative time string (e.g., "3 hours ago") instead of the formatted date.
17
+ *
18
+ * @default false
19
+ */
7
20
  fromNow?: boolean;
21
+ /**
22
+ * When true, adds a native HTML `title` attribute with the formatted date so the full value is shown on hover.
23
+ *
24
+ * @default false
25
+ */
8
26
  withTitle?: boolean;
27
+ /**
28
+ * Custom `TemporalFormat` for the hover `title` attribute. Only used when `withTitle` is true.
29
+ */
9
30
  titleFormat?: TemporalFormat;
31
+ /**
32
+ * A `TimeZone` object to format the date in a specific timezone rather than the user's local timezone.
33
+ */
10
34
  timezone?: TimeZone;
35
+ /**
36
+ * When true, renders the text in a muted neutral color for less visual emphasis.
37
+ *
38
+ * @default false
39
+ */
11
40
  subtle?: boolean;
12
41
  }
13
42
  export declare const MS_PER_HOUR: number;
14
43
  /**
15
- * DateTime component
44
+ * DateTime renders a locale-aware, formatted date and/or time inside a semantic `<time>` element.
45
+ * It supports absolute formatting via `TemporalFormat` presets (e.g., `DateTimeFormat.DATE`, `DateTimeFormat.DATE_LONG_TIME`)
46
+ * and relative "time ago" display via the `fromNow` prop. Timezone-aware formatting is available through the `timezone` prop.
16
47
  *
17
- * @param { DateTimeProps } props - The properties for the DateTime component.
18
- * @param props.value Date | string | number | null | undefined
19
- * @param props.format DateTimeFormat | TemporalFormat | string
20
- * @param props.className string
21
- * @param props.fromNow boolean
22
- * @param props.withTitle boolean
23
- * @param props.titleFormat string
24
- * @param props.timezone TimeZone
25
- * @param props.subtle boolean
48
+ * ### When to use
49
+ * Use DateTime whenever you need to display a date, time, or relative timestamp in the UI — for example, "Last seen 3 hours ago" or "Feb 17, 2026".
50
+ *
51
+ * ### When not to use
52
+ * Do not use DateTime for date input or selection — use `DayRangePicker` or `TimeRangeField`.
53
+ * Do not use for duration formatting (e.g., "2h 30m") — use dedicated duration utilities instead.
54
+ *
55
+ * @example Displaying a formatted date
56
+ * ```tsx
57
+ * import { DateTime } from "@trackunit/react-date-and-time-components";
58
+ * import { DateTimeFormat } from "@trackunit/shared-utils";
59
+ *
60
+ * const AssetLastService = () => (
61
+ * <DateTime value="2026-01-15T10:30:00Z" format={DateTimeFormat.DATE_LONG} />
62
+ * );
63
+ * ```
64
+ * @example Showing relative time
65
+ * ```tsx
66
+ * import { DateTime } from "@trackunit/react-date-and-time-components";
67
+ *
68
+ * const LastSeenLabel = ({ lastSeen }: { lastSeen: Date }) => (
69
+ * <DateTime value={lastSeen} fromNow />
70
+ * );
71
+ * ```
72
+ * @param {DateTimeProps} props - The props for the DateTime component
26
73
  */
27
74
  export declare const DateTime: ({ value, format, className, fromNow, withTitle, titleFormat, timezone, "data-testid": dataTestId, subtle, ref, }: DateTimeProps) => import("react/jsx-runtime").JSX.Element;