@indico-data/design-system 2.60.9 → 2.60.10
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/lib/components/forms/date/inputDateRangePicker/InputDateRangePicker.d.ts +3 -0
- package/lib/index.d.ts +3 -0
- package/lib/index.esm.js +13 -4
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +13 -4
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/forms/date/inputDateRangePicker/InputDateRangePicker.stories.tsx +38 -3
- package/src/components/forms/date/inputDateRangePicker/InputDateRangePicker.tsx +28 -3
|
@@ -11,6 +11,7 @@ interface InputDateRangePickerProps {
|
|
|
11
11
|
month?: Date;
|
|
12
12
|
selected?: DateRange | undefined;
|
|
13
13
|
isOpen?: boolean;
|
|
14
|
+
setIsOpen?: React.Dispatch<React.SetStateAction<boolean>>;
|
|
14
15
|
className?: string;
|
|
15
16
|
inputIconName?: IconName;
|
|
16
17
|
inputPlaceholder?: string;
|
|
@@ -20,6 +21,8 @@ interface InputDateRangePickerProps {
|
|
|
20
21
|
gutterWidth?: number;
|
|
21
22
|
fromLabel?: string;
|
|
22
23
|
toLabel?: string;
|
|
24
|
+
closeOnSelect?: boolean;
|
|
25
|
+
clearOnClose?: boolean;
|
|
23
26
|
}
|
|
24
27
|
export declare function InputDateRangePicker(props: InputDateRangePickerProps): import("react/jsx-runtime").JSX.Element;
|
|
25
28
|
export {};
|
package/lib/index.d.ts
CHANGED
|
@@ -465,6 +465,7 @@ interface InputDateRangePickerProps {
|
|
|
465
465
|
month?: Date;
|
|
466
466
|
selected?: DateRange | undefined;
|
|
467
467
|
isOpen?: boolean;
|
|
468
|
+
setIsOpen?: React.Dispatch<React.SetStateAction<boolean>>;
|
|
468
469
|
className?: string;
|
|
469
470
|
inputIconName?: IconName$2;
|
|
470
471
|
inputPlaceholder?: string;
|
|
@@ -474,6 +475,8 @@ interface InputDateRangePickerProps {
|
|
|
474
475
|
gutterWidth?: number;
|
|
475
476
|
fromLabel?: string;
|
|
476
477
|
toLabel?: string;
|
|
478
|
+
closeOnSelect?: boolean;
|
|
479
|
+
clearOnClose?: boolean;
|
|
477
480
|
}
|
|
478
481
|
declare function InputDateRangePicker(props: InputDateRangePickerProps): react_jsx_runtime.JSX.Element;
|
|
479
482
|
|
package/lib/index.esm.js
CHANGED
|
@@ -19093,7 +19093,7 @@ function SingleInputDatePicker(props) {
|
|
|
19093
19093
|
}
|
|
19094
19094
|
|
|
19095
19095
|
function InputDateRangePicker(props) {
|
|
19096
|
-
const { ariaLabel, className, isDisabled, disableBeforeDate, disableAfterDate, captionLayout, month, id, onSelect, selected, isOpen, inputPlaceholder, inputIconName, toErrorMessage, fromErrorMessage, gutterWidth, fromLabel, toLabel } = props, rest = __rest(props, ["ariaLabel", "className", "isDisabled", "disableBeforeDate", "disableAfterDate", "captionLayout", "month", "id", "onSelect", "selected", "isOpen", "inputPlaceholder", "inputIconName", "toErrorMessage", "fromErrorMessage", "gutterWidth", "fromLabel", "toLabel"]);
|
|
19096
|
+
const { ariaLabel, className, isDisabled, disableBeforeDate, disableAfterDate, captionLayout, month, id, onSelect, selected, isOpen, setIsOpen, inputPlaceholder, inputIconName, toErrorMessage, fromErrorMessage, gutterWidth, fromLabel, toLabel, closeOnSelect, clearOnClose } = props, rest = __rest(props, ["ariaLabel", "className", "isDisabled", "disableBeforeDate", "disableAfterDate", "captionLayout", "month", "id", "onSelect", "selected", "isOpen", "setIsOpen", "inputPlaceholder", "inputIconName", "toErrorMessage", "fromErrorMessage", "gutterWidth", "fromLabel", "toLabel", "closeOnSelect", "clearOnClose"]);
|
|
19097
19097
|
const inputId = useId$1();
|
|
19098
19098
|
// Hold the input values in state
|
|
19099
19099
|
const [localTextValueFrom, setLocalTextValueFrom] = useState((selected === null || selected === void 0 ? void 0 : selected.from) ? formatDateAsString(selected.from) : '');
|
|
@@ -19110,6 +19110,15 @@ function InputDateRangePicker(props) {
|
|
|
19110
19110
|
setLocalTextValueFrom(date.from ? formatDateAsString(date.from) : '');
|
|
19111
19111
|
setLocalTextValueTo(date.to ? formatDateAsString(date.to) : '');
|
|
19112
19112
|
onSelect(date);
|
|
19113
|
+
// Close the picker ONLY when a complete range is selected (from and to are different dates)
|
|
19114
|
+
if (closeOnSelect &&
|
|
19115
|
+
date.from &&
|
|
19116
|
+
date.to &&
|
|
19117
|
+
setIsOpen &&
|
|
19118
|
+
date.from.getTime() !== date.to.getTime() // Ensure from and to are different dates
|
|
19119
|
+
) {
|
|
19120
|
+
setIsOpen(false);
|
|
19121
|
+
}
|
|
19113
19122
|
}
|
|
19114
19123
|
};
|
|
19115
19124
|
// When the text input is changed, update the selected date.
|
|
@@ -19137,13 +19146,13 @@ function InputDateRangePicker(props) {
|
|
|
19137
19146
|
};
|
|
19138
19147
|
// clear selection if clear on close is true
|
|
19139
19148
|
useEffect(() => {
|
|
19140
|
-
if (!isOpen) {
|
|
19149
|
+
if (!isOpen && clearOnClose) {
|
|
19141
19150
|
onSelect(undefined);
|
|
19142
19151
|
setLocalTextValueFrom('');
|
|
19143
19152
|
setLocalTextValueTo('');
|
|
19144
19153
|
}
|
|
19145
|
-
}, [isOpen]);
|
|
19146
|
-
return (jsxs(FloatUI, { isOpen: isOpen, ariaLabel: ariaLabel, children: [jsxs(Row, { gutterWidth: gutterWidth, children: [jsx(Col, { children: jsx(LabeledInput, { id: `${inputId}-from`, value: localTextValueFrom, placeholder: inputPlaceholder, isDisabled: isDisabled, iconName: inputIconName, onChange: (e) => handleInputChange(e, 'from'), errorMessage: fromErrorMessage, label: fromLabel, name: 'From Date', "data-testid": "date-picker-from" }) }), jsx(Col, { children: jsx(LabeledInput, { id: `${inputId}-to`, value: localTextValueTo, placeholder: inputPlaceholder, isDisabled: isDisabled, iconName: inputIconName, onChange: (e) => handleInputChange(e, 'to'), errorMessage: toErrorMessage, label: toLabel, name: 'To Date', "data-testid": "date-picker-to" }) })] }), jsx(DatePicker, Object.assign({ captionLayout: captionLayout, month: localMonth, onMonthChange: (date) => setLocalMonth(date), mode: "range", selected: selected, onSelect: handleDayPickerSelect }, rest))] }));
|
|
19154
|
+
}, [isOpen, clearOnClose]);
|
|
19155
|
+
return (jsxs(FloatUI, { isOpen: isOpen, setIsOpen: setIsOpen, ariaLabel: ariaLabel, children: [jsxs(Row, { gutterWidth: gutterWidth, children: [jsx(Col, { children: jsx(LabeledInput, { id: `${inputId}-from`, value: localTextValueFrom, placeholder: inputPlaceholder, isDisabled: isDisabled, iconName: inputIconName, onChange: (e) => handleInputChange(e, 'from'), errorMessage: fromErrorMessage, label: fromLabel, name: 'From Date', "data-testid": "date-picker-from" }) }), jsx(Col, { children: jsx(LabeledInput, { id: `${inputId}-to`, value: localTextValueTo, placeholder: inputPlaceholder, isDisabled: isDisabled, iconName: inputIconName, onChange: (e) => handleInputChange(e, 'to'), errorMessage: toErrorMessage, label: toLabel, name: 'To Date', "data-testid": "date-picker-to" }) })] }), jsx(DatePicker, Object.assign({ captionLayout: captionLayout, month: localMonth, onMonthChange: (date) => setLocalMonth(date), mode: "range", selected: selected, onSelect: handleDayPickerSelect }, rest))] }));
|
|
19147
19156
|
}
|
|
19148
19157
|
|
|
19149
19158
|
const Form = (_a) => {
|