@youngonesworks/ui 1.0.11 → 1.0.15
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/actionIcon/index.d.ts +2 -1
- 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 +154 -24
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +154 -26
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -6,6 +6,7 @@ export interface ActionIconProps {
|
|
|
6
6
|
disabled?: boolean;
|
|
7
7
|
type?: 'button' | 'submit' | 'reset' | undefined;
|
|
8
8
|
styleVariant?: 'default' | 'transparent' | 'small' | 'round';
|
|
9
|
+
tooltipTitle?: string;
|
|
9
10
|
onClick?: (event: MouseEvent<HTMLButtonElement>) => void;
|
|
10
11
|
icon?: React.ReactNode;
|
|
11
12
|
iconSize?: number;
|
|
@@ -22,7 +23,7 @@ export interface ActionIconProps {
|
|
|
22
23
|
height?: string;
|
|
23
24
|
}
|
|
24
25
|
declare const ActionIcon: {
|
|
25
|
-
({ ref, title, disabled, styleVariant, icon, type, "data-testid": testId, iconSize, strokeWidth, onClick, className, ...props }: ActionIconProps): import("react/jsx-runtime").JSX.Element;
|
|
26
|
+
({ ref, title, disabled, styleVariant, icon, type, tooltipTitle, "data-testid": testId, iconSize, strokeWidth, onClick, className, ...props }: ActionIconProps): import("react/jsx-runtime").JSX.Element;
|
|
26
27
|
displayName: string;
|
|
27
28
|
};
|
|
28
29
|
export { ActionIcon };
|
|
@@ -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
|
@@ -281,34 +281,35 @@ function formatIcon(icon, defaultFormatAttributes) {
|
|
|
281
281
|
}
|
|
282
282
|
//#endregion
|
|
283
283
|
//#region src/components/actionIcon/index.tsx
|
|
284
|
-
const ActionIcon = ({ ref, title, disabled = false, styleVariant = "default", icon, type = "button", "data-testid": testId, iconSize = 20, strokeWidth = 1, onClick, className, ...props }) => {
|
|
284
|
+
const ActionIcon = ({ ref, title, disabled = false, styleVariant = "default", icon, type = "button", tooltipTitle, "data-testid": testId, iconSize = 20, strokeWidth = 1, onClick, className, ...props }) => {
|
|
285
285
|
const variantClassNames = (0, clsx.default)({
|
|
286
286
|
"active:translate-y-[1px] content-center flex items-center justify-center rounded-[4px] border border-gray-200 hover:border-black text-black child:p-10 w-[36px] h-[36px] disabled:text-gray-500": styleVariant === ACTION_ICON_STYLE_VARIANT.DEFAULT,
|
|
287
287
|
"active:translate-y-[1px] border-none content-center flex items-center justify-center rounded-[4px] border text-black child:p-10 w-[36px] h-[36px] disabled:text-gray-500": styleVariant === ACTION_ICON_STYLE_VARIANT.TRANSPARENT,
|
|
288
288
|
"active:translate-y-[1px] content-center flex items-center justify-center rounded-[4px] child:p-10 w-[37px] h-[37px] text-black rounded-full bg-primary hover:bg-turquoise-700 disabled:turquoise-50 disabled:text-gray-800": styleVariant === ACTION_ICON_STYLE_VARIANT.ROUND,
|
|
289
289
|
"w-7 h-7 active:translate-y-[1px] content-center flex items-center justify-center rounded-[4px] border border-gray-200 hover:border-black text-black hover:bg-ultra-light-blue-gray disabled:text-gray-500": styleVariant === ACTION_ICON_STYLE_VARIANT.SMALL
|
|
290
290
|
});
|
|
291
|
-
|
|
291
|
+
const renderButton = () => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
292
|
+
title,
|
|
293
|
+
type,
|
|
294
|
+
disabled,
|
|
295
|
+
"data-testid": testId,
|
|
296
|
+
"data-component": "ActionIcon",
|
|
297
|
+
className: cn(variantClassNames, { "hover:bg-transparant cursor-not-allowed hover:border-gray-200": disabled }, className),
|
|
298
|
+
onClick,
|
|
299
|
+
ref,
|
|
300
|
+
"data-tooltip-id": tooltipTitle,
|
|
301
|
+
"data-tooltip-content": tooltipTitle,
|
|
302
|
+
...props,
|
|
303
|
+
children: icon ? formatIcon(icon, {
|
|
304
|
+
stroke: strokeWidth,
|
|
305
|
+
size: iconSize
|
|
306
|
+
}) : props.children
|
|
307
|
+
});
|
|
308
|
+
return tooltipTitle ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Tooltip, {
|
|
292
309
|
size: "sm",
|
|
293
|
-
content:
|
|
294
|
-
children:
|
|
295
|
-
|
|
296
|
-
type,
|
|
297
|
-
disabled,
|
|
298
|
-
"data-testid": testId,
|
|
299
|
-
"data-component": "ActionIcon",
|
|
300
|
-
className: cn(variantClassNames, { "hover:bg-transparant cursor-not-allowed hover:border-gray-200": disabled }, className),
|
|
301
|
-
onClick,
|
|
302
|
-
ref,
|
|
303
|
-
"data-tooltip-id": title,
|
|
304
|
-
"data-tooltip-content": title,
|
|
305
|
-
...props,
|
|
306
|
-
children: icon ? formatIcon(icon, {
|
|
307
|
-
stroke: strokeWidth,
|
|
308
|
-
size: iconSize
|
|
309
|
-
}) : props.children
|
|
310
|
-
})
|
|
311
|
-
}) });
|
|
310
|
+
content: tooltipTitle,
|
|
311
|
+
children: renderButton()
|
|
312
|
+
}) : renderButton();
|
|
312
313
|
};
|
|
313
314
|
ActionIcon.displayName = "ActionIcon";
|
|
314
315
|
//#endregion
|
|
@@ -1250,6 +1251,7 @@ const Divider = ({ className, ...props }) => /* @__PURE__ */ (0, react_jsx_runti
|
|
|
1250
1251
|
const FavouriteButton = (0, react.forwardRef)((props, ref) => {
|
|
1251
1252
|
const { onClick, favourite, iconFilled, iconOutline, favouriteTitle, iconColorSelected = "text-secondary", iconColor = "text-gray-800", iconSize, className = "", styleVariant = "transparent", children, ...rest } = props;
|
|
1252
1253
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ActionIcon, {
|
|
1254
|
+
tooltipTitle: favouriteTitle || "Favorite",
|
|
1253
1255
|
onClick,
|
|
1254
1256
|
"data-component": "favouriteButton",
|
|
1255
1257
|
title: favouriteTitle || "Favorite",
|
|
@@ -1819,12 +1821,12 @@ const Modal = ({ title, children, withCloseButton = true, opened, additionalClas
|
|
|
1819
1821
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
1820
1822
|
className: "relative z-10 w-full",
|
|
1821
1823
|
children: withCloseButton && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ActionIcon, {
|
|
1824
|
+
title: "Close modal",
|
|
1822
1825
|
onClick: handleClose,
|
|
1823
|
-
"aria-label": "
|
|
1826
|
+
"aria-label": "Close modal",
|
|
1824
1827
|
className: "absolute top-0 right-0",
|
|
1825
1828
|
"data-testid": "close-modal",
|
|
1826
|
-
icon: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_tabler_icons_react.IconX, {})
|
|
1827
|
-
title: "Close modal"
|
|
1829
|
+
icon: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_tabler_icons_react.IconX, {})
|
|
1828
1830
|
})
|
|
1829
1831
|
}),
|
|
1830
1832
|
title && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
@@ -2919,6 +2921,132 @@ const TimeInput = (0, react.forwardRef)(({ label, error, withSeconds, className
|
|
|
2919
2921
|
});
|
|
2920
2922
|
});
|
|
2921
2923
|
//#endregion
|
|
2924
|
+
//#region src/components/toast/Toast.tsx
|
|
2925
|
+
const Toast = ({ toast, onClose }) => {
|
|
2926
|
+
const icon = (0, react.useMemo)(() => {
|
|
2927
|
+
switch (toast.type) {
|
|
2928
|
+
case "success": return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_tabler_icons_react.IconCircleCheck, {
|
|
2929
|
+
className: "text-navy-blue",
|
|
2930
|
+
stroke: 2,
|
|
2931
|
+
size: 26
|
|
2932
|
+
});
|
|
2933
|
+
case "warning": return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_tabler_icons_react.IconAlertCircle, {
|
|
2934
|
+
className: "text-warning",
|
|
2935
|
+
size: 26
|
|
2936
|
+
});
|
|
2937
|
+
case "error": return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_tabler_icons_react.IconAlertCircle, {
|
|
2938
|
+
className: "text-red-500",
|
|
2939
|
+
size: 26
|
|
2940
|
+
});
|
|
2941
|
+
default: return null;
|
|
2942
|
+
}
|
|
2943
|
+
}, [toast.type]);
|
|
2944
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
2945
|
+
"data-testid": `toast-${toast.type || "default"}`,
|
|
2946
|
+
className: "bg-gradient-blue-turquoise mb-4 w-full max-w-[1400px] rounded p-px drop-shadow-sm",
|
|
2947
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
2948
|
+
"data-testid": "toast-content",
|
|
2949
|
+
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"),
|
|
2950
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
2951
|
+
className: "flex items-center gap-6",
|
|
2952
|
+
children: [icon && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
2953
|
+
"data-testid": "toast-icon",
|
|
2954
|
+
children: icon
|
|
2955
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
2956
|
+
"data-testid": "toast-message",
|
|
2957
|
+
className: "yo-text-body m-0 text-black",
|
|
2958
|
+
children: toast.message
|
|
2959
|
+
})]
|
|
2960
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ActionIcon, {
|
|
2961
|
+
styleVariant: "transparent",
|
|
2962
|
+
onClick: onClose,
|
|
2963
|
+
title: "",
|
|
2964
|
+
"aria-label": "Close",
|
|
2965
|
+
className: "text-inherit",
|
|
2966
|
+
"data-testid": "closeToast",
|
|
2967
|
+
icon: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_tabler_icons_react.IconX, { size: 20 })
|
|
2968
|
+
})]
|
|
2969
|
+
})
|
|
2970
|
+
}, toast.id);
|
|
2971
|
+
};
|
|
2972
|
+
Toast.displayName = "Toast";
|
|
2973
|
+
//#endregion
|
|
2974
|
+
//#region src/components/toast/ToastContext.tsx
|
|
2975
|
+
const ToastStateContext = (0, react.createContext)([]);
|
|
2976
|
+
const ToastDispatchContext = (0, react.createContext)(void 0);
|
|
2977
|
+
const useToastDispatchContext = () => (0, react.useContext)(ToastDispatchContext);
|
|
2978
|
+
//#endregion
|
|
2979
|
+
//#region src/components/toast/ToastProvider.tsx
|
|
2980
|
+
const toastReducer = (state, action) => {
|
|
2981
|
+
switch (action.type) {
|
|
2982
|
+
case "ADD": return [action.toast, ...state];
|
|
2983
|
+
case "DELETE": return state.filter((t) => t.id !== action.toast.id);
|
|
2984
|
+
}
|
|
2985
|
+
};
|
|
2986
|
+
const toastTimers = /* @__PURE__ */ new Map();
|
|
2987
|
+
const ToastProvider = ({ children, autoDelete = true, dismissTime = 5e3 }) => {
|
|
2988
|
+
const [toasts, dispatch] = (0, react.useReducer)(toastReducer, []);
|
|
2989
|
+
(0, react.useEffect)(() => {
|
|
2990
|
+
if (!autoDelete) return;
|
|
2991
|
+
for (const toast of toasts) if (toast.timeout !== false && !toastTimers.has(toast.id)) {
|
|
2992
|
+
const timer = setTimeout(() => {
|
|
2993
|
+
dispatch({
|
|
2994
|
+
type: "DELETE",
|
|
2995
|
+
toast: { id: toast.id }
|
|
2996
|
+
});
|
|
2997
|
+
toastTimers.delete(toast.id);
|
|
2998
|
+
}, toast.timeout ?? dismissTime);
|
|
2999
|
+
toastTimers.set(toast.id, timer);
|
|
3000
|
+
}
|
|
3001
|
+
}, [
|
|
3002
|
+
autoDelete,
|
|
3003
|
+
dismissTime,
|
|
3004
|
+
toasts
|
|
3005
|
+
]);
|
|
3006
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ToastStateContext.Provider, {
|
|
3007
|
+
value: toasts,
|
|
3008
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(ToastDispatchContext.Provider, {
|
|
3009
|
+
value: dispatch,
|
|
3010
|
+
children: [children, toasts.length > 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
3011
|
+
"data-component": "ToastContainer",
|
|
3012
|
+
className: "fixed top-8 left-1/2 z-1000 -translate-x-1/2",
|
|
3013
|
+
children: toasts.map((toast) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Toast, {
|
|
3014
|
+
toast,
|
|
3015
|
+
onClose: () => dispatch({
|
|
3016
|
+
type: "DELETE",
|
|
3017
|
+
toast: { id: toast.id }
|
|
3018
|
+
})
|
|
3019
|
+
}, toast.id))
|
|
3020
|
+
})]
|
|
3021
|
+
})
|
|
3022
|
+
});
|
|
3023
|
+
};
|
|
3024
|
+
ToastProvider.displayName = "ToastProvider";
|
|
3025
|
+
//#endregion
|
|
3026
|
+
//#region src/components/toast/useToast.tsx
|
|
3027
|
+
const useToast = () => {
|
|
3028
|
+
const dispatch = useToastDispatchContext();
|
|
3029
|
+
return {
|
|
3030
|
+
addToast: (0, react.useCallback)(({ message, type, timeout }) => {
|
|
3031
|
+
dispatch?.({
|
|
3032
|
+
type: "ADD",
|
|
3033
|
+
toast: {
|
|
3034
|
+
id: crypto.randomUUID(),
|
|
3035
|
+
message,
|
|
3036
|
+
type,
|
|
3037
|
+
timeout
|
|
3038
|
+
}
|
|
3039
|
+
});
|
|
3040
|
+
}, [dispatch]),
|
|
3041
|
+
deleteToast: (0, react.useCallback)((id) => {
|
|
3042
|
+
dispatch?.({
|
|
3043
|
+
type: "DELETE",
|
|
3044
|
+
toast: { id }
|
|
3045
|
+
});
|
|
3046
|
+
}, [dispatch])
|
|
3047
|
+
};
|
|
3048
|
+
};
|
|
3049
|
+
//#endregion
|
|
2922
3050
|
//#region src/components/toggle/index.tsx
|
|
2923
3051
|
const Toggle = ({ onClick, value, disabled = false }) => {
|
|
2924
3052
|
const handleToggle = (e) => {
|
|
@@ -3556,6 +3684,7 @@ exports.TextInput = TextInput;
|
|
|
3556
3684
|
exports.Textarea = Textarea;
|
|
3557
3685
|
exports.ThemeIcon = ThemeIcon;
|
|
3558
3686
|
exports.TimeInput = TimeInput;
|
|
3687
|
+
exports.ToastProvider = ToastProvider;
|
|
3559
3688
|
exports.Toggle = Toggle;
|
|
3560
3689
|
exports.Tooltip = Tooltip;
|
|
3561
3690
|
exports.TruncatedText = TruncatedText;
|
|
@@ -3564,5 +3693,6 @@ exports.UnorderedListItem = UnorderedListItem;
|
|
|
3564
3693
|
exports.UnstyledButton = UnstyledButton;
|
|
3565
3694
|
exports.WysiwygEditor = WysiwygEditor;
|
|
3566
3695
|
exports.buttonVariants = buttonVariants;
|
|
3696
|
+
exports.useToast = useToast;
|
|
3567
3697
|
|
|
3568
3698
|
//# sourceMappingURL=index.cjs.map
|