@indico-data/design-system 2.60.7 → 2.60.8

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/index.js CHANGED
@@ -19116,6 +19116,60 @@ function SingleInputDatePicker(props) {
19116
19116
  return (jsxRuntime.jsxs(FloatUI, { isOpen: isOpen, ariaLabel: ariaLabel, children: [jsxRuntime.jsx(LabeledInput, { id: inputId, value: localTextValue, placeholder: inputPlaceholder, isDisabled: isDisabled, iconName: inputIconName, isClearable: isClearable, onChange: handleInputChange, errorMessage: errorMessage, label: 'Single Date Picker', name: 'Date Picker' }), jsxRuntime.jsx(DatePicker, Object.assign({ captionLayout: captionLayout, mode: "single", selected: selected, onSelect: handleDayPickerSelect, month: localMonth, onMonthChange: setLocalMonth }, rest))] }));
19117
19117
  }
19118
19118
 
19119
+ function InputDateRangePicker(props) {
19120
+ const { ariaLabel, className, isDisabled, disableBeforeDate, disableAfterDate, captionLayout, month, id, onSelect, selected, isOpen, inputPlaceholder, inputIconName, toErrorMessage, fromErrorMessage } = props, rest = __rest(props, ["ariaLabel", "className", "isDisabled", "disableBeforeDate", "disableAfterDate", "captionLayout", "month", "id", "onSelect", "selected", "isOpen", "inputPlaceholder", "inputIconName", "toErrorMessage", "fromErrorMessage"]);
19121
+ const inputId = React.useId();
19122
+ // Hold the input values in state
19123
+ const [localTextValueFrom, setLocalTextValueFrom] = React.useState((selected === null || selected === void 0 ? void 0 : selected.from) ? formatDateAsString(selected.from) : '');
19124
+ const [localTextValueTo, setLocalTextValueTo] = React.useState((selected === null || selected === void 0 ? void 0 : selected.to) ? formatDateAsString(selected.to) : '');
19125
+ const [localMonth, setLocalMonth] = React.useState((selected === null || selected === void 0 ? void 0 : selected.from) || new Date());
19126
+ // When the day picker is selected, update the text values.
19127
+ const handleDayPickerSelect = (date) => {
19128
+ if (!date) {
19129
+ setLocalTextValueFrom('');
19130
+ setLocalTextValueTo('');
19131
+ onSelect(undefined);
19132
+ }
19133
+ else {
19134
+ setLocalTextValueFrom(date.from ? formatDateAsString(date.from) : '');
19135
+ setLocalTextValueTo(date.to ? formatDateAsString(date.to) : '');
19136
+ onSelect(date);
19137
+ }
19138
+ };
19139
+ // When the text input is changed, update the selected date.
19140
+ const handleInputChange = (e, type) => {
19141
+ const value = e.target.value;
19142
+ if (type === 'from') {
19143
+ setLocalTextValueFrom(value);
19144
+ }
19145
+ else {
19146
+ setLocalTextValueTo(value);
19147
+ }
19148
+ const parsedDate = parse(value, 'MM/dd/yyyy', new Date());
19149
+ if (isValid(parsedDate)) {
19150
+ onSelect({
19151
+ from: type === 'from' ? parsedDate : selected === null || selected === void 0 ? void 0 : selected.from,
19152
+ to: type === 'to' ? parsedDate : selected === null || selected === void 0 ? void 0 : selected.to,
19153
+ });
19154
+ }
19155
+ else {
19156
+ onSelect({
19157
+ from: type === 'from' ? undefined : selected === null || selected === void 0 ? void 0 : selected.from,
19158
+ to: type === 'to' ? undefined : selected === null || selected === void 0 ? void 0 : selected.to,
19159
+ });
19160
+ }
19161
+ };
19162
+ // clear selection if clear on close is true
19163
+ React.useEffect(() => {
19164
+ if (!isOpen) {
19165
+ onSelect(undefined);
19166
+ setLocalTextValueFrom('');
19167
+ setLocalTextValueTo('');
19168
+ }
19169
+ }, [isOpen]);
19170
+ return (jsxRuntime.jsxs(FloatUI, { isOpen: isOpen, ariaLabel: ariaLabel, children: [jsxRuntime.jsxs(Row, { children: [jsxRuntime.jsx(Col, { children: jsxRuntime.jsx(LabeledInput, { id: `${inputId}-from`, value: localTextValueFrom, placeholder: inputPlaceholder, isDisabled: isDisabled, iconName: inputIconName, onChange: (e) => handleInputChange(e, 'from'), errorMessage: fromErrorMessage, label: 'From Date', name: 'From Date', "data-testid": "date-picker-from" }) }), jsxRuntime.jsx(Col, { children: jsxRuntime.jsx(LabeledInput, { id: `${inputId}-to`, value: localTextValueTo, placeholder: inputPlaceholder, isDisabled: isDisabled, iconName: inputIconName, onChange: (e) => handleInputChange(e, 'to'), errorMessage: toErrorMessage, label: 'To Date', name: 'To Date', "data-testid": "date-picker-to" }) })] }), jsxRuntime.jsx(DatePicker, Object.assign({ captionLayout: captionLayout, month: localMonth, onMonthChange: (date) => setLocalMonth(date), mode: "range", selected: selected, onSelect: handleDayPickerSelect }, rest))] }));
19171
+ }
19172
+
19119
19173
  const Form = (_a) => {
19120
19174
  var { children, onSubmit, action, method, target, autocomplete, noValidate, enctype, rel } = _a, rest = __rest(_a, ["children", "onSubmit", "action", "method", "target", "autocomplete", "noValidate", "enctype", "rel"]);
19121
19175
  const handleSubmit = (e) => {
@@ -43068,6 +43122,7 @@ exports.Form = Form;
43068
43122
  exports.Icon = Icon;
43069
43123
  exports.IconTriggerDatePicker = IconTriggerDatePicker;
43070
43124
  exports.Input = LabeledInput;
43125
+ exports.InputDateRangePicker = InputDateRangePicker;
43071
43126
  exports.Menu = Menu;
43072
43127
  exports.Modal = Modal;
43073
43128
  exports.Pagination = Pagination;