@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
package/package.json
CHANGED
|
@@ -89,7 +89,7 @@ const meta: Meta<typeof InputDateRangePicker> = {
|
|
|
89
89
|
},
|
|
90
90
|
},
|
|
91
91
|
isOpen: {
|
|
92
|
-
control:
|
|
92
|
+
control: 'boolean',
|
|
93
93
|
description:
|
|
94
94
|
'Whether the floatingUI component wrapped around the date picker is opened or closed.',
|
|
95
95
|
table: {
|
|
@@ -189,6 +189,26 @@ const meta: Meta<typeof InputDateRangePicker> = {
|
|
|
189
189
|
},
|
|
190
190
|
},
|
|
191
191
|
},
|
|
192
|
+
closeOnSelect: {
|
|
193
|
+
control: 'boolean',
|
|
194
|
+
description: 'Whether to close the date picker when a complete range is selected.',
|
|
195
|
+
table: {
|
|
196
|
+
category: 'Props',
|
|
197
|
+
type: {
|
|
198
|
+
summary: 'boolean',
|
|
199
|
+
},
|
|
200
|
+
},
|
|
201
|
+
},
|
|
202
|
+
clearOnClose: {
|
|
203
|
+
control: 'boolean',
|
|
204
|
+
description: 'Whether to clear the selected dates when the picker is closed.',
|
|
205
|
+
table: {
|
|
206
|
+
category: 'Props',
|
|
207
|
+
type: {
|
|
208
|
+
summary: 'boolean',
|
|
209
|
+
},
|
|
210
|
+
},
|
|
211
|
+
},
|
|
192
212
|
'data-testid': {
|
|
193
213
|
table: {
|
|
194
214
|
disable: true,
|
|
@@ -214,15 +234,30 @@ export const RangeInput: Story = {
|
|
|
214
234
|
toLabel: 'To Date',
|
|
215
235
|
gutterWidth: 2,
|
|
216
236
|
isOpen: false,
|
|
237
|
+
closeOnSelect: true,
|
|
238
|
+
clearOnClose: false,
|
|
217
239
|
selected: { from: new Date(), to: new Date(new Date().getTime() + 5 * 24 * 60 * 60 * 1000) },
|
|
218
240
|
},
|
|
219
241
|
render: (args) => {
|
|
220
|
-
const [{ selected }, updateArgs] = useArgs();
|
|
242
|
+
const [{ selected, isOpen }, updateArgs] = useArgs();
|
|
221
243
|
|
|
222
244
|
const handleSelect = (date: DateRange | undefined) => {
|
|
223
245
|
updateArgs({ selected: date });
|
|
224
246
|
};
|
|
225
247
|
|
|
226
|
-
|
|
248
|
+
const handleSetIsOpen = (value: React.SetStateAction<boolean>) => {
|
|
249
|
+
const newIsOpen = typeof value === 'function' ? value(isOpen) : value;
|
|
250
|
+
updateArgs({ isOpen: newIsOpen });
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
return (
|
|
254
|
+
<InputDateRangePicker
|
|
255
|
+
{...args}
|
|
256
|
+
selected={selected}
|
|
257
|
+
onSelect={handleSelect}
|
|
258
|
+
isOpen={isOpen}
|
|
259
|
+
setIsOpen={handleSetIsOpen}
|
|
260
|
+
/>
|
|
261
|
+
);
|
|
227
262
|
},
|
|
228
263
|
};
|
|
@@ -7,6 +7,7 @@ import { DateRange } from 'react-day-picker';
|
|
|
7
7
|
import { FloatUI } from '../../../floatUI';
|
|
8
8
|
import { Col, Row } from '../../../grid';
|
|
9
9
|
import { formatDateAsString } from '../inputDatePicker/helpers';
|
|
10
|
+
import { Button } from '../../../button';
|
|
10
11
|
|
|
11
12
|
interface InputDateRangePickerProps {
|
|
12
13
|
ariaLabel: string;
|
|
@@ -19,6 +20,7 @@ interface InputDateRangePickerProps {
|
|
|
19
20
|
month?: Date;
|
|
20
21
|
selected?: DateRange | undefined;
|
|
21
22
|
isOpen?: boolean;
|
|
23
|
+
setIsOpen?: React.Dispatch<React.SetStateAction<boolean>>;
|
|
22
24
|
className?: string;
|
|
23
25
|
inputIconName?: IconName;
|
|
24
26
|
inputPlaceholder?: string;
|
|
@@ -28,6 +30,8 @@ interface InputDateRangePickerProps {
|
|
|
28
30
|
gutterWidth?: number;
|
|
29
31
|
fromLabel?: string;
|
|
30
32
|
toLabel?: string;
|
|
33
|
+
closeOnSelect?: boolean;
|
|
34
|
+
clearOnClose?: boolean;
|
|
31
35
|
}
|
|
32
36
|
|
|
33
37
|
export function InputDateRangePicker(props: InputDateRangePickerProps) {
|
|
@@ -43,6 +47,7 @@ export function InputDateRangePicker(props: InputDateRangePickerProps) {
|
|
|
43
47
|
onSelect,
|
|
44
48
|
selected,
|
|
45
49
|
isOpen,
|
|
50
|
+
setIsOpen,
|
|
46
51
|
inputPlaceholder,
|
|
47
52
|
inputIconName,
|
|
48
53
|
toErrorMessage,
|
|
@@ -50,6 +55,8 @@ export function InputDateRangePicker(props: InputDateRangePickerProps) {
|
|
|
50
55
|
gutterWidth,
|
|
51
56
|
fromLabel,
|
|
52
57
|
toLabel,
|
|
58
|
+
closeOnSelect,
|
|
59
|
+
clearOnClose,
|
|
53
60
|
...rest
|
|
54
61
|
} = props;
|
|
55
62
|
|
|
@@ -75,6 +82,17 @@ export function InputDateRangePicker(props: InputDateRangePickerProps) {
|
|
|
75
82
|
setLocalTextValueFrom(date.from ? formatDateAsString(date.from) : '');
|
|
76
83
|
setLocalTextValueTo(date.to ? formatDateAsString(date.to) : '');
|
|
77
84
|
onSelect(date);
|
|
85
|
+
|
|
86
|
+
// Close the picker ONLY when a complete range is selected (from and to are different dates)
|
|
87
|
+
if (
|
|
88
|
+
closeOnSelect &&
|
|
89
|
+
date.from &&
|
|
90
|
+
date.to &&
|
|
91
|
+
setIsOpen &&
|
|
92
|
+
date.from.getTime() !== date.to.getTime() // Ensure from and to are different dates
|
|
93
|
+
) {
|
|
94
|
+
setIsOpen(false);
|
|
95
|
+
}
|
|
78
96
|
}
|
|
79
97
|
};
|
|
80
98
|
|
|
@@ -104,15 +122,22 @@ export function InputDateRangePicker(props: InputDateRangePickerProps) {
|
|
|
104
122
|
|
|
105
123
|
// clear selection if clear on close is true
|
|
106
124
|
useEffect(() => {
|
|
107
|
-
if (!isOpen) {
|
|
125
|
+
if (!isOpen && clearOnClose) {
|
|
108
126
|
onSelect(undefined);
|
|
109
127
|
setLocalTextValueFrom('');
|
|
110
128
|
setLocalTextValueTo('');
|
|
111
129
|
}
|
|
112
|
-
}, [isOpen]);
|
|
130
|
+
}, [isOpen, clearOnClose]);
|
|
131
|
+
|
|
132
|
+
// Handle set date button click
|
|
133
|
+
const handleSetDate = () => {
|
|
134
|
+
if (setIsOpen) {
|
|
135
|
+
setIsOpen(false);
|
|
136
|
+
}
|
|
137
|
+
};
|
|
113
138
|
|
|
114
139
|
return (
|
|
115
|
-
<FloatUI isOpen={isOpen} ariaLabel={ariaLabel}>
|
|
140
|
+
<FloatUI isOpen={isOpen} setIsOpen={setIsOpen} ariaLabel={ariaLabel}>
|
|
116
141
|
<Row gutterWidth={gutterWidth}>
|
|
117
142
|
<Col>
|
|
118
143
|
<Input
|