@trackunit/react-date-and-time-components 1.10.118 → 1.10.121
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 +14 -14
- package/index.esm.js +14 -14
- package/package.json +9 -9
- package/src/DayPicker/DayPicker.d.ts +1 -1
- package/src/DayPicker/DayRangePicker.d.ts +1 -1
- package/src/DayPicker/DayRangePicker.stories.d.ts +2 -2
- package/src/DayRangeSelect/DayRangeSelect.d.ts +1 -1
- package/src/DayRangeSelect/DayRangeSelect.stories.d.ts +2 -2
- package/src/DayRangeSelect/components/DayRangeSelectOptions.d.ts +1 -1
- package/src/Timeline/Timeline.d.ts +1 -1
- package/src/Timeline/Timeline.stories.d.ts +1 -1
- package/src/Timeline/TimelineElement.d.ts +1 -1
- package/src/dateTime/DateTime.d.ts +1 -1
- package/src/dateTime/DateTime.stories.d.ts +2 -2
package/index.cjs.js
CHANGED
|
@@ -104,7 +104,7 @@ const MS_PER_HOUR = 60 * 60 * 1000;
|
|
|
104
104
|
* @param props.timezone TimeZone
|
|
105
105
|
* @param props.subtle boolean
|
|
106
106
|
*/
|
|
107
|
-
const DateTime = ({ value, format, className, fromNow = false, withTitle = false, titleFormat, timezone, dataTestId, subtle = false, }) => {
|
|
107
|
+
const DateTime = ({ value, format, className, fromNow = false, withTitle = false, titleFormat, timezone, "data-testid": dataTestId, subtle = false, }) => {
|
|
108
108
|
const { t } = useTranslation();
|
|
109
109
|
const locale = reactDateAndTimeHooks.useLocale();
|
|
110
110
|
const nowDate = react.useMemo(() => new Date(), []);
|
|
@@ -141,7 +141,7 @@ const DateTimeHumanized = ({ value }) => {
|
|
|
141
141
|
* @param {DayRangePickerProps} props - The props for the DayRangePicker component
|
|
142
142
|
* @returns {ReactElement} DayRangePicker component
|
|
143
143
|
*/
|
|
144
|
-
const DayRangePicker = ({ onRangeSelect, selectedDays, disabledDays, dataTestId, language, className, timezone, cancelButtonLabel, onClose, }) => {
|
|
144
|
+
const DayRangePicker = ({ onRangeSelect, selectedDays, disabledDays, "data-testid": dataTestId, language, className, timezone, cancelButtonLabel, onClose, }) => {
|
|
145
145
|
const [newRange, setNewRange] = react.useState(selectedDays ?? { start: undefined, end: undefined });
|
|
146
146
|
const [t] = useTranslation();
|
|
147
147
|
const { subtract } = reactDateAndTimeHooks.useDateAndTime();
|
|
@@ -211,7 +211,7 @@ const DayRangePicker = ({ onRangeSelect, selectedDays, disabledDays, dataTestId,
|
|
|
211
211
|
}, value:
|
|
212
212
|
// type is wrong here if we add array of 2 elements if end is undefined and set to null it will not highlight the start date
|
|
213
213
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
214
|
-
newRange.end ? [newRange.start ?? null, newRange.end ?? null] : (newRange.start ?? null) }), jsxRuntime.jsx("hr", {}), jsxRuntime.jsxs("div", { className: "flex w-full gap-2", children: [jsxRuntime.jsx(reactComponents.Button, { className: "mr-auto",
|
|
214
|
+
newRange.end ? [newRange.start ?? null, newRange.end ?? null] : (newRange.start ?? null) }), jsxRuntime.jsx("hr", {}), jsxRuntime.jsxs("div", { className: "flex w-full gap-2", children: [jsxRuntime.jsx(reactComponents.Button, { className: "mr-auto", "data-testid": "range-popover-clear-button", onClick: clearSelectedDays, size: "small", variant: "secondary", children: t("layout.actions.clear") }), jsxRuntime.jsx(reactComponents.Button, { "data-testid": "range-popover-cancel-button", onClick: () => handleCancel(), size: "small", variant: "ghost-neutral", children: cancelButtonLabel ? cancelButtonLabel : t("layout.actions.cancel") }), jsxRuntime.jsx(reactComponents.Button, { "data-testid": "range-popover-apply-button", disabled: !newRange.start || !newRange.end, onClick: () => handleApply(), size: "small", children: t("layout.actions.apply") })] })] }));
|
|
215
215
|
};
|
|
216
216
|
|
|
217
217
|
const temporalArithmeticTypeMapping = {
|
|
@@ -276,7 +276,7 @@ const useFormatTemporalPeriodLabel = () => {
|
|
|
276
276
|
/**
|
|
277
277
|
* Renders a list of options for the DayRangeSelect component.
|
|
278
278
|
*/
|
|
279
|
-
const DayRangeSelectOptions = ({ dataTestId, temporalPeriods, selectedDateRange, onSelect, }) => {
|
|
279
|
+
const DayRangeSelectOptions = ({ "data-testid": dataTestId, temporalPeriods, selectedDateRange, onSelect, }) => {
|
|
280
280
|
const [t] = useTranslation();
|
|
281
281
|
const formatTemporalPeriodLabel = useFormatTemporalPeriodLabel();
|
|
282
282
|
const calculateDateRange = useCalculateDateRange();
|
|
@@ -292,14 +292,14 @@ const DayRangeSelectOptions = ({ dataTestId, temporalPeriods, selectedDateRange,
|
|
|
292
292
|
}, [calculateDateRange, onSelect, temporalPeriods]);
|
|
293
293
|
const options = react.useMemo(() => {
|
|
294
294
|
if (!temporalPeriods.length) {
|
|
295
|
-
return (jsxRuntime.jsx(reactComponents.MenuItem, {
|
|
295
|
+
return (jsxRuntime.jsx(reactComponents.MenuItem, { "data-testid": dataTestId ? `${dataTestId}-no-options` : undefined, disabled: true, label: t("input.noOptions") }));
|
|
296
296
|
}
|
|
297
297
|
return temporalPeriods.map((temporalPeriod, index) => {
|
|
298
298
|
// NOTE: Check for temporalPeriod as well to make sure not to select an options when it's a custom date range selection
|
|
299
299
|
const isSelected = selectedDateRange &&
|
|
300
300
|
selectedDateRange.temporalPeriod &&
|
|
301
301
|
stringifyTemporalPeriod(selectedDateRange.temporalPeriod) === stringifyTemporalPeriod(temporalPeriod);
|
|
302
|
-
return (jsxRuntime.jsx(reactComponents.MenuItem, {
|
|
302
|
+
return (jsxRuntime.jsx(reactComponents.MenuItem, { "data-testid": dataTestId ? `${dataTestId}-${index.toString()}` : undefined, label: formatTemporalPeriodLabel(temporalPeriod), onClick: () => handleSelect(index), selected: isSelected, suffix: isSelected ? jsxRuntime.jsx(reactComponents.Icon, { color: "primary", name: "Check", size: "small" }) : null }, index));
|
|
303
303
|
});
|
|
304
304
|
}, [temporalPeriods, selectedDateRange, formatTemporalPeriodLabel, handleSelect, dataTestId, t]);
|
|
305
305
|
return options;
|
|
@@ -534,7 +534,7 @@ const isTemporalDirection = (direction) => {
|
|
|
534
534
|
/**
|
|
535
535
|
* Day range select component.
|
|
536
536
|
*/
|
|
537
|
-
const DayRangeSelect = ({ className, dataTestId, disabled, selectedDateRange, onRangeSelect, allowedDirection = undefined, initialDateRangeOptions, showDateRangeSearch = true, showCustomDateRangeOption = true, timezone, maxDaysInRange, size = "medium", fullWidth = false, actionButton, }) => {
|
|
537
|
+
const DayRangeSelect = ({ className, "data-testid": dataTestId, disabled, selectedDateRange, onRangeSelect, allowedDirection = undefined, initialDateRangeOptions, showDateRangeSearch = true, showCustomDateRangeOption = true, timezone, maxDaysInRange, size = "medium", fullWidth = false, actionButton, }) => {
|
|
538
538
|
const [t] = useTranslation();
|
|
539
539
|
const parseTemporalPeriodFromText = useParseTemporalPeriodFromText();
|
|
540
540
|
const filterTemporalPeriodsInRange = useFilterTemporalPeriodsInRange();
|
|
@@ -628,10 +628,10 @@ const DayRangeSelect = ({ className, dataTestId, disabled, selectedDateRange, on
|
|
|
628
628
|
setSelectedRange(_selectedDateRange);
|
|
629
629
|
onRangeSelect(_selectedDateRange);
|
|
630
630
|
}, [onRangeSelect, handleReset]);
|
|
631
|
-
return (jsxRuntime.jsxs(reactComponents.Popover, { onOpenStateChange: state => !state && setIsCustomDateRangeOpen(false), placement: "bottom-start", children: [jsxRuntime.jsx(reactComponents.PopoverTrigger, { children: !actionButton ? (jsxRuntime.jsx(reactComponents.Button, { className: cvaTriggerButton({ active: !!selectedDateRange, className }),
|
|
632
|
-
return !isCustomDateRangeOpen ? (jsxRuntime.jsxs(reactComponents.MenuList, { className: "min-w-[280px]", children: [jsxRuntime.jsxs("div", { className: "flex flex-col gap-1", children: [showDateRangeSearch ? (jsxRuntime.jsx(reactFormComponents.Search, { className: "w-full",
|
|
631
|
+
return (jsxRuntime.jsxs(reactComponents.Popover, { onOpenStateChange: state => !state && setIsCustomDateRangeOpen(false), placement: "bottom-start", children: [jsxRuntime.jsx(reactComponents.PopoverTrigger, { children: !actionButton ? (jsxRuntime.jsx(reactComponents.Button, { className: cvaTriggerButton({ active: !!selectedDateRange, className }), "data-testid": dataTestId, disabled: disabled, fullWidth: fullWidth, prefix: jsxRuntime.jsx(reactComponents.Icon, { ariaLabel: t("input.icon.tooltip.calendar"), color: disabled ? "neutral" : selectedDateRange ? "primary" : undefined, name: "Calendar", size: size === "large" ? "medium" : "small" }), size: size, variant: "secondary", children: popoverTriggerLabel ?? t("trigger.selectDateRange") })) : (jsxRuntime.jsx("div", { children: actionButton })) }), jsxRuntime.jsx(reactComponents.PopoverContent, { "data-testid": dataTestId ? `${dataTestId}-popover-content` : undefined, children: closeMenu => {
|
|
632
|
+
return !isCustomDateRangeOpen ? (jsxRuntime.jsxs(reactComponents.MenuList, { className: "min-w-[280px]", children: [jsxRuntime.jsxs("div", { className: "flex flex-col gap-1", children: [showDateRangeSearch ? (jsxRuntime.jsx(reactFormComponents.Search, { className: "w-full", "data-testid": dataTestId ? `${dataTestId}-search-input` : undefined, onChange: event => handleDateRangeSearch(event.target.value), onClear: () => handleDateRangeSearch(""), placeholder: allowedDirection === "last"
|
|
633
633
|
? t("input.placeholder.customRange.last")
|
|
634
|
-
: t("input.placeholder.customRange.next"), value: dateRangeSearchValue })) : null, jsxRuntime.jsx(reactComponents.Button, { className: "ml-auto",
|
|
634
|
+
: t("input.placeholder.customRange.next"), value: dateRangeSearchValue })) : null, jsxRuntime.jsx(reactComponents.Button, { className: "ml-auto", "data-testid": dataTestId ? `${dataTestId}-reset-button` : undefined, disabled: !selectedDateRange, onClick: handleReset, size: "small", variant: "ghost", children: t("layout.actions.reset") })] }), jsxRuntime.jsx("hr", { className: "my-1 border-neutral-200", role: "separator" }), jsxRuntime.jsx(DayRangeSelectOptions, { "data-testid": dataTestId ? `${dataTestId}-options` : undefined, onSelect: value => handleOptionsSelect(value, closeMenu), selectedDateRange: currentSelectedRange, temporalPeriods: temporalPeriods }), showCustomDateRangeOption ? (jsxRuntime.jsxs("section", { children: [jsxRuntime.jsx(reactComponents.MenuDivider, {}), jsxRuntime.jsx(reactComponents.MenuItem, { "data-testid": dataTestId ? `${dataTestId}-custom-range` : undefined, label: t("trigger.customRange"), onClick: () => setIsCustomDateRangeOpen(true), selected: isCustomDateRangeSelected, suffix: jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [isCustomDateRangeSelected ? jsxRuntime.jsx(reactComponents.Icon, { color: "primary", name: "Check", size: "small" }) : null, jsxRuntime.jsx(reactComponents.Icon, { name: "ChevronRight", size: "small" })] }) })] })) : null] })) : (jsxRuntime.jsx(reactComponents.Card, { children: jsxRuntime.jsx(DayRangePicker, { cancelButtonLabel: t("layout.actions.back"), disabledDays: customDateRangeDisabledDays, language: "en", onClose: () => setIsCustomDateRangeOpen(false), onRangeSelect: dateRange => handleCustomDateRangeSelect(dateRange
|
|
635
635
|
? {
|
|
636
636
|
start: dateRange.start ?? undefined,
|
|
637
637
|
end: dateRange.end ?? undefined,
|
|
@@ -646,7 +646,7 @@ const DayRangeSelect = ({ className, dataTestId, disabled, selectedDateRange, on
|
|
|
646
646
|
* @param {DayPickerProps} props - The props for the DayPicker component
|
|
647
647
|
* @returns {ReactElement} DayPicker component
|
|
648
648
|
*/
|
|
649
|
-
const DayPicker = ({ onDaySelect, disabledDays, selectedDay, language, className, dataTestId, }) => {
|
|
649
|
+
const DayPicker = ({ onDaySelect, disabledDays, selectedDay, language, className, "data-testid": dataTestId, }) => {
|
|
650
650
|
const { subtract } = reactDateAndTimeHooks.useDateAndTime();
|
|
651
651
|
const calculateDateRange = useCalculateDateRange();
|
|
652
652
|
return (jsxRuntime.jsx("div", { "data-testid": dataTestId, children: jsxRuntime.jsx(Calendar, { activeStartDate: selectedDay ?? undefined, allowPartialRange: true, className: tailwindMerge.twMerge("custom-day-picker", "range-picker", className, "p-0"), locale: language, onChange: value => {
|
|
@@ -760,7 +760,7 @@ const ITEMS_PER_PAGE = 20;
|
|
|
760
760
|
* @param {TimelineProps} props - The props for the Timeline component
|
|
761
761
|
* @returns {ReactElement} Timeline component
|
|
762
762
|
*/
|
|
763
|
-
const Timeline = ({ className, dataTestId, children, dateHeader, customHeader, toggleButton, }) => {
|
|
763
|
+
const Timeline = ({ className, "data-testid": dataTestId, children, dateHeader, customHeader, toggleButton, }) => {
|
|
764
764
|
const ref = react.useRef(null);
|
|
765
765
|
const [isOpen, setIsOpen] = react.useState(false);
|
|
766
766
|
const [visibleCount, setVisibleCount] = react.useState(ITEMS_PER_PAGE);
|
|
@@ -836,7 +836,7 @@ const Timeline = ({ className, dataTestId, children, dateHeader, customHeader, t
|
|
|
836
836
|
* @param {TimeLineElementProps} props the props
|
|
837
837
|
* @returns {ReactElement} component
|
|
838
838
|
*/
|
|
839
|
-
const TimelineElement = ({ date, children, className, dataTestId = "timeline-element", header, onClick, actionButton, selected, customDot, lineStyle = "solid", hoverBehavior = false, }) => {
|
|
839
|
+
const TimelineElement = ({ date, children, className, "data-testid": dataTestId = "timeline-element", header, onClick, actionButton, selected, customDot, lineStyle = "solid", hoverBehavior = false, }) => {
|
|
840
840
|
const [isHovered, setIsHovered] = react.useState(false);
|
|
841
841
|
const { formatDate } = reactDateAndTimeHooks.useDateAndTime();
|
|
842
842
|
const locale = reactDateAndTimeHooks.useLocale();
|
|
@@ -894,7 +894,7 @@ const timelineElementTime = (formattedDate, locale) => {
|
|
|
894
894
|
const CircleIcon = ({ selected, hovered }) => (jsxRuntime.jsxs("svg", { className: "relative z-[2]", "data-testid": "timeline-circle-icon", height: "24", viewBox: "0 0 24 24", width: "24", children: [jsxRuntime.jsx("circle", { cx: "12", cy: "12", fill: selected ? "#EFF6FF" : hovered ? "#F9FAFB" : "white", r: "10" }), jsxRuntime.jsx("circle", { cx: "12", cy: "12", fill: "#2563EB", r: "8" }), jsxRuntime.jsx("circle", { cx: "12", cy: "12", fill: "white", r: "3" })] }));
|
|
895
895
|
const DotIcon = () => (jsxRuntime.jsxs("svg", { className: "relative z-[2]", "data-testid": "timeline-dot-icon", height: "24", viewBox: "0 0 24 24", width: "24", children: [jsxRuntime.jsx("circle", { cx: "12", cy: "12", fill: "white", r: "6" }), jsxRuntime.jsx("circle", { cx: "12", cy: "12", fill: "#2563EB", r: "4" })] }));
|
|
896
896
|
const defaultDot = (hovered, selected) => hovered || selected ? jsxRuntime.jsx(CircleIcon, { hovered: hovered, selected: selected }) : jsxRuntime.jsx(DotIcon, {});
|
|
897
|
-
const customDotElement = (name, hovered, selected, color, keepOnSelection) => (hovered || selected) && !keepOnSelection ? (jsxRuntime.jsx(CircleIcon, { hovered: hovered, selected: selected })) : (jsxRuntime.jsx("div", { className: "flex h-6 w-6 items-center justify-center", children: jsxRuntime.jsx("div", { className: cvaCustomDot(), children: jsxRuntime.jsx(reactComponents.Icon, { className: "block", color: color,
|
|
897
|
+
const customDotElement = (name, hovered, selected, color, keepOnSelection) => (hovered || selected) && !keepOnSelection ? (jsxRuntime.jsx(CircleIcon, { hovered: hovered, selected: selected })) : (jsxRuntime.jsx("div", { className: "flex h-6 w-6 items-center justify-center", children: jsxRuntime.jsx("div", { className: cvaCustomDot(), children: jsxRuntime.jsx(reactComponents.Icon, { className: "block", color: color, "data-testid": "timeline-custom-dot", name: name, size: "small" }) }) }));
|
|
898
898
|
|
|
899
899
|
/*
|
|
900
900
|
* ----------------------------
|
package/index.esm.js
CHANGED
|
@@ -102,7 +102,7 @@ const MS_PER_HOUR = 60 * 60 * 1000;
|
|
|
102
102
|
* @param props.timezone TimeZone
|
|
103
103
|
* @param props.subtle boolean
|
|
104
104
|
*/
|
|
105
|
-
const DateTime = ({ value, format, className, fromNow = false, withTitle = false, titleFormat, timezone, dataTestId, subtle = false, }) => {
|
|
105
|
+
const DateTime = ({ value, format, className, fromNow = false, withTitle = false, titleFormat, timezone, "data-testid": dataTestId, subtle = false, }) => {
|
|
106
106
|
const { t } = useTranslation();
|
|
107
107
|
const locale = useLocale();
|
|
108
108
|
const nowDate = useMemo(() => new Date(), []);
|
|
@@ -139,7 +139,7 @@ const DateTimeHumanized = ({ value }) => {
|
|
|
139
139
|
* @param {DayRangePickerProps} props - The props for the DayRangePicker component
|
|
140
140
|
* @returns {ReactElement} DayRangePicker component
|
|
141
141
|
*/
|
|
142
|
-
const DayRangePicker = ({ onRangeSelect, selectedDays, disabledDays, dataTestId, language, className, timezone, cancelButtonLabel, onClose, }) => {
|
|
142
|
+
const DayRangePicker = ({ onRangeSelect, selectedDays, disabledDays, "data-testid": dataTestId, language, className, timezone, cancelButtonLabel, onClose, }) => {
|
|
143
143
|
const [newRange, setNewRange] = useState(selectedDays ?? { start: undefined, end: undefined });
|
|
144
144
|
const [t] = useTranslation();
|
|
145
145
|
const { subtract } = useDateAndTime();
|
|
@@ -209,7 +209,7 @@ const DayRangePicker = ({ onRangeSelect, selectedDays, disabledDays, dataTestId,
|
|
|
209
209
|
}, value:
|
|
210
210
|
// type is wrong here if we add array of 2 elements if end is undefined and set to null it will not highlight the start date
|
|
211
211
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
212
|
-
newRange.end ? [newRange.start ?? null, newRange.end ?? null] : (newRange.start ?? null) }), jsx("hr", {}), jsxs("div", { className: "flex w-full gap-2", children: [jsx(Button, { className: "mr-auto",
|
|
212
|
+
newRange.end ? [newRange.start ?? null, newRange.end ?? null] : (newRange.start ?? null) }), jsx("hr", {}), jsxs("div", { className: "flex w-full gap-2", children: [jsx(Button, { className: "mr-auto", "data-testid": "range-popover-clear-button", onClick: clearSelectedDays, size: "small", variant: "secondary", children: t("layout.actions.clear") }), jsx(Button, { "data-testid": "range-popover-cancel-button", onClick: () => handleCancel(), size: "small", variant: "ghost-neutral", children: cancelButtonLabel ? cancelButtonLabel : t("layout.actions.cancel") }), jsx(Button, { "data-testid": "range-popover-apply-button", disabled: !newRange.start || !newRange.end, onClick: () => handleApply(), size: "small", children: t("layout.actions.apply") })] })] }));
|
|
213
213
|
};
|
|
214
214
|
|
|
215
215
|
const temporalArithmeticTypeMapping = {
|
|
@@ -274,7 +274,7 @@ const useFormatTemporalPeriodLabel = () => {
|
|
|
274
274
|
/**
|
|
275
275
|
* Renders a list of options for the DayRangeSelect component.
|
|
276
276
|
*/
|
|
277
|
-
const DayRangeSelectOptions = ({ dataTestId, temporalPeriods, selectedDateRange, onSelect, }) => {
|
|
277
|
+
const DayRangeSelectOptions = ({ "data-testid": dataTestId, temporalPeriods, selectedDateRange, onSelect, }) => {
|
|
278
278
|
const [t] = useTranslation();
|
|
279
279
|
const formatTemporalPeriodLabel = useFormatTemporalPeriodLabel();
|
|
280
280
|
const calculateDateRange = useCalculateDateRange();
|
|
@@ -290,14 +290,14 @@ const DayRangeSelectOptions = ({ dataTestId, temporalPeriods, selectedDateRange,
|
|
|
290
290
|
}, [calculateDateRange, onSelect, temporalPeriods]);
|
|
291
291
|
const options = useMemo(() => {
|
|
292
292
|
if (!temporalPeriods.length) {
|
|
293
|
-
return (jsx(MenuItem, {
|
|
293
|
+
return (jsx(MenuItem, { "data-testid": dataTestId ? `${dataTestId}-no-options` : undefined, disabled: true, label: t("input.noOptions") }));
|
|
294
294
|
}
|
|
295
295
|
return temporalPeriods.map((temporalPeriod, index) => {
|
|
296
296
|
// NOTE: Check for temporalPeriod as well to make sure not to select an options when it's a custom date range selection
|
|
297
297
|
const isSelected = selectedDateRange &&
|
|
298
298
|
selectedDateRange.temporalPeriod &&
|
|
299
299
|
stringifyTemporalPeriod(selectedDateRange.temporalPeriod) === stringifyTemporalPeriod(temporalPeriod);
|
|
300
|
-
return (jsx(MenuItem, {
|
|
300
|
+
return (jsx(MenuItem, { "data-testid": dataTestId ? `${dataTestId}-${index.toString()}` : undefined, label: formatTemporalPeriodLabel(temporalPeriod), onClick: () => handleSelect(index), selected: isSelected, suffix: isSelected ? jsx(Icon, { color: "primary", name: "Check", size: "small" }) : null }, index));
|
|
301
301
|
});
|
|
302
302
|
}, [temporalPeriods, selectedDateRange, formatTemporalPeriodLabel, handleSelect, dataTestId, t]);
|
|
303
303
|
return options;
|
|
@@ -532,7 +532,7 @@ const isTemporalDirection = (direction) => {
|
|
|
532
532
|
/**
|
|
533
533
|
* Day range select component.
|
|
534
534
|
*/
|
|
535
|
-
const DayRangeSelect = ({ className, dataTestId, disabled, selectedDateRange, onRangeSelect, allowedDirection = undefined, initialDateRangeOptions, showDateRangeSearch = true, showCustomDateRangeOption = true, timezone, maxDaysInRange, size = "medium", fullWidth = false, actionButton, }) => {
|
|
535
|
+
const DayRangeSelect = ({ className, "data-testid": dataTestId, disabled, selectedDateRange, onRangeSelect, allowedDirection = undefined, initialDateRangeOptions, showDateRangeSearch = true, showCustomDateRangeOption = true, timezone, maxDaysInRange, size = "medium", fullWidth = false, actionButton, }) => {
|
|
536
536
|
const [t] = useTranslation();
|
|
537
537
|
const parseTemporalPeriodFromText = useParseTemporalPeriodFromText();
|
|
538
538
|
const filterTemporalPeriodsInRange = useFilterTemporalPeriodsInRange();
|
|
@@ -626,10 +626,10 @@ const DayRangeSelect = ({ className, dataTestId, disabled, selectedDateRange, on
|
|
|
626
626
|
setSelectedRange(_selectedDateRange);
|
|
627
627
|
onRangeSelect(_selectedDateRange);
|
|
628
628
|
}, [onRangeSelect, handleReset]);
|
|
629
|
-
return (jsxs(Popover, { onOpenStateChange: state => !state && setIsCustomDateRangeOpen(false), placement: "bottom-start", children: [jsx(PopoverTrigger, { children: !actionButton ? (jsx(Button, { className: cvaTriggerButton({ active: !!selectedDateRange, className }),
|
|
630
|
-
return !isCustomDateRangeOpen ? (jsxs(MenuList, { className: "min-w-[280px]", children: [jsxs("div", { className: "flex flex-col gap-1", children: [showDateRangeSearch ? (jsx(Search, { className: "w-full",
|
|
629
|
+
return (jsxs(Popover, { onOpenStateChange: state => !state && setIsCustomDateRangeOpen(false), placement: "bottom-start", children: [jsx(PopoverTrigger, { children: !actionButton ? (jsx(Button, { className: cvaTriggerButton({ active: !!selectedDateRange, className }), "data-testid": dataTestId, disabled: disabled, fullWidth: fullWidth, prefix: jsx(Icon, { ariaLabel: t("input.icon.tooltip.calendar"), color: disabled ? "neutral" : selectedDateRange ? "primary" : undefined, name: "Calendar", size: size === "large" ? "medium" : "small" }), size: size, variant: "secondary", children: popoverTriggerLabel ?? t("trigger.selectDateRange") })) : (jsx("div", { children: actionButton })) }), jsx(PopoverContent, { "data-testid": dataTestId ? `${dataTestId}-popover-content` : undefined, children: closeMenu => {
|
|
630
|
+
return !isCustomDateRangeOpen ? (jsxs(MenuList, { className: "min-w-[280px]", children: [jsxs("div", { className: "flex flex-col gap-1", children: [showDateRangeSearch ? (jsx(Search, { className: "w-full", "data-testid": dataTestId ? `${dataTestId}-search-input` : undefined, onChange: event => handleDateRangeSearch(event.target.value), onClear: () => handleDateRangeSearch(""), placeholder: allowedDirection === "last"
|
|
631
631
|
? t("input.placeholder.customRange.last")
|
|
632
|
-
: t("input.placeholder.customRange.next"), value: dateRangeSearchValue })) : null, jsx(Button, { className: "ml-auto",
|
|
632
|
+
: t("input.placeholder.customRange.next"), value: dateRangeSearchValue })) : null, jsx(Button, { className: "ml-auto", "data-testid": dataTestId ? `${dataTestId}-reset-button` : undefined, disabled: !selectedDateRange, onClick: handleReset, size: "small", variant: "ghost", children: t("layout.actions.reset") })] }), jsx("hr", { className: "my-1 border-neutral-200", role: "separator" }), jsx(DayRangeSelectOptions, { "data-testid": dataTestId ? `${dataTestId}-options` : undefined, onSelect: value => handleOptionsSelect(value, closeMenu), selectedDateRange: currentSelectedRange, temporalPeriods: temporalPeriods }), showCustomDateRangeOption ? (jsxs("section", { children: [jsx(MenuDivider, {}), jsx(MenuItem, { "data-testid": dataTestId ? `${dataTestId}-custom-range` : undefined, label: t("trigger.customRange"), onClick: () => setIsCustomDateRangeOpen(true), selected: isCustomDateRangeSelected, suffix: jsxs(Fragment, { children: [isCustomDateRangeSelected ? jsx(Icon, { color: "primary", name: "Check", size: "small" }) : null, jsx(Icon, { name: "ChevronRight", size: "small" })] }) })] })) : null] })) : (jsx(Card, { children: jsx(DayRangePicker, { cancelButtonLabel: t("layout.actions.back"), disabledDays: customDateRangeDisabledDays, language: "en", onClose: () => setIsCustomDateRangeOpen(false), onRangeSelect: dateRange => handleCustomDateRangeSelect(dateRange
|
|
633
633
|
? {
|
|
634
634
|
start: dateRange.start ?? undefined,
|
|
635
635
|
end: dateRange.end ?? undefined,
|
|
@@ -644,7 +644,7 @@ const DayRangeSelect = ({ className, dataTestId, disabled, selectedDateRange, on
|
|
|
644
644
|
* @param {DayPickerProps} props - The props for the DayPicker component
|
|
645
645
|
* @returns {ReactElement} DayPicker component
|
|
646
646
|
*/
|
|
647
|
-
const DayPicker = ({ onDaySelect, disabledDays, selectedDay, language, className, dataTestId, }) => {
|
|
647
|
+
const DayPicker = ({ onDaySelect, disabledDays, selectedDay, language, className, "data-testid": dataTestId, }) => {
|
|
648
648
|
const { subtract } = useDateAndTime();
|
|
649
649
|
const calculateDateRange = useCalculateDateRange();
|
|
650
650
|
return (jsx("div", { "data-testid": dataTestId, children: jsx(Calendar, { activeStartDate: selectedDay ?? undefined, allowPartialRange: true, className: twMerge("custom-day-picker", "range-picker", className, "p-0"), locale: language, onChange: value => {
|
|
@@ -758,7 +758,7 @@ const ITEMS_PER_PAGE = 20;
|
|
|
758
758
|
* @param {TimelineProps} props - The props for the Timeline component
|
|
759
759
|
* @returns {ReactElement} Timeline component
|
|
760
760
|
*/
|
|
761
|
-
const Timeline = ({ className, dataTestId, children, dateHeader, customHeader, toggleButton, }) => {
|
|
761
|
+
const Timeline = ({ className, "data-testid": dataTestId, children, dateHeader, customHeader, toggleButton, }) => {
|
|
762
762
|
const ref = useRef(null);
|
|
763
763
|
const [isOpen, setIsOpen] = useState(false);
|
|
764
764
|
const [visibleCount, setVisibleCount] = useState(ITEMS_PER_PAGE);
|
|
@@ -834,7 +834,7 @@ const Timeline = ({ className, dataTestId, children, dateHeader, customHeader, t
|
|
|
834
834
|
* @param {TimeLineElementProps} props the props
|
|
835
835
|
* @returns {ReactElement} component
|
|
836
836
|
*/
|
|
837
|
-
const TimelineElement = ({ date, children, className, dataTestId = "timeline-element", header, onClick, actionButton, selected, customDot, lineStyle = "solid", hoverBehavior = false, }) => {
|
|
837
|
+
const TimelineElement = ({ date, children, className, "data-testid": dataTestId = "timeline-element", header, onClick, actionButton, selected, customDot, lineStyle = "solid", hoverBehavior = false, }) => {
|
|
838
838
|
const [isHovered, setIsHovered] = useState(false);
|
|
839
839
|
const { formatDate } = useDateAndTime();
|
|
840
840
|
const locale = useLocale();
|
|
@@ -892,7 +892,7 @@ const timelineElementTime = (formattedDate, locale) => {
|
|
|
892
892
|
const CircleIcon = ({ selected, hovered }) => (jsxs("svg", { className: "relative z-[2]", "data-testid": "timeline-circle-icon", height: "24", viewBox: "0 0 24 24", width: "24", children: [jsx("circle", { cx: "12", cy: "12", fill: selected ? "#EFF6FF" : hovered ? "#F9FAFB" : "white", r: "10" }), jsx("circle", { cx: "12", cy: "12", fill: "#2563EB", r: "8" }), jsx("circle", { cx: "12", cy: "12", fill: "white", r: "3" })] }));
|
|
893
893
|
const DotIcon = () => (jsxs("svg", { className: "relative z-[2]", "data-testid": "timeline-dot-icon", height: "24", viewBox: "0 0 24 24", width: "24", children: [jsx("circle", { cx: "12", cy: "12", fill: "white", r: "6" }), jsx("circle", { cx: "12", cy: "12", fill: "#2563EB", r: "4" })] }));
|
|
894
894
|
const defaultDot = (hovered, selected) => hovered || selected ? jsx(CircleIcon, { hovered: hovered, selected: selected }) : jsx(DotIcon, {});
|
|
895
|
-
const customDotElement = (name, hovered, selected, color, keepOnSelection) => (hovered || selected) && !keepOnSelection ? (jsx(CircleIcon, { hovered: hovered, selected: selected })) : (jsx("div", { className: "flex h-6 w-6 items-center justify-center", children: jsx("div", { className: cvaCustomDot(), children: jsx(Icon, { className: "block", color: color,
|
|
895
|
+
const customDotElement = (name, hovered, selected, color, keepOnSelection) => (hovered || selected) && !keepOnSelection ? (jsx(CircleIcon, { hovered: hovered, selected: selected })) : (jsx("div", { className: "flex h-6 w-6 items-center justify-center", children: jsx("div", { className: cvaCustomDot(), children: jsx(Icon, { className: "block", color: color, "data-testid": "timeline-custom-dot", name: name, size: "small" }) }) }));
|
|
896
896
|
|
|
897
897
|
/*
|
|
898
898
|
* ----------------------------
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trackunit/react-date-and-time-components",
|
|
3
|
-
"version": "1.10.
|
|
3
|
+
"version": "1.10.121",
|
|
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.10.
|
|
12
|
-
"@trackunit/date-and-time-utils": "1.7.
|
|
13
|
-
"@trackunit/react-date-and-time-hooks": "1.7.
|
|
14
|
-
"@trackunit/css-class-variance-utilities": "1.7.
|
|
15
|
-
"@trackunit/ui-icons": "1.7.
|
|
16
|
-
"@trackunit/shared-utils": "1.9.
|
|
17
|
-
"@trackunit/i18n-library-translation": "1.7.
|
|
18
|
-
"@trackunit/react-form-components": "1.8.
|
|
11
|
+
"@trackunit/react-components": "1.10.51",
|
|
12
|
+
"@trackunit/date-and-time-utils": "1.7.77",
|
|
13
|
+
"@trackunit/react-date-and-time-hooks": "1.7.107",
|
|
14
|
+
"@trackunit/css-class-variance-utilities": "1.7.77",
|
|
15
|
+
"@trackunit/ui-icons": "1.7.78",
|
|
16
|
+
"@trackunit/shared-utils": "1.9.77",
|
|
17
|
+
"@trackunit/i18n-library-translation": "1.7.94",
|
|
18
|
+
"@trackunit/react-form-components": "1.8.118",
|
|
19
19
|
"string-ts": "^2.0.0",
|
|
20
20
|
"tailwind-merge": "^2.0.0",
|
|
21
21
|
"react-calendar": "^6.0.0"
|
|
@@ -34,4 +34,4 @@ export interface DayPickerProps extends CommonProps {
|
|
|
34
34
|
* @param {DayPickerProps} props - The props for the DayPicker component
|
|
35
35
|
* @returns {ReactElement} DayPicker component
|
|
36
36
|
*/
|
|
37
|
-
export declare const DayPicker: ({ onDaySelect, disabledDays, selectedDay, language, className, dataTestId, }: DayPickerProps) => ReactElement;
|
|
37
|
+
export declare const DayPicker: ({ onDaySelect, disabledDays, selectedDay, language, className, "data-testid": dataTestId, }: DayPickerProps) => ReactElement;
|
|
@@ -38,4 +38,4 @@ export interface DayRangePickerProps extends CommonProps {
|
|
|
38
38
|
* @param {DayRangePickerProps} props - The props for the DayRangePicker component
|
|
39
39
|
* @returns {ReactElement} DayRangePicker component
|
|
40
40
|
*/
|
|
41
|
-
export declare const DayRangePicker: ({ onRangeSelect, selectedDays, disabledDays, dataTestId, language, className, timezone, cancelButtonLabel, onClose, }: DayRangePickerProps) => ReactElement;
|
|
41
|
+
export declare const DayRangePicker: ({ onRangeSelect, selectedDays, disabledDays, "data-testid": dataTestId, language, className, timezone, cancelButtonLabel, onClose, }: DayRangePickerProps) => ReactElement;
|
|
@@ -4,7 +4,7 @@ import { DayRangePickerProps } from "./DayRangePicker";
|
|
|
4
4
|
type Story = StoryObj<typeof meta>;
|
|
5
5
|
declare const meta: {
|
|
6
6
|
title: string;
|
|
7
|
-
component: ({ onRangeSelect, selectedDays, disabledDays, dataTestId, language, className, timezone, cancelButtonLabel, onClose, }: DayRangePickerProps) => ReactElement;
|
|
7
|
+
component: ({ onRangeSelect, selectedDays, disabledDays, "data-testid": dataTestId, language, className, timezone, cancelButtonLabel, onClose, }: DayRangePickerProps) => ReactElement;
|
|
8
8
|
tags: string[];
|
|
9
9
|
parameters: {
|
|
10
10
|
docs: {
|
|
@@ -23,7 +23,7 @@ declare const meta: {
|
|
|
23
23
|
cancelButtonLabel?: string | undefined;
|
|
24
24
|
onClose?: (() => void) | undefined;
|
|
25
25
|
className?: string | undefined;
|
|
26
|
-
|
|
26
|
+
"data-testid"?: string | undefined;
|
|
27
27
|
}>) => import("react/jsx-runtime").JSX.Element)[];
|
|
28
28
|
};
|
|
29
29
|
export default meta;
|
|
@@ -60,4 +60,4 @@ export type DayRangeSelectProps = CommonProps & {
|
|
|
60
60
|
/**
|
|
61
61
|
* Day range select component.
|
|
62
62
|
*/
|
|
63
|
-
export declare const DayRangeSelect: ({ className, dataTestId, disabled, selectedDateRange, onRangeSelect, allowedDirection, initialDateRangeOptions, showDateRangeSearch, showCustomDateRangeOption, timezone, maxDaysInRange, size, fullWidth, actionButton, }: DayRangeSelectProps) => import("react/jsx-runtime").JSX.Element;
|
|
63
|
+
export declare const DayRangeSelect: ({ className, "data-testid": dataTestId, disabled, selectedDateRange, onRangeSelect, allowedDirection, initialDateRangeOptions, showDateRangeSearch, showCustomDateRangeOption, timezone, maxDaysInRange, size, fullWidth, actionButton, }: DayRangeSelectProps) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -5,7 +5,7 @@ import { DayRangeSelectProps } from "./DayRangeSelect";
|
|
|
5
5
|
type Story = StoryObj<typeof meta>;
|
|
6
6
|
declare const meta: {
|
|
7
7
|
title: string;
|
|
8
|
-
component: ({ className, dataTestId, disabled, selectedDateRange, onRangeSelect, allowedDirection, initialDateRangeOptions, showDateRangeSearch, showCustomDateRangeOption, timezone, maxDaysInRange, size, fullWidth, actionButton, }: DayRangeSelectProps) => import("react/jsx-runtime").JSX.Element;
|
|
8
|
+
component: ({ className, "data-testid": dataTestId, disabled, selectedDateRange, onRangeSelect, allowedDirection, initialDateRangeOptions, showDateRangeSearch, showCustomDateRangeOption, timezone, maxDaysInRange, size, fullWidth, actionButton, }: DayRangeSelectProps) => import("react/jsx-runtime").JSX.Element;
|
|
9
9
|
tags: string[];
|
|
10
10
|
parameters: {
|
|
11
11
|
docs: {
|
|
@@ -17,7 +17,7 @@ declare const meta: {
|
|
|
17
17
|
};
|
|
18
18
|
decorators: ((Story: import("storybook/internal/csf").PartialStoryFn<import("@storybook/react-webpack5").ReactRenderer, {
|
|
19
19
|
className?: string | undefined;
|
|
20
|
-
|
|
20
|
+
"data-testid"?: string | undefined;
|
|
21
21
|
disabled?: boolean | undefined;
|
|
22
22
|
selectedDateRange?: (DateRange | import("./types").TemporalPeriod) | undefined;
|
|
23
23
|
initialDateRangeOptions?: Array<import("./types").TemporalPeriod> | undefined;
|
|
@@ -8,4 +8,4 @@ export type DayRangeSelectOptionsProps = CommonProps & {
|
|
|
8
8
|
/**
|
|
9
9
|
* Renders a list of options for the DayRangeSelect component.
|
|
10
10
|
*/
|
|
11
|
-
export declare const DayRangeSelectOptions: ({ dataTestId, temporalPeriods, selectedDateRange, onSelect, }: DayRangeSelectOptionsProps) => import("react/jsx-runtime").JSX.Element | import("react/jsx-runtime").JSX.Element[];
|
|
11
|
+
export declare const DayRangeSelectOptions: ({ "data-testid": dataTestId, temporalPeriods, selectedDateRange, onSelect, }: DayRangeSelectOptionsProps) => import("react/jsx-runtime").JSX.Element | import("react/jsx-runtime").JSX.Element[];
|
|
@@ -25,4 +25,4 @@ export interface TimelineProps extends CommonProps {
|
|
|
25
25
|
* @param {TimelineProps} props - The props for the Timeline component
|
|
26
26
|
* @returns {ReactElement} Timeline component
|
|
27
27
|
*/
|
|
28
|
-
export declare const Timeline: ({ className, dataTestId, children, dateHeader, customHeader, toggleButton, }: TimelineProps) => import("react/jsx-runtime").JSX.Element;
|
|
28
|
+
export declare const Timeline: ({ className, "data-testid": dataTestId, children, dateHeader, customHeader, toggleButton, }: TimelineProps) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -4,7 +4,7 @@ import { TimelineProps } from "./Timeline";
|
|
|
4
4
|
type Story = StoryObjWithOptionalArgs<typeof meta, "children">;
|
|
5
5
|
declare const meta: {
|
|
6
6
|
title: string;
|
|
7
|
-
component: ({ className, dataTestId, children, dateHeader, customHeader, toggleButton, }: TimelineProps) => import("react/jsx-runtime").JSX.Element;
|
|
7
|
+
component: ({ className, "data-testid": dataTestId, children, dateHeader, customHeader, toggleButton, }: TimelineProps) => import("react/jsx-runtime").JSX.Element;
|
|
8
8
|
tags: string[];
|
|
9
9
|
parameters: {
|
|
10
10
|
docs: {
|
|
@@ -26,5 +26,5 @@ interface TimeLineElementProps extends CommonProps {
|
|
|
26
26
|
* @param {TimeLineElementProps} props the props
|
|
27
27
|
* @returns {ReactElement} component
|
|
28
28
|
*/
|
|
29
|
-
export declare const TimelineElement: ({ date, children, className, dataTestId, header, onClick, actionButton, selected, customDot, lineStyle, hoverBehavior, }: TimeLineElementProps) => import("react/jsx-runtime").JSX.Element;
|
|
29
|
+
export declare const TimelineElement: ({ date, children, className, "data-testid": dataTestId, header, onClick, actionButton, selected, customDot, lineStyle, hoverBehavior, }: TimeLineElementProps) => import("react/jsx-runtime").JSX.Element;
|
|
30
30
|
export {};
|
|
@@ -24,4 +24,4 @@ export declare const MS_PER_HOUR: number;
|
|
|
24
24
|
* @param props.timezone TimeZone
|
|
25
25
|
* @param props.subtle boolean
|
|
26
26
|
*/
|
|
27
|
-
export declare const DateTime: ({ value, format, className, fromNow, withTitle, titleFormat, timezone, dataTestId, subtle, }: DateTimeProps) => import("react/jsx-runtime").JSX.Element;
|
|
27
|
+
export declare const DateTime: ({ value, format, className, fromNow, withTitle, titleFormat, timezone, "data-testid": dataTestId, subtle, }: DateTimeProps) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -5,7 +5,7 @@ type Story = StoryObj<typeof meta>;
|
|
|
5
5
|
declare const meta: {
|
|
6
6
|
title: string;
|
|
7
7
|
tags: string[];
|
|
8
|
-
component: ({ value, format, className, fromNow, withTitle, titleFormat, timezone, dataTestId, subtle, }: DateTimeProps) => import("react/jsx-runtime").JSX.Element;
|
|
8
|
+
component: ({ value, format, className, fromNow, withTitle, titleFormat, timezone, "data-testid": dataTestId, subtle, }: DateTimeProps) => import("react/jsx-runtime").JSX.Element;
|
|
9
9
|
decorators: ((Story: import("storybook/internal/csf").PartialStoryFn<import("@storybook/react-webpack5").ReactRenderer, {
|
|
10
10
|
value: Date | string | number | null | undefined;
|
|
11
11
|
format?: import("@trackunit/date-and-time-utils").TemporalFormat | undefined;
|
|
@@ -15,7 +15,7 @@ declare const meta: {
|
|
|
15
15
|
timezone?: import("..").TimeZone | undefined;
|
|
16
16
|
subtle?: boolean | undefined;
|
|
17
17
|
className?: string | undefined;
|
|
18
|
-
|
|
18
|
+
"data-testid"?: string | undefined;
|
|
19
19
|
}>) => import("react/jsx-runtime").JSX.Element)[];
|
|
20
20
|
};
|
|
21
21
|
export default meta;
|