@northlight/ui 2.37.0 → 2.38.1
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/dist/es/northlight.d.ts +5 -0
- package/dist/es/northlight.js +94 -14
- package/dist/es/northlight.js.map +1 -1
- package/dist/umd/northlight.cjs +94 -14
- package/dist/umd/northlight.cjs.map +1 -1
- package/dist/umd/northlight.min.cjs +3 -3
- package/dist/umd/northlight.min.cjs.map +1 -1
- package/package.json +2 -2
package/dist/es/northlight.d.ts
CHANGED
|
@@ -1006,6 +1006,11 @@ 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;
|
|
1013
|
+
onCancelChanges?: () => void;
|
|
1009
1014
|
}
|
|
1010
1015
|
interface DatePickerFieldProps extends Omit<InputProps, 'onChange'>, InputFieldProps {
|
|
1011
1016
|
name: string;
|
package/dist/es/northlight.js
CHANGED
|
@@ -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:
|
|
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,13 @@ 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,
|
|
7912
|
+
onCancelChanges
|
|
7897
7913
|
} = props;
|
|
7898
7914
|
const ref = useRef();
|
|
7899
7915
|
const { group } = useMultiStyleConfig("DatePicker");
|
|
@@ -7908,10 +7924,19 @@ const DateRangePicker = (props) => {
|
|
|
7908
7924
|
minValue: isNil(minValue) ? void 0 : parseDate(minValue),
|
|
7909
7925
|
maxValue: isNil(maxValue) ? void 0 : parseDate(maxValue)
|
|
7910
7926
|
};
|
|
7911
|
-
const state = useDateRangePickerState(
|
|
7927
|
+
const state = useDateRangePickerState({
|
|
7928
|
+
value: parsedProps.value,
|
|
7929
|
+
onChange: parsedProps.onChange,
|
|
7930
|
+
minValue: parsedProps.minValue,
|
|
7931
|
+
maxValue: parsedProps.maxValue,
|
|
7932
|
+
isDisabled,
|
|
7933
|
+
isInvalid,
|
|
7934
|
+
placeholderValue: props.placeholderValue,
|
|
7935
|
+
isDateUnavailable: props.isDateUnavailable,
|
|
7936
|
+
allowsNonContiguousRanges: props.allowsNonContiguousRanges,
|
|
7912
7937
|
shouldCloseOnSelect: false,
|
|
7913
7938
|
hideTimeZone: true
|
|
7914
|
-
})
|
|
7939
|
+
});
|
|
7915
7940
|
useEffect(() => {
|
|
7916
7941
|
setIsOpen(state.isOpen);
|
|
7917
7942
|
}, [state.isOpen]);
|
|
@@ -7923,20 +7948,64 @@ const DateRangePicker = (props) => {
|
|
|
7923
7948
|
dialogProps,
|
|
7924
7949
|
calendarProps
|
|
7925
7950
|
} = useDateRangePicker(
|
|
7926
|
-
|
|
7927
|
-
|
|
7928
|
-
|
|
7951
|
+
{
|
|
7952
|
+
onChange: (date) => {
|
|
7953
|
+
onChangeCallback({
|
|
7954
|
+
startDate: date == null ? void 0 : date.start.toString(),
|
|
7955
|
+
endDate: date == null ? void 0 : date.end.toString()
|
|
7956
|
+
});
|
|
7957
|
+
},
|
|
7958
|
+
value: parseValue(value),
|
|
7959
|
+
minValue: parsedProps.minValue || parseDate("1994-03-08"),
|
|
7960
|
+
maxValue: parsedProps.maxValue,
|
|
7961
|
+
placeholderValue: props.placeholderValue,
|
|
7962
|
+
isDateUnavailable: props.isDateUnavailable,
|
|
7963
|
+
allowsNonContiguousRanges: props.allowsNonContiguousRanges,
|
|
7964
|
+
isDisabled,
|
|
7965
|
+
isInvalid,
|
|
7966
|
+
startName: props.startName,
|
|
7967
|
+
endName: props.endName
|
|
7968
|
+
},
|
|
7929
7969
|
state,
|
|
7930
7970
|
ref
|
|
7931
7971
|
);
|
|
7932
7972
|
const togglePopup = () => state.setOpen(!state.isOpen);
|
|
7933
7973
|
const handleClose = () => {
|
|
7974
|
+
onChangeCallback(savedDateRange);
|
|
7934
7975
|
state.setOpen(false);
|
|
7935
7976
|
};
|
|
7936
7977
|
useOutsideClick({
|
|
7937
7978
|
ref,
|
|
7938
7979
|
handler: () => state.setOpen(false)
|
|
7939
7980
|
});
|
|
7981
|
+
const ResetButton = CustomResetButton || /* @__PURE__ */ React.createElement(
|
|
7982
|
+
IconButton,
|
|
7983
|
+
{
|
|
7984
|
+
"aria-label": "reset-date",
|
|
7985
|
+
variant: "danger",
|
|
7986
|
+
size: "sm",
|
|
7987
|
+
fontSize: "xs",
|
|
7988
|
+
hidden: !isClearable,
|
|
7989
|
+
isDisabled,
|
|
7990
|
+
onClick: resetDate,
|
|
7991
|
+
icon: /* @__PURE__ */ React.createElement(Icon, { as: XCloseSolid })
|
|
7992
|
+
}
|
|
7993
|
+
);
|
|
7994
|
+
const isCurrentDateSaved = isDatesEqual(value, savedDateRange);
|
|
7995
|
+
const isCurrentDateDefault = isDatesEqual(value, defaultDateRange);
|
|
7996
|
+
const cancelDateChange = () => {
|
|
7997
|
+
if (onCancelChanges) {
|
|
7998
|
+
onCancelChanges();
|
|
7999
|
+
} else {
|
|
8000
|
+
resetDate();
|
|
8001
|
+
}
|
|
8002
|
+
};
|
|
8003
|
+
const handleSave = () => {
|
|
8004
|
+
onSave == null ? void 0 : onSave();
|
|
8005
|
+
handleClose();
|
|
8006
|
+
};
|
|
8007
|
+
const shouldShowResetButton = !state.isOpen && isCurrentDateSaved && !isCurrentDateDefault;
|
|
8008
|
+
const shouldShowSaveAndCancelButtons = !state.isOpen && !isCurrentDateSaved;
|
|
7940
8009
|
return /* @__PURE__ */ React.createElement(
|
|
7941
8010
|
Popover,
|
|
7942
8011
|
{
|
|
@@ -7958,19 +8027,28 @@ const DateRangePicker = (props) => {
|
|
|
7958
8027
|
isDisabled,
|
|
7959
8028
|
handleClick: togglePopup
|
|
7960
8029
|
})
|
|
7961
|
-
))), /* @__PURE__ */ React.createElement(
|
|
8030
|
+
))), shouldShowResetButton && ResetButton, shouldShowSaveAndCancelButtons && /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(
|
|
7962
8031
|
IconButton,
|
|
7963
8032
|
{
|
|
7964
|
-
"aria-label": "
|
|
7965
|
-
variant: "
|
|
8033
|
+
"aria-label": "cancel-date-change",
|
|
8034
|
+
variant: "ghost",
|
|
7966
8035
|
size: "sm",
|
|
7967
8036
|
fontSize: "xs",
|
|
7968
|
-
onClick:
|
|
7969
|
-
hidden: !isClearable,
|
|
8037
|
+
onClick: cancelDateChange,
|
|
7970
8038
|
isDisabled,
|
|
7971
8039
|
icon: /* @__PURE__ */ React.createElement(Icon, { as: XCloseSolid })
|
|
7972
8040
|
}
|
|
7973
|
-
)
|
|
8041
|
+
), /* @__PURE__ */ React.createElement(
|
|
8042
|
+
IconButton,
|
|
8043
|
+
{
|
|
8044
|
+
"aria-label": "save-date",
|
|
8045
|
+
variant: "brand",
|
|
8046
|
+
size: "sm",
|
|
8047
|
+
fontSize: "xs",
|
|
8048
|
+
onClick: handleSave,
|
|
8049
|
+
icon: /* @__PURE__ */ React.createElement(Icon, { as: CheckSolid })
|
|
8050
|
+
}
|
|
8051
|
+
)))),
|
|
7974
8052
|
/* @__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
8053
|
RangeCalendar,
|
|
7976
8054
|
__spreadProps$e(__spreadValues$1p({}, calendarProps), {
|
|
@@ -7981,6 +8059,8 @@ const DateRangePicker = (props) => {
|
|
|
7981
8059
|
isClearable,
|
|
7982
8060
|
firstDayOfWeek,
|
|
7983
8061
|
onSave,
|
|
8062
|
+
onCancel: onCancelChanges,
|
|
8063
|
+
clearButtonLabel,
|
|
7984
8064
|
buttonLabel
|
|
7985
8065
|
})
|
|
7986
8066
|
)))))
|