@betterinternship/components 3.1.1 → 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.
- package/dist/components/file-upload.d.ts +13 -0
- package/dist/components/file-upload.js +70 -12
- package/dist/components/file-upload.js.map +1 -1
- package/dist/components/sonner-toast.d.ts +36 -101
- package/dist/components/sonner-toast.js +175 -69
- package/dist/components/sonner-toast.js.map +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
|
@@ -1,16 +1,29 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
export type FileUploadVariant = "compact" | "dropzone";
|
|
3
|
+
export type FileRejectReason = "type" | "size";
|
|
3
4
|
export type FileUploadProps = {
|
|
4
5
|
label: string;
|
|
5
6
|
name: string;
|
|
6
7
|
variant?: FileUploadVariant;
|
|
8
|
+
/** Same format as the input's `accept`: extensions (".pdf") and/or MIME types ("image/*"). Also checked on drop. */
|
|
7
9
|
accept?: string;
|
|
10
|
+
/** Files larger than this are rejected through `onReject` instead of being selected. */
|
|
11
|
+
maxSizeMB?: number;
|
|
8
12
|
multiple?: boolean;
|
|
9
13
|
required?: boolean;
|
|
10
14
|
placeholder?: string;
|
|
11
15
|
disabled?: boolean;
|
|
12
16
|
className?: string;
|
|
17
|
+
/**
|
|
18
|
+
* The selected file, when the parent owns it. Pass `null` to clear the field.
|
|
19
|
+
* Leave undefined to let the field remember the last pick itself.
|
|
20
|
+
*/
|
|
21
|
+
value?: File | null;
|
|
22
|
+
/** Shown under the field and marks it invalid. */
|
|
23
|
+
error?: string | null;
|
|
13
24
|
onFileSelect?: (file: File | null) => void;
|
|
14
25
|
onFilesSelect?: (files: File[]) => void;
|
|
26
|
+
/** Called with each file that fails `accept` or `maxSizeMB`. */
|
|
27
|
+
onReject?: (file: File, reason: FileRejectReason) => void;
|
|
15
28
|
};
|
|
16
29
|
export declare const FileUpload: React.ForwardRefExoticComponent<FileUploadProps & React.RefAttributes<HTMLInputElement>>;
|
|
@@ -5,23 +5,81 @@ import { Upload } from 'lucide-react';
|
|
|
5
5
|
import { cn } from '../utils.js';
|
|
6
6
|
import { FieldLabel } from './label.js';
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
/** True when the file matches one of the `accept` entries (or there are none). */
|
|
9
|
+
function matchesAccept(file, accept) {
|
|
10
|
+
if (!accept)
|
|
11
|
+
return true;
|
|
12
|
+
const name = file.name.toLowerCase();
|
|
13
|
+
const type = file.type.toLowerCase();
|
|
14
|
+
return accept
|
|
15
|
+
.split(",")
|
|
16
|
+
.map((entry) => entry.trim().toLowerCase())
|
|
17
|
+
.filter(Boolean)
|
|
18
|
+
.some((entry) => entry.startsWith(".")
|
|
19
|
+
? name.endsWith(entry)
|
|
20
|
+
: entry.endsWith("/*")
|
|
21
|
+
? type.startsWith(entry.slice(0, -1))
|
|
22
|
+
: type === entry);
|
|
23
|
+
}
|
|
24
|
+
const FileUpload = React.forwardRef(({ label, name, variant = "compact", accept, maxSizeMB, multiple, required, placeholder, disabled, className, value, error, onFileSelect, onFilesSelect, onReject, }, ref) => {
|
|
9
25
|
const inputRef = React.useRef(null);
|
|
10
|
-
const [
|
|
26
|
+
const [pickedName, setPickedName] = React.useState(null);
|
|
11
27
|
const [dragging, setDragging] = React.useState(false);
|
|
28
|
+
const errorId = `${name}-error`;
|
|
29
|
+
const controlled = value !== undefined;
|
|
30
|
+
const fileName = controlled ? (value?.name ?? null) : pickedName;
|
|
12
31
|
const selectFiles = (files) => {
|
|
13
|
-
const
|
|
14
|
-
|
|
32
|
+
const accepted = files.filter((file) => {
|
|
33
|
+
if (!matchesAccept(file, accept)) {
|
|
34
|
+
onReject?.(file, "type");
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
if (maxSizeMB !== undefined && file.size > maxSizeMB * 1024 * 1024) {
|
|
38
|
+
onReject?.(file, "size");
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
return true;
|
|
42
|
+
});
|
|
43
|
+
// Every file was rejected: keep the current selection as it was.
|
|
44
|
+
if (files.length > 0 && accepted.length === 0)
|
|
45
|
+
return;
|
|
46
|
+
const file = accepted[0] ?? null;
|
|
47
|
+
setPickedName(accepted.length > 1
|
|
48
|
+
? `${accepted.length} files selected`
|
|
49
|
+
: (file?.name ?? null));
|
|
15
50
|
onFileSelect?.(file);
|
|
16
|
-
onFilesSelect?.(
|
|
51
|
+
onFilesSelect?.(accepted);
|
|
17
52
|
};
|
|
18
|
-
const openPicker = () => {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
53
|
+
const openPicker = () => {
|
|
54
|
+
if (!disabled)
|
|
55
|
+
inputRef.current?.click();
|
|
56
|
+
};
|
|
57
|
+
return (jsxs("div", { className: cn("grid gap-field-label-gap", className), children: [jsxs(FieldLabel, { htmlFor: name, children: [label, required && jsx("span", { className: "text-destructive", children: " *" })] }), jsxs("button", { type: "button", disabled: disabled, onClick: openPicker, "aria-invalid": error ? true : undefined, "aria-describedby": error ? errorId : undefined, onDragEnter: (event) => {
|
|
58
|
+
event.preventDefault();
|
|
59
|
+
setDragging(true);
|
|
60
|
+
}, onDragOver: (event) => {
|
|
61
|
+
event.preventDefault();
|
|
62
|
+
if (!disabled)
|
|
63
|
+
setDragging(true);
|
|
64
|
+
}, onDragLeave: () => setDragging(false), onDrop: (event) => {
|
|
65
|
+
event.preventDefault();
|
|
66
|
+
setDragging(false);
|
|
67
|
+
if (disabled)
|
|
68
|
+
return;
|
|
69
|
+
selectFiles(Array.from(event.dataTransfer.files).slice(0, multiple ? undefined : 1));
|
|
70
|
+
}, className: cn("flex w-full cursor-pointer items-center gap-2 border border-input text-left text-sm text-muted-foreground transition-colors hover:border-input-hover hover:bg-accent focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring motion-reduce:transition-none disabled:cursor-not-allowed disabled:opacity-60", variant === "dropzone"
|
|
71
|
+
? "min-h-36 flex-col justify-center rounded-card border-solid border-border px-6 py-6 text-center"
|
|
72
|
+
: "min-h-11 rounded-control-lg px-4 py-2", dragging && "border-primary bg-primary-tint", error && "border-destructive"), children: [jsx(Upload, { className: "size-5 shrink-0 text-primary" }), jsx("span", { className: cn("min-w-0 truncate", fileName && "text-foreground"), children: fileName ?? placeholder ?? "Drop a file here or click to upload" })] }), jsx("input", { ref: (node) => {
|
|
73
|
+
inputRef.current = node;
|
|
74
|
+
if (typeof ref === "function")
|
|
75
|
+
ref(node);
|
|
76
|
+
else if (ref)
|
|
77
|
+
ref.current = node;
|
|
78
|
+
}, id: name, type: "file", name: name, accept: accept, multiple: multiple, required: required, disabled: disabled, onChange: (event) => {
|
|
79
|
+
selectFiles(Array.from(event.target.files ?? []));
|
|
80
|
+
// Let the same file be picked again, e.g. after a rejection.
|
|
81
|
+
event.target.value = "";
|
|
82
|
+
}, className: "sr-only" }), error && (jsx("p", { id: errorId, role: "alert", className: "m-0 text-xs text-destructive", children: error }))] }));
|
|
25
83
|
});
|
|
26
84
|
FileUpload.displayName = "FileUpload";
|
|
27
85
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file-upload.js","sources":["../../src/components/file-upload.tsx"],"sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\nimport { Upload } from \"lucide-react\";\nimport { cn } from \"@/utils\";\nimport { FieldLabel } from \"./label\";\n\nexport type FileUploadVariant = \"compact\" | \"dropzone\";\nexport type FileUploadProps = {\n label: string;\n name: string;\n variant?: FileUploadVariant;\n accept?: string;\n multiple?: boolean;\n required?: boolean;\n placeholder?: string;\n disabled?: boolean;\n className?: string;\n onFileSelect?: (file: File | null) => void;\n onFilesSelect?: (files: File[]) => void;\n};\n\nexport const FileUpload = React.forwardRef<HTMLInputElement, FileUploadProps>(\n ({
|
|
1
|
+
{"version":3,"file":"file-upload.js","sources":["../../src/components/file-upload.tsx"],"sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\nimport { Upload } from \"lucide-react\";\nimport { cn } from \"@/utils\";\nimport { FieldLabel } from \"./label\";\n\nexport type FileUploadVariant = \"compact\" | \"dropzone\";\nexport type FileRejectReason = \"type\" | \"size\";\nexport type FileUploadProps = {\n label: string;\n name: string;\n variant?: FileUploadVariant;\n /** Same format as the input's `accept`: extensions (\".pdf\") and/or MIME types (\"image/*\"). Also checked on drop. */\n accept?: string;\n /** Files larger than this are rejected through `onReject` instead of being selected. */\n maxSizeMB?: number;\n multiple?: boolean;\n required?: boolean;\n placeholder?: string;\n disabled?: boolean;\n className?: string;\n /**\n * The selected file, when the parent owns it. Pass `null` to clear the field.\n * Leave undefined to let the field remember the last pick itself.\n */\n value?: File | null;\n /** Shown under the field and marks it invalid. */\n error?: string | null;\n onFileSelect?: (file: File | null) => void;\n onFilesSelect?: (files: File[]) => void;\n /** Called with each file that fails `accept` or `maxSizeMB`. */\n onReject?: (file: File, reason: FileRejectReason) => void;\n};\n\n/** True when the file matches one of the `accept` entries (or there are none). */\nfunction matchesAccept(file: File, accept?: string) {\n if (!accept) return true;\n const name = file.name.toLowerCase();\n const type = file.type.toLowerCase();\n return accept\n .split(\",\")\n .map((entry) => entry.trim().toLowerCase())\n .filter(Boolean)\n .some((entry) =>\n entry.startsWith(\".\")\n ? name.endsWith(entry)\n : entry.endsWith(\"/*\")\n ? type.startsWith(entry.slice(0, -1))\n : type === entry,\n );\n}\n\nexport const FileUpload = React.forwardRef<HTMLInputElement, FileUploadProps>(\n (\n {\n label,\n name,\n variant = \"compact\",\n accept,\n maxSizeMB,\n multiple,\n required,\n placeholder,\n disabled,\n className,\n value,\n error,\n onFileSelect,\n onFilesSelect,\n onReject,\n },\n ref,\n ) => {\n const inputRef = React.useRef<HTMLInputElement>(null);\n const [pickedName, setPickedName] = React.useState<string | null>(null);\n const [dragging, setDragging] = React.useState(false);\n const errorId = `${name}-error`;\n const controlled = value !== undefined;\n const fileName = controlled ? (value?.name ?? null) : pickedName;\n\n const selectFiles = (files: File[]) => {\n const accepted = files.filter((file) => {\n if (!matchesAccept(file, accept)) {\n onReject?.(file, \"type\");\n return false;\n }\n if (maxSizeMB !== undefined && file.size > maxSizeMB * 1024 * 1024) {\n onReject?.(file, \"size\");\n return false;\n }\n return true;\n });\n // Every file was rejected: keep the current selection as it was.\n if (files.length > 0 && accepted.length === 0) return;\n\n const file = accepted[0] ?? null;\n setPickedName(\n accepted.length > 1\n ? `${accepted.length} files selected`\n : (file?.name ?? null),\n );\n onFileSelect?.(file);\n onFilesSelect?.(accepted);\n };\n const openPicker = () => {\n if (!disabled) inputRef.current?.click();\n };\n\n return (\n <div className={cn(\"grid gap-field-label-gap\", className)}>\n <FieldLabel htmlFor={name}>\n {label}\n {required && <span className=\"text-destructive\"> *</span>}\n </FieldLabel>\n <button\n type=\"button\"\n disabled={disabled}\n onClick={openPicker}\n aria-invalid={error ? true : undefined}\n aria-describedby={error ? errorId : undefined}\n onDragEnter={(event) => {\n event.preventDefault();\n setDragging(true);\n }}\n onDragOver={(event) => {\n event.preventDefault();\n if (!disabled) setDragging(true);\n }}\n onDragLeave={() => setDragging(false)}\n onDrop={(event) => {\n event.preventDefault();\n setDragging(false);\n if (disabled) return;\n selectFiles(\n Array.from(event.dataTransfer.files).slice(\n 0,\n multiple ? undefined : 1,\n ),\n );\n }}\n className={cn(\n \"flex w-full cursor-pointer items-center gap-2 border border-input text-left text-sm text-muted-foreground transition-colors hover:border-input-hover hover:bg-accent focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring motion-reduce:transition-none disabled:cursor-not-allowed disabled:opacity-60\",\n variant === \"dropzone\"\n ? \"min-h-36 flex-col justify-center rounded-card border-solid border-border px-6 py-6 text-center\"\n : \"min-h-11 rounded-control-lg px-4 py-2\",\n dragging && \"border-primary bg-primary-tint\",\n error && \"border-destructive\",\n )}\n >\n <Upload className=\"size-5 shrink-0 text-primary\" />\n <span className={cn(\"min-w-0 truncate\", fileName && \"text-foreground\")}>\n {fileName ?? placeholder ?? \"Drop a file here or click to upload\"}\n </span>\n </button>\n <input\n ref={(node) => {\n inputRef.current = node;\n if (typeof ref === \"function\") ref(node);\n else if (ref) ref.current = node;\n }}\n id={name}\n type=\"file\"\n name={name}\n accept={accept}\n multiple={multiple}\n required={required}\n disabled={disabled}\n onChange={(event) => {\n selectFiles(Array.from(event.target.files ?? []));\n // Let the same file be picked again, e.g. after a rejection.\n event.target.value = \"\";\n }}\n className=\"sr-only\"\n />\n {error && (\n <p id={errorId} role=\"alert\" className=\"m-0 text-xs text-destructive\">\n {error}\n </p>\n )}\n </div>\n );\n },\n);\nFileUpload.displayName = \"FileUpload\";\n"],"names":[],"mappings":";;;;;;;AAmCA;AACA;AACE;AAAa;;;AAGb;;AAEG;;;AAIG;AACA;AACE;AACA;AAEV;;;AAwBI;AACA;AACA;AACA;AACA;AAEA;;;AAGM;AACA;;AAEF;AACE;AACA;;AAEF;AACF;;;;;AAKA;AAEI;;AAGJ;AACA;AACF;;AAEE;AAAe;AACjB;AAEA;;;AAeM;;AAGE;;AACF;;;AAKE;;;;AAWE;;AAaF;;;AAEK;AAAS;AAChB;AASE;;AAEA;;AAWV;AAEF;;"}
|
|
@@ -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';
|