@youngonesworks/ui 1.0.11 → 1.0.14
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/components/toast/Toast.d.ts +16 -0
- package/dist/components/toast/Toast.stories.d.ts +10 -0
- package/dist/components/toast/Toast.test.d.ts +1 -0
- package/dist/components/toast/ToastContext.d.ts +10 -0
- package/dist/components/toast/ToastProvider.d.ts +11 -0
- package/dist/components/toast/index.d.ts +3 -0
- package/dist/components/toast/useToast.d.ts +11 -0
- package/dist/index.cjs +128 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +128 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export interface IToast {
|
|
2
|
+
id: string;
|
|
3
|
+
message?: string;
|
|
4
|
+
type?: TToastType;
|
|
5
|
+
timeout?: number | false;
|
|
6
|
+
}
|
|
7
|
+
export type TToastType = 'warning' | 'success' | 'error';
|
|
8
|
+
interface IToastProps {
|
|
9
|
+
toast: IToast;
|
|
10
|
+
onClose: () => void;
|
|
11
|
+
}
|
|
12
|
+
declare const Toast: {
|
|
13
|
+
({ toast, onClose }: IToastProps): import("react/jsx-runtime").JSX.Element;
|
|
14
|
+
displayName: string;
|
|
15
|
+
};
|
|
16
|
+
export default Toast;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/react-vite';
|
|
2
|
+
import Toast from './Toast';
|
|
3
|
+
declare const meta: Meta<typeof Toast>;
|
|
4
|
+
export default meta;
|
|
5
|
+
type Story = StoryObj<typeof Toast>;
|
|
6
|
+
export declare const Success: Story;
|
|
7
|
+
export declare const Warning: Story;
|
|
8
|
+
export declare const Error: Story;
|
|
9
|
+
export declare const NoType: Story;
|
|
10
|
+
export declare const LongMessage: Story;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type Dispatch } from 'react';
|
|
2
|
+
import { type IToast } from './Toast';
|
|
3
|
+
export interface IToastDispatchProps {
|
|
4
|
+
type: 'ADD' | 'DELETE';
|
|
5
|
+
toast: IToast;
|
|
6
|
+
}
|
|
7
|
+
export declare const ToastStateContext: import("react").Context<IToast[]>;
|
|
8
|
+
export declare const ToastDispatchContext: import("react").Context<Dispatch<IToastDispatchProps> | undefined>;
|
|
9
|
+
export declare const useToastStateContext: () => IToast[];
|
|
10
|
+
export declare const useToastDispatchContext: () => Dispatch<IToastDispatchProps> | undefined;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
interface IToastProviderProps {
|
|
3
|
+
children: ReactNode;
|
|
4
|
+
autoDelete?: boolean;
|
|
5
|
+
dismissTime?: number;
|
|
6
|
+
}
|
|
7
|
+
export declare const ToastProvider: {
|
|
8
|
+
({ children, autoDelete, dismissTime }: IToastProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
9
|
+
displayName: string;
|
|
10
|
+
};
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type TToastType } from './Toast';
|
|
2
|
+
interface IAddToastOptions {
|
|
3
|
+
message: string;
|
|
4
|
+
type: TToastType;
|
|
5
|
+
timeout?: number | false;
|
|
6
|
+
}
|
|
7
|
+
export declare const useToast: () => {
|
|
8
|
+
addToast: ({ message, type, timeout }: IAddToastOptions) => void;
|
|
9
|
+
deleteToast: (id: string) => void;
|
|
10
|
+
};
|
|
11
|
+
export {};
|
package/dist/index.cjs
CHANGED
|
@@ -2919,6 +2919,132 @@ const TimeInput = (0, react.forwardRef)(({ label, error, withSeconds, className
|
|
|
2919
2919
|
});
|
|
2920
2920
|
});
|
|
2921
2921
|
//#endregion
|
|
2922
|
+
//#region src/components/toast/Toast.tsx
|
|
2923
|
+
const Toast = ({ toast, onClose }) => {
|
|
2924
|
+
const icon = (0, react.useMemo)(() => {
|
|
2925
|
+
switch (toast.type) {
|
|
2926
|
+
case "success": return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_tabler_icons_react.IconCircleCheck, {
|
|
2927
|
+
className: "text-navy-blue",
|
|
2928
|
+
stroke: 2,
|
|
2929
|
+
size: 26
|
|
2930
|
+
});
|
|
2931
|
+
case "warning": return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_tabler_icons_react.IconAlertCircle, {
|
|
2932
|
+
className: "text-warning",
|
|
2933
|
+
size: 26
|
|
2934
|
+
});
|
|
2935
|
+
case "error": return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_tabler_icons_react.IconAlertCircle, {
|
|
2936
|
+
className: "text-red-500",
|
|
2937
|
+
size: 26
|
|
2938
|
+
});
|
|
2939
|
+
default: return null;
|
|
2940
|
+
}
|
|
2941
|
+
}, [toast.type]);
|
|
2942
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
2943
|
+
"data-testid": `toast-${toast.type || "default"}`,
|
|
2944
|
+
className: "bg-gradient-blue-turquoise mb-4 w-full max-w-[1400px] rounded p-px drop-shadow-sm",
|
|
2945
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
2946
|
+
"data-testid": "toast-content",
|
|
2947
|
+
className: cn("flex w-full max-w-[1400px] min-w-[350px] items-center justify-between", "gap-6 rounded-[0.20rem] bg-white p-5 md:gap-12"),
|
|
2948
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
2949
|
+
className: "flex items-center gap-6",
|
|
2950
|
+
children: [icon && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
2951
|
+
"data-testid": "toast-icon",
|
|
2952
|
+
children: icon
|
|
2953
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
2954
|
+
"data-testid": "toast-message",
|
|
2955
|
+
className: "yo-text-body m-0 text-black",
|
|
2956
|
+
children: toast.message
|
|
2957
|
+
})]
|
|
2958
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ActionIcon, {
|
|
2959
|
+
styleVariant: "transparent",
|
|
2960
|
+
onClick: onClose,
|
|
2961
|
+
title: "",
|
|
2962
|
+
"aria-label": "Close",
|
|
2963
|
+
className: "text-inherit",
|
|
2964
|
+
"data-testid": "closeToast",
|
|
2965
|
+
icon: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_tabler_icons_react.IconX, { size: 20 })
|
|
2966
|
+
})]
|
|
2967
|
+
})
|
|
2968
|
+
}, toast.id);
|
|
2969
|
+
};
|
|
2970
|
+
Toast.displayName = "Toast";
|
|
2971
|
+
//#endregion
|
|
2972
|
+
//#region src/components/toast/ToastContext.tsx
|
|
2973
|
+
const ToastStateContext = (0, react.createContext)([]);
|
|
2974
|
+
const ToastDispatchContext = (0, react.createContext)(void 0);
|
|
2975
|
+
const useToastDispatchContext = () => (0, react.useContext)(ToastDispatchContext);
|
|
2976
|
+
//#endregion
|
|
2977
|
+
//#region src/components/toast/ToastProvider.tsx
|
|
2978
|
+
const toastReducer = (state, action) => {
|
|
2979
|
+
switch (action.type) {
|
|
2980
|
+
case "ADD": return [action.toast, ...state];
|
|
2981
|
+
case "DELETE": return state.filter((t) => t.id !== action.toast.id);
|
|
2982
|
+
}
|
|
2983
|
+
};
|
|
2984
|
+
const toastTimers = /* @__PURE__ */ new Map();
|
|
2985
|
+
const ToastProvider = ({ children, autoDelete = true, dismissTime = 5e3 }) => {
|
|
2986
|
+
const [toasts, dispatch] = (0, react.useReducer)(toastReducer, []);
|
|
2987
|
+
(0, react.useEffect)(() => {
|
|
2988
|
+
if (!autoDelete) return;
|
|
2989
|
+
for (const toast of toasts) if (toast.timeout !== false && !toastTimers.has(toast.id)) {
|
|
2990
|
+
const timer = setTimeout(() => {
|
|
2991
|
+
dispatch({
|
|
2992
|
+
type: "DELETE",
|
|
2993
|
+
toast: { id: toast.id }
|
|
2994
|
+
});
|
|
2995
|
+
toastTimers.delete(toast.id);
|
|
2996
|
+
}, toast.timeout ?? dismissTime);
|
|
2997
|
+
toastTimers.set(toast.id, timer);
|
|
2998
|
+
}
|
|
2999
|
+
}, [
|
|
3000
|
+
autoDelete,
|
|
3001
|
+
dismissTime,
|
|
3002
|
+
toasts
|
|
3003
|
+
]);
|
|
3004
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ToastStateContext.Provider, {
|
|
3005
|
+
value: toasts,
|
|
3006
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(ToastDispatchContext.Provider, {
|
|
3007
|
+
value: dispatch,
|
|
3008
|
+
children: [children, toasts.length > 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
3009
|
+
"data-component": "ToastContainer",
|
|
3010
|
+
className: "fixed top-8 left-1/2 z-1000 -translate-x-1/2",
|
|
3011
|
+
children: toasts.map((toast) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Toast, {
|
|
3012
|
+
toast,
|
|
3013
|
+
onClose: () => dispatch({
|
|
3014
|
+
type: "DELETE",
|
|
3015
|
+
toast: { id: toast.id }
|
|
3016
|
+
})
|
|
3017
|
+
}, toast.id))
|
|
3018
|
+
})]
|
|
3019
|
+
})
|
|
3020
|
+
});
|
|
3021
|
+
};
|
|
3022
|
+
ToastProvider.displayName = "ToastProvider";
|
|
3023
|
+
//#endregion
|
|
3024
|
+
//#region src/components/toast/useToast.tsx
|
|
3025
|
+
const useToast = () => {
|
|
3026
|
+
const dispatch = useToastDispatchContext();
|
|
3027
|
+
return {
|
|
3028
|
+
addToast: (0, react.useCallback)(({ message, type, timeout }) => {
|
|
3029
|
+
dispatch?.({
|
|
3030
|
+
type: "ADD",
|
|
3031
|
+
toast: {
|
|
3032
|
+
id: crypto.randomUUID(),
|
|
3033
|
+
message,
|
|
3034
|
+
type,
|
|
3035
|
+
timeout
|
|
3036
|
+
}
|
|
3037
|
+
});
|
|
3038
|
+
}, [dispatch]),
|
|
3039
|
+
deleteToast: (0, react.useCallback)((id) => {
|
|
3040
|
+
dispatch?.({
|
|
3041
|
+
type: "DELETE",
|
|
3042
|
+
toast: { id }
|
|
3043
|
+
});
|
|
3044
|
+
}, [dispatch])
|
|
3045
|
+
};
|
|
3046
|
+
};
|
|
3047
|
+
//#endregion
|
|
2922
3048
|
//#region src/components/toggle/index.tsx
|
|
2923
3049
|
const Toggle = ({ onClick, value, disabled = false }) => {
|
|
2924
3050
|
const handleToggle = (e) => {
|
|
@@ -3556,6 +3682,7 @@ exports.TextInput = TextInput;
|
|
|
3556
3682
|
exports.Textarea = Textarea;
|
|
3557
3683
|
exports.ThemeIcon = ThemeIcon;
|
|
3558
3684
|
exports.TimeInput = TimeInput;
|
|
3685
|
+
exports.ToastProvider = ToastProvider;
|
|
3559
3686
|
exports.Toggle = Toggle;
|
|
3560
3687
|
exports.Tooltip = Tooltip;
|
|
3561
3688
|
exports.TruncatedText = TruncatedText;
|
|
@@ -3564,5 +3691,6 @@ exports.UnorderedListItem = UnorderedListItem;
|
|
|
3564
3691
|
exports.UnstyledButton = UnstyledButton;
|
|
3565
3692
|
exports.WysiwygEditor = WysiwygEditor;
|
|
3566
3693
|
exports.buttonVariants = buttonVariants;
|
|
3694
|
+
exports.useToast = useToast;
|
|
3567
3695
|
|
|
3568
3696
|
//# sourceMappingURL=index.cjs.map
|