@rockshin/tao-ui 0.0.14 → 0.0.16
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/component-manifest.json +645 -147
- package/dist/components/sonner/index.d.ts +1 -0
- package/dist/components/sonner/index.js +1 -0
- package/dist/components/sonner/sonner.css +221 -0
- package/dist/components/sonner/sonner.d.ts +58 -0
- package/dist/components/sonner/sonner.js +364 -0
- package/dist/docs/component-docs.js +2 -0
- package/dist/docs/components/sonner.doc.d.ts +18 -0
- package/dist/docs/components/sonner.doc.js +47 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/llms.txt +14 -1
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Sonner, toast, type SonnerAction, type SonnerPosition, type SonnerPromiseMessages, type SonnerProps, type SonnerSemanticPart, type SonnerToastItem, type SonnerToastOptions, type SonnerType, } from './sonner';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Sonner, toast } from "./sonner.js";
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
[data-tao-sonner-viewport] {
|
|
2
|
+
z-index: var(--tao-z-index-popup);
|
|
3
|
+
gap: var(--tao-sonner-gap, 12px);
|
|
4
|
+
pointer-events: none;
|
|
5
|
+
max-width: min(420px, calc(100vw - var(--tao-sonner-offset, 24px) * 2));
|
|
6
|
+
flex-direction: column;
|
|
7
|
+
display: flex;
|
|
8
|
+
position: fixed;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
[data-tao-sonner-viewport][data-tao-position^="top"] {
|
|
12
|
+
top: var(--tao-sonner-offset, 24px);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
[data-tao-sonner-viewport][data-tao-position^="bottom"] {
|
|
16
|
+
bottom: var(--tao-sonner-offset, 24px);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
[data-tao-sonner-viewport][data-tao-position$="left"] {
|
|
20
|
+
left: var(--tao-sonner-offset, 24px);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
[data-tao-sonner-viewport][data-tao-position$="right"] {
|
|
24
|
+
right: var(--tao-sonner-offset, 24px);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
[data-tao-sonner-viewport][data-tao-position$="center"] {
|
|
28
|
+
left: 50%;
|
|
29
|
+
transform: translateX(-50%);
|
|
30
|
+
}
|
|
31
|
+
|
|
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));
|
|
36
|
+
pointer-events: auto;
|
|
37
|
+
border: 1px solid var(--tao-color-border);
|
|
38
|
+
background: var(--tao-color-bg-elevated);
|
|
39
|
+
color: var(--tao-color-text);
|
|
40
|
+
border-radius: var(--tao-radius-lg);
|
|
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);
|
|
51
|
+
align-items: flex-start;
|
|
52
|
+
gap: 12px;
|
|
53
|
+
padding: 14px;
|
|
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%);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
[data-tao-sonner-toast][data-tao-type="success"] {
|
|
111
|
+
background: var(--tao-success-bg);
|
|
112
|
+
border-color: var(--tao-success-border);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
[data-tao-sonner-toast][data-tao-type="error"] {
|
|
116
|
+
background: var(--tao-error-bg);
|
|
117
|
+
border-color: var(--tao-error-border);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
[data-tao-sonner-toast][data-tao-type="warning"] {
|
|
121
|
+
background: var(--tao-warning-bg);
|
|
122
|
+
border-color: var(--tao-warning-border);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
[data-tao-sonner-toast][data-tao-type="info"] {
|
|
126
|
+
background: var(--tao-primary-bg);
|
|
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);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
[data-tao-sonner-content] {
|
|
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;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
[data-tao-sonner-title] {
|
|
147
|
+
font-size: var(--tao-font-size-base);
|
|
148
|
+
font-weight: var(--tao-font-weight-strong);
|
|
149
|
+
line-height: var(--tao-line-height);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
[data-tao-sonner-description] {
|
|
153
|
+
font-size: var(--tao-font-size-sm);
|
|
154
|
+
color: var(--tao-color-text-secondary);
|
|
155
|
+
line-height: var(--tao-line-height);
|
|
156
|
+
margin-top: 4px;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
[data-tao-sonner-actions] {
|
|
160
|
+
transition: opacity var(--tao-motion-duration-slow) var(--tao-motion-ease-out-quint);
|
|
161
|
+
flex-shrink: 0;
|
|
162
|
+
align-items: flex-start;
|
|
163
|
+
gap: 8px;
|
|
164
|
+
display: flex;
|
|
165
|
+
}
|
|
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
|
+
|
|
178
|
+
[data-tao-sonner-close] {
|
|
179
|
+
appearance: none;
|
|
180
|
+
color: var(--tao-color-text-tertiary);
|
|
181
|
+
cursor: pointer;
|
|
182
|
+
width: 18px;
|
|
183
|
+
min-width: 18px;
|
|
184
|
+
height: 18px;
|
|
185
|
+
transition: color var(--tao-motion-duration-fast) var(--tao-motion-ease-out);
|
|
186
|
+
background: none;
|
|
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;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
[data-tao-sonner-close]:hover {
|
|
209
|
+
color: var(--tao-color-text);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
@media (width <= 640px) {
|
|
213
|
+
[data-tao-sonner-viewport] {
|
|
214
|
+
max-width: calc(100vw - var(--tao-sonner-offset, 24px) * 2);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
[data-tao-sonner-toast] {
|
|
218
|
+
min-width: 0;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { type SemanticClassNames, type SemanticStyles } from '../../utils/semantic';
|
|
2
|
+
import type { CSSProperties, ReactNode } from 'react';
|
|
3
|
+
import './sonner.css';
|
|
4
|
+
export type SonnerSemanticPart = 'viewport' | 'toast' | 'content' | 'title' | 'description' | 'actions' | 'action' | 'cancel' | 'close';
|
|
5
|
+
export type SonnerType = 'default' | 'success' | 'error' | 'warning' | 'info' | 'loading' | 'custom';
|
|
6
|
+
export type SonnerPosition = 'top-left' | 'top-center' | 'top-right' | 'bottom-left' | 'bottom-center' | 'bottom-right';
|
|
7
|
+
export interface SonnerAction {
|
|
8
|
+
label: ReactNode;
|
|
9
|
+
onClick?: () => void;
|
|
10
|
+
}
|
|
11
|
+
export interface SonnerToastOptions {
|
|
12
|
+
id?: string;
|
|
13
|
+
title?: ReactNode;
|
|
14
|
+
description?: ReactNode;
|
|
15
|
+
action?: SonnerAction;
|
|
16
|
+
cancel?: SonnerAction;
|
|
17
|
+
duration?: number;
|
|
18
|
+
closable?: boolean;
|
|
19
|
+
}
|
|
20
|
+
export interface SonnerPromiseMessages<T> {
|
|
21
|
+
loading: SonnerToastOptions | ReactNode;
|
|
22
|
+
success?: SonnerToastOptions | ReactNode | ((value: T) => SonnerToastOptions | ReactNode);
|
|
23
|
+
error?: SonnerToastOptions | ReactNode | ((error: unknown) => SonnerToastOptions | ReactNode);
|
|
24
|
+
}
|
|
25
|
+
export interface SonnerToastItem extends SonnerToastOptions {
|
|
26
|
+
id: string;
|
|
27
|
+
type: SonnerType;
|
|
28
|
+
createdAt: number;
|
|
29
|
+
custom?: ReactNode;
|
|
30
|
+
removing?: boolean;
|
|
31
|
+
}
|
|
32
|
+
export interface SonnerProps {
|
|
33
|
+
position?: SonnerPosition;
|
|
34
|
+
visibleToasts?: number;
|
|
35
|
+
offset?: number;
|
|
36
|
+
gap?: number;
|
|
37
|
+
expand?: boolean;
|
|
38
|
+
richColors?: boolean;
|
|
39
|
+
closeButton?: boolean;
|
|
40
|
+
duration?: number;
|
|
41
|
+
className?: string;
|
|
42
|
+
style?: CSSProperties;
|
|
43
|
+
classNames?: SemanticClassNames<SonnerSemanticPart>;
|
|
44
|
+
styles?: SemanticStyles<SonnerSemanticPart>;
|
|
45
|
+
}
|
|
46
|
+
declare function dismiss(id?: string): void;
|
|
47
|
+
export declare function Sonner({ position, visibleToasts, offset, gap, expand, richColors, closeButton, duration, className, style, classNames, styles, }: SonnerProps): import("react/jsx-runtime").JSX.Element;
|
|
48
|
+
export declare const toast: ((options: SonnerToastOptions | ReactNode) => string) & {
|
|
49
|
+
success: (options: SonnerToastOptions | ReactNode) => string;
|
|
50
|
+
error: (options: SonnerToastOptions | ReactNode) => string;
|
|
51
|
+
warning: (options: SonnerToastOptions | ReactNode) => string;
|
|
52
|
+
info: (options: SonnerToastOptions | ReactNode) => string;
|
|
53
|
+
loading: (options: SonnerToastOptions | ReactNode) => string;
|
|
54
|
+
custom: (node: ReactNode, options?: Omit<SonnerToastOptions, "title" | "description">) => string;
|
|
55
|
+
promise: <T>(promise: Promise<T>, messages: SonnerPromiseMessages<T>) => Promise<T>;
|
|
56
|
+
dismiss: typeof dismiss;
|
|
57
|
+
};
|
|
58
|
+
export {};
|
|
@@ -0,0 +1,364 @@
|
|
|
1
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { TaoPortalScope, useTaoConfig } from "../../provider/tao-provider.js";
|
|
3
|
+
import { cx } from "../../utils/semantic.js";
|
|
4
|
+
import { Button } from "../button/button.js";
|
|
5
|
+
import { useEffect, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
|
|
6
|
+
import "./sonner.css";
|
|
7
|
+
const listeners = new Set();
|
|
8
|
+
let state = {
|
|
9
|
+
toasts: []
|
|
10
|
+
};
|
|
11
|
+
let seed = 0;
|
|
12
|
+
const timers = new Map();
|
|
13
|
+
const removeTimers = new Map();
|
|
14
|
+
const REMOVE_DELAY = 220;
|
|
15
|
+
function emit() {
|
|
16
|
+
listeners.forEach((listener)=>listener());
|
|
17
|
+
}
|
|
18
|
+
function subscribe(listener) {
|
|
19
|
+
listeners.add(listener);
|
|
20
|
+
return ()=>listeners.delete(listener);
|
|
21
|
+
}
|
|
22
|
+
function getSnapshot() {
|
|
23
|
+
return state;
|
|
24
|
+
}
|
|
25
|
+
function clearTimer(id) {
|
|
26
|
+
const timer = timers.get(id);
|
|
27
|
+
if (timer) {
|
|
28
|
+
clearTimeout(timer);
|
|
29
|
+
timers.delete(id);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function clearRemoveTimer(id) {
|
|
33
|
+
const timer = removeTimers.get(id);
|
|
34
|
+
if (timer) {
|
|
35
|
+
clearTimeout(timer);
|
|
36
|
+
removeTimers.delete(id);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
function dismiss(id) {
|
|
40
|
+
if (!id) {
|
|
41
|
+
state.toasts.forEach((toast)=>clearTimer(toast.id));
|
|
42
|
+
state.toasts.forEach((toast)=>clearRemoveTimer(toast.id));
|
|
43
|
+
state = {
|
|
44
|
+
toasts: state.toasts.map((toast)=>({
|
|
45
|
+
...toast,
|
|
46
|
+
removing: true
|
|
47
|
+
}))
|
|
48
|
+
};
|
|
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
|
+
});
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
clearTimer(id);
|
|
62
|
+
clearRemoveTimer(id);
|
|
63
|
+
state = {
|
|
64
|
+
toasts: state.toasts.map((toast)=>toast.id === id ? {
|
|
65
|
+
...toast,
|
|
66
|
+
removing: true
|
|
67
|
+
} : toast)
|
|
68
|
+
};
|
|
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));
|
|
77
|
+
}
|
|
78
|
+
function scheduleDismiss(id, duration) {
|
|
79
|
+
clearTimer(id);
|
|
80
|
+
if (null == duration || duration <= 0) return;
|
|
81
|
+
timers.set(id, setTimeout(()=>{
|
|
82
|
+
dismiss(id);
|
|
83
|
+
}, duration));
|
|
84
|
+
}
|
|
85
|
+
function isToastOptions(value) {
|
|
86
|
+
return null != value && 'object' == typeof value && !Array.isArray(value) && !('$$typeof' in value);
|
|
87
|
+
}
|
|
88
|
+
function normalizeOptions(options) {
|
|
89
|
+
return isToastOptions(options) ? options : {
|
|
90
|
+
title: options
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
function create(type, options, custom) {
|
|
94
|
+
const normalized = normalizeOptions(options);
|
|
95
|
+
const id = normalized.id ?? `toast-${Date.now()}-${seed++}`;
|
|
96
|
+
const next = {
|
|
97
|
+
...normalized,
|
|
98
|
+
id,
|
|
99
|
+
type,
|
|
100
|
+
createdAt: Date.now(),
|
|
101
|
+
custom
|
|
102
|
+
};
|
|
103
|
+
state = {
|
|
104
|
+
toasts: [
|
|
105
|
+
...state.toasts.filter((toast)=>toast.id !== id),
|
|
106
|
+
next
|
|
107
|
+
]
|
|
108
|
+
};
|
|
109
|
+
emit();
|
|
110
|
+
scheduleDismiss(id, normalized.duration);
|
|
111
|
+
return id;
|
|
112
|
+
}
|
|
113
|
+
function resolveDataType(type, richColors) {
|
|
114
|
+
if ('custom' === type) return 'custom';
|
|
115
|
+
if ('loading' === type) return 'loading';
|
|
116
|
+
if (!richColors) return 'default';
|
|
117
|
+
return type;
|
|
118
|
+
}
|
|
119
|
+
function getAriaLabel(type) {
|
|
120
|
+
switch(type){
|
|
121
|
+
case 'success':
|
|
122
|
+
return 'Success notification';
|
|
123
|
+
case 'error':
|
|
124
|
+
return 'Error notification';
|
|
125
|
+
case 'warning':
|
|
126
|
+
return 'Warning notification';
|
|
127
|
+
case 'info':
|
|
128
|
+
return 'Info notification';
|
|
129
|
+
case 'loading':
|
|
130
|
+
return 'Loading notification';
|
|
131
|
+
default:
|
|
132
|
+
return 'Notification';
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
function renderPromiseState(stateValue, payload) {
|
|
136
|
+
if (!stateValue) return;
|
|
137
|
+
if ('function' == typeof stateValue) return stateValue(payload);
|
|
138
|
+
return stateValue;
|
|
139
|
+
}
|
|
140
|
+
function Sonner({ position = 'bottom-right', visibleToasts = 3, offset = 24, gap = 12, expand = true, richColors = false, closeButton = false, duration = 4000, className, style, classNames, styles }) {
|
|
141
|
+
useTaoConfig();
|
|
142
|
+
const snapshot = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
|
|
143
|
+
const [heights, setHeights] = useState([]);
|
|
144
|
+
useEffect(()=>{
|
|
145
|
+
for (const toast of snapshot.toasts)if (!timers.has(toast.id)) scheduleDismiss(toast.id, toast.duration ?? duration);
|
|
146
|
+
}, [
|
|
147
|
+
duration,
|
|
148
|
+
snapshot.toasts
|
|
149
|
+
]);
|
|
150
|
+
const visible = useMemo(()=>{
|
|
151
|
+
const toasts = snapshot.toasts;
|
|
152
|
+
const sliced = expand ? toasts : toasts.slice(-visibleToasts);
|
|
153
|
+
return sliced.slice(-visibleToasts).reverse();
|
|
154
|
+
}, [
|
|
155
|
+
expand,
|
|
156
|
+
snapshot.toasts,
|
|
157
|
+
visibleToasts
|
|
158
|
+
]);
|
|
159
|
+
const frontToastHeight = heights[0]?.height ?? 0;
|
|
160
|
+
return /*#__PURE__*/ jsx(TaoPortalScope, {
|
|
161
|
+
children: /*#__PURE__*/ jsx("div", {
|
|
162
|
+
className: cx(classNames?.viewport, className),
|
|
163
|
+
style: {
|
|
164
|
+
...styles?.viewport,
|
|
165
|
+
...style,
|
|
166
|
+
['--tao-sonner-offset']: `${offset}px`,
|
|
167
|
+
['--tao-sonner-gap']: `${gap}px`,
|
|
168
|
+
['--tao-sonner-front-height']: `${frontToastHeight}px`
|
|
169
|
+
},
|
|
170
|
+
"data-tao-sonner-viewport": "",
|
|
171
|
+
"data-tao-position": position,
|
|
172
|
+
children: visible.map((toast_0, index)=>{
|
|
173
|
+
const showClose = toast_0.closable ?? closeButton;
|
|
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
|
|
189
|
+
}, toast_0.id);
|
|
190
|
+
})
|
|
191
|
+
})
|
|
192
|
+
});
|
|
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
|
+
}
|
|
327
|
+
const baseToast = (options)=>create('default', options);
|
|
328
|
+
const sonner_toast = Object.assign(baseToast, {
|
|
329
|
+
success: (options)=>create('success', options),
|
|
330
|
+
error: (options)=>create('error', options),
|
|
331
|
+
warning: (options)=>create('warning', options),
|
|
332
|
+
info: (options)=>create('info', options),
|
|
333
|
+
loading: (options)=>create('loading', isToastOptions(options) ? {
|
|
334
|
+
...options,
|
|
335
|
+
duration: options.duration ?? 0
|
|
336
|
+
} : {
|
|
337
|
+
title: options,
|
|
338
|
+
duration: 0
|
|
339
|
+
}),
|
|
340
|
+
custom: (node, options = {})=>create('custom', options, node),
|
|
341
|
+
promise: async (promise, messages)=>{
|
|
342
|
+
const id = create('loading', isToastOptions(messages.loading) ? {
|
|
343
|
+
...messages.loading,
|
|
344
|
+
duration: messages.loading.duration ?? 0
|
|
345
|
+
} : {
|
|
346
|
+
title: messages.loading,
|
|
347
|
+
duration: 0
|
|
348
|
+
});
|
|
349
|
+
try {
|
|
350
|
+
const value = await promise;
|
|
351
|
+
dismiss(id);
|
|
352
|
+
const success = renderPromiseState(messages.success, value);
|
|
353
|
+
if (success) create('success', success);
|
|
354
|
+
return value;
|
|
355
|
+
} catch (error) {
|
|
356
|
+
dismiss(id);
|
|
357
|
+
const failure = renderPromiseState(messages.error, error);
|
|
358
|
+
if (failure) create('error', failure);
|
|
359
|
+
throw error;
|
|
360
|
+
}
|
|
361
|
+
},
|
|
362
|
+
dismiss: dismiss
|
|
363
|
+
});
|
|
364
|
+
export { Sonner, sonner_toast as toast };
|
|
@@ -19,6 +19,7 @@ import { radioDoc } from "./components/radio.doc.js";
|
|
|
19
19
|
import { rangePickerDoc } from "./components/range-picker.doc.js";
|
|
20
20
|
import { scrollAreaDoc } from "./components/scroll-area.doc.js";
|
|
21
21
|
import { selectDoc } from "./components/select.doc.js";
|
|
22
|
+
import { sonnerDoc } from "./components/sonner.doc.js";
|
|
22
23
|
import { spinnerDoc } from "./components/spinner.doc.js";
|
|
23
24
|
import { splitterDoc } from "./components/splitter.doc.js";
|
|
24
25
|
import { stackDoc } from "./components/stack.doc.js";
|
|
@@ -50,6 +51,7 @@ const componentDocs = [
|
|
|
50
51
|
rangePickerDoc,
|
|
51
52
|
scrollAreaDoc,
|
|
52
53
|
selectDoc,
|
|
54
|
+
sonnerDoc,
|
|
53
55
|
spinnerDoc,
|
|
54
56
|
splitterDoc,
|
|
55
57
|
stackDoc,
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export declare const sonnerDoc: {
|
|
2
|
+
name: string;
|
|
3
|
+
displayName: string;
|
|
4
|
+
category: "Feedback";
|
|
5
|
+
description: string;
|
|
6
|
+
exports: string[];
|
|
7
|
+
source: string;
|
|
8
|
+
story: string;
|
|
9
|
+
tests: string[];
|
|
10
|
+
semanticParts: string[];
|
|
11
|
+
keywords: string[];
|
|
12
|
+
related: string[];
|
|
13
|
+
usage: {
|
|
14
|
+
description: string;
|
|
15
|
+
bestPractices: string[];
|
|
16
|
+
avoid: string[];
|
|
17
|
+
};
|
|
18
|
+
};
|