@useblu/ocean-react 1.36.3 → 1.37.2

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.es.js CHANGED
@@ -4960,10 +4960,12 @@ var Carousel = function (_a) {
4960
4960
  function useInputFilled(_a) {
4961
4961
  var value = _a.value, defaultValue = _a.defaultValue, onChange = _a.onChange;
4962
4962
  var _b = useState(Boolean(value || defaultValue)), filled = _b[0], setFilled = _b[1];
4963
+ var _c = useState(value || defaultValue), inputValue = _c[0], setInputValue = _c[1];
4963
4964
  var handleChange = useCallback(function (event) {
4964
4965
  if (onChange)
4965
4966
  return onChange(event);
4966
4967
  setFilled(Boolean(event.target.value));
4968
+ setInputValue(event.target.value);
4967
4969
  }, [onChange]);
4968
4970
  useEffect(function () {
4969
4971
  setFilled(Boolean(value));
@@ -4971,7 +4973,7 @@ function useInputFilled(_a) {
4971
4973
  useEffect(function () {
4972
4974
  setFilled(Boolean(defaultValue));
4973
4975
  }, [defaultValue]);
4974
- return { filled: filled, handleChange: handleChange };
4976
+ return { inputValue: inputValue, filled: filled, handleChange: handleChange };
4975
4977
  }
4976
4978
 
4977
4979
  function FormLabelBase(_a, ref) {
@@ -4998,7 +5000,7 @@ var FormControl = function (_a) {
4998
5000
  };
4999
5001
 
5000
5002
  var Input = e.forwardRef(function Input(_a, ref) {
5001
- var type = _a.type, label = _a.label, helperText = _a.helperText, error = _a.error, disabled = _a.disabled, defaultValue = _a.defaultValue, tooltipMessage = _a.tooltipMessage, position = _a.position, adornment = _a.adornment, className = _a.className, id = _a.id, onChange = _a.onChange, value = _a.value, rest = __rest$1(_a, ["type", "label", "helperText", "error", "disabled", "defaultValue", "tooltipMessage", "position", "adornment", "className", "id", "onChange", "value"]);
5003
+ var type = _a.type, label = _a.label, helperText = _a.helperText, error = _a.error, disabled = _a.disabled, defaultValue = _a.defaultValue, placeholder = _a.placeholder, tooltipMessage = _a.tooltipMessage, position = _a.position, adornment = _a.adornment, className = _a.className, id = _a.id, onChange = _a.onChange, value = _a.value, rest = __rest$1(_a, ["type", "label", "helperText", "error", "disabled", "defaultValue", "placeholder", "tooltipMessage", "position", "adornment", "className", "id", "onChange", "value"]);
5002
5004
  var _b = useInputFilled({
5003
5005
  defaultValue: defaultValue,
5004
5006
  value: value,
@@ -5006,7 +5008,7 @@ var Input = e.forwardRef(function Input(_a, ref) {
5006
5008
  }), filled = _b.filled, handleChange = _b.handleChange;
5007
5009
  return (e.createElement(FormControl, { label: label, tooltipMessage: tooltipMessage, htmlFor: id, helperText: helperText, error: error, disabled: disabled },
5008
5010
  e.createElement("div", { className: classNames('ods-input', filled && 'ods-input--filled', disabled && 'ods-input--disabled', error && 'ods-input--error', position === 'left' && 'ods-input--left', adornment && !filled ? 'ods-input--disabled--text' : '', className) },
5009
- e.createElement("input", __assign$1({ ref: ref, type: type || 'text', id: id, disabled: disabled, onChange: handleChange, defaultValue: defaultValue, value: value }, rest)),
5011
+ e.createElement("input", __assign$1({ ref: ref, type: type || 'text', id: id, disabled: disabled, onChange: handleChange, defaultValue: defaultValue, placeholder: placeholder, value: value }, rest)),
5010
5012
  adornment && (e.createElement("div", { className: classNames('ods-input__adornment', {
5011
5013
  'ods-input__adornment--placeholder': !filled
5012
5014
  }) }, adornment)))));
@@ -5049,14 +5051,14 @@ var Link = forwardRef(function Link(_a, ref) {
5049
5051
  });
5050
5052
 
5051
5053
  var TextArea = e.forwardRef(function TextArea(_a, ref) {
5052
- var className = _a.className, label = _a.label, helperText = _a.helperText, error = _a.error, id = _a.id, disabled = _a.disabled, onChange = _a.onChange, value = _a.value, defaultValue = _a.defaultValue, rest = __rest$1(_a, ["className", "label", "helperText", "error", "id", "disabled", "onChange", "value", "defaultValue"]);
5054
+ var className = _a.className, label = _a.label, placeholder = _a.placeholder, helperText = _a.helperText, error = _a.error, id = _a.id, disabled = _a.disabled, onChange = _a.onChange, value = _a.value, defaultValue = _a.defaultValue, rest = __rest$1(_a, ["className", "label", "placeholder", "helperText", "error", "id", "disabled", "onChange", "value", "defaultValue"]);
5053
5055
  var _b = useInputFilled({
5054
5056
  defaultValue: defaultValue,
5055
5057
  value: value,
5056
5058
  onChange: onChange
5057
5059
  }), filled = _b.filled, handleChange = _b.handleChange;
5058
5060
  return (e.createElement(FormControl, { label: label, htmlFor: id, helperText: helperText, error: error, disabled: disabled },
5059
- e.createElement("textarea", __assign$1({ ref: ref, id: id, className: classNames('ods-textarea', filled && 'ods-textarea--filled', error && 'ods-textarea--error', className), disabled: disabled, onChange: handleChange, defaultValue: defaultValue, value: value }, rest))));
5061
+ e.createElement("textarea", __assign$1({ ref: ref, id: id, className: classNames('ods-textarea', filled && 'ods-textarea--filled', error && 'ods-textarea--error', className), disabled: disabled, onChange: handleChange, placeholder: placeholder, defaultValue: defaultValue, value: value }, rest))));
5060
5062
  });
5061
5063
 
5062
5064
  var Context = e.createContext({});
@@ -8241,24 +8243,22 @@ function IconButtonBase(_a, ref) {
8241
8243
  var IconButton = e.forwardRef(IconButtonBase);
8242
8244
 
8243
8245
  var Search = e.forwardRef(function Input(_a, ref) {
8244
- var className = _a.className, id = _a.id, disabled = _a.disabled, value = _a.value, defaultValue = _a.defaultValue, onChange = _a.onChange, rest = __rest$1(_a, ["className", "id", "disabled", "value", "defaultValue", "onChange"]);
8245
- var _b = useState(defaultValue || value), inputValue = _b[0], setInputValue = _b[1];
8246
+ var className = _a.className, id = _a.id, disabled = _a.disabled, value = _a.value, defaultValue = _a.defaultValue, placeholder = _a.placeholder, onChange = _a.onChange, rest = __rest$1(_a, ["className", "id", "disabled", "value", "defaultValue", "placeholder", "onChange"]);
8247
+ var _b = useInputFilled({
8248
+ defaultValue: defaultValue,
8249
+ value: value,
8250
+ onChange: onChange
8251
+ }), inputValue = _b.inputValue, filled = _b.filled, handleChange = _b.handleChange;
8246
8252
  return (e.createElement(FormControl, { htmlFor: id, disabled: disabled },
8247
- e.createElement("div", { className: classNames('ods-search', inputValue && 'ods-search--filled', disabled && 'ods-search--disabled', className) },
8253
+ e.createElement("div", { className: classNames('ods-search', filled && 'ods-search--filled', disabled && 'ods-search--disabled', className) },
8248
8254
  e.createElement("div", { className: "ods-search__adornment" },
8249
8255
  e.createElement(jt, null)),
8250
- e.createElement("input", __assign$1({ ref: ref, type: "text", id: id, disabled: disabled, onChange: function (e) {
8251
- setInputValue(e.target.value);
8252
- if (onChange)
8253
- onChange(e);
8254
- }, value: inputValue }, rest)),
8255
- inputValue && (e.createElement(IconButton, { "data-testid": "close", onClick: function () {
8256
- setInputValue('');
8256
+ e.createElement("input", __assign$1({ ref: ref, type: "text", id: id, disabled: disabled, onChange: handleChange, placeholder: placeholder, defaultValue: defaultValue, value: inputValue || '' }, rest)),
8257
+ filled && (e.createElement(IconButton, { "data-testid": "close", onClick: function () {
8257
8258
  var e = {
8258
8259
  target: { value: '' }
8259
8260
  };
8260
- if (onChange)
8261
- onChange(e);
8261
+ handleChange(e);
8262
8262
  }, className: "ods-search__clean", size: "sm" },
8263
8263
  e.createElement(Ma, null))))));
8264
8264
  });
@@ -31859,8 +31859,24 @@ var locale = {
31859
31859
  }
31860
31860
  };
31861
31861
 
31862
- function useDatePicker(_a) {
31863
- var values = _a.values, onSelect = _a.onSelect, startsToday = _a.startsToday, locale$1 = _a.locale;
31862
+ var handleValidateStartsToday = function (startsToday, day) {
31863
+ return Boolean(startsToday && day < new Date(new Date().setDate(new Date().getDate() - 1)));
31864
+ };
31865
+ var dateMask = function (value) {
31866
+ var v = value.replace(/\D/g, '').slice(0, 10);
31867
+ if (v.length >= 5)
31868
+ return "".concat(v.slice(0, 2), "/").concat(v.slice(2, 4), "/").concat(v.slice(4));
31869
+ if (v.length >= 3)
31870
+ return "".concat(v.slice(0, 2), "/").concat(v.slice(2));
31871
+ return v;
31872
+ };
31873
+ var formatDay$1 = function (day) { return format(day, 'd'); };
31874
+ var getInputPlaceholder = function (localeOption) {
31875
+ return localeOption.code === 'pt-BR' ? 'dd/mm/aaaa' : 'mm/dd/yyyy';
31876
+ };
31877
+
31878
+ function useDatePickerSingle(_a) {
31879
+ var value = _a.value, onSelect = _a.onSelect, startsToday = _a.startsToday, locale$1 = _a.locale;
31864
31880
  var localeOption = locale$1 || locale;
31865
31881
  var localeDateFormat = localeOption &&
31866
31882
  localeOption.formatLong &&
@@ -31869,51 +31885,22 @@ function useDatePicker(_a) {
31869
31885
  var input2Ref = e.useRef(null);
31870
31886
  var _b = e.useState(false), showDayPicker = _b[0], setShowDayPicker = _b[1];
31871
31887
  var _c = e.useState(''), currentField = _c[0], setCurrentField = _c[1];
31872
- var _d = e.useState({ from: '', to: '' }), datePickerCache = _d[0], setDatePickerCache = _d[1];
31873
- var fromDate = parse(values.from, localeDateFormat, new Date());
31874
- var toDate = parse(values.to, localeDateFormat, new Date());
31888
+ var _d = e.useState(''), datePickerCache = _d[0], setDatePickerCache = _d[1];
31889
+ var fromDate = parse(value || '', localeDateFormat, new Date());
31875
31890
  e.useEffect(function () {
31876
- if (values.from === '')
31891
+ if (value === '')
31877
31892
  setCurrentField('');
31878
- }, [values.from]);
31893
+ }, [value]);
31879
31894
  var updateState = function (updateData, updateCache) {
31880
31895
  onSelect(updateData);
31881
31896
  updateCache && setDatePickerCache(updateData);
31882
31897
  };
31883
- var handleValidateStartsToday = function (day) {
31884
- return Boolean(startsToday &&
31885
- day < new Date(new Date().setDate(new Date().getDate() - 1)));
31886
- };
31887
- var handleDayMouseEnter = function (day) {
31888
- var formattedDay = format(day, localeDateFormat);
31889
- if (currentField === 'end-date' && !(values.from && day < fromDate)) {
31890
- setCurrentField('end-date');
31891
- updateState({ from: values.from, to: formattedDay });
31892
- }
31893
- };
31894
31898
  var handleDayClick = function (day) {
31895
- if (!(startsToday && handleValidateStartsToday(day))) {
31899
+ if (!(startsToday && handleValidateStartsToday(startsToday, day))) {
31896
31900
  var formattedDay = format(day, localeDateFormat);
31897
- if (currentField === 'start-date') {
31898
- if (day > toDate) {
31899
- updateState({ from: formattedDay, to: '' }, true);
31900
- }
31901
- else {
31902
- updateState({ from: formattedDay, to: values.to });
31903
- setDatePickerCache({ from: formattedDay, to: values.to });
31904
- }
31905
- setCurrentField('end-date');
31906
- }
31907
- if (currentField === 'end-date') {
31908
- if (day < fromDate) {
31909
- updateState({ from: formattedDay, to: '' }, true);
31910
- }
31911
- else {
31912
- updateState({ from: values.from, to: formattedDay }, true);
31913
- setShowDayPicker(false);
31914
- setCurrentField('');
31915
- }
31916
- }
31901
+ updateState(formattedDay, true);
31902
+ setCurrentField('');
31903
+ setShowDayPicker(false);
31917
31904
  }
31918
31905
  };
31919
31906
  var createHandleToggleClick = function (fieldId) {
@@ -31921,16 +31908,8 @@ function useDatePicker(_a) {
31921
31908
  setCurrentField(fieldId);
31922
31909
  };
31923
31910
  var disabledDays = function (day) {
31924
- var startToday = handleValidateStartsToday(day);
31925
- return startToday || (currentField === 'end-date' && day < fromDate);
31926
- };
31927
- var dateMask = function (value) {
31928
- var v = value.replace(/\D/g, '').slice(0, 10);
31929
- if (v.length >= 5)
31930
- return "".concat(v.slice(0, 2), "/").concat(v.slice(2, 4), "/").concat(v.slice(4));
31931
- if (v.length >= 3)
31932
- return "".concat(v.slice(0, 2), "/").concat(v.slice(2));
31933
- return v;
31911
+ var startToday = handleValidateStartsToday(startsToday, day);
31912
+ return startToday;
31934
31913
  };
31935
31914
  var closeCalendarDelay = function () {
31936
31915
  setTimeout(function () { return setShowDayPicker(false); }, 500);
@@ -31938,80 +31917,54 @@ function useDatePicker(_a) {
31938
31917
  var inputChange = function (_a) {
31939
31918
  var target = _a.target;
31940
31919
  var dataFormatted = dateMask(target.value);
31941
- if (target.id === 'start-date') {
31942
- setCurrentField('start-date');
31943
- updateState({ from: dataFormatted, to: '' }, true);
31944
- if (dataFormatted.length === localeDateFormat.length) {
31945
- setCurrentField('end-date');
31946
- if (input2Ref && input2Ref.current)
31947
- input2Ref.current.focus();
31948
- }
31949
- }
31950
- else {
31951
- setCurrentField('end-date');
31952
- updateState({ from: values.from, to: dataFormatted }, true);
31953
- if (dataFormatted.length === localeDateFormat.length) {
31954
- setCurrentField('');
31955
- closeCalendarDelay();
31956
- }
31920
+ updateState(dataFormatted, true);
31921
+ if (dataFormatted.length === localeDateFormat.length) {
31922
+ setCurrentField('');
31923
+ closeCalendarDelay();
31957
31924
  }
31958
31925
  };
31959
31926
  var handleCloseByOutside = function () {
31960
31927
  if (showDayPicker) {
31961
31928
  setShowDayPicker(false);
31962
31929
  setCurrentField('');
31963
- if (datePickerCache.from !== '' && datePickerCache.to !== '')
31930
+ if (datePickerCache)
31964
31931
  updateState(datePickerCache);
31965
31932
  }
31966
31933
  };
31967
31934
  var CustomStyles = {
31968
- root: "ods-datepicker__calendar ".concat(currentField === 'start-date'
31969
- ? 'ods-datepicker_calendar_m1'
31970
- : 'ods-datepicker_calendar_m2'),
31971
- caption: 'ods-datepicker__caption',
31972
- nav_button: 'ods-datepicker__navButtons',
31973
- nav_button_previous: 'ods-datepicker__navButtonPrev',
31974
- nav_button_next: 'ods-datepicker__navButtonNext',
31975
- nav_icon: 'ods-datepicker__navIcon',
31976
- table: 'ods-datepicker__table',
31977
- head: 'ods-datepicker__head',
31978
- head_row: 'ods-datepicker__headRow',
31979
- tbody: 'ods-datepicker__body',
31980
- row: 'ods-datepicker__row',
31981
- cell: 'ods-datepicker__cell',
31982
- day: 'ods-datepicker__day',
31983
- day_today: 'ods-datepicker__today',
31984
- day_selected: 'ods-datepicker__selected',
31985
- day_disabled: 'ods-datepicker__disabled',
31986
- day_range_start: 'ods-datepicker__selectedStart',
31987
- day_range_end: 'ods-datepicker__selectedEnd',
31988
- day_range_middle: 'ods-datepicker__selectedMiddle'
31989
- };
31990
- var selectedDays = {
31991
- from: fromDate,
31992
- to: toDate
31993
- };
31994
- var formatDay = function (day) { return format(day, 'd'); };
31995
- var getInputPlaceholder = function () {
31996
- return localeOption.code === 'pt-BR' ? 'dd/mm/aaaa' : 'mm/dd/yyyy';
31935
+ root: 'ods-date__calendar ods-date_calendar_m1',
31936
+ caption: 'ods-date__caption',
31937
+ nav_button: 'ods-date__navButtons',
31938
+ nav_button_previous: 'ods-date__navButtonPrev-datepicker',
31939
+ nav_button_next: 'ods-date__navButtonNext-datepicker',
31940
+ nav_icon: 'ods-date__navIcon',
31941
+ table: 'ods-date__table',
31942
+ head: 'ods-date__head',
31943
+ head_row: 'ods-date__headRow',
31944
+ tbody: 'ods-date__body',
31945
+ row: 'ods-date__row',
31946
+ cell: 'ods-date__cell',
31947
+ day: 'ods-date__day',
31948
+ day_today: 'ods-date__today',
31949
+ day_selected: 'ods-date__selected-datepicker',
31950
+ day_disabled: 'ods-date__disabled'
31997
31951
  };
31952
+ var selectedDay = fromDate;
31953
+ var inputPlaceholder = getInputPlaceholder(localeOption);
31998
31954
  return {
31999
31955
  input1Ref: input1Ref,
32000
31956
  input2Ref: input2Ref,
32001
31957
  showDayPicker: showDayPicker,
32002
- fromDate: fromDate,
32003
- toDate: toDate,
32004
- selectedDays: selectedDays,
31958
+ selectedDay: selectedDay,
32005
31959
  CustomStyles: CustomStyles,
32006
31960
  localeOption: localeOption,
32007
31961
  currentField: currentField,
32008
- handleDayMouseEnter: handleDayMouseEnter,
31962
+ inputPlaceholder: inputPlaceholder,
32009
31963
  handleDayClick: handleDayClick,
32010
31964
  inputChange: inputChange,
32011
31965
  createHandleToggleClick: createHandleToggleClick,
32012
31966
  disabledDays: disabledDays,
32013
- formatDay: formatDay,
32014
- getInputPlaceholder: getInputPlaceholder,
31967
+ formatDay: formatDay$1,
32015
31968
  handleCloseByOutside: handleCloseByOutside
32016
31969
  };
32017
31970
  }
@@ -34079,39 +34032,218 @@ function DayPicker(props) {
34079
34032
  e.createElement(Root, null)));
34080
34033
  }
34081
34034
 
34082
- var DatePicker = e.forwardRef(function DatePicker(_a, ref) {
34083
- var labels = _a.labels, values = _a.values, onSelect = _a.onSelect, editable = _a.editable, disabled = _a.disabled, error = _a.error, helperText = _a.helperText, startsToday = _a.startsToday, className = _a.className, locale = _a.locale, rest = __rest$1(_a, ["labels", "values", "onSelect", "editable", "disabled", "error", "helperText", "startsToday", "className", "locale"]);
34084
- var _b = useDatePicker({ values: values, onSelect: onSelect, startsToday: startsToday, locale: locale }), input1Ref = _b.input1Ref, input2Ref = _b.input2Ref, showDayPicker = _b.showDayPicker, selectedDays = _b.selectedDays, CustomStyles = _b.CustomStyles, localeOption = _b.localeOption, currentField = _b.currentField, handleDayMouseEnter = _b.handleDayMouseEnter, handleDayClick = _b.handleDayClick, inputChange = _b.inputChange, createHandleToggleClick = _b.createHandleToggleClick, disabledDays = _b.disabledDays, formatDay = _b.formatDay, getInputPlaceholder = _b.getInputPlaceholder, handleCloseByOutside = _b.handleCloseByOutside;
34085
- var DatePickerHeader = function (props) {
34086
- var _a = useNavigation(), goToMonth = _a.goToMonth, nextMonth = _a.nextMonth, previousMonth = _a.previousMonth;
34087
- return (e.createElement("div", { className: "ods-datepicker__caption" },
34088
- e.createElement(IconButton, { type: "button", "data-testid": "calendar-left-arrow", size: "sm", className: classNames('ods-datepicker__navButtons', 'ods-datepicker__navButtonPrev'), disabled: !previousMonth, onClick: function () { return previousMonth && goToMonth(previousMonth); } },
34089
- e.createElement($, { size: 20 })),
34090
- e.createElement("h2", { "data-testid": "calendar-caption-month" }, format(props.displayMonth, 'MMMM yyyy', { locale: localeOption })),
34091
- e.createElement(IconButton, { type: "button", "data-testid": "calendar-right-arrow", size: "sm", className: classNames('ods-datepicker__navButtons', 'ods-datepicker__navButtonNext'), disabled: !nextMonth, onClick: function () { return nextMonth && goToMonth(nextMonth); } },
34092
- e.createElement(ee, { size: 20 }))));
34035
+ var DatePickerHeader = function (_a) {
34036
+ var displayMonth = _a.displayMonth, locale = _a.locale, _b = _a.mode, mode = _b === void 0 ? 'range' : _b;
34037
+ var _c = useNavigation(), goToMonth = _c.goToMonth, nextMonth = _c.nextMonth, previousMonth = _c.previousMonth;
34038
+ return (e.createElement("div", { className: "ods-date__caption" },
34039
+ e.createElement(IconButton, { type: "button", "data-testid": "calendar-left-arrow", size: "sm", className: classNames('ods-date__navButtons', {
34040
+ 'ods-date__navButtonPrev': mode === 'range',
34041
+ 'ods-date__navButtonPrev-datepicker': mode === 'single'
34042
+ }), disabled: !previousMonth, onClick: function () { return previousMonth && goToMonth(previousMonth); } },
34043
+ e.createElement($, { size: 20 })),
34044
+ e.createElement("h2", { "data-testid": "calendar-caption-month" }, format(displayMonth, 'MMMM yyyy', { locale: locale })),
34045
+ e.createElement(IconButton, { type: "button", "data-testid": "calendar-right-arrow", size: "sm", className: classNames('ods-date__navButtons', {
34046
+ 'ods-date__navButtonNext': mode === 'range',
34047
+ 'ods-date__navButtonNext-datepicker': mode === 'single'
34048
+ }), disabled: !nextMonth, onClick: function () { return nextMonth && goToMonth(nextMonth); } },
34049
+ e.createElement(ee, { size: 20 }))));
34050
+ };
34051
+
34052
+ var DatePickerSingle = e.forwardRef(function DatePickerSingle(_a, ref) {
34053
+ var label = _a.label, value = _a.value, onSelect = _a.onSelect, editable = _a.editable, disabled = _a.disabled, error = _a.error, helperText = _a.helperText, startsToday = _a.startsToday, className = _a.className, locale = _a.locale, rest = __rest$1(_a, ["label", "value", "onSelect", "editable", "disabled", "error", "helperText", "startsToday", "className", "locale"]);
34054
+ var _b = useDatePickerSingle({ value: value, onSelect: onSelect, startsToday: startsToday, locale: locale }), input1Ref = _b.input1Ref, showDayPicker = _b.showDayPicker, selectedDay = _b.selectedDay, CustomStyles = _b.CustomStyles, localeOption = _b.localeOption, currentField = _b.currentField, inputPlaceholder = _b.inputPlaceholder, handleDayClick = _b.handleDayClick, inputChange = _b.inputChange, createHandleToggleClick = _b.createHandleToggleClick, disabledDays = _b.disabledDays, formatDay = _b.formatDay, handleCloseByOutside = _b.handleCloseByOutside;
34055
+ return (e.createElement("div", null,
34056
+ showDayPicker && (e.createElement("div", { className: "ods-date-background", "data-testid": "date-picker-outside", onClick: handleCloseByOutside })),
34057
+ e.createElement("div", __assign$1({ className: classNames('ods-date', className), ref: ref }, rest),
34058
+ e.createElement("div", { className: "ods-date__form-row-datepicker" },
34059
+ e.createElement("div", { className: "ods-date__form-controls", "data-testid": "date-picker-first-field-wrapper", onClick: function () { return createHandleToggleClick('start-date'); } },
34060
+ label && e.createElement("label", { htmlFor: "start-date" }, label),
34061
+ e.createElement(Input, { ref: input1Ref, "data-testid": "datepicker-input-1", id: "start-date", type: "text", className: classNames({
34062
+ 'date-field-focussed': currentField === 'start-date'
34063
+ }), name: "start-date", value: value, onChange: (editable && inputChange) || undefined, placeholder: inputPlaceholder, adornment: e.createElement(wn, { size: 20, stroke: "#B6B9CC" }), autoComplete: "off", readOnly: !editable, disabled: disabled, error: !disabled && error, inputMode: "numeric", helperText: (!disabled && !showDayPicker && error && helperText) ||
34064
+ undefined, maxLength: 10 })),
34065
+ !disabled && showDayPicker && (e.createElement("div", { "data-testid": "datepicker-calendar" },
34066
+ e.createElement(DayPicker, { mode: "single", locale: localeOption, weekStartsOn: 0, classNames: CustomStyles, className: className, onDayClick: function (day) { return handleDayClick(day); }, formatters: { formatDay: formatDay }, selected: selectedDay, disabled: disabledDays, components: {
34067
+ Caption: function (_a) {
34068
+ var displayMonth = _a.displayMonth;
34069
+ return DatePickerHeader({
34070
+ displayMonth: displayMonth,
34071
+ locale: localeOption,
34072
+ mode: 'single'
34073
+ });
34074
+ }
34075
+ } })))))));
34076
+ });
34077
+
34078
+ function useDatePicker(_a) {
34079
+ var values = _a.values, onSelect = _a.onSelect, startsToday = _a.startsToday, locale$1 = _a.locale;
34080
+ var localeOption = locale$1 || locale;
34081
+ var localeDateFormat = localeOption &&
34082
+ localeOption.formatLong &&
34083
+ localeOption.formatLong.date({ width: 'short' });
34084
+ var input1Ref = e.useRef(null);
34085
+ var input2Ref = e.useRef(null);
34086
+ var _b = e.useState(false), showDayPicker = _b[0], setShowDayPicker = _b[1];
34087
+ var _c = e.useState(''), currentField = _c[0], setCurrentField = _c[1];
34088
+ var _d = e.useState({ from: '', to: '' }), datePickerCache = _d[0], setDatePickerCache = _d[1];
34089
+ var fromDate = parse(values.from, localeDateFormat, new Date());
34090
+ var toDate = parse(values.to, localeDateFormat, new Date());
34091
+ e.useEffect(function () {
34092
+ if (values.from === '')
34093
+ setCurrentField('');
34094
+ }, [values.from]);
34095
+ var updateState = function (updateData, updateCache) {
34096
+ onSelect(updateData);
34097
+ updateCache && setDatePickerCache(updateData);
34093
34098
  };
34099
+ var handleDayMouseEnter = function (day) {
34100
+ var formattedDay = format(day, localeDateFormat);
34101
+ if (currentField === 'end-date' && !(values.from && day < fromDate)) {
34102
+ setCurrentField('end-date');
34103
+ updateState({ from: values.from, to: formattedDay });
34104
+ }
34105
+ };
34106
+ var handleDayClick = function (day) {
34107
+ if (!(startsToday && handleValidateStartsToday(startsToday, day))) {
34108
+ var formattedDay = format(day, localeDateFormat);
34109
+ if (currentField === 'start-date') {
34110
+ if (day > toDate) {
34111
+ updateState({ from: formattedDay, to: '' }, true);
34112
+ }
34113
+ else {
34114
+ updateState({ from: formattedDay, to: values.to });
34115
+ setDatePickerCache({ from: formattedDay, to: values.to });
34116
+ }
34117
+ setCurrentField('end-date');
34118
+ }
34119
+ if (currentField === 'end-date') {
34120
+ if (day < fromDate) {
34121
+ updateState({ from: formattedDay, to: '' }, true);
34122
+ }
34123
+ else {
34124
+ updateState({ from: values.from, to: formattedDay }, true);
34125
+ setShowDayPicker(false);
34126
+ setCurrentField('');
34127
+ }
34128
+ }
34129
+ }
34130
+ };
34131
+ var createHandleToggleClick = function (fieldId) {
34132
+ setShowDayPicker(!showDayPicker);
34133
+ setCurrentField(fieldId);
34134
+ };
34135
+ var disabledDays = function (day) {
34136
+ var startToday = handleValidateStartsToday(startsToday, day);
34137
+ return startToday || (currentField === 'end-date' && day < fromDate);
34138
+ };
34139
+ var closeCalendarDelay = function () {
34140
+ setTimeout(function () { return setShowDayPicker(false); }, 500);
34141
+ };
34142
+ var inputChange = function (_a) {
34143
+ var target = _a.target;
34144
+ var dataFormatted = dateMask(target.value);
34145
+ if (target.id === 'start-date') {
34146
+ setCurrentField('start-date');
34147
+ updateState({ from: dataFormatted, to: '' }, true);
34148
+ if (dataFormatted.length === localeDateFormat.length) {
34149
+ setCurrentField('end-date');
34150
+ if (input2Ref && input2Ref.current)
34151
+ input2Ref.current.focus();
34152
+ }
34153
+ }
34154
+ else {
34155
+ setCurrentField('end-date');
34156
+ updateState({ from: values.from, to: dataFormatted }, true);
34157
+ if (dataFormatted.length === localeDateFormat.length) {
34158
+ setCurrentField('');
34159
+ closeCalendarDelay();
34160
+ }
34161
+ }
34162
+ };
34163
+ var handleCloseByOutside = function () {
34164
+ if (showDayPicker) {
34165
+ setShowDayPicker(false);
34166
+ setCurrentField('');
34167
+ if (datePickerCache.from !== '' && datePickerCache.to !== '')
34168
+ updateState(datePickerCache);
34169
+ }
34170
+ };
34171
+ var CustomStyles = {
34172
+ root: "ods-date__calendar ".concat(currentField === 'start-date'
34173
+ ? 'ods-date_calendar_m1'
34174
+ : 'ods-date_calendar_m2'),
34175
+ caption: 'ods-date__caption',
34176
+ nav_button: 'ods-date__navButtons',
34177
+ nav_button_previous: 'ods-date__navButtonPrev',
34178
+ nav_button_next: 'ods-date__navButtonNext',
34179
+ nav_icon: 'ods-date__navIcon',
34180
+ table: 'ods-date__table',
34181
+ head: 'ods-date__head',
34182
+ head_row: 'ods-date__headRow',
34183
+ tbody: 'ods-date__body',
34184
+ row: 'ods-date__row',
34185
+ cell: 'ods-date__cell',
34186
+ day: 'ods-date__day',
34187
+ day_today: 'ods-date__today',
34188
+ day_selected: 'ods-date__selected',
34189
+ day_disabled: 'ods-date__disabled',
34190
+ day_range_start: 'ods-date__selectedStart',
34191
+ day_range_end: 'ods-date__selectedEnd',
34192
+ day_range_middle: 'ods-date__selectedMiddle'
34193
+ };
34194
+ var selectedDays = {
34195
+ from: fromDate,
34196
+ to: toDate
34197
+ };
34198
+ var inputPlaceholder = getInputPlaceholder(localeOption);
34199
+ return {
34200
+ input1Ref: input1Ref,
34201
+ input2Ref: input2Ref,
34202
+ showDayPicker: showDayPicker,
34203
+ fromDate: fromDate,
34204
+ toDate: toDate,
34205
+ selectedDays: selectedDays,
34206
+ CustomStyles: CustomStyles,
34207
+ localeOption: localeOption,
34208
+ currentField: currentField,
34209
+ inputPlaceholder: inputPlaceholder,
34210
+ handleDayMouseEnter: handleDayMouseEnter,
34211
+ handleDayClick: handleDayClick,
34212
+ inputChange: inputChange,
34213
+ createHandleToggleClick: createHandleToggleClick,
34214
+ disabledDays: disabledDays,
34215
+ formatDay: formatDay$1,
34216
+ handleCloseByOutside: handleCloseByOutside
34217
+ };
34218
+ }
34219
+
34220
+ var DatePickerRange = e.forwardRef(function DatePickerRange(_a, ref) {
34221
+ var labels = _a.labels, values = _a.values, onSelect = _a.onSelect, editable = _a.editable, disabled = _a.disabled, error = _a.error, helperText = _a.helperText, startsToday = _a.startsToday, className = _a.className, locale = _a.locale, rest = __rest$1(_a, ["labels", "values", "onSelect", "editable", "disabled", "error", "helperText", "startsToday", "className", "locale"]);
34222
+ var _b = useDatePicker({ values: values, onSelect: onSelect, startsToday: startsToday, locale: locale }), input1Ref = _b.input1Ref, input2Ref = _b.input2Ref, showDayPicker = _b.showDayPicker, selectedDays = _b.selectedDays, CustomStyles = _b.CustomStyles, localeOption = _b.localeOption, currentField = _b.currentField, inputPlaceholder = _b.inputPlaceholder, handleDayMouseEnter = _b.handleDayMouseEnter, handleDayClick = _b.handleDayClick, inputChange = _b.inputChange, createHandleToggleClick = _b.createHandleToggleClick, disabledDays = _b.disabledDays, formatDay = _b.formatDay, handleCloseByOutside = _b.handleCloseByOutside;
34094
34223
  return (e.createElement("div", null,
34095
- showDayPicker && (e.createElement("div", { className: "ods-datepicker-background", "data-testid": "date-picker-outside", onClick: handleCloseByOutside })),
34096
- e.createElement("div", __assign$1({ className: classNames('ods-datepicker', className), ref: ref }, rest),
34097
- e.createElement("div", { className: "ods-datepicker__form-row" },
34098
- e.createElement("div", { className: "ods-datepicker__form-controls", "data-testid": "date-picker-first-field-wrapper", onClick: function () { return createHandleToggleClick('start-date'); } },
34224
+ showDayPicker && (e.createElement("div", { className: "ods-date-background", "data-testid": "date-picker-outside", onClick: handleCloseByOutside })),
34225
+ e.createElement("div", __assign$1({ className: classNames('ods-date', className), ref: ref }, rest),
34226
+ e.createElement("div", { className: "ods-date__form-row" },
34227
+ e.createElement("div", { className: "ods-date__form-controls", "data-testid": "date-picker-first-field-wrapper", onClick: function () { return createHandleToggleClick('start-date'); } },
34099
34228
  labels && labels.from && (e.createElement("label", { htmlFor: "start-date" }, labels.from)),
34100
34229
  e.createElement(Input, { ref: input1Ref, "data-testid": "datepicker-input-1", id: "start-date", type: "text", className: classNames({
34101
34230
  'date-field-focussed': currentField === 'start-date'
34102
- }), name: "start-date", value: values.from, onChange: (editable && inputChange) || undefined, placeholder: getInputPlaceholder(), adornment: e.createElement(wn, { size: 20, stroke: "#B6B9CC" }), autoComplete: "off", readOnly: !editable, disabled: disabled, error: !disabled && error, inputMode: "numeric", helperText: (!disabled && !showDayPicker && error && helperText) ||
34231
+ }), name: "start-date", value: values.from, onChange: (editable && inputChange) || undefined, placeholder: inputPlaceholder, adornment: e.createElement(wn, { size: 20, stroke: "#B6B9CC" }), autoComplete: "off", readOnly: !editable, disabled: disabled, error: !disabled && error, inputMode: "numeric", helperText: (!disabled && !showDayPicker && error && helperText) ||
34103
34232
  undefined, maxLength: 10 })),
34104
- e.createElement("div", { className: "ods-datepicker__form-controls", "data-testid": "date-picker-second-field-wrapper", onClick: function () { return createHandleToggleClick('end-date'); } },
34233
+ e.createElement("div", { className: "ods-date__form-controls", "data-testid": "date-picker-second-field-wrapper", onClick: function () { return createHandleToggleClick('end-date'); } },
34105
34234
  labels && labels.to && (e.createElement("label", { htmlFor: "end-date" }, labels.to)),
34106
34235
  e.createElement(Input, { ref: input2Ref, "data-testid": "datepicker-input-2", id: "end-date", type: "text", className: classNames({
34107
34236
  'date-field-focussed': currentField === 'end-date'
34108
- }), name: "end-date", value: values.to, onChange: (editable && inputChange) || undefined, placeholder: getInputPlaceholder(), adornment: e.createElement(wn, { size: 20, stroke: "#B6B9CC" }), autoComplete: "off", readOnly: !editable, disabled: disabled, error: !disabled && error, inputMode: "numeric", helperText: (!disabled && !showDayPicker && error && helperText) ||
34237
+ }), name: "end-date", value: values.to, onChange: (editable && inputChange) || undefined, placeholder: inputPlaceholder, adornment: e.createElement(wn, { size: 20, stroke: "#B6B9CC" }), autoComplete: "off", readOnly: !editable, disabled: disabled, error: !disabled && error, inputMode: "numeric", helperText: (!disabled && !showDayPicker && error && helperText) ||
34109
34238
  undefined, maxLength: 10 })),
34110
34239
  !disabled && showDayPicker && (e.createElement("div", { "data-testid": "datepicker-calendar" },
34111
34240
  e.createElement(DayPicker, { mode: "range", locale: localeOption, weekStartsOn: 0, classNames: CustomStyles, className: className, onDayClick: function (day) { return handleDayClick(day); }, onDayMouseEnter: function (day) { return handleDayMouseEnter(day); }, formatters: { formatDay: formatDay }, selected: selectedDays, disabled: disabledDays, components: {
34112
- Caption: DatePickerHeader
34241
+ Caption: function (_a) {
34242
+ var displayMonth = _a.displayMonth;
34243
+ return DatePickerHeader({ displayMonth: displayMonth, locale: localeOption });
34244
+ }
34113
34245
  } })))))));
34114
34246
  });
34115
34247
 
34116
- export { Alert, Badge, Button$1 as Button, Carousel, Checkbox, Col, Container, CrossSellCard, DatePicker, Divider, index$1 as Grid, IconButton, Input, Link, List, Modal, Progress, Radio, Row$1 as Row, Search, Select, Stepper, Steps, SubHeader, Switch, Tag, TextArea, TopBar, TransactionListItem, Typography };
34248
+ export { Alert, Badge, Button$1 as Button, Carousel, Checkbox, Col, Container, CrossSellCard, DatePickerSingle as DatePicker, DatePickerRange as DateRange, Divider, index$1 as Grid, IconButton, Input, Link, List, Modal, Progress, Radio, Row$1 as Row, Search, Select, Stepper, Steps, SubHeader, Switch, Tag, TextArea, TopBar, TransactionListItem, Typography };
34117
34249
  //# sourceMappingURL=index.es.js.map