@opentui-ui/toast 0.0.1
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/README.md +660 -0
- package/dist/icons-DXx_5j_z.mjs +181 -0
- package/dist/icons-DXx_5j_z.mjs.map +1 -0
- package/dist/icons.d.mts +116 -0
- package/dist/icons.d.mts.map +1 -0
- package/dist/icons.mjs +3 -0
- package/dist/index.d.mts +53 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +4 -0
- package/dist/react.d.mts +13 -0
- package/dist/react.d.mts.map +1 -0
- package/dist/react.mjs +14 -0
- package/dist/react.mjs.map +1 -0
- package/dist/state-CoqnQZsz.d.mts +157 -0
- package/dist/state-CoqnQZsz.d.mts.map +1 -0
- package/dist/themes.d.mts +69 -0
- package/dist/themes.d.mts.map +1 -0
- package/dist/themes.mjs +118 -0
- package/dist/themes.mjs.map +1 -0
- package/dist/toaster-CQ5RySDh.mjs +1118 -0
- package/dist/toaster-CQ5RySDh.mjs.map +1 -0
- package/dist/types-BnTc6iEw.d.mts +342 -0
- package/dist/types-BnTc6iEw.d.mts.map +1 -0
- package/package.json +70 -0
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
//#region src/types.ts
|
|
2
|
+
/**
|
|
3
|
+
* Check if a value is a SpinnerConfig object
|
|
4
|
+
*/
|
|
5
|
+
function isSpinnerConfig(value) {
|
|
6
|
+
return typeof value === "object" && value !== null && "frames" in value && "interval" in value && Array.isArray(value.frames);
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Check if an action object is a valid Action
|
|
10
|
+
*/
|
|
11
|
+
function isAction(action) {
|
|
12
|
+
return typeof action === "object" && action !== null && "label" in action && "onClick" in action;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
//#endregion
|
|
16
|
+
//#region src/icons.ts
|
|
17
|
+
/**
|
|
18
|
+
* Default spinner configuration for loading toasts
|
|
19
|
+
*
|
|
20
|
+
* Uses a circular animation pattern. Override this by providing
|
|
21
|
+
* a custom `loading` value in the `icons` option.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* // Use a different spinner pattern
|
|
26
|
+
* const toaster = new ToasterRenderable(ctx, {
|
|
27
|
+
* icons: {
|
|
28
|
+
* ...DEFAULT_ICONS,
|
|
29
|
+
* loading: {
|
|
30
|
+
* frames: ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'],
|
|
31
|
+
* interval: 80,
|
|
32
|
+
* },
|
|
33
|
+
* },
|
|
34
|
+
* });
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
const DEFAULT_SPINNER = {
|
|
38
|
+
frames: [
|
|
39
|
+
"◜",
|
|
40
|
+
"◠",
|
|
41
|
+
"◝",
|
|
42
|
+
"◞",
|
|
43
|
+
"◡",
|
|
44
|
+
"◟"
|
|
45
|
+
],
|
|
46
|
+
interval: 100
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Default Unicode icons for toast notifications
|
|
50
|
+
*
|
|
51
|
+
* These work in most modern terminals. Use these as the base
|
|
52
|
+
* and override specific icons as needed.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```ts
|
|
56
|
+
* import { DEFAULT_ICONS, ToasterRenderable } from '@opentui-ui/toast';
|
|
57
|
+
*
|
|
58
|
+
* // Use defaults with a custom success icon
|
|
59
|
+
* const toaster = new ToasterRenderable(ctx, {
|
|
60
|
+
* icons: { ...DEFAULT_ICONS, success: '++' },
|
|
61
|
+
* });
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
const DEFAULT_ICONS = {
|
|
65
|
+
success: "✓",
|
|
66
|
+
error: "✗",
|
|
67
|
+
warning: "!",
|
|
68
|
+
info: "ℹ",
|
|
69
|
+
loading: DEFAULT_SPINNER,
|
|
70
|
+
close: "×"
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* ASCII-only icons for terminals with limited Unicode support
|
|
74
|
+
*
|
|
75
|
+
* Use these when targeting older terminals or environments
|
|
76
|
+
* where Unicode characters may not render correctly.
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```ts
|
|
80
|
+
* import { ASCII_ICONS, ToasterRenderable } from '@opentui-ui/toast';
|
|
81
|
+
*
|
|
82
|
+
* const toaster = new ToasterRenderable(ctx, {
|
|
83
|
+
* icons: ASCII_ICONS,
|
|
84
|
+
* });
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
const ASCII_ICONS = {
|
|
88
|
+
success: "[/]",
|
|
89
|
+
error: "[x]",
|
|
90
|
+
warning: "[!]",
|
|
91
|
+
info: "[i]",
|
|
92
|
+
loading: "...",
|
|
93
|
+
close: "x"
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* Minimal icons using simple single characters
|
|
97
|
+
*
|
|
98
|
+
* Perfect for clean, unobtrusive toast notifications.
|
|
99
|
+
* Pairs well with the `minimal` theme.
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* ```ts
|
|
103
|
+
* import { MINIMAL_ICONS, ToasterRenderable } from '@opentui-ui/toast';
|
|
104
|
+
* import { minimal } from '@opentui-ui/toast/themes';
|
|
105
|
+
*
|
|
106
|
+
* const toaster = new ToasterRenderable(ctx, {
|
|
107
|
+
* ...minimal,
|
|
108
|
+
* icons: MINIMAL_ICONS,
|
|
109
|
+
* });
|
|
110
|
+
* ```
|
|
111
|
+
*/
|
|
112
|
+
const MINIMAL_ICONS = {
|
|
113
|
+
success: "*",
|
|
114
|
+
error: "!",
|
|
115
|
+
warning: "!",
|
|
116
|
+
info: "i",
|
|
117
|
+
loading: "~",
|
|
118
|
+
close: "x"
|
|
119
|
+
};
|
|
120
|
+
/**
|
|
121
|
+
* Emoji icons for terminals with good emoji support
|
|
122
|
+
*
|
|
123
|
+
* Note: Emoji rendering varies across terminals. Test in your
|
|
124
|
+
* target environment before using in production.
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* ```ts
|
|
128
|
+
* import { EMOJI_ICONS, ToasterRenderable } from '@opentui-ui/toast';
|
|
129
|
+
*
|
|
130
|
+
* const toaster = new ToasterRenderable(ctx, {
|
|
131
|
+
* icons: EMOJI_ICONS,
|
|
132
|
+
* });
|
|
133
|
+
* ```
|
|
134
|
+
*/
|
|
135
|
+
const EMOJI_ICONS = {
|
|
136
|
+
success: "✅",
|
|
137
|
+
error: "❌",
|
|
138
|
+
warning: "⚠️",
|
|
139
|
+
info: "ℹ️",
|
|
140
|
+
loading: "⏳",
|
|
141
|
+
close: "✖️"
|
|
142
|
+
};
|
|
143
|
+
/**
|
|
144
|
+
* Get the icon string for a specific toast type
|
|
145
|
+
*
|
|
146
|
+
* For loading type, returns the first frame if it's a SpinnerConfig,
|
|
147
|
+
* or the static string otherwise.
|
|
148
|
+
*
|
|
149
|
+
* @internal - Used by ToastRenderable, not part of public API
|
|
150
|
+
*/
|
|
151
|
+
function getTypeIcon(type, icons) {
|
|
152
|
+
switch (type) {
|
|
153
|
+
case "success": return icons.success;
|
|
154
|
+
case "error": return icons.error;
|
|
155
|
+
case "warning": return icons.warning;
|
|
156
|
+
case "info": return icons.info;
|
|
157
|
+
case "loading": return getLoadingIcon(icons.loading);
|
|
158
|
+
default: return "";
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Get the initial loading icon (first frame if spinner, or static string)
|
|
163
|
+
*
|
|
164
|
+
* @internal
|
|
165
|
+
*/
|
|
166
|
+
function getLoadingIcon(loading) {
|
|
167
|
+
if (isSpinnerConfig(loading)) return loading.frames[0] ?? "◌";
|
|
168
|
+
return loading;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Get the spinner config if loading is animated, or null if static
|
|
172
|
+
*
|
|
173
|
+
* @internal
|
|
174
|
+
*/
|
|
175
|
+
function getSpinnerConfig(loading) {
|
|
176
|
+
return isSpinnerConfig(loading) ? loading : null;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
//#endregion
|
|
180
|
+
export { MINIMAL_ICONS as a, getTypeIcon as c, EMOJI_ICONS as i, isAction as l, DEFAULT_ICONS as n, getLoadingIcon as o, DEFAULT_SPINNER as r, getSpinnerConfig as s, ASCII_ICONS as t, isSpinnerConfig as u };
|
|
181
|
+
//# sourceMappingURL=icons-DXx_5j_z.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"icons-DXx_5j_z.mjs","names":["DEFAULT_SPINNER: SpinnerConfig","DEFAULT_ICONS: ToastIcons","ASCII_ICONS: ToastIcons","MINIMAL_ICONS: ToastIcons","EMOJI_ICONS: ToastIcons"],"sources":["../src/types.ts","../src/icons.ts"],"sourcesContent":["import type { BorderCharacters, BorderSides, BorderStyle } from \"@opentui/core\";\n\n/**\n * Toast notification types\n */\nexport type ToastType =\n | \"default\"\n | \"success\"\n | \"error\"\n | \"warning\"\n | \"info\"\n | \"loading\";\n\n/**\n * Position options for the toaster\n */\nexport type Position =\n | \"top-left\"\n | \"top-center\"\n | \"top-right\"\n | \"bottom-left\"\n | \"bottom-center\"\n | \"bottom-right\";\n\n/**\n * Stacking mode for multiple toasts\n */\nexport type StackingMode = \"single\" | \"stack\";\n\n/**\n * Action button configuration\n */\nexport interface Action {\n label: string;\n onClick: () => void;\n}\n\n/**\n * Terminal-specific toast styling options\n *\n * These map to terminal box rendering properties and provide\n * intuitive shorthands for common patterns.\n */\nexport interface ToastStyle {\n /**\n * Border configuration\n * - `true` = full border (all sides)\n * - `false` = no border\n * - `[\"left\", \"right\"]` = specific sides only\n */\n border?: boolean | BorderSides[];\n\n /**\n * Border color (hex, rgb, or named color)\n */\n borderColor?: string;\n\n /**\n * Border style for terminal rendering\n * @default 'single'\n */\n borderStyle?: BorderStyle;\n\n /**\n * Custom border characters for full control over border rendering\n *\n * When provided, this overrides the borderStyle setting.\n * Use this to create unique border styles with custom characters.\n */\n customBorderChars?: BorderCharacters;\n\n /**\n * Minimum height in terminal rows\n */\n minHeight?: number;\n\n /**\n * Maximum width in terminal columns\n */\n maxWidth?: number;\n\n /**\n * Minimum width in terminal columns\n */\n minWidth?: number;\n\n /**\n * Uniform padding (all sides)\n */\n padding?: number;\n\n /**\n * Horizontal padding (left + right)\n */\n paddingX?: number;\n\n /**\n * Vertical padding (top + bottom)\n */\n paddingY?: number;\n\n /**\n * Top padding\n */\n paddingTop?: number;\n\n /**\n * Bottom padding\n */\n paddingBottom?: number;\n\n /**\n * Left padding\n */\n paddingLeft?: number;\n\n /**\n * Right padding\n */\n paddingRight?: number;\n\n /**\n * Background color (hex, rgb, or named color)\n */\n backgroundColor?: string;\n\n /**\n * Text/foreground color (hex, rgb, or named color)\n */\n foregroundColor?: string;\n\n /**\n * Muted text color (for descriptions)\n */\n mutedColor?: string;\n\n /**\n * Icon color override (defaults to borderColor)\n */\n iconColor?: string;\n}\n\n/**\n * Per-type toast options\n *\n * Each type can override style and duration.\n */\nexport interface TypeToastOptions {\n /** Style overrides for this toast type */\n style?: Partial<ToastStyle>;\n /** Duration override for this toast type */\n duration?: number;\n}\n\n/**\n * Default options for all toasts, with per-type overrides\n *\n * Similar to react-hot-toast's toastOptions API:\n * @example\n * ```ts\n * toastOptions={{\n * style: { backgroundColor: '#1a1a1a' },\n * duration: 5000,\n * success: {\n * style: { borderColor: '#22c55e' },\n * duration: 3000,\n * },\n * error: {\n * style: { borderColor: '#ef4444' },\n * },\n * }}\n * ```\n */\nexport interface ToastOptions {\n /** Base styles applied to all toasts */\n style?: ToastStyle;\n /** Default duration for all toasts (ms) */\n duration?: number;\n /** Options for default toasts */\n default?: TypeToastOptions;\n /** Options for success toasts */\n success?: TypeToastOptions;\n /** Options for error toasts */\n error?: TypeToastOptions;\n /** Options for warning toasts */\n warning?: TypeToastOptions;\n /** Options for info toasts */\n info?: TypeToastOptions;\n /** Options for loading toasts */\n loading?: TypeToastOptions;\n}\n\n/**\n * Internal toast representation\n */\nexport interface Toast {\n id: string | number;\n type: ToastType;\n title?: string | (() => string);\n description?: string | (() => string);\n duration?: number;\n dismissible?: boolean;\n icon?: string;\n action?: Action;\n onDismiss?: (toast: Toast) => void;\n onAutoClose?: (toast: Toast) => void;\n closeButton?: boolean;\n /**\n * Per-toast style overrides (highest priority)\n */\n style?: Partial<ToastStyle>;\n}\n\n/**\n * Toast to be dismissed\n */\nexport interface ToastToDismiss {\n id: string | number;\n dismiss: boolean;\n}\n\n/**\n * External toast options (user-facing API)\n *\n * This is the options object passed to `toast()`, `toast.success()`, etc.\n */\nexport interface ExternalToast\n extends Partial<Omit<Toast, \"id\" | \"type\" | \"title\" | \"promise\">> {\n id?: string | number;\n}\n\n/**\n * Promise type for toast.promise()\n */\nexport type PromiseT<Data = unknown> = Promise<Data> | (() => Promise<Data>);\n\n/**\n * Extended result type for promise toasts\n */\nexport interface PromiseExtendedResult extends ExternalToast {\n message: string;\n}\n\n/**\n * Promise result - can be a string or extended object\n */\nexport type PromiseTResult<Data = unknown> =\n | string\n | ((data: Data) => string | Promise<string>);\n\n/**\n * Promise toast configuration\n */\nexport interface PromiseData<ToastData = unknown> {\n loading?: string;\n success?:\n | PromiseTResult<ToastData>\n | PromiseExtendedResult\n | ((\n data: ToastData,\n ) => PromiseExtendedResult | Promise<PromiseExtendedResult>);\n error?:\n | PromiseTResult\n | PromiseExtendedResult\n | ((\n error: unknown,\n ) => PromiseExtendedResult | Promise<PromiseExtendedResult>);\n description?: PromiseTResult<ToastData>;\n finally?: () => void | Promise<void>;\n}\n\n/**\n * Spinner configuration for animated loading icons\n *\n * @example\n * ```ts\n * // Dots spinner\n * { frames: [\"⠋\", \"⠙\", \"⠹\", \"⠸\", \"⠼\", \"⠴\", \"⠦\", \"⠧\", \"⠇\", \"⠏\"], interval: 80 }\n *\n * // Simple spinner\n * { frames: [\"-\", \"\\\\\", \"|\", \"/\"], interval: 100 }\n * ```\n */\nexport interface SpinnerConfig {\n /** Array of frames to cycle through */\n frames: string[];\n /** Interval between frames in milliseconds */\n interval: number;\n}\n\n/**\n * Check if a value is a SpinnerConfig object\n */\nexport function isSpinnerConfig(\n value: string | SpinnerConfig,\n): value is SpinnerConfig {\n return (\n typeof value === \"object\" &&\n value !== null &&\n \"frames\" in value &&\n \"interval\" in value &&\n Array.isArray(value.frames)\n );\n}\n\n/**\n * Icon configuration\n */\nexport interface ToastIcons {\n success: string;\n error: string;\n warning: string;\n info: string;\n /**\n * Loading icon - can be a static string or an animated spinner config\n *\n * @example\n * ```ts\n * // Static icon\n * loading: \"◌\"\n *\n * // Animated spinner\n * loading: {\n * frames: [\"◜\", \"◠\", \"◝\", \"◞\", \"◡\", \"◟\"],\n * interval: 100,\n * }\n * ```\n */\n loading: string | SpinnerConfig;\n close: string;\n}\n\n/**\n * Offset configuration for toaster positioning\n */\nexport interface ToasterOffset {\n top?: number;\n right?: number;\n bottom?: number;\n left?: number;\n}\n\n/**\n * Toaster component options\n */\nexport interface ToasterOptions {\n /**\n * Position of the toaster on screen\n * @default 'bottom-right'\n */\n position?: Position;\n\n /**\n * Gap between toasts in terminal rows\n * @default 1\n */\n gap?: number;\n\n /**\n * Maximum number of visible toasts in stack mode\n * @default 3\n */\n visibleToasts?: number;\n\n /**\n * Show close button on toasts\n * @default false\n */\n closeButton?: boolean;\n\n /**\n * Offset from screen edges\n */\n offset?: ToasterOffset;\n\n /**\n * Custom icons, or `false` to disable icons entirely\n *\n * @example\n * ```ts\n * // Custom icons\n * icons: { success: \"✓\", error: \"✗\" }\n *\n * // Disable icons\n * icons: false\n * ```\n */\n icons?: Partial<ToastIcons> | false;\n\n /**\n * How to handle multiple toasts\n * @default 'single'\n */\n stackingMode?: StackingMode;\n\n /**\n * Maximum width for toasts\n * @default 60\n */\n maxWidth?: number;\n\n /**\n * Default options for toasts (styles, duration, per-type overrides)\n *\n * @example\n * ```ts\n * toastOptions: {\n * style: { backgroundColor: '#1a1a1a' },\n * duration: 5000,\n * success: {\n * style: { borderColor: '#22c55e' },\n * duration: 3000,\n * },\n * }\n * ```\n */\n toastOptions?: ToastOptions;\n}\n\n/**\n * Check if an action object is a valid Action\n */\nexport function isAction(action: Action | unknown): action is Action {\n return (\n typeof action === \"object\" &&\n action !== null &&\n \"label\" in action &&\n \"onClick\" in action\n );\n}\n","import type { SpinnerConfig, ToastIcons, ToastType } from \"./types\";\nimport { isSpinnerConfig } from \"./types\";\n\n/**\n * Default spinner configuration for loading toasts\n *\n * Uses a circular animation pattern. Override this by providing\n * a custom `loading` value in the `icons` option.\n *\n * @example\n * ```ts\n * // Use a different spinner pattern\n * const toaster = new ToasterRenderable(ctx, {\n * icons: {\n * ...DEFAULT_ICONS,\n * loading: {\n * frames: ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'],\n * interval: 80,\n * },\n * },\n * });\n * ```\n */\nexport const DEFAULT_SPINNER: SpinnerConfig = {\n frames: [\"◜\", \"◠\", \"◝\", \"◞\", \"◡\", \"◟\"],\n interval: 100,\n};\n\n/**\n * Default Unicode icons for toast notifications\n *\n * These work in most modern terminals. Use these as the base\n * and override specific icons as needed.\n *\n * @example\n * ```ts\n * import { DEFAULT_ICONS, ToasterRenderable } from '@opentui-ui/toast';\n *\n * // Use defaults with a custom success icon\n * const toaster = new ToasterRenderable(ctx, {\n * icons: { ...DEFAULT_ICONS, success: '++' },\n * });\n * ```\n */\nexport const DEFAULT_ICONS: ToastIcons = {\n success: \"\\u2713\", // checkmark\n error: \"\\u2717\", // X mark\n warning: \"\\u0021\", // exclamation mark\n info: \"\\u2139\", // information\n loading: DEFAULT_SPINNER,\n close: \"\\u00D7\", // multiplication sign (x)\n};\n\n/**\n * ASCII-only icons for terminals with limited Unicode support\n *\n * Use these when targeting older terminals or environments\n * where Unicode characters may not render correctly.\n *\n * @example\n * ```ts\n * import { ASCII_ICONS, ToasterRenderable } from '@opentui-ui/toast';\n *\n * const toaster = new ToasterRenderable(ctx, {\n * icons: ASCII_ICONS,\n * });\n * ```\n */\nexport const ASCII_ICONS: ToastIcons = {\n success: \"[/]\",\n error: \"[x]\",\n warning: \"[!]\",\n info: \"[i]\",\n loading: \"...\",\n close: \"x\",\n};\n\n/**\n * Minimal icons using simple single characters\n *\n * Perfect for clean, unobtrusive toast notifications.\n * Pairs well with the `minimal` theme.\n *\n * @example\n * ```ts\n * import { MINIMAL_ICONS, ToasterRenderable } from '@opentui-ui/toast';\n * import { minimal } from '@opentui-ui/toast/themes';\n *\n * const toaster = new ToasterRenderable(ctx, {\n * ...minimal,\n * icons: MINIMAL_ICONS,\n * });\n * ```\n */\nexport const MINIMAL_ICONS: ToastIcons = {\n success: \"*\",\n error: \"!\",\n warning: \"!\",\n info: \"i\",\n loading: \"~\",\n close: \"x\",\n};\n\n/**\n * Emoji icons for terminals with good emoji support\n *\n * Note: Emoji rendering varies across terminals. Test in your\n * target environment before using in production.\n *\n * @example\n * ```ts\n * import { EMOJI_ICONS, ToasterRenderable } from '@opentui-ui/toast';\n *\n * const toaster = new ToasterRenderable(ctx, {\n * icons: EMOJI_ICONS,\n * });\n * ```\n */\nexport const EMOJI_ICONS: ToastIcons = {\n success: \"\\u2705\", // green checkmark\n error: \"\\u274C\", // red X\n warning: \"\\u26A0\\uFE0F\", // warning with variation selector\n info: \"\\u2139\\uFE0F\", // info with variation selector\n loading: \"\\u23F3\", // hourglass\n close: \"\\u2716\\uFE0F\", // heavy multiplication X\n};\n\n/**\n * Get the icon string for a specific toast type\n *\n * For loading type, returns the first frame if it's a SpinnerConfig,\n * or the static string otherwise.\n *\n * @internal - Used by ToastRenderable, not part of public API\n */\nexport function getTypeIcon(type: ToastType, icons: ToastIcons): string {\n switch (type) {\n case \"success\":\n return icons.success;\n case \"error\":\n return icons.error;\n case \"warning\":\n return icons.warning;\n case \"info\":\n return icons.info;\n case \"loading\":\n return getLoadingIcon(icons.loading);\n default:\n return \"\";\n }\n}\n\n/**\n * Get the initial loading icon (first frame if spinner, or static string)\n *\n * @internal\n */\nexport function getLoadingIcon(loading: string | SpinnerConfig): string {\n if (isSpinnerConfig(loading)) {\n return loading.frames[0] ?? \"\\u25CC\"; // dotted circle (fallback when spinner unavailable)\n }\n return loading;\n}\n\n/**\n * Get the spinner config if loading is animated, or null if static\n *\n * @internal\n */\nexport function getSpinnerConfig(\n loading: string | SpinnerConfig,\n): SpinnerConfig | null {\n return isSpinnerConfig(loading) ? loading : null;\n}\n"],"mappings":";;;;AAqSA,SAAgB,gBACd,OACwB;AACxB,QACE,OAAO,UAAU,YACjB,UAAU,QACV,YAAY,SACZ,cAAc,SACd,MAAM,QAAQ,MAAM,OAAO;;;;;AAyH/B,SAAgB,SAAS,QAA4C;AACnE,QACE,OAAO,WAAW,YAClB,WAAW,QACX,WAAW,UACX,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;ACpZjB,MAAaA,kBAAiC;CAC5C,QAAQ;EAAC;EAAK;EAAK;EAAK;EAAK;EAAK;EAAI;CACtC,UAAU;CACX;;;;;;;;;;;;;;;;;AAkBD,MAAaC,gBAA4B;CACvC,SAAS;CACT,OAAO;CACP,SAAS;CACT,MAAM;CACN,SAAS;CACT,OAAO;CACR;;;;;;;;;;;;;;;;AAiBD,MAAaC,cAA0B;CACrC,SAAS;CACT,OAAO;CACP,SAAS;CACT,MAAM;CACN,SAAS;CACT,OAAO;CACR;;;;;;;;;;;;;;;;;;AAmBD,MAAaC,gBAA4B;CACvC,SAAS;CACT,OAAO;CACP,SAAS;CACT,MAAM;CACN,SAAS;CACT,OAAO;CACR;;;;;;;;;;;;;;;;AAiBD,MAAaC,cAA0B;CACrC,SAAS;CACT,OAAO;CACP,SAAS;CACT,MAAM;CACN,SAAS;CACT,OAAO;CACR;;;;;;;;;AAUD,SAAgB,YAAY,MAAiB,OAA2B;AACtE,SAAQ,MAAR;EACE,KAAK,UACH,QAAO,MAAM;EACf,KAAK,QACH,QAAO,MAAM;EACf,KAAK,UACH,QAAO,MAAM;EACf,KAAK,OACH,QAAO,MAAM;EACf,KAAK,UACH,QAAO,eAAe,MAAM,QAAQ;EACtC,QACE,QAAO;;;;;;;;AASb,SAAgB,eAAe,SAAyC;AACtE,KAAI,gBAAgB,QAAQ,CAC1B,QAAO,QAAQ,OAAO,MAAM;AAE9B,QAAO;;;;;;;AAQT,SAAgB,iBACd,SACsB;AACtB,QAAO,gBAAgB,QAAQ,GAAG,UAAU"}
|
package/dist/icons.d.mts
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { f as ToastType, l as ToastIcons, o as SpinnerConfig } from "./types-BnTc6iEw.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/icons.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Default spinner configuration for loading toasts
|
|
7
|
+
*
|
|
8
|
+
* Uses a circular animation pattern. Override this by providing
|
|
9
|
+
* a custom `loading` value in the `icons` option.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* // Use a different spinner pattern
|
|
14
|
+
* const toaster = new ToasterRenderable(ctx, {
|
|
15
|
+
* icons: {
|
|
16
|
+
* ...DEFAULT_ICONS,
|
|
17
|
+
* loading: {
|
|
18
|
+
* frames: ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'],
|
|
19
|
+
* interval: 80,
|
|
20
|
+
* },
|
|
21
|
+
* },
|
|
22
|
+
* });
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
declare const DEFAULT_SPINNER: SpinnerConfig;
|
|
26
|
+
/**
|
|
27
|
+
* Default Unicode icons for toast notifications
|
|
28
|
+
*
|
|
29
|
+
* These work in most modern terminals. Use these as the base
|
|
30
|
+
* and override specific icons as needed.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```ts
|
|
34
|
+
* import { DEFAULT_ICONS, ToasterRenderable } from '@opentui-ui/toast';
|
|
35
|
+
*
|
|
36
|
+
* // Use defaults with a custom success icon
|
|
37
|
+
* const toaster = new ToasterRenderable(ctx, {
|
|
38
|
+
* icons: { ...DEFAULT_ICONS, success: '++' },
|
|
39
|
+
* });
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
declare const DEFAULT_ICONS: ToastIcons;
|
|
43
|
+
/**
|
|
44
|
+
* ASCII-only icons for terminals with limited Unicode support
|
|
45
|
+
*
|
|
46
|
+
* Use these when targeting older terminals or environments
|
|
47
|
+
* where Unicode characters may not render correctly.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```ts
|
|
51
|
+
* import { ASCII_ICONS, ToasterRenderable } from '@opentui-ui/toast';
|
|
52
|
+
*
|
|
53
|
+
* const toaster = new ToasterRenderable(ctx, {
|
|
54
|
+
* icons: ASCII_ICONS,
|
|
55
|
+
* });
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
declare const ASCII_ICONS: ToastIcons;
|
|
59
|
+
/**
|
|
60
|
+
* Minimal icons using simple single characters
|
|
61
|
+
*
|
|
62
|
+
* Perfect for clean, unobtrusive toast notifications.
|
|
63
|
+
* Pairs well with the `minimal` theme.
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```ts
|
|
67
|
+
* import { MINIMAL_ICONS, ToasterRenderable } from '@opentui-ui/toast';
|
|
68
|
+
* import { minimal } from '@opentui-ui/toast/themes';
|
|
69
|
+
*
|
|
70
|
+
* const toaster = new ToasterRenderable(ctx, {
|
|
71
|
+
* ...minimal,
|
|
72
|
+
* icons: MINIMAL_ICONS,
|
|
73
|
+
* });
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
declare const MINIMAL_ICONS: ToastIcons;
|
|
77
|
+
/**
|
|
78
|
+
* Emoji icons for terminals with good emoji support
|
|
79
|
+
*
|
|
80
|
+
* Note: Emoji rendering varies across terminals. Test in your
|
|
81
|
+
* target environment before using in production.
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```ts
|
|
85
|
+
* import { EMOJI_ICONS, ToasterRenderable } from '@opentui-ui/toast';
|
|
86
|
+
*
|
|
87
|
+
* const toaster = new ToasterRenderable(ctx, {
|
|
88
|
+
* icons: EMOJI_ICONS,
|
|
89
|
+
* });
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
declare const EMOJI_ICONS: ToastIcons;
|
|
93
|
+
/**
|
|
94
|
+
* Get the icon string for a specific toast type
|
|
95
|
+
*
|
|
96
|
+
* For loading type, returns the first frame if it's a SpinnerConfig,
|
|
97
|
+
* or the static string otherwise.
|
|
98
|
+
*
|
|
99
|
+
* @internal - Used by ToastRenderable, not part of public API
|
|
100
|
+
*/
|
|
101
|
+
declare function getTypeIcon(type: ToastType, icons: ToastIcons): string;
|
|
102
|
+
/**
|
|
103
|
+
* Get the initial loading icon (first frame if spinner, or static string)
|
|
104
|
+
*
|
|
105
|
+
* @internal
|
|
106
|
+
*/
|
|
107
|
+
declare function getLoadingIcon(loading: string | SpinnerConfig): string;
|
|
108
|
+
/**
|
|
109
|
+
* Get the spinner config if loading is animated, or null if static
|
|
110
|
+
*
|
|
111
|
+
* @internal
|
|
112
|
+
*/
|
|
113
|
+
declare function getSpinnerConfig(loading: string | SpinnerConfig): SpinnerConfig | null;
|
|
114
|
+
//#endregion
|
|
115
|
+
export { ASCII_ICONS, DEFAULT_ICONS, DEFAULT_SPINNER, EMOJI_ICONS, MINIMAL_ICONS, getLoadingIcon, getSpinnerConfig, getTypeIcon };
|
|
116
|
+
//# sourceMappingURL=icons.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"icons.d.mts","names":[],"sources":["../src/icons.ts"],"sourcesContent":[],"mappings":";;;;;;AAuBA;AAqBA;AAwBA;AA0BA;AAwBA;AAiBA;AAsBA;AAYA;;;;;;;;;;;cAlJa,iBAAiB;;;;;;;;;;;;;;;;;cAqBjB,eAAe;;;;;;;;;;;;;;;;cAwBf,aAAa;;;;;;;;;;;;;;;;;;cA0Bb,eAAe;;;;;;;;;;;;;;;;cAwBf,aAAa;;;;;;;;;iBAiBV,WAAA,OAAkB,kBAAkB;;;;;;iBAsBpC,cAAA,mBAAiC;;;;;;iBAYjC,gBAAA,mBACI,gBACjB"}
|
package/dist/icons.mjs
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { a as MINIMAL_ICONS, c as getTypeIcon, i as EMOJI_ICONS, n as DEFAULT_ICONS, o as getLoadingIcon, r as DEFAULT_SPINNER, s as getSpinnerConfig, t as ASCII_ICONS } from "./icons-DXx_5j_z.mjs";
|
|
2
|
+
|
|
3
|
+
export { ASCII_ICONS, DEFAULT_ICONS, DEFAULT_SPINNER, EMOJI_ICONS, MINIMAL_ICONS, getLoadingIcon, getSpinnerConfig, getTypeIcon };
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { _ as isSpinnerConfig, d as ToastStyle, f as ToastType, g as isAction, h as TypeToastOptions, i as PromiseData, l as ToastIcons, m as ToasterOptions, n as ExternalToast, o as SpinnerConfig, p as ToasterOffset, r as Position, s as StackingMode, t as Action, u as ToastOptions } from "./types-BnTc6iEw.mjs";
|
|
2
|
+
import { ASCII_ICONS, DEFAULT_ICONS, EMOJI_ICONS, MINIMAL_ICONS } from "./icons.mjs";
|
|
3
|
+
import { n as ToasterRenderable, t as toast } from "./state-CoqnQZsz.mjs";
|
|
4
|
+
|
|
5
|
+
//#region src/constants.d.ts
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Common toast duration presets (in milliseconds)
|
|
9
|
+
*
|
|
10
|
+
* Use these for consistent, readable duration values across your app.
|
|
11
|
+
*
|
|
12
|
+
* | Preset | Duration | Use Case |
|
|
13
|
+
* |--------------|------------|---------------------------|
|
|
14
|
+
* | `SHORT` | 2000ms | Brief confirmations |
|
|
15
|
+
* | `DEFAULT` | 4000ms | Standard notifications |
|
|
16
|
+
* | `LONG` | 6000ms | Important messages |
|
|
17
|
+
* | `EXTENDED` | 10000ms | Critical information |
|
|
18
|
+
* | `PERSISTENT` | Infinity | Requires manual dismissal |
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* import { toast, TOAST_DURATION } from '@opentui-ui/toast';
|
|
23
|
+
*
|
|
24
|
+
* // Quick confirmation
|
|
25
|
+
* toast.success('Copied!', { duration: TOAST_DURATION.SHORT });
|
|
26
|
+
*
|
|
27
|
+
* // Important warning
|
|
28
|
+
* toast.warning('Check your settings', { duration: TOAST_DURATION.LONG });
|
|
29
|
+
*
|
|
30
|
+
* // Critical error that requires acknowledgment
|
|
31
|
+
* toast.error('Connection lost', { duration: TOAST_DURATION.PERSISTENT });
|
|
32
|
+
*
|
|
33
|
+
* // Set as default for all toasts
|
|
34
|
+
* const toaster = new ToasterRenderable(ctx, {
|
|
35
|
+
* toastOptions: { duration: TOAST_DURATION.LONG },
|
|
36
|
+
* });
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
declare const TOAST_DURATION: {
|
|
40
|
+
/** 2 seconds - for brief confirmations */
|
|
41
|
+
readonly SHORT: 2000;
|
|
42
|
+
/** 4 seconds - default duration */
|
|
43
|
+
readonly DEFAULT: 4000;
|
|
44
|
+
/** 6 seconds - for important messages */
|
|
45
|
+
readonly LONG: 6000;
|
|
46
|
+
/** 10 seconds - for critical information */
|
|
47
|
+
readonly EXTENDED: 10000;
|
|
48
|
+
/** Never auto-dismiss - requires manual dismissal */
|
|
49
|
+
readonly PERSISTENT: number;
|
|
50
|
+
};
|
|
51
|
+
//#endregion
|
|
52
|
+
export { ASCII_ICONS, type Action, DEFAULT_ICONS, EMOJI_ICONS, type ExternalToast, MINIMAL_ICONS, type Position, type PromiseData, type SpinnerConfig, type StackingMode, TOAST_DURATION, type ToastIcons, type ToastOptions, type ToastStyle, type ToastType, type ToasterOffset, type ToasterOptions, ToasterRenderable, type TypeToastOptions, isAction, isSpinnerConfig, toast };
|
|
53
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/constants.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;AAkCA;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAAa"}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { n as toast, r as TOAST_DURATION, t as ToasterRenderable } from "./toaster-CQ5RySDh.mjs";
|
|
2
|
+
import { a as MINIMAL_ICONS, i as EMOJI_ICONS, l as isAction, n as DEFAULT_ICONS, t as ASCII_ICONS, u as isSpinnerConfig } from "./icons-DXx_5j_z.mjs";
|
|
3
|
+
|
|
4
|
+
export { ASCII_ICONS, DEFAULT_ICONS, EMOJI_ICONS, MINIMAL_ICONS, TOAST_DURATION, ToasterRenderable, isAction, isSpinnerConfig, toast };
|
package/dist/react.d.mts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { m as ToasterOptions } from "./types-BnTc6iEw.mjs";
|
|
2
|
+
import { n as ToasterRenderable, t as toast } from "./state-CoqnQZsz.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/react.d.ts
|
|
5
|
+
declare module "@opentui/react" {
|
|
6
|
+
interface OpenTUIComponents {
|
|
7
|
+
toaster: typeof ToasterRenderable;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
declare function Toaster(props: ToasterOptions): React.ReactNode;
|
|
11
|
+
//#endregion
|
|
12
|
+
export { Toaster, toast };
|
|
13
|
+
//# sourceMappingURL=react.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react.d.mts","names":[],"sources":["../src/react.tsx"],"sourcesContent":[],"mappings":";;;;;EAI8C,UAAA,iBAAA,CAAA;IAAA,OAAA,EAAA,OAK1B,iBAL0B;;;AAKT,iBAOrB,OAAA,CAPqB,KAAA,EAON,cAPM,CAAA,EAOQ,KAAA,CAAA,SAPR"}
|
package/dist/react.mjs
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { n as toast, t as ToasterRenderable } from "./toaster-CQ5RySDh.mjs";
|
|
2
|
+
import { extend } from "@opentui/react";
|
|
3
|
+
import { jsx } from "@opentui/react/jsx-runtime";
|
|
4
|
+
|
|
5
|
+
//#region src/react.tsx
|
|
6
|
+
/** @jsxImportSource @opentui/react */
|
|
7
|
+
extend({ toaster: ToasterRenderable });
|
|
8
|
+
function Toaster(props) {
|
|
9
|
+
return /* @__PURE__ */ jsx("toaster", { ...props });
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
//#endregion
|
|
13
|
+
export { Toaster, toast };
|
|
14
|
+
//# sourceMappingURL=react.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react.mjs","names":[],"sources":["../src/react.tsx"],"sourcesContent":["/** @jsxImportSource @opentui/react */\n\nimport { extend } from \"@opentui/react\";\nimport { ToasterRenderable } from \"./renderables\";\nimport type { ToasterOptions } from \"./types\";\n\n// Add TypeScript support\ndeclare module \"@opentui/react\" {\n interface OpenTUIComponents {\n toaster: typeof ToasterRenderable;\n }\n}\n\n// Register the toaster component\nextend({ toaster: ToasterRenderable });\n\nexport function Toaster(props: ToasterOptions) {\n return <toaster {...props} />;\n}\n\nexport { toast } from \"./state\";\n"],"mappings":";;;;;;AAcA,OAAO,EAAE,SAAS,mBAAmB,CAAC;AAEtC,SAAgB,QAAQ,OAAuB;AAC7C,QAAO,oBAAC,aAAQ,GAAI,QAAS"}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { a as PromiseT, c as Toast, i as PromiseData, m as ToasterOptions, n as ExternalToast } from "./types-BnTc6iEw.mjs";
|
|
2
|
+
import { BoxRenderable, RenderContext } from "@opentui/core";
|
|
3
|
+
|
|
4
|
+
//#region src/renderables/toaster.d.ts
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* ToasterRenderable - Container for toast notifications
|
|
8
|
+
*
|
|
9
|
+
* Features:
|
|
10
|
+
* - Subscribes to ToastState for automatic toast management
|
|
11
|
+
* - Supports 6 position variants (top/bottom + left/center/right)
|
|
12
|
+
* - Single or stack mode for multiple toasts
|
|
13
|
+
* - Configurable visible toast limit in stack mode
|
|
14
|
+
* - Automatic oldest toast removal when limit exceeded
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* import { ToasterRenderable, toast } from '@opentui-ui/toast';
|
|
19
|
+
*
|
|
20
|
+
* // Basic usage - add to your app once
|
|
21
|
+
* const toaster = new ToasterRenderable(ctx);
|
|
22
|
+
* ctx.root.add(toaster);
|
|
23
|
+
*
|
|
24
|
+
* // Then show toasts from anywhere
|
|
25
|
+
* toast.success('Hello World!');
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* // With full configuration
|
|
31
|
+
* const toaster = new ToasterRenderable(ctx, {
|
|
32
|
+
* position: 'top-right',
|
|
33
|
+
* stackingMode: 'stack',
|
|
34
|
+
* visibleToasts: 5,
|
|
35
|
+
* closeButton: true,
|
|
36
|
+
* gap: 1,
|
|
37
|
+
* toastOptions: {
|
|
38
|
+
* style: { backgroundColor: '#1a1a1a' },
|
|
39
|
+
* duration: 5000,
|
|
40
|
+
* success: { style: { borderColor: '#22c55e' } },
|
|
41
|
+
* error: { style: { borderColor: '#ef4444' } },
|
|
42
|
+
* },
|
|
43
|
+
* });
|
|
44
|
+
* ```
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```ts
|
|
48
|
+
* // With a theme preset
|
|
49
|
+
* import { minimal } from '@opentui-ui/toast/themes';
|
|
50
|
+
*
|
|
51
|
+
* const toaster = new ToasterRenderable(ctx, {
|
|
52
|
+
* ...minimal,
|
|
53
|
+
* position: 'bottom-center',
|
|
54
|
+
* });
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
declare class ToasterRenderable extends BoxRenderable {
|
|
58
|
+
private _options;
|
|
59
|
+
private _toastRenderables;
|
|
60
|
+
private _unsubscribe;
|
|
61
|
+
constructor(ctx: RenderContext, options?: ToasterOptions);
|
|
62
|
+
/**
|
|
63
|
+
* Subscribe to toast state changes
|
|
64
|
+
*/
|
|
65
|
+
private subscribe;
|
|
66
|
+
/**
|
|
67
|
+
* Add a new toast or update an existing one
|
|
68
|
+
*/
|
|
69
|
+
private addOrUpdateToast;
|
|
70
|
+
/**
|
|
71
|
+
* Remove a toast by ID
|
|
72
|
+
*/
|
|
73
|
+
private removeToast;
|
|
74
|
+
/**
|
|
75
|
+
* Handle when a toast is fully removed
|
|
76
|
+
*/
|
|
77
|
+
private handleToastRemoved;
|
|
78
|
+
/**
|
|
79
|
+
* Get the current number of visible toasts
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```ts
|
|
83
|
+
* if (toaster.toastCount > 0) {
|
|
84
|
+
* console.log(`Showing ${toaster.toastCount} notifications`);
|
|
85
|
+
* }
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
88
|
+
get toastCount(): number;
|
|
89
|
+
/**
|
|
90
|
+
* Dismiss all toasts managed by this toaster
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* ```ts
|
|
94
|
+
* // Clear all notifications
|
|
95
|
+
* toaster.dismissAll();
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
dismissAll(): void;
|
|
99
|
+
/**
|
|
100
|
+
* Clean up on destroy
|
|
101
|
+
*/
|
|
102
|
+
destroy(): void;
|
|
103
|
+
}
|
|
104
|
+
//#endregion
|
|
105
|
+
//#region src/state.d.ts
|
|
106
|
+
type TitleT = string | (() => string);
|
|
107
|
+
/**
|
|
108
|
+
* Observer class implementing the pub/sub pattern for toast state management.
|
|
109
|
+
* This is the core of the Sonner-compatible API.
|
|
110
|
+
*/
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* The main toast API - a function with methods attached
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* ```ts
|
|
117
|
+
* // Basic usage
|
|
118
|
+
* toast('Hello World');
|
|
119
|
+
*
|
|
120
|
+
* // With variants
|
|
121
|
+
* toast.success('Operation completed');
|
|
122
|
+
* toast.error('Something went wrong');
|
|
123
|
+
* toast.warning('Be careful');
|
|
124
|
+
* toast.info('Did you know?');
|
|
125
|
+
* toast.loading('Processing...');
|
|
126
|
+
*
|
|
127
|
+
* // Promise toast
|
|
128
|
+
* toast.promise(fetchData(), {
|
|
129
|
+
* loading: 'Loading...',
|
|
130
|
+
* success: 'Data loaded!',
|
|
131
|
+
* error: 'Failed to load',
|
|
132
|
+
* });
|
|
133
|
+
*
|
|
134
|
+
* // Dismiss
|
|
135
|
+
* const id = toast('Hello');
|
|
136
|
+
* toast.dismiss(id);
|
|
137
|
+
* toast.dismiss(); // dismiss all
|
|
138
|
+
* ```
|
|
139
|
+
*/
|
|
140
|
+
declare const toast: ((message: TitleT, data?: ExternalToast) => string | number) & {
|
|
141
|
+
success: (message: TitleT, data?: ExternalToast) => string | number;
|
|
142
|
+
info: (message: TitleT, data?: ExternalToast) => string | number;
|
|
143
|
+
warning: (message: TitleT, data?: ExternalToast) => string | number;
|
|
144
|
+
error: (message: TitleT, data?: ExternalToast) => string | number;
|
|
145
|
+
message: (message: TitleT, data?: ExternalToast) => string | number;
|
|
146
|
+
promise: <ToastData>(promise: PromiseT<ToastData>, data?: PromiseData<ToastData> | undefined) => {
|
|
147
|
+
unwrap: () => Promise<ToastData>;
|
|
148
|
+
} | undefined;
|
|
149
|
+
dismiss: (id?: string | number) => string | number | undefined;
|
|
150
|
+
loading: (message: TitleT, data?: ExternalToast) => string | number;
|
|
151
|
+
} & {
|
|
152
|
+
getHistory: () => Toast[];
|
|
153
|
+
getToasts: () => Toast[];
|
|
154
|
+
};
|
|
155
|
+
//#endregion
|
|
156
|
+
export { ToasterRenderable as n, toast as t };
|
|
157
|
+
//# sourceMappingURL=state-CoqnQZsz.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state-CoqnQZsz.d.mts","names":[],"sources":["../src/renderables/toaster.ts","../src/state.ts"],"sourcesContent":[],"mappings":";;;;;;;;;ACQiB;AAqejB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cD3aa,iBAAA,SAA0B,aAAA;;;;mBAKpB,yBAAwB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KC3DtC,MAAA;;;ADsDL;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cC2aa,kBAtDF,eACF;qBAxPa,eAAe;kBAalB,eAAe;qBAaZ,eAAe;mBAvCjB,eAAe;qBAbb,eAAe;gCAsGf,SAAA,mBAAA,YAAA;;;;qBA/BA,eAAe"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { m as ToasterOptions } from "./types-BnTc6iEw.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/themes.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A theme configuration for the toaster.
|
|
7
|
+
* Extends ToasterOptions with metadata.
|
|
8
|
+
*/
|
|
9
|
+
interface ToasterTheme extends ToasterOptions {
|
|
10
|
+
/** Human-readable name for the theme */
|
|
11
|
+
name: string;
|
|
12
|
+
/** Brief description of the theme */
|
|
13
|
+
description: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Minimal theme - clean and unobtrusive
|
|
17
|
+
*
|
|
18
|
+
* No borders, subtle styling. Perfect for apps where
|
|
19
|
+
* toasts should be informative but not distracting.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
23
|
+
* import { ToasterRenderable } from '@opentui-ui/toast';
|
|
24
|
+
* import { minimal } from '@opentui-ui/toast/themes';
|
|
25
|
+
*
|
|
26
|
+
* const toaster = new ToasterRenderable(ctx, minimal);
|
|
27
|
+
*
|
|
28
|
+
* // Or customize it
|
|
29
|
+
* const toaster = new ToasterRenderable(ctx, {
|
|
30
|
+
* ...minimal,
|
|
31
|
+
* position: 'top-center',
|
|
32
|
+
* stackingMode: 'stack',
|
|
33
|
+
* });
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
declare const minimal: ToasterTheme;
|
|
37
|
+
/**
|
|
38
|
+
* Monochrome theme - grayscale only
|
|
39
|
+
*
|
|
40
|
+
* No colors, just shades of gray. Useful for
|
|
41
|
+
* accessibility or when color is not desired.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```ts
|
|
45
|
+
* import { ToasterRenderable } from '@opentui-ui/toast';
|
|
46
|
+
* import { monochrome } from '@opentui-ui/toast/themes';
|
|
47
|
+
*
|
|
48
|
+
* const toaster = new ToasterRenderable(ctx, monochrome);
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
declare const monochrome: ToasterTheme;
|
|
52
|
+
/**
|
|
53
|
+
* All available themes as a single object
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```ts
|
|
57
|
+
* import { themes } from '@opentui-ui/toast/themes';
|
|
58
|
+
*
|
|
59
|
+
* // Access themes by name
|
|
60
|
+
* const toaster = new ToasterRenderable(ctx, themes.minimal);
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
declare const themes: {
|
|
64
|
+
readonly minimal: ToasterTheme;
|
|
65
|
+
readonly monochrome: ToasterTheme;
|
|
66
|
+
};
|
|
67
|
+
//#endregion
|
|
68
|
+
export { ToasterTheme, minimal, monochrome, themes };
|
|
69
|
+
//# sourceMappingURL=themes.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"themes.d.mts","names":[],"sources":["../src/themes.ts"],"sourcesContent":[],"mappings":";;;;;;;;UAsBiB,YAAA,SAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;cAgCzB,SAAS;;;;;;;;;;;;;;;cAoCT,YAAY;;;;;;;;;;;;cA0CZ;oBAGH;uBAAA"}
|