@rockshin/tao-ui 0.0.15 → 0.0.17
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/button/button.css +51 -0
- package/dist/components/button/button.d.ts +5 -1
- package/dist/components/button/button.js +96 -39
- package/dist/components/sonner/sonner.css +113 -10
- package/dist/components/sonner/sonner.d.ts +1 -0
- package/dist/components/sonner/sonner.js +189 -74
- package/package.json +1 -1
|
@@ -101,6 +101,57 @@ button[data-tao-button]:disabled {
|
|
|
101
101
|
cursor: not-allowed;
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
+
[data-tao-button-icon] {
|
|
105
|
+
flex: none;
|
|
106
|
+
justify-content: center;
|
|
107
|
+
align-items: center;
|
|
108
|
+
width: 1.25em;
|
|
109
|
+
height: 1.25em;
|
|
110
|
+
display: inline-flex;
|
|
111
|
+
position: relative;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
[data-tao-button-icon-idle], [data-tao-button-icon-spin] {
|
|
115
|
+
transition: opacity var(--tao-motion-duration-fast) var(--tao-motion-ease-out);
|
|
116
|
+
justify-content: center;
|
|
117
|
+
align-items: center;
|
|
118
|
+
line-height: 0;
|
|
119
|
+
display: inline-flex;
|
|
120
|
+
position: absolute;
|
|
121
|
+
inset: 0;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
[data-tao-button-icon-idle] > svg, [data-tao-button-spinner] {
|
|
125
|
+
width: 1.25em;
|
|
126
|
+
height: 1.25em;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
[data-tao-button-icon]:not([data-tao-loading]) [data-tao-button-icon-spin] {
|
|
130
|
+
opacity: 0;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
[data-tao-button-icon]:not([data-tao-loading]) [data-tao-button-icon-idle] {
|
|
134
|
+
opacity: 1;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
[data-tao-button-icon][data-tao-loading] [data-tao-button-icon-idle] {
|
|
138
|
+
opacity: 0;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
[data-tao-button-icon][data-tao-loading] [data-tao-button-icon-spin] {
|
|
142
|
+
opacity: 1;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
[data-tao-button-spinner] {
|
|
146
|
+
animation: .8s linear infinite tao-button-spin;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
@keyframes tao-button-spin {
|
|
150
|
+
to {
|
|
151
|
+
transform: rotate(360deg);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
104
155
|
button[data-tao-button]:focus-visible {
|
|
105
156
|
box-shadow: 0 0 0 var(--tao-ring-width) var(--tao-control-outline);
|
|
106
157
|
outline: none;
|
|
@@ -8,8 +8,12 @@ export interface ButtonProps extends Omit<ButtonHTMLAttributes<HTMLButtonElement
|
|
|
8
8
|
size?: TaoSize;
|
|
9
9
|
disabled?: boolean;
|
|
10
10
|
loading?: boolean;
|
|
11
|
+
/** Left-leading decorative icon (non-loading state). */
|
|
12
|
+
icon?: ReactNode;
|
|
13
|
+
/** Icon shown while loading. Defaults to a built-in spinner. */
|
|
14
|
+
loadingIcon?: ReactNode;
|
|
11
15
|
children?: ReactNode;
|
|
12
16
|
classNames?: SemanticClassNames<ButtonSemanticPart>;
|
|
13
17
|
styles?: SemanticStyles<ButtonSemanticPart>;
|
|
14
18
|
}
|
|
15
|
-
export declare function Button({ variant, size, disabled, loading, children, className, style, classNames, styles, ...rest }: ButtonProps): import("react/jsx-runtime").JSX.Element;
|
|
19
|
+
export declare function Button({ variant, size, disabled, loading, icon, loadingIcon, children, className, style, classNames, styles, ...rest }: ButtonProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,73 +1,102 @@
|
|
|
1
|
-
import { jsx } from "react/jsx-runtime";
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { c } from "react/compiler-runtime";
|
|
3
3
|
import { useTaoConfig } from "../../provider/tao-provider.js";
|
|
4
4
|
import { cx } from "../../utils/semantic.js";
|
|
5
5
|
import "./button.css";
|
|
6
6
|
function Button(t0) {
|
|
7
|
-
const $ = c(
|
|
7
|
+
const $ = c(34);
|
|
8
8
|
let children;
|
|
9
9
|
let className;
|
|
10
10
|
let classNames;
|
|
11
11
|
let disabled;
|
|
12
|
+
let icon;
|
|
12
13
|
let loading;
|
|
14
|
+
let loadingIcon;
|
|
13
15
|
let rest;
|
|
14
16
|
let size;
|
|
15
17
|
let style;
|
|
16
18
|
let styles;
|
|
17
19
|
let t1;
|
|
18
20
|
if ($[0] !== t0) {
|
|
19
|
-
({ variant: t1, size, disabled, loading, children, className, style, classNames, styles, ...rest } = t0);
|
|
21
|
+
({ variant: t1, size, disabled, loading, icon, loadingIcon, children, className, style, classNames, styles, ...rest } = t0);
|
|
20
22
|
$[0] = t0;
|
|
21
23
|
$[1] = children;
|
|
22
24
|
$[2] = className;
|
|
23
25
|
$[3] = classNames;
|
|
24
26
|
$[4] = disabled;
|
|
25
|
-
$[5] =
|
|
26
|
-
$[6] =
|
|
27
|
-
$[7] =
|
|
28
|
-
$[8] =
|
|
29
|
-
$[9] =
|
|
30
|
-
$[10] =
|
|
27
|
+
$[5] = icon;
|
|
28
|
+
$[6] = loading;
|
|
29
|
+
$[7] = loadingIcon;
|
|
30
|
+
$[8] = rest;
|
|
31
|
+
$[9] = size;
|
|
32
|
+
$[10] = style;
|
|
33
|
+
$[11] = styles;
|
|
34
|
+
$[12] = t1;
|
|
31
35
|
} else {
|
|
32
36
|
children = $[1];
|
|
33
37
|
className = $[2];
|
|
34
38
|
classNames = $[3];
|
|
35
39
|
disabled = $[4];
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
icon = $[5];
|
|
41
|
+
loading = $[6];
|
|
42
|
+
loadingIcon = $[7];
|
|
43
|
+
rest = $[8];
|
|
44
|
+
size = $[9];
|
|
45
|
+
style = $[10];
|
|
46
|
+
styles = $[11];
|
|
47
|
+
t1 = $[12];
|
|
42
48
|
}
|
|
43
49
|
const variant = void 0 === t1 ? "primary" : t1;
|
|
44
50
|
const ctx = useTaoConfig();
|
|
45
51
|
const resolvedSize = size ?? ctx.size;
|
|
46
52
|
const resolvedDisabled = disabled ?? ctx.disabled ?? false;
|
|
47
53
|
const isDisabled = resolvedDisabled || loading;
|
|
54
|
+
const hasIconSlot = null != icon || loading;
|
|
48
55
|
const t2 = classNames?.root;
|
|
49
56
|
let t3;
|
|
50
|
-
if ($[
|
|
57
|
+
if ($[13] !== className || $[14] !== t2) {
|
|
51
58
|
t3 = cx(t2, className);
|
|
52
|
-
$[
|
|
53
|
-
$[
|
|
54
|
-
$[
|
|
55
|
-
} else t3 = $[
|
|
59
|
+
$[13] = className;
|
|
60
|
+
$[14] = t2;
|
|
61
|
+
$[15] = t3;
|
|
62
|
+
} else t3 = $[15];
|
|
56
63
|
const t4 = styles?.root;
|
|
57
64
|
let t5;
|
|
58
|
-
if ($[
|
|
65
|
+
if ($[16] !== style || $[17] !== t4) {
|
|
59
66
|
t5 = {
|
|
60
67
|
...t4,
|
|
61
68
|
...style
|
|
62
69
|
};
|
|
63
|
-
$[
|
|
64
|
-
$[
|
|
65
|
-
$[
|
|
66
|
-
} else t5 = $[
|
|
70
|
+
$[16] = style;
|
|
71
|
+
$[17] = t4;
|
|
72
|
+
$[18] = t5;
|
|
73
|
+
} else t5 = $[18];
|
|
67
74
|
const t6 = loading || void 0;
|
|
68
75
|
let t7;
|
|
69
|
-
if ($[
|
|
70
|
-
t7 = /*#__PURE__*/
|
|
76
|
+
if ($[19] !== hasIconSlot || $[20] !== icon || $[21] !== loading || $[22] !== loadingIcon) {
|
|
77
|
+
t7 = hasIconSlot && /*#__PURE__*/ jsxs("span", {
|
|
78
|
+
"data-tao-button-icon": "",
|
|
79
|
+
"data-tao-loading": loading || void 0,
|
|
80
|
+
children: [
|
|
81
|
+
null != icon && /*#__PURE__*/ jsx("span", {
|
|
82
|
+
"data-tao-button-icon-idle": "",
|
|
83
|
+
children: icon
|
|
84
|
+
}),
|
|
85
|
+
/*#__PURE__*/ jsx("span", {
|
|
86
|
+
"data-tao-button-icon-spin": "",
|
|
87
|
+
children: loadingIcon ?? /*#__PURE__*/ jsx(LoadingSpinner, {})
|
|
88
|
+
})
|
|
89
|
+
]
|
|
90
|
+
});
|
|
91
|
+
$[19] = hasIconSlot;
|
|
92
|
+
$[20] = icon;
|
|
93
|
+
$[21] = loading;
|
|
94
|
+
$[22] = loadingIcon;
|
|
95
|
+
$[23] = t7;
|
|
96
|
+
} else t7 = $[23];
|
|
97
|
+
let t8;
|
|
98
|
+
if ($[24] !== children || $[25] !== isDisabled || $[26] !== resolvedSize || $[27] !== rest || $[28] !== t3 || $[29] !== t5 || $[30] !== t6 || $[31] !== t7 || $[32] !== variant) {
|
|
99
|
+
t8 = /*#__PURE__*/ jsxs("button", {
|
|
71
100
|
type: "button",
|
|
72
101
|
...rest,
|
|
73
102
|
className: t3,
|
|
@@ -77,18 +106,46 @@ function Button(t0) {
|
|
|
77
106
|
"data-tao-button": "",
|
|
78
107
|
"data-tao-variant": variant,
|
|
79
108
|
"data-tao-size": resolvedSize,
|
|
80
|
-
children:
|
|
109
|
+
children: [
|
|
110
|
+
t7,
|
|
111
|
+
children
|
|
112
|
+
]
|
|
113
|
+
});
|
|
114
|
+
$[24] = children;
|
|
115
|
+
$[25] = isDisabled;
|
|
116
|
+
$[26] = resolvedSize;
|
|
117
|
+
$[27] = rest;
|
|
118
|
+
$[28] = t3;
|
|
119
|
+
$[29] = t5;
|
|
120
|
+
$[30] = t6;
|
|
121
|
+
$[31] = t7;
|
|
122
|
+
$[32] = variant;
|
|
123
|
+
$[33] = t8;
|
|
124
|
+
} else t8 = $[33];
|
|
125
|
+
return t8;
|
|
126
|
+
}
|
|
127
|
+
function LoadingSpinner() {
|
|
128
|
+
const $ = c(1);
|
|
129
|
+
let t0;
|
|
130
|
+
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
|
|
131
|
+
t0 = /*#__PURE__*/ jsx("svg", {
|
|
132
|
+
"data-tao-button-spinner": "",
|
|
133
|
+
viewBox: "0 0 50 50",
|
|
134
|
+
fill: "none",
|
|
135
|
+
"aria-hidden": "true",
|
|
136
|
+
focusable: "false",
|
|
137
|
+
children: /*#__PURE__*/ jsx("circle", {
|
|
138
|
+
cx: "25",
|
|
139
|
+
cy: "25",
|
|
140
|
+
r: "20",
|
|
141
|
+
stroke: "currentColor",
|
|
142
|
+
strokeWidth: "5",
|
|
143
|
+
strokeLinecap: "round",
|
|
144
|
+
strokeDasharray: "90 40"
|
|
145
|
+
})
|
|
81
146
|
});
|
|
82
|
-
$[
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
$[20] = rest;
|
|
86
|
-
$[21] = t3;
|
|
87
|
-
$[22] = t5;
|
|
88
|
-
$[23] = t6;
|
|
89
|
-
$[24] = variant;
|
|
90
|
-
$[25] = t7;
|
|
91
|
-
} else t7 = $[25];
|
|
92
|
-
return t7;
|
|
147
|
+
$[0] = t0;
|
|
148
|
+
} else t0 = $[0];
|
|
149
|
+
return t0;
|
|
93
150
|
}
|
|
94
151
|
export { Button };
|
|
@@ -30,17 +30,81 @@
|
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
[data-tao-sonner-toast] {
|
|
33
|
+
--tao-sonner-enter-y: 100%;
|
|
34
|
+
--tao-sonner-scale: 1;
|
|
35
|
+
--tao-sonner-y: translateY(var(--tao-sonner-enter-y));
|
|
33
36
|
pointer-events: auto;
|
|
34
37
|
border: 1px solid var(--tao-color-border);
|
|
35
38
|
background: var(--tao-color-bg-elevated);
|
|
36
39
|
color: var(--tao-color-text);
|
|
37
40
|
border-radius: var(--tao-radius-lg);
|
|
38
41
|
box-shadow: var(--tao-box-shadow-secondary);
|
|
42
|
+
opacity: 0;
|
|
43
|
+
min-width: 320px;
|
|
44
|
+
height: auto;
|
|
45
|
+
z-index: var(--tao-sonner-z-index, 1);
|
|
46
|
+
transform: var(--tao-sonner-y) scale(var(--tao-sonner-scale));
|
|
47
|
+
transition: transform var(--tao-motion-duration-slow) var(--tao-motion-ease-out-quint),
|
|
48
|
+
opacity var(--tao-motion-duration-slow) var(--tao-motion-ease-out-quint),
|
|
49
|
+
height var(--tao-motion-duration-slow) var(--tao-motion-ease-out-quint),
|
|
50
|
+
box-shadow var(--tao-motion-duration-mid) var(--tao-motion-ease-out);
|
|
39
51
|
align-items: flex-start;
|
|
40
52
|
gap: 12px;
|
|
41
|
-
min-width: 320px;
|
|
42
53
|
padding: 14px;
|
|
43
54
|
display: flex;
|
|
55
|
+
position: relative;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
[data-tao-sonner-toast][data-tao-y-position="top"] {
|
|
59
|
+
--tao-sonner-enter-y: -100%;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
[data-tao-sonner-toast][data-tao-mounted="true"] {
|
|
63
|
+
opacity: 1;
|
|
64
|
+
--tao-sonner-y: translateY(0);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
[data-tao-sonner-toast][data-tao-mounted="true"][data-tao-expanded="true"][data-tao-y-position="bottom"], [data-tao-sonner-toast][data-tao-mounted="true"][data-tao-expanded="true"][data-tao-y-position="top"] {
|
|
68
|
+
--tao-sonner-y: translateY(0);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
[data-tao-sonner-toast][data-tao-expanded="false"][data-tao-front="false"] {
|
|
72
|
+
height: var(--tao-sonner-front-height, auto);
|
|
73
|
+
--tao-sonner-scale: calc(1 - min(var(--tao-sonner-toasts-before), 2) * .03);
|
|
74
|
+
box-shadow: var(--tao-box-shadow-tertiary, var(--tao-box-shadow-secondary));
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
[data-tao-sonner-toast][data-tao-expanded="false"][data-tao-front="false"][data-tao-y-position="bottom"] {
|
|
78
|
+
--tao-sonner-y: translateY(calc(var(--tao-sonner-toasts-before) * -.65 * var(--tao-sonner-gap, 12px)));
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
[data-tao-sonner-toast][data-tao-expanded="false"][data-tao-front="false"][data-tao-y-position="top"] {
|
|
82
|
+
--tao-sonner-y: translateY(calc(var(--tao-sonner-toasts-before) * .65 * var(--tao-sonner-gap, 12px)));
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
[data-tao-sonner-toast][data-tao-expanded="false"][data-tao-front="false"] > * {
|
|
86
|
+
opacity: .18;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
[data-tao-sonner-toast][data-tao-visible="false"] {
|
|
90
|
+
opacity: 0;
|
|
91
|
+
pointer-events: none;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
[data-tao-sonner-toast][data-tao-removing="true"] {
|
|
95
|
+
opacity: 0;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
[data-tao-sonner-toast][data-tao-removing="true"][data-tao-front="true"][data-tao-y-position="top"] {
|
|
99
|
+
--tao-sonner-y: translateY(-100%);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
[data-tao-sonner-toast][data-tao-removing="true"][data-tao-front="true"][data-tao-y-position="bottom"] {
|
|
103
|
+
--tao-sonner-y: translateY(100%);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
[data-tao-sonner-toast][data-tao-removing="true"][data-tao-front="false"][data-tao-y-position="top"], [data-tao-sonner-toast][data-tao-removing="true"][data-tao-front="false"][data-tao-y-position="bottom"] {
|
|
107
|
+
--tao-sonner-y: translateY(40%);
|
|
44
108
|
}
|
|
45
109
|
|
|
46
110
|
[data-tao-sonner-toast][data-tao-type="success"] {
|
|
@@ -59,13 +123,24 @@
|
|
|
59
123
|
}
|
|
60
124
|
|
|
61
125
|
[data-tao-sonner-toast][data-tao-type="info"] {
|
|
62
|
-
background:
|
|
126
|
+
background: var(--tao-primary-bg);
|
|
63
127
|
border-color: var(--tao-primary-border);
|
|
128
|
+
color: var(--tao-color-primary);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
[data-tao-sonner-toast][data-tao-type="info"] [data-tao-sonner-description] {
|
|
132
|
+
color: inherit;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
[data-tao-sonner-toast][data-tao-type="info"] [data-tao-sonner-close] {
|
|
136
|
+
color: var(--tao-color-primary);
|
|
64
137
|
}
|
|
65
138
|
|
|
66
139
|
[data-tao-sonner-content] {
|
|
67
|
-
flex: 1;
|
|
68
140
|
min-width: 0;
|
|
141
|
+
transition: opacity var(--tao-motion-duration-slow) var(--tao-motion-ease-out-quint);
|
|
142
|
+
flex: 1;
|
|
143
|
+
padding-right: 28px;
|
|
69
144
|
}
|
|
70
145
|
|
|
71
146
|
[data-tao-sonner-title] {
|
|
@@ -82,28 +157,56 @@
|
|
|
82
157
|
}
|
|
83
158
|
|
|
84
159
|
[data-tao-sonner-actions] {
|
|
160
|
+
transition: opacity var(--tao-motion-duration-slow) var(--tao-motion-ease-out-quint);
|
|
85
161
|
flex-shrink: 0;
|
|
86
|
-
align-items:
|
|
162
|
+
align-items: flex-start;
|
|
87
163
|
gap: 8px;
|
|
88
164
|
display: flex;
|
|
89
165
|
}
|
|
90
166
|
|
|
167
|
+
[data-tao-sonner-actions]:not([data-tao-close-only]) {
|
|
168
|
+
padding-right: 22px;
|
|
169
|
+
position: relative;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
[data-tao-sonner-actions][data-tao-close-only] {
|
|
173
|
+
position: absolute;
|
|
174
|
+
top: 12px;
|
|
175
|
+
right: 12px;
|
|
176
|
+
}
|
|
177
|
+
|
|
91
178
|
[data-tao-sonner-close] {
|
|
92
179
|
appearance: none;
|
|
93
180
|
color: var(--tao-color-text-tertiary);
|
|
94
|
-
border-radius: var(--tao-radius-sm);
|
|
95
181
|
cursor: pointer;
|
|
96
|
-
width:
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
182
|
+
width: 18px;
|
|
183
|
+
min-width: 18px;
|
|
184
|
+
height: 18px;
|
|
185
|
+
transition: color var(--tao-motion-duration-fast) var(--tao-motion-ease-out);
|
|
100
186
|
background: none;
|
|
101
187
|
border: 0;
|
|
188
|
+
justify-content: center;
|
|
189
|
+
align-items: center;
|
|
190
|
+
padding: 0;
|
|
191
|
+
font-size: 18px;
|
|
192
|
+
line-height: 1;
|
|
193
|
+
display: inline-flex;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
[data-tao-sonner-actions][data-tao-close-only] [data-tao-sonner-close] {
|
|
197
|
+
position: absolute;
|
|
198
|
+
top: 0;
|
|
199
|
+
right: 0;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
[data-tao-sonner-actions]:not([data-tao-close-only]) [data-tao-sonner-close] {
|
|
203
|
+
position: absolute;
|
|
204
|
+
top: 1px;
|
|
205
|
+
right: 0;
|
|
102
206
|
}
|
|
103
207
|
|
|
104
208
|
[data-tao-sonner-close]:hover {
|
|
105
209
|
color: var(--tao-color-text);
|
|
106
|
-
background: var(--tao-color-fill-secondary);
|
|
107
210
|
}
|
|
108
211
|
|
|
109
212
|
@media (width <= 640px) {
|
|
@@ -2,7 +2,7 @@ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
import { TaoPortalScope, useTaoConfig } from "../../provider/tao-provider.js";
|
|
3
3
|
import { cx } from "../../utils/semantic.js";
|
|
4
4
|
import { Button } from "../button/button.js";
|
|
5
|
-
import { useEffect, useMemo, useSyncExternalStore } from "react";
|
|
5
|
+
import { useEffect, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
|
|
6
6
|
import "./sonner.css";
|
|
7
7
|
const listeners = new Set();
|
|
8
8
|
let state = {
|
|
@@ -10,6 +10,8 @@ let state = {
|
|
|
10
10
|
};
|
|
11
11
|
let seed = 0;
|
|
12
12
|
const timers = new Map();
|
|
13
|
+
const removeTimers = new Map();
|
|
14
|
+
const REMOVE_DELAY = 220;
|
|
13
15
|
function emit() {
|
|
14
16
|
listeners.forEach((listener)=>listener());
|
|
15
17
|
}
|
|
@@ -27,20 +29,51 @@ function clearTimer(id) {
|
|
|
27
29
|
timers.delete(id);
|
|
28
30
|
}
|
|
29
31
|
}
|
|
32
|
+
function clearRemoveTimer(id) {
|
|
33
|
+
const timer = removeTimers.get(id);
|
|
34
|
+
if (timer) {
|
|
35
|
+
clearTimeout(timer);
|
|
36
|
+
removeTimers.delete(id);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
30
39
|
function dismiss(id) {
|
|
31
40
|
if (!id) {
|
|
32
41
|
state.toasts.forEach((toast)=>clearTimer(toast.id));
|
|
42
|
+
state.toasts.forEach((toast)=>clearRemoveTimer(toast.id));
|
|
33
43
|
state = {
|
|
34
|
-
toasts:
|
|
44
|
+
toasts: state.toasts.map((toast)=>({
|
|
45
|
+
...toast,
|
|
46
|
+
removing: true
|
|
47
|
+
}))
|
|
35
48
|
};
|
|
36
49
|
emit();
|
|
50
|
+
state.toasts.forEach((toast)=>{
|
|
51
|
+
removeTimers.set(toast.id, setTimeout(()=>{
|
|
52
|
+
removeTimers.delete(toast.id);
|
|
53
|
+
state = {
|
|
54
|
+
toasts: state.toasts.filter((item)=>item.id !== toast.id)
|
|
55
|
+
};
|
|
56
|
+
emit();
|
|
57
|
+
}, REMOVE_DELAY));
|
|
58
|
+
});
|
|
37
59
|
return;
|
|
38
60
|
}
|
|
39
61
|
clearTimer(id);
|
|
62
|
+
clearRemoveTimer(id);
|
|
40
63
|
state = {
|
|
41
|
-
toasts: state.toasts.
|
|
64
|
+
toasts: state.toasts.map((toast)=>toast.id === id ? {
|
|
65
|
+
...toast,
|
|
66
|
+
removing: true
|
|
67
|
+
} : toast)
|
|
42
68
|
};
|
|
43
69
|
emit();
|
|
70
|
+
removeTimers.set(id, setTimeout(()=>{
|
|
71
|
+
removeTimers.delete(id);
|
|
72
|
+
state = {
|
|
73
|
+
toasts: state.toasts.filter((toast)=>toast.id !== id)
|
|
74
|
+
};
|
|
75
|
+
emit();
|
|
76
|
+
}, REMOVE_DELAY));
|
|
44
77
|
}
|
|
45
78
|
function scheduleDismiss(id, duration) {
|
|
46
79
|
clearTimer(id);
|
|
@@ -107,6 +140,7 @@ function renderPromiseState(stateValue, payload) {
|
|
|
107
140
|
function Sonner({ position = 'bottom-right', visibleToasts = 3, offset = 24, gap = 12, expand = true, richColors = false, closeButton = false, duration = 4000, className, style, classNames, styles }) {
|
|
108
141
|
useTaoConfig();
|
|
109
142
|
const snapshot = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
|
|
143
|
+
const [heights, setHeights] = useState([]);
|
|
110
144
|
useEffect(()=>{
|
|
111
145
|
for (const toast of snapshot.toasts)if (!timers.has(toast.id)) scheduleDismiss(toast.id, toast.duration ?? duration);
|
|
112
146
|
}, [
|
|
@@ -122,6 +156,7 @@ function Sonner({ position = 'bottom-right', visibleToasts = 3, offset = 24, gap
|
|
|
122
156
|
snapshot.toasts,
|
|
123
157
|
visibleToasts
|
|
124
158
|
]);
|
|
159
|
+
const frontToastHeight = heights[0]?.height ?? 0;
|
|
125
160
|
return /*#__PURE__*/ jsx(TaoPortalScope, {
|
|
126
161
|
children: /*#__PURE__*/ jsx("div", {
|
|
127
162
|
className: cx(classNames?.viewport, className),
|
|
@@ -129,86 +164,166 @@ function Sonner({ position = 'bottom-right', visibleToasts = 3, offset = 24, gap
|
|
|
129
164
|
...styles?.viewport,
|
|
130
165
|
...style,
|
|
131
166
|
['--tao-sonner-offset']: `${offset}px`,
|
|
132
|
-
['--tao-sonner-gap']: `${gap}px
|
|
167
|
+
['--tao-sonner-gap']: `${gap}px`,
|
|
168
|
+
['--tao-sonner-front-height']: `${frontToastHeight}px`
|
|
133
169
|
},
|
|
134
170
|
"data-tao-sonner-viewport": "",
|
|
135
171
|
"data-tao-position": position,
|
|
136
|
-
children: visible.map((toast_0)=>{
|
|
172
|
+
children: visible.map((toast_0, index)=>{
|
|
137
173
|
const showClose = toast_0.closable ?? closeButton;
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
toast_0.title ? /*#__PURE__*/ jsx("div", {
|
|
154
|
-
className: cx(classNames?.title),
|
|
155
|
-
style: styles?.title,
|
|
156
|
-
"data-tao-sonner-title": "",
|
|
157
|
-
children: toast_0.title
|
|
158
|
-
}) : null,
|
|
159
|
-
toast_0.description ? /*#__PURE__*/ jsx("div", {
|
|
160
|
-
className: cx(classNames?.description),
|
|
161
|
-
style: styles?.description,
|
|
162
|
-
"data-tao-sonner-description": "",
|
|
163
|
-
children: toast_0.description
|
|
164
|
-
}) : null
|
|
165
|
-
]
|
|
166
|
-
}),
|
|
167
|
-
(toast_0.action || toast_0.cancel || showClose) && /*#__PURE__*/ jsxs("div", {
|
|
168
|
-
className: cx(classNames?.actions),
|
|
169
|
-
style: styles?.actions,
|
|
170
|
-
"data-tao-sonner-actions": "",
|
|
171
|
-
children: [
|
|
172
|
-
toast_0.cancel ? /*#__PURE__*/ jsx(Button, {
|
|
173
|
-
variant: "ghost",
|
|
174
|
-
size: "small",
|
|
175
|
-
className: cx(classNames?.cancel),
|
|
176
|
-
style: styles?.cancel,
|
|
177
|
-
onClick: ()=>{
|
|
178
|
-
toast_0.cancel?.onClick?.();
|
|
179
|
-
dismiss(toast_0.id);
|
|
180
|
-
},
|
|
181
|
-
children: toast_0.cancel.label
|
|
182
|
-
}) : null,
|
|
183
|
-
toast_0.action ? /*#__PURE__*/ jsx(Button, {
|
|
184
|
-
variant: "secondary",
|
|
185
|
-
size: "small",
|
|
186
|
-
className: cx(classNames?.action),
|
|
187
|
-
style: styles?.action,
|
|
188
|
-
onClick: ()=>{
|
|
189
|
-
toast_0.action?.onClick?.();
|
|
190
|
-
dismiss(toast_0.id);
|
|
191
|
-
},
|
|
192
|
-
children: toast_0.action.label
|
|
193
|
-
}) : null,
|
|
194
|
-
showClose ? /*#__PURE__*/ jsx("button", {
|
|
195
|
-
type: "button",
|
|
196
|
-
"aria-label": "Close notification",
|
|
197
|
-
className: cx(classNames?.close),
|
|
198
|
-
style: styles?.close,
|
|
199
|
-
"data-tao-sonner-close": "",
|
|
200
|
-
onClick: ()=>dismiss(toast_0.id),
|
|
201
|
-
children: "\xd7"
|
|
202
|
-
}) : null
|
|
203
|
-
]
|
|
204
|
-
})
|
|
205
|
-
]
|
|
206
|
-
})
|
|
174
|
+
const yPosition = position.startsWith('top') ? 'top' : 'bottom';
|
|
175
|
+
return /*#__PURE__*/ jsx(ToastView, {
|
|
176
|
+
toast: toast_0,
|
|
177
|
+
richColors: richColors,
|
|
178
|
+
showClose: showClose,
|
|
179
|
+
yPosition: yPosition,
|
|
180
|
+
index: index,
|
|
181
|
+
visibleToasts: visible.length,
|
|
182
|
+
expanded: expand,
|
|
183
|
+
gap: gap,
|
|
184
|
+
heights: heights,
|
|
185
|
+
frontToastHeight: frontToastHeight,
|
|
186
|
+
setHeights: setHeights,
|
|
187
|
+
classNames: classNames,
|
|
188
|
+
styles: styles
|
|
207
189
|
}, toast_0.id);
|
|
208
190
|
})
|
|
209
191
|
})
|
|
210
192
|
});
|
|
211
193
|
}
|
|
194
|
+
function ToastView({ toast, richColors, showClose, yPosition, index, visibleToasts, expanded, gap, heights, frontToastHeight, setHeights, classNames, styles }) {
|
|
195
|
+
const [mounted, setMounted] = useState(false);
|
|
196
|
+
const [offsetBeforeRemove, setOffsetBeforeRemove] = useState(0);
|
|
197
|
+
const ref = useRef(null);
|
|
198
|
+
const offset = useMemo(()=>heights.slice(0, index).reduce((sum, item)=>sum + item.height, 0) + index * gap, [
|
|
199
|
+
gap,
|
|
200
|
+
heights,
|
|
201
|
+
index
|
|
202
|
+
]);
|
|
203
|
+
useEffect(()=>{
|
|
204
|
+
const frame = requestAnimationFrame(()=>setMounted(true));
|
|
205
|
+
return ()=>cancelAnimationFrame(frame);
|
|
206
|
+
}, []);
|
|
207
|
+
useEffect(()=>{
|
|
208
|
+
if (toast.removing) setOffsetBeforeRemove(offset);
|
|
209
|
+
}, [
|
|
210
|
+
offset,
|
|
211
|
+
toast.removing
|
|
212
|
+
]);
|
|
213
|
+
useLayoutEffect(()=>{
|
|
214
|
+
const node = ref.current;
|
|
215
|
+
if (!node) return;
|
|
216
|
+
const nextHeight = node.getBoundingClientRect().height;
|
|
217
|
+
setHeights((current)=>{
|
|
218
|
+
const filtered = current.filter((item_0)=>item_0.id !== toast.id);
|
|
219
|
+
return [
|
|
220
|
+
...filtered,
|
|
221
|
+
{
|
|
222
|
+
id: toast.id,
|
|
223
|
+
height: nextHeight
|
|
224
|
+
}
|
|
225
|
+
];
|
|
226
|
+
});
|
|
227
|
+
return ()=>{
|
|
228
|
+
setHeights((current_0)=>current_0.filter((item_1)=>item_1.id !== toast.id));
|
|
229
|
+
};
|
|
230
|
+
}, [
|
|
231
|
+
setHeights,
|
|
232
|
+
toast.description,
|
|
233
|
+
toast.id,
|
|
234
|
+
toast.title,
|
|
235
|
+
toast.action,
|
|
236
|
+
toast.cancel,
|
|
237
|
+
toast.custom
|
|
238
|
+
]);
|
|
239
|
+
const isFront = 0 === index;
|
|
240
|
+
const isVisible = index < visibleToasts;
|
|
241
|
+
const activeOffset = toast.removing ? offsetBeforeRemove : offset;
|
|
242
|
+
return /*#__PURE__*/ jsx("div", {
|
|
243
|
+
ref: ref,
|
|
244
|
+
className: cx(classNames?.toast),
|
|
245
|
+
role: "status",
|
|
246
|
+
"aria-live": "polite",
|
|
247
|
+
"aria-label": getAriaLabel(toast.type),
|
|
248
|
+
"data-tao-sonner-toast": "",
|
|
249
|
+
"data-tao-type": resolveDataType(toast.type, richColors),
|
|
250
|
+
"data-tao-mounted": mounted,
|
|
251
|
+
"data-tao-y-position": yPosition,
|
|
252
|
+
"data-tao-removing": toast.removing ? 'true' : 'false',
|
|
253
|
+
"data-tao-front": isFront ? 'true' : 'false',
|
|
254
|
+
"data-tao-expanded": expanded ? 'true' : 'false',
|
|
255
|
+
"data-tao-visible": isVisible ? 'true' : 'false',
|
|
256
|
+
style: {
|
|
257
|
+
...styles?.toast,
|
|
258
|
+
['--tao-sonner-toasts-before']: String(index),
|
|
259
|
+
['--tao-sonner-offset-y']: `${activeOffset}px`,
|
|
260
|
+
['--tao-sonner-front-height']: `${frontToastHeight}px`,
|
|
261
|
+
['--tao-sonner-z-index']: String(visibleToasts - index)
|
|
262
|
+
},
|
|
263
|
+
children: toast.custom ? toast.custom : /*#__PURE__*/ jsxs(Fragment, {
|
|
264
|
+
children: [
|
|
265
|
+
/*#__PURE__*/ jsxs("div", {
|
|
266
|
+
className: cx(classNames?.content),
|
|
267
|
+
style: styles?.content,
|
|
268
|
+
"data-tao-sonner-content": "",
|
|
269
|
+
children: [
|
|
270
|
+
toast.title ? /*#__PURE__*/ jsx("div", {
|
|
271
|
+
className: cx(classNames?.title),
|
|
272
|
+
style: styles?.title,
|
|
273
|
+
"data-tao-sonner-title": "",
|
|
274
|
+
children: toast.title
|
|
275
|
+
}) : null,
|
|
276
|
+
toast.description ? /*#__PURE__*/ jsx("div", {
|
|
277
|
+
className: cx(classNames?.description),
|
|
278
|
+
style: styles?.description,
|
|
279
|
+
"data-tao-sonner-description": "",
|
|
280
|
+
children: toast.description
|
|
281
|
+
}) : null
|
|
282
|
+
]
|
|
283
|
+
}),
|
|
284
|
+
(toast.action || toast.cancel || showClose) && /*#__PURE__*/ jsxs("div", {
|
|
285
|
+
className: cx(classNames?.actions),
|
|
286
|
+
style: styles?.actions,
|
|
287
|
+
"data-tao-sonner-actions": "",
|
|
288
|
+
"data-tao-close-only": toast.action || toast.cancel || !showClose ? void 0 : '',
|
|
289
|
+
children: [
|
|
290
|
+
toast.cancel ? /*#__PURE__*/ jsx(Button, {
|
|
291
|
+
variant: "ghost",
|
|
292
|
+
size: "small",
|
|
293
|
+
className: cx(classNames?.cancel),
|
|
294
|
+
style: styles?.cancel,
|
|
295
|
+
onClick: ()=>{
|
|
296
|
+
toast.cancel?.onClick?.();
|
|
297
|
+
dismiss(toast.id);
|
|
298
|
+
},
|
|
299
|
+
children: toast.cancel.label
|
|
300
|
+
}) : null,
|
|
301
|
+
toast.action ? /*#__PURE__*/ jsx(Button, {
|
|
302
|
+
variant: "secondary",
|
|
303
|
+
size: "small",
|
|
304
|
+
className: cx(classNames?.action),
|
|
305
|
+
style: styles?.action,
|
|
306
|
+
onClick: ()=>{
|
|
307
|
+
toast.action?.onClick?.();
|
|
308
|
+
dismiss(toast.id);
|
|
309
|
+
},
|
|
310
|
+
children: toast.action.label
|
|
311
|
+
}) : null,
|
|
312
|
+
showClose ? /*#__PURE__*/ jsx("button", {
|
|
313
|
+
type: "button",
|
|
314
|
+
"aria-label": "Close notification",
|
|
315
|
+
className: cx(classNames?.close),
|
|
316
|
+
style: styles?.close,
|
|
317
|
+
"data-tao-sonner-close": "",
|
|
318
|
+
onClick: ()=>dismiss(toast.id),
|
|
319
|
+
children: "\xd7"
|
|
320
|
+
}) : null
|
|
321
|
+
]
|
|
322
|
+
})
|
|
323
|
+
]
|
|
324
|
+
})
|
|
325
|
+
});
|
|
326
|
+
}
|
|
212
327
|
const baseToast = (options)=>create('default', options);
|
|
213
328
|
const sonner_toast = Object.assign(baseToast, {
|
|
214
329
|
success: (options)=>create('success', options),
|