@northlight/ui 2.36.12 → 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.
@@ -1005,6 +1005,11 @@ interface DateRangePickerProps extends Omit<AriaDateRangePickerProps<DateValue>,
1005
1005
  fiscalStartDay?: number;
1006
1006
  renderInPortal?: boolean;
1007
1007
  buttonLabel?: string;
1008
+ setIsOpen?: (isOpen: boolean) => void;
1009
+ savedDateRange?: DateRange | null;
1010
+ defaultDateRange?: DateRange | null;
1011
+ CustomResetButton?: React.ReactNode;
1012
+ clearButtonLabel?: string;
1008
1013
  }
1009
1014
  interface DatePickerFieldProps extends Omit<InputProps, 'onChange'>, InputFieldProps {
1010
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,
@@ -7891,7 +7902,13 @@ const DateRangePicker = (props) => {
7891
7902
  renderInPortal = false,
7892
7903
  firstDayOfWeek,
7893
7904
  onSave,
7894
- buttonLabel = "Save"
7905
+ buttonLabel = "Save",
7906
+ clearButtonLabel = "Clear",
7907
+ setIsOpen = () => {
7908
+ },
7909
+ savedDateRange = value,
7910
+ defaultDateRange = value,
7911
+ CustomResetButton
7895
7912
  } = props;
7896
7913
  const ref = useRef();
7897
7914
  const { group } = useMultiStyleConfig("DatePicker");
@@ -7906,10 +7923,22 @@ const DateRangePicker = (props) => {
7906
7923
  minValue: isNil(minValue) ? void 0 : parseDate(minValue),
7907
7924
  maxValue: isNil(maxValue) ? void 0 : parseDate(maxValue)
7908
7925
  };
7909
- 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,
7910
7936
  shouldCloseOnSelect: false,
7911
7937
  hideTimeZone: true
7912
- }));
7938
+ });
7939
+ useEffect(() => {
7940
+ setIsOpen(state.isOpen);
7941
+ }, [state.isOpen]);
7913
7942
  const {
7914
7943
  groupProps,
7915
7944
  startFieldProps,
@@ -7918,20 +7947,60 @@ const DateRangePicker = (props) => {
7918
7947
  dialogProps,
7919
7948
  calendarProps
7920
7949
  } = useDateRangePicker(
7921
- __spreadProps$e(__spreadValues$1p(__spreadValues$1p({}, props), parsedProps), {
7922
- minValue: parsedProps.minValue || parseDate("1994-03-08")
7923
- }),
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
+ },
7924
7968
  state,
7925
7969
  ref
7926
7970
  );
7927
7971
  const togglePopup = () => state.setOpen(!state.isOpen);
7928
7972
  const handleClose = () => {
7973
+ onChangeCallback(savedDateRange);
7929
7974
  state.setOpen(false);
7930
7975
  };
7931
7976
  useOutsideClick({
7932
7977
  ref,
7933
7978
  handler: () => state.setOpen(false)
7934
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;
7935
8004
  return /* @__PURE__ */ React.createElement(
7936
8005
  Popover,
7937
8006
  {
@@ -7953,19 +8022,28 @@ const DateRangePicker = (props) => {
7953
8022
  isDisabled,
7954
8023
  handleClick: togglePopup
7955
8024
  })
7956
- ))), /* @__PURE__ */ React.createElement(
8025
+ ))), shouldShowResetButton && ResetButton, shouldShowSaveAndCancelButtons && /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(
7957
8026
  IconButton,
7958
8027
  {
7959
- "aria-label": "reset-date",
7960
- variant: "danger",
8028
+ "aria-label": "cancel-date-change",
8029
+ variant: "ghost",
7961
8030
  size: "sm",
7962
8031
  fontSize: "xs",
7963
- onClick: resetDate,
7964
- hidden: !isClearable,
8032
+ onClick: cancelDateChange,
7965
8033
  isDisabled,
7966
8034
  icon: /* @__PURE__ */ React.createElement(Icon, { as: XCloseSolid })
7967
8035
  }
7968
- ))),
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
+ )))),
7969
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(
7970
8048
  RangeCalendar,
7971
8049
  __spreadProps$e(__spreadValues$1p({}, calendarProps), {
@@ -7976,6 +8054,8 @@ const DateRangePicker = (props) => {
7976
8054
  isClearable,
7977
8055
  firstDayOfWeek,
7978
8056
  onSave,
8057
+ onCancel: cancelDateChange,
8058
+ clearButtonLabel,
7979
8059
  buttonLabel
7980
8060
  })
7981
8061
  )))))