@wallarm-org/design-system 0.16.3 → 0.16.4
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 +1 -0
- package/dist/components/Toast/Toast.js +37 -29
- package/dist/components/Toast/ToastDescription.js +1 -1
- package/dist/components/Toast/ToastProgress.d.ts +6 -0
- package/dist/components/Toast/ToastProgress.js +41 -0
- package/dist/components/Toast/ToastTitle.js +1 -1
- package/dist/metadata/components.json +2 -2
- package/package.json +1 -1
|
@@ -9,8 +9,9 @@ import { Loader } from "../Loader/index.js";
|
|
|
9
9
|
import { ToastClose } from "./ToastClose.js";
|
|
10
10
|
import { ToastDescription } from "./ToastDescription.js";
|
|
11
11
|
import { ToastIcon } from "./ToastIcon.js";
|
|
12
|
+
import { ToastProgress } from "./ToastProgress.js";
|
|
12
13
|
import { ToastTitle } from "./ToastTitle.js";
|
|
13
|
-
const toastVariants = cva('group relative flex min-w-[256px] max-w-[560px] items-start gap-12 rounded-
|
|
14
|
+
const toastVariants = cva('group relative flex min-w-[256px] max-w-[560px] items-start gap-12 rounded-16 bg-component-toast-bg p-12 pl-16 shadow-lg transition-all', {
|
|
14
15
|
variants: {
|
|
15
16
|
variant: {
|
|
16
17
|
extended: 'flex-col',
|
|
@@ -39,6 +40,8 @@ const toastIconMap = {
|
|
|
39
40
|
className: 'text-blue-500'
|
|
40
41
|
}
|
|
41
42
|
};
|
|
43
|
+
const SIMPLE_TOAST_DURATION_MS = 5000;
|
|
44
|
+
const EXTENDED_TOAST_DURATION_MS = 10000;
|
|
42
45
|
const Toast_Toast = ({ toast })=>{
|
|
43
46
|
const toastVariant = toast.variant || 'simple';
|
|
44
47
|
const isSimple = 'simple' === toastVariant;
|
|
@@ -81,35 +84,40 @@ const Toast_Toast = ({ toast })=>{
|
|
|
81
84
|
className: cn(toastVariants({
|
|
82
85
|
variant: toastVariant
|
|
83
86
|
})),
|
|
84
|
-
children: /*#__PURE__*/
|
|
87
|
+
children: /*#__PURE__*/ jsxs(TestIdProvider, {
|
|
85
88
|
value: toast.id,
|
|
86
|
-
children:
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
89
|
+
children: [
|
|
90
|
+
/*#__PURE__*/ jsxs("div", {
|
|
91
|
+
className: cn('flex w-full gap-8 relative z-10', isSimple ? 'items-center' : 'items-start'),
|
|
92
|
+
children: [
|
|
93
|
+
toastIcon && /*#__PURE__*/ jsx(ToastIcon, {
|
|
94
|
+
children: toastIcon
|
|
95
|
+
}),
|
|
96
|
+
/*#__PURE__*/ jsxs("div", {
|
|
97
|
+
className: cn('flex-1 flex', isSimple ? 'flex-row gap-16 items-center' : 'flex-col gap-8'),
|
|
98
|
+
children: [
|
|
99
|
+
/*#__PURE__*/ jsxs("div", {
|
|
100
|
+
className: "flex-1 py-2",
|
|
101
|
+
children: [
|
|
102
|
+
toast.title && /*#__PURE__*/ jsx(ToastTitle, {
|
|
103
|
+
variant: toastVariant,
|
|
104
|
+
children: toast.title
|
|
105
|
+
}),
|
|
106
|
+
!isSimple && toast.description && /*#__PURE__*/ jsx(ToastDescription, {
|
|
107
|
+
children: toast.description
|
|
108
|
+
})
|
|
109
|
+
]
|
|
110
|
+
}),
|
|
111
|
+
toast.actions && toast.actions
|
|
112
|
+
]
|
|
113
|
+
}),
|
|
114
|
+
closable && /*#__PURE__*/ jsx(ToastClose, {})
|
|
115
|
+
]
|
|
116
|
+
}),
|
|
117
|
+
'loading' !== toast.type && /*#__PURE__*/ jsx(ToastProgress, {
|
|
118
|
+
duration: toast.duration ?? (isSimple ? SIMPLE_TOAST_DURATION_MS : EXTENDED_TOAST_DURATION_MS)
|
|
119
|
+
})
|
|
120
|
+
]
|
|
113
121
|
})
|
|
114
122
|
}, toast.id);
|
|
115
123
|
};
|
|
@@ -10,7 +10,7 @@ const ToastDescription = /*#__PURE__*/ forwardRef(({ children }, ref)=>{
|
|
|
10
10
|
/*#__PURE__*/ jsx(OverflowTooltipTrigger, {
|
|
11
11
|
children: /*#__PURE__*/ jsx(Text, {
|
|
12
12
|
ref: ref,
|
|
13
|
-
size: "
|
|
13
|
+
size: "sm",
|
|
14
14
|
color: "secondary-alt",
|
|
15
15
|
lineClamp: 4,
|
|
16
16
|
"data-testid": testId,
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
3
|
+
import { cn } from "../../utils/cn.js";
|
|
4
|
+
const ToastProgress = ({ duration })=>{
|
|
5
|
+
const [progress, setProgress] = useState(0);
|
|
6
|
+
const elapsedRef = useRef(0);
|
|
7
|
+
const lastTickRef = useRef(0);
|
|
8
|
+
const rafRef = useRef(0);
|
|
9
|
+
const containerRef = useRef(null);
|
|
10
|
+
const isPaused = useCallback(()=>{
|
|
11
|
+
const root = containerRef.current?.closest('[data-scope="toast"][data-part="root"]');
|
|
12
|
+
return root?.hasAttribute('data-paused') ?? false;
|
|
13
|
+
}, []);
|
|
14
|
+
useEffect(()=>{
|
|
15
|
+
lastTickRef.current = performance.now();
|
|
16
|
+
const tick = (now)=>{
|
|
17
|
+
if (!isPaused()) elapsedRef.current += now - lastTickRef.current;
|
|
18
|
+
lastTickRef.current = now;
|
|
19
|
+
const fraction = Math.min(elapsedRef.current / duration, 1);
|
|
20
|
+
setProgress(fraction);
|
|
21
|
+
if (fraction < 1) rafRef.current = requestAnimationFrame(tick);
|
|
22
|
+
};
|
|
23
|
+
rafRef.current = requestAnimationFrame(tick);
|
|
24
|
+
return ()=>cancelAnimationFrame(rafRef.current);
|
|
25
|
+
}, [
|
|
26
|
+
duration,
|
|
27
|
+
isPaused
|
|
28
|
+
]);
|
|
29
|
+
return /*#__PURE__*/ jsx("div", {
|
|
30
|
+
ref: containerRef,
|
|
31
|
+
className: cn('absolute inset-0 rounded-16 overflow-hidden pointer-events-none'),
|
|
32
|
+
children: /*#__PURE__*/ jsx("div", {
|
|
33
|
+
className: "h-full bg-states-primary-alt-default-alt transition-none",
|
|
34
|
+
style: {
|
|
35
|
+
width: `${100 * progress}%`
|
|
36
|
+
}
|
|
37
|
+
})
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
ToastProgress.displayName = 'ToastProgress';
|
|
41
|
+
export { ToastProgress };
|
|
@@ -11,7 +11,7 @@ const ToastTitle = /*#__PURE__*/ forwardRef(({ children, variant = 'extended' },
|
|
|
11
11
|
/*#__PURE__*/ jsx(OverflowTooltipTrigger, {
|
|
12
12
|
children: /*#__PURE__*/ jsx(Text, {
|
|
13
13
|
ref: ref,
|
|
14
|
-
size: "
|
|
14
|
+
size: "sm",
|
|
15
15
|
weight: "medium",
|
|
16
16
|
color: "primary-alt",
|
|
17
17
|
lineClamp: isSimple ? 1 : 2,
|