@betterinternship/components 3.1.2 → 3.1.3
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.
|
@@ -1,106 +1,41 @@
|
|
|
1
|
-
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { toast as sonnerToast, type ExternalToast } from "sonner";
|
|
3
|
+
export type { ToastT } from "sonner";
|
|
4
|
+
/** sonner's options, plus making the whole toast clickable. */
|
|
5
|
+
export type ToastOptions = ExternalToast & {
|
|
6
|
+
/** Go here when the toast is clicked. Shows a chevron at the end of the toast. */
|
|
7
|
+
href?: string;
|
|
8
|
+
/** Run this when the toast is clicked (when it is not a link). */
|
|
9
|
+
onClick?: () => void;
|
|
10
|
+
};
|
|
11
|
+
/** @deprecated Use ToastOptions. */
|
|
12
|
+
export type { ExternalToast };
|
|
13
|
+
type Message = React.ReactNode | (() => React.ReactNode);
|
|
14
|
+
type ToastFn = (message: Message, data?: ToastOptions) => string | number;
|
|
15
|
+
/**
|
|
16
|
+
* sonner's toast, themed by SonnerToaster, plus `href` / `onClick` to make the
|
|
17
|
+
* whole toast clickable: toast.success("Application sent", { href: "/applications" }).
|
|
18
|
+
* sonner is a peer dependency, so this reaches the same Toaster.
|
|
19
|
+
*/
|
|
20
|
+
type ClickableMethod = "success" | "error" | "warning" | "info" | "message" | "loading";
|
|
21
|
+
export type Toast = ToastFn & Omit<typeof sonnerToast, ClickableMethod> & Record<ClickableMethod, ToastFn>;
|
|
22
|
+
export declare const toast: Toast;
|
|
23
|
+
/** Mount once near the app root. */
|
|
24
|
+
export declare function SonnerToaster(): import("react/jsx-runtime").JSX.Element;
|
|
25
|
+
interface LegacyPresetOptions {
|
|
2
26
|
center?: boolean;
|
|
3
27
|
fitContent?: boolean;
|
|
4
28
|
color?: string;
|
|
5
29
|
}
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
width?: string | undefined;
|
|
11
|
-
background: string;
|
|
12
|
-
color: string;
|
|
13
|
-
border: string;
|
|
14
|
-
display: string;
|
|
15
|
-
alignItems: string;
|
|
16
|
-
justifyContent: string;
|
|
17
|
-
borderRadius: string;
|
|
18
|
-
boxShadow: string;
|
|
19
|
-
padding: string;
|
|
20
|
-
minHeight: string;
|
|
21
|
-
};
|
|
22
|
-
};
|
|
23
|
-
destructive: {
|
|
24
|
-
icon: import("react").ReactNode;
|
|
25
|
-
style: {
|
|
26
|
-
width?: string | undefined;
|
|
27
|
-
background: string;
|
|
28
|
-
color: string;
|
|
29
|
-
border: string;
|
|
30
|
-
display: string;
|
|
31
|
-
alignItems: string;
|
|
32
|
-
justifyContent: string;
|
|
33
|
-
borderRadius: string;
|
|
34
|
-
boxShadow: string;
|
|
35
|
-
padding: string;
|
|
36
|
-
minHeight: string;
|
|
37
|
-
};
|
|
38
|
-
};
|
|
39
|
-
alert: {
|
|
40
|
-
icon: import("react").ReactNode;
|
|
41
|
-
style: {
|
|
42
|
-
width?: string | undefined;
|
|
43
|
-
background: string;
|
|
44
|
-
color: string;
|
|
45
|
-
border: string;
|
|
46
|
-
display: string;
|
|
47
|
-
alignItems: string;
|
|
48
|
-
justifyContent: string;
|
|
49
|
-
borderRadius: string;
|
|
50
|
-
boxShadow: string;
|
|
51
|
-
padding: string;
|
|
52
|
-
minHeight: string;
|
|
53
|
-
};
|
|
54
|
-
};
|
|
55
|
-
info: {
|
|
56
|
-
icon: import("react").ReactNode;
|
|
57
|
-
style: {
|
|
58
|
-
width?: string | undefined;
|
|
59
|
-
background: string;
|
|
60
|
-
color: string;
|
|
61
|
-
border: string;
|
|
62
|
-
display: string;
|
|
63
|
-
alignItems: string;
|
|
64
|
-
justifyContent: string;
|
|
65
|
-
borderRadius: string;
|
|
66
|
-
boxShadow: string;
|
|
67
|
-
padding: string;
|
|
68
|
-
minHeight: string;
|
|
69
|
-
};
|
|
70
|
-
};
|
|
71
|
-
loading: {
|
|
72
|
-
duration: number;
|
|
73
|
-
icon: import("react").ReactNode;
|
|
74
|
-
style: {
|
|
75
|
-
width?: string | undefined;
|
|
76
|
-
background: string;
|
|
77
|
-
color: string;
|
|
78
|
-
border: string;
|
|
79
|
-
display: string;
|
|
80
|
-
alignItems: string;
|
|
81
|
-
justifyContent: string;
|
|
82
|
-
borderRadius: string;
|
|
83
|
-
boxShadow: string;
|
|
84
|
-
padding: string;
|
|
85
|
-
minHeight: string;
|
|
86
|
-
};
|
|
87
|
-
};
|
|
30
|
+
type ToastPreset = {
|
|
31
|
+
icon?: React.ReactNode;
|
|
32
|
+
className?: string;
|
|
33
|
+
duration?: number;
|
|
88
34
|
};
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
display: string;
|
|
97
|
-
alignItems: string;
|
|
98
|
-
justifyContent: string;
|
|
99
|
-
borderRadius: string;
|
|
100
|
-
boxShadow: string;
|
|
101
|
-
padding: string;
|
|
102
|
-
minHeight: string;
|
|
103
|
-
};
|
|
104
|
-
};
|
|
105
|
-
export declare function SonnerToaster(): import("react/jsx-runtime").JSX.Element;
|
|
106
|
-
export {};
|
|
35
|
+
/** @deprecated Use toast.success / error / warning / info / loading instead. */
|
|
36
|
+
export declare const toastPresets: Record<"success" | "destructive" | "alert" | "info" | "loading", ToastPreset>;
|
|
37
|
+
/**
|
|
38
|
+
* @deprecated Toasts are themed by type in SonnerToaster. This keeps the icon
|
|
39
|
+
* and neutral card; the background colour is no longer applied.
|
|
40
|
+
*/
|
|
41
|
+
export declare function createCustomToastPreset(_background: string, icon: React.ReactNode, _options?: LegacyPresetOptions): ToastPreset;
|
|
@@ -1,78 +1,184 @@
|
|
|
1
|
+
"use client";
|
|
1
2
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
3
|
+
import Link from 'next/link';
|
|
4
|
+
import { toast as toast$1, Toaster } from 'sonner';
|
|
5
|
+
import { Loader2, Info, AlertTriangle, AlertCircle, CheckCircle, ChevronRight } from 'lucide-react';
|
|
4
6
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
minHeight: "3.25rem",
|
|
20
|
-
...(fitContent && { width: "fit-content" }),
|
|
21
|
-
},
|
|
7
|
+
let clickableToastCount = 0;
|
|
8
|
+
/**
|
|
9
|
+
* The message as a link (or button) stretched over the whole toast, with an
|
|
10
|
+
* chevron so it reads as clickable. Clicking it also closes the toast.
|
|
11
|
+
*/
|
|
12
|
+
function withClick(message, data) {
|
|
13
|
+
if (!data?.href && !data?.onClick)
|
|
14
|
+
return [message, data];
|
|
15
|
+
const { href, onClick, ...rest } = data;
|
|
16
|
+
const id = rest.id ?? `bi-toast-${++clickableToastCount}`;
|
|
17
|
+
const label = (jsxs("span", { className: "bi-toast-link-label", children: [typeof message === "function" ? message() : message, jsx(ChevronRight, { "aria-hidden": "true", className: "bi-toast-link-arrow" })] }));
|
|
18
|
+
const close = () => {
|
|
19
|
+
onClick?.();
|
|
20
|
+
toast$1.dismiss(id);
|
|
22
21
|
};
|
|
22
|
+
const content = href ? (jsx(Link, { href: href, onClick: close, className: "bi-toast-link", children: label })) : (jsx("button", { type: "button", onClick: close, className: "bi-toast-link", children: label }));
|
|
23
|
+
return [content, { ...rest, id, className: [rest.className, "bi-toast-clickable"].filter(Boolean).join(" ") }];
|
|
24
|
+
}
|
|
25
|
+
const wrap = (fn) => (message, data) => fn(...withClick(message, data));
|
|
26
|
+
const toast = Object.assign(wrap(toast$1), {
|
|
27
|
+
...toast$1,
|
|
28
|
+
success: wrap(toast$1.success),
|
|
29
|
+
error: wrap(toast$1.error),
|
|
30
|
+
warning: wrap(toast$1.warning),
|
|
31
|
+
info: wrap(toast$1.info),
|
|
32
|
+
message: wrap(toast$1.message),
|
|
33
|
+
loading: wrap(toast$1.loading),
|
|
34
|
+
});
|
|
35
|
+
/*
|
|
36
|
+
* Toasts are themed by type inside SonnerToaster, so callers just use this
|
|
37
|
+
* package's toast: toast.success(), toast.error(), toast.warning(), toast.info(),
|
|
38
|
+
* toast.loading() and toast.promise(). Each type gets its icon, a tinted card
|
|
39
|
+
* and a matching close button; plain toast() gets the neutral card. Pass
|
|
40
|
+
* `href` or `onClick` to make the whole toast clickable (it shows a chevron).
|
|
41
|
+
*/
|
|
42
|
+
const icons = {
|
|
43
|
+
success: jsx(CheckCircle, { className: "size-5 text-supportive", "aria-hidden": "true" }),
|
|
44
|
+
error: jsx(AlertCircle, { className: "size-5 text-destructive", "aria-hidden": "true" }),
|
|
45
|
+
warning: jsx(AlertTriangle, { className: "size-5 text-warning", "aria-hidden": "true" }),
|
|
46
|
+
info: jsx(Info, { className: "size-5 text-landing-blue", "aria-hidden": "true" }),
|
|
47
|
+
loading: (jsx(Loader2, { className: "size-5 animate-spin text-muted-foreground motion-reduce:animate-none", "aria-hidden": "true" })),
|
|
23
48
|
};
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
49
|
+
// Plain CSS on sonner's data attributes: works without Tailwind having to
|
|
50
|
+
// find generated class names, and beats sonner's own [data-styled] rules.
|
|
51
|
+
const toastCss = `
|
|
52
|
+
[data-sonner-toast][data-styled="true"] {
|
|
53
|
+
--toast-tint: var(--color-border);
|
|
54
|
+
align-items: center;
|
|
55
|
+
gap: 0.75rem;
|
|
56
|
+
min-height: 3.25rem;
|
|
57
|
+
padding: 0.75rem 2.75rem 0.75rem 1rem;
|
|
58
|
+
border-radius: var(--radius-control-lg);
|
|
59
|
+
border: 1px solid color-mix(in srgb, var(--toast-tint) 48%, var(--color-border));
|
|
60
|
+
background: color-mix(in srgb, var(--toast-tint) 9%, var(--color-background));
|
|
61
|
+
color: var(--color-foreground);
|
|
62
|
+
box-shadow: 0 16px 40px -16px rgb(16 16 68 / 0.55);
|
|
63
|
+
font-family: var(--font-sans);
|
|
64
|
+
}
|
|
65
|
+
[data-sonner-toast][data-styled="true"]:is([data-type="default"], [data-type="loading"]) {
|
|
66
|
+
background: var(--color-background);
|
|
67
|
+
border-color: var(--color-border);
|
|
68
|
+
}
|
|
69
|
+
/* By type, or by the legacy preset class on a plain toast(). */
|
|
70
|
+
[data-sonner-toast][data-styled="true"]:is([data-type="success"], .bi-toast-success) { --toast-tint: var(--color-supportive); }
|
|
71
|
+
[data-sonner-toast][data-styled="true"]:is([data-type="error"], .bi-toast-error) { --toast-tint: var(--color-destructive); }
|
|
72
|
+
[data-sonner-toast][data-styled="true"]:is([data-type="warning"], .bi-toast-warning) { --toast-tint: var(--color-warning); }
|
|
73
|
+
[data-sonner-toast][data-styled="true"]:is([data-type="info"], .bi-toast-info) { --toast-tint: var(--color-landing-blue); }
|
|
74
|
+
[data-sonner-toast][data-styled="true"]:is(.bi-toast-success, .bi-toast-error, .bi-toast-warning, .bi-toast-info) {
|
|
75
|
+
background: color-mix(in srgb, var(--toast-tint) 9%, var(--color-background));
|
|
76
|
+
border-color: color-mix(in srgb, var(--toast-tint) 48%, var(--color-border));
|
|
77
|
+
}
|
|
78
|
+
[data-sonner-toast] [data-title] {
|
|
79
|
+
font-size: 0.875rem;
|
|
80
|
+
font-weight: 500;
|
|
81
|
+
color: var(--color-foreground);
|
|
82
|
+
}
|
|
83
|
+
[data-sonner-toast] [data-description] {
|
|
84
|
+
font-size: 0.875rem;
|
|
85
|
+
color: var(--color-muted-foreground);
|
|
86
|
+
}
|
|
87
|
+
[data-sonner-toast] [data-icon] {
|
|
88
|
+
margin: 0;
|
|
89
|
+
width: 1.25rem;
|
|
90
|
+
height: 1.25rem;
|
|
91
|
+
}
|
|
92
|
+
/* Clickable toasts: the link covers the toast and clicking it closes the
|
|
93
|
+
toast, so there is no close button; the chevron sits at the far right. */
|
|
94
|
+
[data-sonner-toast][data-styled="true"].bi-toast-clickable {
|
|
95
|
+
cursor: pointer;
|
|
96
|
+
padding-right: 1rem;
|
|
97
|
+
}
|
|
98
|
+
[data-sonner-toast].bi-toast-clickable [data-close-button] { display: none !important; }
|
|
99
|
+
[data-sonner-toast].bi-toast-clickable:hover { filter: brightness(0.98); }
|
|
100
|
+
/* The text area grows so the arrow can sit at the far right. */
|
|
101
|
+
[data-sonner-toast].bi-toast-clickable [data-content],
|
|
102
|
+
[data-sonner-toast].bi-toast-clickable [data-title] {
|
|
103
|
+
flex: 1;
|
|
104
|
+
min-width: 0;
|
|
105
|
+
}
|
|
106
|
+
[data-sonner-toast] .bi-toast-link {
|
|
107
|
+
all: unset;
|
|
108
|
+
display: block;
|
|
109
|
+
width: 100%;
|
|
110
|
+
cursor: pointer;
|
|
111
|
+
color: inherit;
|
|
36
112
|
}
|
|
113
|
+
[data-sonner-toast] .bi-toast-link::after {
|
|
114
|
+
content: "";
|
|
115
|
+
position: absolute;
|
|
116
|
+
inset: 0;
|
|
117
|
+
border-radius: inherit;
|
|
118
|
+
}
|
|
119
|
+
[data-sonner-toast] .bi-toast-link:focus-visible::after {
|
|
120
|
+
outline: 2px solid var(--color-ring);
|
|
121
|
+
outline-offset: 2px;
|
|
122
|
+
}
|
|
123
|
+
[data-sonner-toast] .bi-toast-link-label {
|
|
124
|
+
display: flex;
|
|
125
|
+
width: 100%;
|
|
126
|
+
align-items: center;
|
|
127
|
+
justify-content: space-between;
|
|
128
|
+
gap: 0.75rem;
|
|
129
|
+
}
|
|
130
|
+
[data-sonner-toast] .bi-toast-link-arrow {
|
|
131
|
+
width: 1rem;
|
|
132
|
+
height: 1rem;
|
|
133
|
+
flex-shrink: 0;
|
|
134
|
+
transition: transform 150ms ease-out;
|
|
135
|
+
}
|
|
136
|
+
[data-sonner-toast].bi-toast-clickable:hover .bi-toast-link-arrow { transform: translateX(2px); }
|
|
137
|
+
@media (prefers-reduced-motion: reduce) {
|
|
138
|
+
[data-sonner-toast] .bi-toast-link-arrow { transition: none; }
|
|
139
|
+
}
|
|
140
|
+
/* sonner adds its own styles after these, so the close button needs
|
|
141
|
+
!important to move from the top-left corner to the right, centred. */
|
|
142
|
+
[data-sonner-toast] [data-close-button] {
|
|
143
|
+
z-index: 1;
|
|
144
|
+
left: auto !important;
|
|
145
|
+
right: 0.625rem !important;
|
|
146
|
+
top: 50% !important;
|
|
147
|
+
transform: translateY(-50%) !important;
|
|
148
|
+
width: 2rem !important;
|
|
149
|
+
height: 2rem !important;
|
|
150
|
+
border: 0 !important;
|
|
151
|
+
background: transparent !important;
|
|
152
|
+
box-shadow: none !important;
|
|
153
|
+
color: var(--color-foreground) !important;
|
|
154
|
+
}
|
|
155
|
+
[data-sonner-toast] [data-close-button]:hover {
|
|
156
|
+
background: var(--color-muted) !important;
|
|
157
|
+
}
|
|
158
|
+
[data-sonner-toast]:is([data-type="success"], [data-type="error"], [data-type="warning"], [data-type="info"], .bi-toast-success, .bi-toast-error, .bi-toast-warning, .bi-toast-info) [data-close-button] {
|
|
159
|
+
color: var(--toast-tint) !important;
|
|
160
|
+
}
|
|
161
|
+
`;
|
|
162
|
+
/** Mount once near the app root. */
|
|
37
163
|
function SonnerToaster() {
|
|
38
|
-
return (jsxs(Fragment, { children: [jsx("style", { children:
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
56
|
-
[data-sonner-toast][data-type="success"] .sonner-close-button {
|
|
57
|
-
color: var(--color-supportive) !important;
|
|
58
|
-
}
|
|
59
|
-
[data-sonner-toast][data-type="error"] .sonner-close-button {
|
|
60
|
-
color: var(--color-destructive) !important;
|
|
61
|
-
}
|
|
62
|
-
[data-sonner-toast][data-type="warning"] .sonner-close-button {
|
|
63
|
-
color: var(--color-warning) !important;
|
|
64
|
-
}
|
|
65
|
-
[data-sonner-toast][data-type="info"] .sonner-close-button {
|
|
66
|
-
color: var(--color-landing-blue) !important;
|
|
67
|
-
}
|
|
68
|
-
` }), jsx(Toaster, { position: "bottom-right", closeButton: true, toastOptions: {
|
|
69
|
-
className: "!rounded-control-lg !shadow-card !max-w-sm",
|
|
70
|
-
style: {
|
|
71
|
-
fontFamily: "var(--font-sans)",
|
|
72
|
-
padding: "0.75rem 1rem",
|
|
73
|
-
},
|
|
74
|
-
} })] }));
|
|
164
|
+
return (jsxs(Fragment, { children: [jsx("style", { children: toastCss }), jsx(Toaster, { position: "bottom-right", closeButton: true, icons: icons, toastOptions: { style: { maxWidth: "24rem" } } })] }));
|
|
165
|
+
}
|
|
166
|
+
/** @deprecated Use toast.success / error / warning / info / loading instead. */
|
|
167
|
+
const toastPresets = {
|
|
168
|
+
success: { icon: icons.success, className: "bi-toast-success" },
|
|
169
|
+
destructive: { icon: icons.error, className: "bi-toast-error" },
|
|
170
|
+
alert: { icon: icons.warning, className: "bi-toast-warning" },
|
|
171
|
+
info: { icon: icons.info, className: "bi-toast-info" },
|
|
172
|
+
// A plain toast() with this preset stays open, like toast.loading().
|
|
173
|
+
loading: { icon: icons.loading, duration: Infinity },
|
|
174
|
+
};
|
|
175
|
+
/**
|
|
176
|
+
* @deprecated Toasts are themed by type in SonnerToaster. This keeps the icon
|
|
177
|
+
* and neutral card; the background colour is no longer applied.
|
|
178
|
+
*/
|
|
179
|
+
function createCustomToastPreset(_background, icon, _options) {
|
|
180
|
+
return { icon };
|
|
75
181
|
}
|
|
76
182
|
|
|
77
|
-
export { SonnerToaster, createCustomToastPreset, toastPresets };
|
|
183
|
+
export { SonnerToaster, createCustomToastPreset, toast, toastPresets };
|
|
78
184
|
//# sourceMappingURL=sonner-toast.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sonner-toast.js","sources":["../../src/components/sonner-toast.tsx"],"sourcesContent":["import { Toaster } from \"sonner\";\nimport { CheckCircle, AlertCircle, AlertTriangle, Info, Loader2 } from \"lucide-react\";\n\ninterface ToastOptions {\n center?: boolean;\n fitContent?: boolean;\n color?: string;\n}\n\nconst createToastPreset = (\n icon: React.ReactNode,\n background: string,\n options: ToastOptions = {}\n) => {\n const { center = false, fitContent = false, color = \"var(--color-foreground)\" } = options;\n return {\n icon,\n style: {\n background: `color-mix(in srgb, ${background} 9%, var(--color-background))`,\n color,\n border: `1px solid color-mix(in srgb, ${background} 48%, var(--color-border))`,\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: center ? \"center\" : \"flex-start\",\n borderRadius: \"var(--radius-control-lg)\",\n boxShadow: \"0 16px 40px -16px rgb(16 16 68 / 0.55)\",\n padding: \"0.75rem 1rem\",\n minHeight: \"3.25rem\",\n ...(fitContent && { width: \"fit-content\" }),\n },\n };\n};\n\nexport const toastPresets = {\n success: createToastPreset(<CheckCircle className=\"h-5 w-5 text-supportive\" />, \"var(--color-supportive)\"),\n destructive: createToastPreset(<AlertCircle className=\"h-5 w-5 text-destructive\" />, \"var(--color-destructive)\"),\n alert: createToastPreset(<AlertTriangle className=\"h-5 w-5 text-warning\" />, \"var(--color-warning)\"),\n info: createToastPreset(<Info className=\"h-5 w-5 text-landing-blue\" />, \"var(--color-landing-control)\"),\n loading: {\n ...createToastPreset(\n <Loader2 className=\"h-5 w-5 animate-spin\" />,\n \"#ffffff\",\n { color: \"#111827\" },\n ),\n duration: Infinity,\n },\n};\n\nexport function createCustomToastPreset(\n background: string,\n icon: React.ReactNode,\n options?: ToastOptions\n) {\n return createToastPreset(icon, background, options);\n}\n\nexport function SonnerToaster() {\n return (\n <>\n <style>{`\n [data-sonner-toast] {\n padding-right: 2.75rem;\n }\n [data-sonner-toast] [data-close-button],\n [data-sonner-toast] .sonner-close-button {\n left: auto !important;\n right: 0.625rem !important;\n top: 50% !important;\n transform: translateY(-50%) !important;\n background: transparent !important;\n border: 0 !important;\n box-shadow: none !important;\n color: var(--color-foreground) !important;\n width: 2rem !important;\n height: 2rem !important;\n font-size: 1.25rem !important;\n }\n [data-sonner-toast][data-type=\"success\"] .sonner-close-button {\n color: var(--color-supportive) !important;\n }\n [data-sonner-toast][data-type=\"error\"] .sonner-close-button {\n color: var(--color-destructive) !important;\n }\n [data-sonner-toast][data-type=\"warning\"] .sonner-close-button {\n color: var(--color-warning) !important;\n }\n [data-sonner-toast][data-type=\"info\"] .sonner-close-button {\n color: var(--color-landing-blue) !important;\n }\n `}</style>\n <Toaster\n position=\"bottom-right\"\n closeButton\n toastOptions={{\n className: \"!rounded-control-lg !shadow-card !max-w-sm\",\n style: {\n fontFamily: \"var(--font-sans)\",\n padding: \"0.75rem 1rem\",\n },\n }}\n />\n </>\n );\n}\n"],"names":["_jsx","_jsxs"],"mappings":";;;;AASA,MAAM,iBAAiB,GAAG,CACxB,IAAqB,EACrB,UAAkB,EAClB,OAAA,GAAwB,EAAE,KACxB;AACF,IAAA,MAAM,EAAE,MAAM,GAAG,KAAK,EAAE,UAAU,GAAG,KAAK,EAAE,KAAK,GAAG,yBAAyB,EAAE,GAAG,OAAO;IACzF,OAAO;QACL,IAAI;AACJ,QAAA,KAAK,EAAE;YACL,UAAU,EAAE,CAAA,mBAAA,EAAsB,UAAU,CAAA,6BAAA,CAA+B;YAC3E,KAAK;YACL,MAAM,EAAE,CAAA,6BAAA,EAAgC,UAAU,CAAA,0BAAA,CAA4B;AAC9E,YAAA,OAAO,EAAE,MAAM;AACf,YAAA,UAAU,EAAE,QAAQ;YACpB,cAAc,EAAE,MAAM,GAAG,QAAQ,GAAG,YAAY;AAChD,YAAA,YAAY,EAAE,0BAA0B;AACxC,YAAA,SAAS,EAAE,wCAAwC;AACnD,YAAA,OAAO,EAAE,cAAc;AACvB,YAAA,SAAS,EAAE,SAAS;YACpB,IAAI,UAAU,IAAI,EAAE,KAAK,EAAE,aAAa,EAAE,CAAC;AAC5C,SAAA;KACF;AACH,CAAC;AAEM,MAAM,YAAY,GAAG;AAC1B,IAAA,OAAO,EAAE,iBAAiB,CAACA,GAAA,CAAC,WAAW,EAAA,EAAC,SAAS,EAAC,yBAAyB,EAAA,CAAG,EAAE,yBAAyB,CAAC;AAC1G,IAAA,WAAW,EAAE,iBAAiB,CAACA,GAAA,CAAC,WAAW,EAAA,EAAC,SAAS,EAAC,0BAA0B,EAAA,CAAG,EAAE,0BAA0B,CAAC;AAChH,IAAA,KAAK,EAAE,iBAAiB,CAACA,GAAA,CAAC,aAAa,EAAA,EAAC,SAAS,EAAC,sBAAsB,EAAA,CAAG,EAAE,sBAAsB,CAAC;AACpG,IAAA,IAAI,EAAE,iBAAiB,CAACA,GAAA,CAAC,IAAI,EAAA,EAAC,SAAS,EAAC,2BAA2B,EAAA,CAAG,EAAE,8BAA8B,CAAC;AACvG,IAAA,OAAO,EAAE;AACP,QAAA,GAAG,iBAAiB,CAClBA,GAAA,CAAC,OAAO,EAAA,EAAC,SAAS,EAAC,sBAAsB,EAAA,CAAG,EAC5C,SAAS,EACT,EAAE,KAAK,EAAE,SAAS,EAAE,CACrB;AACD,QAAA,QAAQ,EAAE,QAAQ;AACnB,KAAA;;SAGa,uBAAuB,CACrC,UAAkB,EAClB,IAAqB,EACrB,OAAsB,EAAA;IAEtB,OAAO,iBAAiB,CAAC,IAAI,EAAE,UAAU,EAAE,OAAO,CAAC;AACrD;SAEgB,aAAa,GAAA;IAC3B,QACEC,4BACED,GAAA,CAAA,OAAA,EAAA,EAAA,QAAA,EAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA8BP,EAAA,CAAS,EACVA,GAAA,CAAC,OAAO,EAAA,EACN,QAAQ,EAAC,cAAc,EACvB,WAAW,EAAA,IAAA,EACX,YAAY,EAAE;AACZ,oBAAA,SAAS,EAAE,4CAA4C;AACvD,oBAAA,KAAK,EAAE;AACL,wBAAA,UAAU,EAAE,kBAAkB;AAC9B,wBAAA,OAAO,EAAE,cAAc;AACxB,qBAAA;iBACF,EAAA,CACD,CAAA,EAAA,CACD;AAEP;;;;"}
|
|
1
|
+
{"version":3,"file":"sonner-toast.js","sources":["../../src/components/sonner-toast.tsx"],"sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\nimport Link from \"next/link\";\nimport { Toaster, toast as sonnerToast, type ExternalToast } from \"sonner\";\nimport {\n AlertCircle,\n AlertTriangle,\n ChevronRight,\n CheckCircle,\n Info,\n Loader2,\n} from \"lucide-react\";\n\nexport type { ToastT } from \"sonner\";\n\n/** sonner's options, plus making the whole toast clickable. */\nexport type ToastOptions = ExternalToast & {\n /** Go here when the toast is clicked. Shows a chevron at the end of the toast. */\n href?: string;\n /** Run this when the toast is clicked (when it is not a link). */\n onClick?: () => void;\n};\n/** @deprecated Use ToastOptions. */\nexport type { ExternalToast };\n\ntype Message = React.ReactNode | (() => React.ReactNode);\n\nlet clickableToastCount = 0;\n\n/**\n * The message as a link (or button) stretched over the whole toast, with an\n * chevron so it reads as clickable. Clicking it also closes the toast.\n */\nfunction withClick(message: Message, data?: ToastOptions): [Message, ExternalToast | undefined] {\n if (!data?.href && !data?.onClick) return [message, data];\n const { href, onClick, ...rest } = data;\n const id = rest.id ?? `bi-toast-${++clickableToastCount}`;\n const label = (\n <span className=\"bi-toast-link-label\">\n {typeof message === \"function\" ? message() : message}\n <ChevronRight aria-hidden=\"true\" className=\"bi-toast-link-arrow\" />\n </span>\n );\n const close = () => {\n onClick?.();\n sonnerToast.dismiss(id);\n };\n const content = href ? (\n <Link href={href} onClick={close} className=\"bi-toast-link\">\n {label}\n </Link>\n ) : (\n <button type=\"button\" onClick={close} className=\"bi-toast-link\">\n {label}\n </button>\n );\n return [content, { ...rest, id, className: [rest.className, \"bi-toast-clickable\"].filter(Boolean).join(\" \") }];\n}\n\ntype ToastFn = (message: Message, data?: ToastOptions) => string | number;\nconst wrap =\n (fn: (message: Message, data?: ExternalToast) => string | number): ToastFn =>\n (message, data) =>\n fn(...withClick(message, data));\n\n/**\n * sonner's toast, themed by SonnerToaster, plus `href` / `onClick` to make the\n * whole toast clickable: toast.success(\"Application sent\", { href: \"/applications\" }).\n * sonner is a peer dependency, so this reaches the same Toaster.\n */\ntype ClickableMethod = \"success\" | \"error\" | \"warning\" | \"info\" | \"message\" | \"loading\";\nexport type Toast = ToastFn &\n Omit<typeof sonnerToast, ClickableMethod> &\n Record<ClickableMethod, ToastFn>;\n\nexport const toast: Toast = Object.assign(wrap(sonnerToast), {\n ...sonnerToast,\n success: wrap(sonnerToast.success),\n error: wrap(sonnerToast.error),\n warning: wrap(sonnerToast.warning),\n info: wrap(sonnerToast.info),\n message: wrap(sonnerToast.message),\n loading: wrap(sonnerToast.loading),\n});\n\n/*\n * Toasts are themed by type inside SonnerToaster, so callers just use this\n * package's toast: toast.success(), toast.error(), toast.warning(), toast.info(),\n * toast.loading() and toast.promise(). Each type gets its icon, a tinted card\n * and a matching close button; plain toast() gets the neutral card. Pass\n * `href` or `onClick` to make the whole toast clickable (it shows a chevron).\n */\n\nconst icons = {\n success: <CheckCircle className=\"size-5 text-supportive\" aria-hidden=\"true\" />,\n error: <AlertCircle className=\"size-5 text-destructive\" aria-hidden=\"true\" />,\n warning: <AlertTriangle className=\"size-5 text-warning\" aria-hidden=\"true\" />,\n info: <Info className=\"size-5 text-landing-blue\" aria-hidden=\"true\" />,\n loading: (\n <Loader2\n className=\"size-5 animate-spin text-muted-foreground motion-reduce:animate-none\"\n aria-hidden=\"true\"\n />\n ),\n};\n\n// Plain CSS on sonner's data attributes: works without Tailwind having to\n// find generated class names, and beats sonner's own [data-styled] rules.\nconst toastCss = `\n[data-sonner-toast][data-styled=\"true\"] {\n --toast-tint: var(--color-border);\n align-items: center;\n gap: 0.75rem;\n min-height: 3.25rem;\n padding: 0.75rem 2.75rem 0.75rem 1rem;\n border-radius: var(--radius-control-lg);\n border: 1px solid color-mix(in srgb, var(--toast-tint) 48%, var(--color-border));\n background: color-mix(in srgb, var(--toast-tint) 9%, var(--color-background));\n color: var(--color-foreground);\n box-shadow: 0 16px 40px -16px rgb(16 16 68 / 0.55);\n font-family: var(--font-sans);\n}\n[data-sonner-toast][data-styled=\"true\"]:is([data-type=\"default\"], [data-type=\"loading\"]) {\n background: var(--color-background);\n border-color: var(--color-border);\n}\n/* By type, or by the legacy preset class on a plain toast(). */\n[data-sonner-toast][data-styled=\"true\"]:is([data-type=\"success\"], .bi-toast-success) { --toast-tint: var(--color-supportive); }\n[data-sonner-toast][data-styled=\"true\"]:is([data-type=\"error\"], .bi-toast-error) { --toast-tint: var(--color-destructive); }\n[data-sonner-toast][data-styled=\"true\"]:is([data-type=\"warning\"], .bi-toast-warning) { --toast-tint: var(--color-warning); }\n[data-sonner-toast][data-styled=\"true\"]:is([data-type=\"info\"], .bi-toast-info) { --toast-tint: var(--color-landing-blue); }\n[data-sonner-toast][data-styled=\"true\"]:is(.bi-toast-success, .bi-toast-error, .bi-toast-warning, .bi-toast-info) {\n background: color-mix(in srgb, var(--toast-tint) 9%, var(--color-background));\n border-color: color-mix(in srgb, var(--toast-tint) 48%, var(--color-border));\n}\n[data-sonner-toast] [data-title] {\n font-size: 0.875rem;\n font-weight: 500;\n color: var(--color-foreground);\n}\n[data-sonner-toast] [data-description] {\n font-size: 0.875rem;\n color: var(--color-muted-foreground);\n}\n[data-sonner-toast] [data-icon] {\n margin: 0;\n width: 1.25rem;\n height: 1.25rem;\n}\n/* Clickable toasts: the link covers the toast and clicking it closes the\n toast, so there is no close button; the chevron sits at the far right. */\n[data-sonner-toast][data-styled=\"true\"].bi-toast-clickable {\n cursor: pointer;\n padding-right: 1rem;\n}\n[data-sonner-toast].bi-toast-clickable [data-close-button] { display: none !important; }\n[data-sonner-toast].bi-toast-clickable:hover { filter: brightness(0.98); }\n/* The text area grows so the arrow can sit at the far right. */\n[data-sonner-toast].bi-toast-clickable [data-content],\n[data-sonner-toast].bi-toast-clickable [data-title] {\n flex: 1;\n min-width: 0;\n}\n[data-sonner-toast] .bi-toast-link {\n all: unset;\n display: block;\n width: 100%;\n cursor: pointer;\n color: inherit;\n}\n[data-sonner-toast] .bi-toast-link::after {\n content: \"\";\n position: absolute;\n inset: 0;\n border-radius: inherit;\n}\n[data-sonner-toast] .bi-toast-link:focus-visible::after {\n outline: 2px solid var(--color-ring);\n outline-offset: 2px;\n}\n[data-sonner-toast] .bi-toast-link-label {\n display: flex;\n width: 100%;\n align-items: center;\n justify-content: space-between;\n gap: 0.75rem;\n}\n[data-sonner-toast] .bi-toast-link-arrow {\n width: 1rem;\n height: 1rem;\n flex-shrink: 0;\n transition: transform 150ms ease-out;\n}\n[data-sonner-toast].bi-toast-clickable:hover .bi-toast-link-arrow { transform: translateX(2px); }\n@media (prefers-reduced-motion: reduce) {\n [data-sonner-toast] .bi-toast-link-arrow { transition: none; }\n}\n/* sonner adds its own styles after these, so the close button needs\n !important to move from the top-left corner to the right, centred. */\n[data-sonner-toast] [data-close-button] {\n z-index: 1;\n left: auto !important;\n right: 0.625rem !important;\n top: 50% !important;\n transform: translateY(-50%) !important;\n width: 2rem !important;\n height: 2rem !important;\n border: 0 !important;\n background: transparent !important;\n box-shadow: none !important;\n color: var(--color-foreground) !important;\n}\n[data-sonner-toast] [data-close-button]:hover {\n background: var(--color-muted) !important;\n}\n[data-sonner-toast]:is([data-type=\"success\"], [data-type=\"error\"], [data-type=\"warning\"], [data-type=\"info\"], .bi-toast-success, .bi-toast-error, .bi-toast-warning, .bi-toast-info) [data-close-button] {\n color: var(--toast-tint) !important;\n}\n`;\n\n/** Mount once near the app root. */\nexport function SonnerToaster() {\n return (\n <>\n <style>{toastCss}</style>\n <Toaster\n position=\"bottom-right\"\n closeButton\n icons={icons}\n toastOptions={{ style: { maxWidth: \"24rem\" } }}\n />\n </>\n );\n}\n\n/* -------------------------------------------------------------------------- */\n/* Deprecated: toasts are themed automatically by type now. The presets stay */\n/* so existing toast(\"…\", toastPresets.x) calls keep their look. */\n/* -------------------------------------------------------------------------- */\n\ninterface LegacyPresetOptions {\n center?: boolean;\n fitContent?: boolean;\n color?: string;\n}\n\ntype ToastPreset = {\n icon?: React.ReactNode;\n className?: string;\n duration?: number;\n};\n\n/** @deprecated Use toast.success / error / warning / info / loading instead. */\nexport const toastPresets: Record<\n \"success\" | \"destructive\" | \"alert\" | \"info\" | \"loading\",\n ToastPreset\n> = {\n success: { icon: icons.success, className: \"bi-toast-success\" },\n destructive: { icon: icons.error, className: \"bi-toast-error\" },\n alert: { icon: icons.warning, className: \"bi-toast-warning\" },\n info: { icon: icons.info, className: \"bi-toast-info\" },\n // A plain toast() with this preset stays open, like toast.loading().\n loading: { icon: icons.loading, duration: Infinity },\n};\n\n/**\n * @deprecated Toasts are themed by type in SonnerToaster. This keeps the icon\n * and neutral card; the background colour is no longer applied.\n */\nexport function createCustomToastPreset(\n _background: string,\n icon: React.ReactNode,\n _options?: LegacyPresetOptions,\n): ToastPreset {\n return { icon };\n}\n"],"names":[],"mappings":";;;;;;AA4BA;AAEA;;;AAGG;AACH;;AACqC;;;AAGnC;;;AAQE;AACF;;AAUA;AACF;AAGA;AAeO;AACL;AACA;AACA;AACA;AACA;AACA;AACA;AACD;AAED;;;;;;AAMG;AAEH;;;;;;;AAaA;AACA;AACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgHA;;AAEE;AAWF;AAmBA;AACO;;;;;;;;AAYP;;;AAGG;;;AAOH;;"}
|
package/dist/index.js
CHANGED
|
@@ -57,7 +57,7 @@ export { Timeline, TimelineItem } from './components/timeline.js';
|
|
|
57
57
|
export { Toggle } from './components/toggle.js';
|
|
58
58
|
export { PageError } from './components/error.js';
|
|
59
59
|
export { Message } from './components/messages.js';
|
|
60
|
-
export { SonnerToaster, createCustomToastPreset, toastPresets } from './components/sonner-toast.js';
|
|
60
|
+
export { SonnerToaster, createCustomToastPreset, toast, toastPresets } from './components/sonner-toast.js';
|
|
61
61
|
export { MobileSheetPortal } from './components/mobile-sheet-portal.js';
|
|
62
62
|
export { FloatingActionButton } from './components/fab.js';
|
|
63
63
|
export { DotMatrix } from './components/dot-matrix.js';
|