@northlight/ui 2.37.0 → 2.38.0

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.
@@ -1006,6 +1006,10 @@ interface DateRangePickerProps extends Omit<AriaDateRangePickerProps<DateValue>,
1006
1006
  renderInPortal?: boolean;
1007
1007
  buttonLabel?: string;
1008
1008
  setIsOpen?: (isOpen: boolean) => void;
1009
+ savedDateRange?: DateRange | null;
1010
+ defaultDateRange?: DateRange | null;
1011
+ CustomResetButton?: React.ReactNode;
1012
+ clearButtonLabel?: string;
1009
1013
  }
1010
1014
  interface DatePickerFieldProps extends Omit<InputProps, 'onChange'>, InputFieldProps {
1011
1015
  name: string;
@@ -7764,7 +7764,9 @@ const RangeCalendar = (props) => {
7764
7764
  maxValue,
7765
7765
  firstDayOfWeek,
7766
7766
  onSave,
7767
- buttonLabel = "Save"
7767
+ buttonLabel = "Save",
7768
+ clearButtonLabel = "Clear",
7769
+ onCancel
7768
7770
  } = props;
7769
7771
  const { locale } = useLocale();
7770
7772
  const ref = useRef(null);
@@ -7795,6 +7797,14 @@ const RangeCalendar = (props) => {
7795
7797
  locale,
7796
7798
  createCalendar: () => new GregorianCalendar()
7797
7799
  });
7800
+ const handleOnReset = () => {
7801
+ if (onCancel) {
7802
+ onCancel();
7803
+ } else {
7804
+ resetDate();
7805
+ }
7806
+ handleClose();
7807
+ };
7798
7808
  const focusDateRange = (dateRange) => {
7799
7809
  if (dateRange && dateRange.start && dateRange.end) {
7800
7810
  calendarOneState.setFocusedDate(dateRange.start);
@@ -7836,7 +7846,7 @@ const RangeCalendar = (props) => {
7836
7846
  range: value,
7837
7847
  firstDayOfWeek
7838
7848
  }
7839
- ))), /* @__PURE__ */ React.createElement(HStack, { pt: "2", alignSelf: "end" }, isClearable && /* @__PURE__ */ React.createElement(Button, { onClick: resetDate, variant: "ghost", size: "sm" }, "Clear"), /* @__PURE__ */ React.createElement(Button, { variant: "brand", onClick: handleSave, size: "sm" }, buttonLabel))))))));
7849
+ ))), /* @__PURE__ */ React.createElement(HStack, { pt: "2", alignSelf: "end" }, isClearable && /* @__PURE__ */ React.createElement(Button, { onClick: handleOnReset, variant: "ghost", size: "sm" }, clearButtonLabel), /* @__PURE__ */ React.createElement(Button, { variant: "brand", onClick: handleSave, size: "sm" }, buttonLabel))))))));
7840
7850
  };
7841
7851
 
7842
7852
  const isValidDateRange = (value) => is(Object, value) && has("startDate", value) && has("endDate", value) && is(String, value.startDate) && is(String, value.endDate);
@@ -7874,6 +7884,7 @@ const PortalWrapper = ({
7874
7884
  }
7875
7885
  return /* @__PURE__ */ React.createElement(React.Fragment, null, children);
7876
7886
  };
7887
+ const isDatesEqual = (date1, date2) => (date1 == null ? void 0 : date1.startDate) === (date2 == null ? void 0 : date2.startDate) && (date1 == null ? void 0 : date1.endDate) === (date2 == null ? void 0 : date2.endDate);
7877
7888
  const DateRangePicker = (props) => {
7878
7889
  const {
7879
7890
  isDisabled,
@@ -7892,8 +7903,12 @@ const DateRangePicker = (props) => {
7892
7903
  firstDayOfWeek,
7893
7904
  onSave,
7894
7905
  buttonLabel = "Save",
7906
+ clearButtonLabel = "Clear",
7895
7907
  setIsOpen = () => {
7896
- }
7908
+ },
7909
+ savedDateRange = value,
7910
+ defaultDateRange = value,
7911
+ CustomResetButton
7897
7912
  } = props;
7898
7913
  const ref = useRef();
7899
7914
  const { group } = useMultiStyleConfig("DatePicker");
@@ -7908,10 +7923,19 @@ const DateRangePicker = (props) => {
7908
7923
  minValue: isNil(minValue) ? void 0 : parseDate(minValue),
7909
7924
  maxValue: isNil(maxValue) ? void 0 : parseDate(maxValue)
7910
7925
  };
7911
- const state = useDateRangePickerState(__spreadProps$e(__spreadValues$1p(__spreadValues$1p({}, props), parsedProps), {
7926
+ const state = useDateRangePickerState({
7927
+ value: parsedProps.value,
7928
+ onChange: parsedProps.onChange,
7929
+ minValue: parsedProps.minValue,
7930
+ maxValue: parsedProps.maxValue,
7931
+ isDisabled,
7932
+ isInvalid,
7933
+ placeholderValue: props.placeholderValue,
7934
+ isDateUnavailable: props.isDateUnavailable,
7935
+ allowsNonContiguousRanges: props.allowsNonContiguousRanges,
7912
7936
  shouldCloseOnSelect: false,
7913
7937
  hideTimeZone: true
7914
- }));
7938
+ });
7915
7939
  useEffect(() => {
7916
7940
  setIsOpen(state.isOpen);
7917
7941
  }, [state.isOpen]);
@@ -7923,20 +7947,60 @@ const DateRangePicker = (props) => {
7923
7947
  dialogProps,
7924
7948
  calendarProps
7925
7949
  } = useDateRangePicker(
7926
- __spreadProps$e(__spreadValues$1p(__spreadValues$1p({}, props), parsedProps), {
7927
- minValue: parsedProps.minValue || parseDate("1994-03-08")
7928
- }),
7950
+ {
7951
+ onChange: (date) => {
7952
+ onChangeCallback({
7953
+ startDate: date == null ? void 0 : date.start.toString(),
7954
+ endDate: date == null ? void 0 : date.end.toString()
7955
+ });
7956
+ },
7957
+ value: parseValue(value),
7958
+ minValue: parsedProps.minValue || parseDate("1994-03-08"),
7959
+ maxValue: parsedProps.maxValue,
7960
+ placeholderValue: props.placeholderValue,
7961
+ isDateUnavailable: props.isDateUnavailable,
7962
+ allowsNonContiguousRanges: props.allowsNonContiguousRanges,
7963
+ isDisabled,
7964
+ isInvalid,
7965
+ startName: props.startName,
7966
+ endName: props.endName
7967
+ },
7929
7968
  state,
7930
7969
  ref
7931
7970
  );
7932
7971
  const togglePopup = () => state.setOpen(!state.isOpen);
7933
7972
  const handleClose = () => {
7973
+ onChangeCallback(savedDateRange);
7934
7974
  state.setOpen(false);
7935
7975
  };
7936
7976
  useOutsideClick({
7937
7977
  ref,
7938
7978
  handler: () => state.setOpen(false)
7939
7979
  });
7980
+ const ResetButton = CustomResetButton || /* @__PURE__ */ React.createElement(
7981
+ IconButton,
7982
+ {
7983
+ "aria-label": "reset-date",
7984
+ variant: "danger",
7985
+ size: "sm",
7986
+ fontSize: "xs",
7987
+ hidden: !isClearable,
7988
+ isDisabled,
7989
+ onClick: resetDate,
7990
+ icon: /* @__PURE__ */ React.createElement(Icon, { as: XCloseSolid })
7991
+ }
7992
+ );
7993
+ const isCurrentDateSaved = isDatesEqual(value, savedDateRange);
7994
+ const isCurrentDateDefault = isDatesEqual(value, defaultDateRange);
7995
+ const cancelDateChange = () => {
7996
+ onChangeCallback(savedDateRange);
7997
+ };
7998
+ const handleSave = () => {
7999
+ onSave == null ? void 0 : onSave();
8000
+ handleClose();
8001
+ };
8002
+ const shouldShowResetButton = !state.isOpen && isCurrentDateSaved && !isCurrentDateDefault;
8003
+ const shouldShowSaveAndCancelButtons = !state.isOpen && !isCurrentDateSaved;
7940
8004
  return /* @__PURE__ */ React.createElement(
7941
8005
  Popover,
7942
8006
  {
@@ -7958,19 +8022,28 @@ const DateRangePicker = (props) => {
7958
8022
  isDisabled,
7959
8023
  handleClick: togglePopup
7960
8024
  })
7961
- ))), /* @__PURE__ */ React.createElement(
8025
+ ))), shouldShowResetButton && ResetButton, shouldShowSaveAndCancelButtons && /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(
7962
8026
  IconButton,
7963
8027
  {
7964
- "aria-label": "reset-date",
7965
- variant: "danger",
8028
+ "aria-label": "cancel-date-change",
8029
+ variant: "ghost",
7966
8030
  size: "sm",
7967
8031
  fontSize: "xs",
7968
- onClick: resetDate,
7969
- hidden: !isClearable,
8032
+ onClick: cancelDateChange,
7970
8033
  isDisabled,
7971
8034
  icon: /* @__PURE__ */ React.createElement(Icon, { as: XCloseSolid })
7972
8035
  }
7973
- ))),
8036
+ ), /* @__PURE__ */ React.createElement(
8037
+ IconButton,
8038
+ {
8039
+ "aria-label": "save-date",
8040
+ variant: "brand",
8041
+ size: "sm",
8042
+ fontSize: "xs",
8043
+ onClick: handleSave,
8044
+ icon: /* @__PURE__ */ React.createElement(Icon, { as: CheckSolid })
8045
+ }
8046
+ )))),
7974
8047
  /* @__PURE__ */ React.createElement(PortalWrapper, { renderInPortal }, state.isOpen && /* @__PURE__ */ React.createElement(PopoverContent, __spreadProps$e(__spreadValues$1p({}, dialogProps), { ref, w: "max-content" }), /* @__PURE__ */ React.createElement(FocusScope, { contain: true, restoreFocus: true }, /* @__PURE__ */ React.createElement(DatePickerLocaleWrapper, { firstDayOfWeek }, /* @__PURE__ */ React.createElement(
7975
8048
  RangeCalendar,
7976
8049
  __spreadProps$e(__spreadValues$1p({}, calendarProps), {
@@ -7981,6 +8054,8 @@ const DateRangePicker = (props) => {
7981
8054
  isClearable,
7982
8055
  firstDayOfWeek,
7983
8056
  onSave,
8057
+ onCancel: cancelDateChange,
8058
+ clearButtonLabel,
7984
8059
  buttonLabel
7985
8060
  })
7986
8061
  )))))