fis-component 0.2.4 → 0.2.6
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/cjs/index.js +91 -11
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/src/components/Toast/Toast.stories.d.ts +11 -0
- package/dist/cjs/types/src/components/Toast/ToastContext.d.ts +14 -2
- package/dist/cjs/types/src/components/Toast/index.d.ts +6 -0
- package/dist/cjs/types/src/index.d.ts +2 -0
- package/dist/esm/index.js +91 -11
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/src/components/Toast/Toast.stories.d.ts +11 -0
- package/dist/esm/types/src/components/Toast/ToastContext.d.ts +14 -2
- package/dist/esm/types/src/components/Toast/index.d.ts +6 -0
- package/dist/esm/types/src/index.d.ts +2 -0
- package/dist/index.d.ts +20 -1
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -24324,7 +24324,7 @@ var __rest$m = undefined && undefined.__rest || function (s, e) {
|
|
|
24324
24324
|
return t;
|
|
24325
24325
|
};
|
|
24326
24326
|
const DEFAULT_OFFSET = 24;
|
|
24327
|
-
const DEFAULT_DURATION = 4.5;
|
|
24327
|
+
const DEFAULT_DURATION$1 = 4.5;
|
|
24328
24328
|
const DEFAULT_PLACEMENT = 'topRight';
|
|
24329
24329
|
const Wrapper = ({
|
|
24330
24330
|
children,
|
|
@@ -24382,7 +24382,7 @@ const Holder = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
|
24382
24382
|
motion: getNotificationMotion,
|
|
24383
24383
|
closable: true,
|
|
24384
24384
|
closeIcon: getCloseIcon(prefixCls),
|
|
24385
|
-
duration: duration !== null && duration !== void 0 ? duration : DEFAULT_DURATION,
|
|
24385
|
+
duration: duration !== null && duration !== void 0 ? duration : DEFAULT_DURATION$1,
|
|
24386
24386
|
getContainer: () => (staticGetContainer === null || staticGetContainer === void 0 ? void 0 : staticGetContainer()) || (getPopupContainer === null || getPopupContainer === void 0 ? void 0 : getPopupContainer()) || document.body,
|
|
24387
24387
|
maxCount,
|
|
24388
24388
|
pauseOnHover,
|
|
@@ -69895,12 +69895,12 @@ const dividerColorMap = {
|
|
|
69895
69895
|
caution: "com/toast/theme/divider/color-stroke/caution",
|
|
69896
69896
|
negative: "com/toast/theme/divider/color-stroke/negative",
|
|
69897
69897
|
};
|
|
69898
|
-
const FISToast$1 = ({ className, theme = "neutral", type = "link", actionPosition = "inline", iconLeft, noIcon = false, title, actionHref, actionLabel, closable = true, onClickAction, }) => {
|
|
69898
|
+
const FISToast$1 = ({ className, theme = "neutral", type = "link", actionPosition = "inline", iconLeft, noIcon = false, title, actionHref, actionLabel, closable = true, onClickAction, onClose, }) => {
|
|
69899
69899
|
const [visible, setVisible] = React.useState(true);
|
|
69900
69900
|
const resolvedIconLeft = React.useMemo(() => (theme === "neutral" ? iconLeft : themeIcons[theme]), [theme, iconLeft]);
|
|
69901
69901
|
return (jsxRuntime.jsxs(DivContainerSC$3, { className: classNames(className, {
|
|
69902
69902
|
hidden: !visible,
|
|
69903
|
-
}), "$theme": theme, children: [!noIcon && jsxRuntime.jsx(DivIconSC$1, { children: resolvedIconLeft }), jsxRuntime.jsxs(DivTitleWrap, { "$actionPosition": actionPosition, "$type": type, children: [jsxRuntime.jsx(PTitleSC, { "$theme": theme, "$actionPosition": actionPosition, children: title }), type === "link" && actionHref && (jsxRuntime.jsx(LinkSC, { href: actionHref, target: "_blank", children: actionLabel })), type === "button" && actionLabel && (jsxRuntime.jsx(FISButton$1, { variant: "tertiary", size: "sm", onClick: onClickAction, children: actionLabel }))] }), closable && (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(FISDivider$1, { direction: "vertical", headpointOffset: "tiny", color: dividerColorMap[theme] }), jsxRuntime.jsx(FISIconButton$1, { size: "sm", icon: jsxRuntime.jsx(ExitIcon, {}), variant: "tertiary-invisible", onClick: () => setVisible(false), style: { alignSelf: "center" } })] }))] }));
|
|
69903
|
+
}), "$theme": theme, children: [!noIcon && jsxRuntime.jsx(DivIconSC$1, { children: resolvedIconLeft }), jsxRuntime.jsxs(DivTitleWrap, { "$actionPosition": actionPosition, "$type": type, children: [jsxRuntime.jsx(PTitleSC, { "$theme": theme, "$actionPosition": actionPosition, children: title }), type === "link" && actionHref && (jsxRuntime.jsx(LinkSC, { href: actionHref, target: "_blank", children: actionLabel })), type === "button" && actionLabel && (jsxRuntime.jsx(FISButton$1, { variant: "tertiary", size: "sm", onClick: onClickAction, children: actionLabel }))] }), closable && (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(FISDivider$1, { direction: "vertical", headpointOffset: "tiny", color: dividerColorMap[theme] }), jsxRuntime.jsx(FISIconButton$1, { size: "sm", icon: jsxRuntime.jsx(ExitIcon, {}), variant: "tertiary-invisible", onClick: () => (onClose ? onClose() : setVisible(false)), style: { alignSelf: "center" } })] }))] }));
|
|
69904
69904
|
};
|
|
69905
69905
|
FISToast$1.displayName = "FISToast";
|
|
69906
69906
|
|
|
@@ -73135,6 +73135,7 @@ const FISInputDate$1 = React.forwardRef((props, ref) => {
|
|
|
73135
73135
|
return parseDateText(text, formats);
|
|
73136
73136
|
};
|
|
73137
73137
|
const [open, setOpen] = React.useState(false);
|
|
73138
|
+
const [hovered, setHovered] = React.useState(false);
|
|
73138
73139
|
const [inputValue, setInputValue] = React.useState(value ? dayjs(value).format(finalFormat) : "");
|
|
73139
73140
|
const [dateValue, setDateValue] = React.useState(value ? dayjs(value) : null);
|
|
73140
73141
|
const inputRef = React.useRef(null);
|
|
@@ -73222,6 +73223,14 @@ const FISInputDate$1 = React.forwardRef((props, ref) => {
|
|
|
73222
73223
|
setInputValue("");
|
|
73223
73224
|
}
|
|
73224
73225
|
};
|
|
73226
|
+
const showClear = allowClear && !disabled && inputValue !== "" && hovered;
|
|
73227
|
+
const handleClear = () => {
|
|
73228
|
+
setInputValue("");
|
|
73229
|
+
setDateValue(null);
|
|
73230
|
+
setOpen(false);
|
|
73231
|
+
if (dateValue)
|
|
73232
|
+
onChange?.(null);
|
|
73233
|
+
};
|
|
73225
73234
|
const handleInputKeyDown = (e) => {
|
|
73226
73235
|
if (e.key === "Enter") {
|
|
73227
73236
|
normalizeInput();
|
|
@@ -73229,7 +73238,7 @@ const FISInputDate$1 = React.forwardRef((props, ref) => {
|
|
|
73229
73238
|
}
|
|
73230
73239
|
originalOnKeyDown?.(e);
|
|
73231
73240
|
};
|
|
73232
|
-
return (jsxRuntime.jsxs(DivWrapperSC$2, { className: className, children: [(textLabel || iconLabel) && (jsxRuntime.jsx(FISInputLabel$1, { textLabel: textLabel, required: required, iconLabel: iconLabel, onClickIconLabel: onClickIconLabel })), jsxRuntime.jsxs(DivInputWrapperSC$1, { children: [jsxRuntime.jsx(FISInputField$1, { ...restProps, ref: mergeRef, typeSuffix: "icon", iconSuffix: jsxRuntime.jsx(DateIcon, {}), value: inputValue, negative: negative, disabled: disabled, placeholder: restProps.placeholder, readOnly: inputReadOnly, autoFocus: autoFocus, onFocus: () => setOpen(true), onChange: handleInputChange, onBlur: handleInputBlur, onKeyDown: handleInputKeyDown, onClickSuffix: () => setOpen(true), autoComplete: "off" }), jsxRuntime.jsx(HiddenDatePickerSC, { open: open, value: dateValue, onChange: (value) => handleChange(value), onOpenChange: handleOpenChange, format: finalFormat, getPopupContainer: getPopupContainer, minDate: minDate, maxDate: maxDate, picker: picker,
|
|
73241
|
+
return (jsxRuntime.jsxs(DivWrapperSC$2, { className: className, children: [(textLabel || iconLabel) && (jsxRuntime.jsx(FISInputLabel$1, { textLabel: textLabel, required: required, iconLabel: iconLabel, onClickIconLabel: onClickIconLabel })), jsxRuntime.jsxs(DivInputWrapperSC$1, { onMouseEnter: () => setHovered(true), onMouseLeave: () => setHovered(false), children: [jsxRuntime.jsx(FISInputField$1, { ...restProps, ref: mergeRef, typeSuffix: "icon", iconSuffix: showClear ? jsxRuntime.jsx(CloseIcon, {}) : jsxRuntime.jsx(DateIcon, {}), value: inputValue, negative: negative, disabled: disabled, placeholder: restProps.placeholder, readOnly: inputReadOnly, autoFocus: autoFocus, onFocus: () => setOpen(true), onChange: handleInputChange, onBlur: handleInputBlur, onKeyDown: handleInputKeyDown, onClickSuffix: showClear ? handleClear : () => setOpen(true), autoComplete: "off" }), jsxRuntime.jsx(HiddenDatePickerSC, { open: open, value: dateValue, onChange: (value) => handleChange(value), onOpenChange: handleOpenChange, format: finalFormat, getPopupContainer: getPopupContainer, minDate: minDate, maxDate: maxDate, picker: picker, showToday: showToday, showTime: showTime, disabledDate: disabledDate, disabledTime: disabledTime })] }), message && (jsxRuntime.jsx(DivHintWrapperSC$1, { children: jsxRuntime.jsx(SpanHintSC$3, { className: classNames({
|
|
73233
73242
|
disabled,
|
|
73234
73243
|
negative,
|
|
73235
73244
|
positive,
|
|
@@ -76812,16 +76821,87 @@ function GlobalStyle({ theme }) {
|
|
|
76812
76821
|
}
|
|
76813
76822
|
|
|
76814
76823
|
const ToastContext = React.createContext(undefined);
|
|
76824
|
+
const DEFAULT_DURATION = 3000;
|
|
76825
|
+
const DEFAULT_POSITION = "top-right";
|
|
76826
|
+
/** Giá trị lớn nhất setTimeout chấp nhận; lớn hơn sẽ bị coi là 0 */
|
|
76827
|
+
const MAX_TIMEOUT = 2147483647;
|
|
76828
|
+
const getIdentity = (options) => options.key !== undefined
|
|
76829
|
+
? JSON.stringify(["key", options.key])
|
|
76830
|
+
: JSON.stringify(["content", options.title, options.theme || "neutral"]);
|
|
76831
|
+
/** Trả về null khi toast không tự tắt */
|
|
76832
|
+
const resolveDuration = (duration) => {
|
|
76833
|
+
const value = duration || DEFAULT_DURATION;
|
|
76834
|
+
if (!Number.isFinite(value))
|
|
76835
|
+
return null;
|
|
76836
|
+
return Math.min(value, MAX_TIMEOUT);
|
|
76837
|
+
};
|
|
76815
76838
|
const ToastProvider = ({ children, }) => {
|
|
76816
76839
|
const [toasts, setToasts] = React.useState([]);
|
|
76840
|
+
const nextIdRef = React.useRef(0);
|
|
76841
|
+
const timersRef = React.useRef(new Map());
|
|
76842
|
+
/** danh tính → id của toast đang hiện, dùng để gộp toast trùng */
|
|
76843
|
+
const identitiesRef = React.useRef(new Map());
|
|
76844
|
+
// Chỉ thao tác ref/timer ở đây; updater của setState luôn thuần
|
|
76845
|
+
const removeToast = React.useCallback((id, identity) => {
|
|
76846
|
+
const timer = timersRef.current.get(id);
|
|
76847
|
+
if (timer !== undefined) {
|
|
76848
|
+
clearTimeout(timer);
|
|
76849
|
+
timersRef.current.delete(id);
|
|
76850
|
+
}
|
|
76851
|
+
if (identitiesRef.current.get(identity) === id) {
|
|
76852
|
+
identitiesRef.current.delete(identity);
|
|
76853
|
+
}
|
|
76854
|
+
setToasts((prev) => prev.filter((toast) => toast.id !== id));
|
|
76855
|
+
}, []);
|
|
76817
76856
|
const showToast = React.useCallback((options) => {
|
|
76818
|
-
const
|
|
76819
|
-
|
|
76820
|
-
|
|
76821
|
-
|
|
76822
|
-
|
|
76857
|
+
const identity = getIdentity(options);
|
|
76858
|
+
const previousId = identitiesRef.current.get(identity);
|
|
76859
|
+
if (previousId !== undefined) {
|
|
76860
|
+
const timer = timersRef.current.get(previousId);
|
|
76861
|
+
if (timer !== undefined) {
|
|
76862
|
+
clearTimeout(timer);
|
|
76863
|
+
timersRef.current.delete(previousId);
|
|
76864
|
+
}
|
|
76865
|
+
}
|
|
76866
|
+
const id = ++nextIdRef.current;
|
|
76867
|
+
identitiesRef.current.set(identity, id);
|
|
76868
|
+
const duration = resolveDuration(options.duration);
|
|
76869
|
+
if (duration !== null) {
|
|
76870
|
+
timersRef.current.set(id, setTimeout(() => removeToast(id, identity), duration));
|
|
76871
|
+
}
|
|
76872
|
+
setToasts((prev) => [
|
|
76873
|
+
...prev.filter((toast) => toast.id !== previousId),
|
|
76874
|
+
{ id, identity, options },
|
|
76875
|
+
]);
|
|
76876
|
+
}, [removeToast]);
|
|
76877
|
+
React.useEffect(() => {
|
|
76878
|
+
const timers = timersRef.current;
|
|
76879
|
+
return () => {
|
|
76880
|
+
timers.forEach((timer) => clearTimeout(timer));
|
|
76881
|
+
timers.clear();
|
|
76882
|
+
};
|
|
76823
76883
|
}, []);
|
|
76824
|
-
|
|
76884
|
+
const groups = React.useMemo(() => {
|
|
76885
|
+
const byPosition = new Map();
|
|
76886
|
+
toasts.forEach((toast) => {
|
|
76887
|
+
const position = toast.options.position ?? DEFAULT_POSITION;
|
|
76888
|
+
const group = byPosition.get(position);
|
|
76889
|
+
if (group)
|
|
76890
|
+
group.push(toast);
|
|
76891
|
+
else
|
|
76892
|
+
byPosition.set(position, [toast]);
|
|
76893
|
+
});
|
|
76894
|
+
return Array.from(byPosition.entries());
|
|
76895
|
+
}, [toasts]);
|
|
76896
|
+
const contextValue = React.useMemo(() => ({ showToast }), [showToast]);
|
|
76897
|
+
return (jsxRuntime.jsxs(ToastContext.Provider, { value: contextValue, children: [children, groups.map(([position, entries]) => (jsxRuntime.jsx(ToastWrapper, { "$position": position, "data-position": position, children: entries.map(({ id, identity, options }) => {
|
|
76898
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
76899
|
+
const { duration, position: _position, key, ...toastProps } = options;
|
|
76900
|
+
return (jsxRuntime.jsx(FISToast$1, { ...toastProps, onClose: () => {
|
|
76901
|
+
options.onClose?.();
|
|
76902
|
+
removeToast(id, identity);
|
|
76903
|
+
} }, id));
|
|
76904
|
+
}) }, position)))] }));
|
|
76825
76905
|
};
|
|
76826
76906
|
|
|
76827
76907
|
const FISThemeProvider = ({ theme: theme$1 = theme, config, children, }) => (jsxRuntime.jsxs(styled.ThemeProvider, { theme: theme$1, children: [jsxRuntime.jsx(GlobalStyle, { theme: theme$1 }), jsxRuntime.jsx(FISConfigProvider, { config: config, children: jsxRuntime.jsx(NotificationProvider, { children: jsxRuntime.jsx(ToastProvider, { children: children }) }) })] }));
|