@iryanraushan/notchify 1.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/LICENSE +21 -0
- package/README.md +224 -0
- package/dist/index.d.mts +48 -0
- package/dist/index.d.ts +48 -0
- package/dist/index.js +203 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +178 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +51 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Raushan Kumar
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
# notchify
|
|
2
|
+
|
|
3
|
+
A classic, macOS-style toast notification library for React and Next.js.
|
|
4
|
+
Dark & light mode ready. Fully themeable. Zero config to get started.
|
|
5
|
+
|
|
6
|
+
| Dark Mode | Light Mode |
|
|
7
|
+
|---|---|
|
|
8
|
+
|  |  |
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
## Features
|
|
12
|
+
|
|
13
|
+
- Dark & light mode out of the box
|
|
14
|
+
- Fully customizable colors, background, border, shadow, and duration
|
|
15
|
+
- Lightweight — no extra dependencies beyond Radix UI
|
|
16
|
+
- Works with React 17+ and Next.js (App & Pages router)
|
|
17
|
+
- TypeScript first
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npm install notchify
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
> Peer dependencies — make sure these are installed in your project:
|
|
28
|
+
> ```bash
|
|
29
|
+
> npm install react react-dom
|
|
30
|
+
> ```
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
## Preview
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
**Variants**
|
|
38
|
+
|
|
39
|
+
| Variant | Dot Color
|
|
40
|
+
|---|---|
|
|
41
|
+
| `default` | Blue `#3b82f6`
|
|
42
|
+
| `success` | Green `#22c55e`
|
|
43
|
+
| `destructive` | Red `#ef4444`
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
## Quick Start
|
|
48
|
+
|
|
49
|
+
**1. Wrap your app with `ToastProvider`**
|
|
50
|
+
|
|
51
|
+
```tsx
|
|
52
|
+
// App.tsx or layout.tsx (Next.js)
|
|
53
|
+
import { ToastProvider } from 'notchify';
|
|
54
|
+
|
|
55
|
+
export default function RootLayout({ children }) {
|
|
56
|
+
return (
|
|
57
|
+
<ToastProvider>
|
|
58
|
+
{children}
|
|
59
|
+
</ToastProvider>
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
**2. Trigger toasts from anywhere**
|
|
65
|
+
|
|
66
|
+
```tsx
|
|
67
|
+
import { useToast } from 'notchify';
|
|
68
|
+
|
|
69
|
+
export default function MyComponent() {
|
|
70
|
+
const { toast } = useToast();
|
|
71
|
+
|
|
72
|
+
return (
|
|
73
|
+
<button onClick={() => toast({ message: 'Saved!', variant: 'success' })}>
|
|
74
|
+
Save
|
|
75
|
+
</button>
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
---
|
|
81
|
+
|
|
82
|
+
## Usage
|
|
83
|
+
|
|
84
|
+
### Variants
|
|
85
|
+
|
|
86
|
+
```tsx
|
|
87
|
+
const { toast } = useToast();
|
|
88
|
+
|
|
89
|
+
// default (blue dot)
|
|
90
|
+
toast({ message: 'Profile updated.' });
|
|
91
|
+
|
|
92
|
+
// success (green dot)
|
|
93
|
+
toast({ message: 'Payment successful!', variant: 'success' });
|
|
94
|
+
|
|
95
|
+
// destructive (red dot)
|
|
96
|
+
toast({ message: 'Failed to delete file.', variant: 'destructive' });
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### Custom Duration (per toast)
|
|
100
|
+
|
|
101
|
+
```tsx
|
|
102
|
+
// show for 6 seconds
|
|
103
|
+
toast({ message: 'This will stay longer.', duration: 6000 });
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
---
|
|
107
|
+
|
|
108
|
+
## Dark & Light Mode
|
|
109
|
+
|
|
110
|
+
Pass `mode` to `ToastProvider`. Defaults to `dark`.
|
|
111
|
+
|
|
112
|
+
```tsx
|
|
113
|
+
<ToastProvider mode="light">
|
|
114
|
+
{children}
|
|
115
|
+
</ToastProvider>
|
|
116
|
+
|
|
117
|
+
<ToastProvider mode="dark">
|
|
118
|
+
{children}
|
|
119
|
+
</ToastProvider>
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
---
|
|
123
|
+
|
|
124
|
+
## Custom Theme
|
|
125
|
+
|
|
126
|
+
Override any visual token globally via the `theme` prop on `ToastProvider`.
|
|
127
|
+
Any value you skip falls back to the default for the current mode.
|
|
128
|
+
|
|
129
|
+
```tsx
|
|
130
|
+
<ToastProvider
|
|
131
|
+
mode="dark"
|
|
132
|
+
theme={{
|
|
133
|
+
background: '#1a1a2e',
|
|
134
|
+
border: '#2a2a4a',
|
|
135
|
+
textColor: '#e0e0ff',
|
|
136
|
+
boxShadow: '0 8px 32px rgba(0,0,0,0.4)',
|
|
137
|
+
defaultDuration: 5000,
|
|
138
|
+
dotColors: {
|
|
139
|
+
default: '#6366f1',
|
|
140
|
+
success: '#00ff88',
|
|
141
|
+
destructive: '#ff4466',
|
|
142
|
+
},
|
|
143
|
+
}}
|
|
144
|
+
>
|
|
145
|
+
{children}
|
|
146
|
+
</ToastProvider>
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
---
|
|
150
|
+
|
|
151
|
+
## API Reference
|
|
152
|
+
|
|
153
|
+
### `<ToastProvider />`
|
|
154
|
+
|
|
155
|
+
| Prop | Type | Default | Description |
|
|
156
|
+
|---|---|---|---|
|
|
157
|
+
| `mode` | `"dark" \| "light"` | `"dark"` | Color mode |
|
|
158
|
+
| `theme` | `ToastTheme` | `{}` | Theme overrides |
|
|
159
|
+
| `children` | `ReactNode` | — | Your app |
|
|
160
|
+
|
|
161
|
+
### `ToastTheme`
|
|
162
|
+
|
|
163
|
+
| Key | Type | Description |
|
|
164
|
+
|---|---|---|
|
|
165
|
+
| `background` | `string` | Toast background color |
|
|
166
|
+
| `border` | `string` | Toast border color |
|
|
167
|
+
| `textColor` | `string` | Message text color |
|
|
168
|
+
| `boxShadow` | `string` | Toast shadow |
|
|
169
|
+
| `defaultDuration` | `number` | Default duration in ms (fallback: `3000`) |
|
|
170
|
+
| `dotColors` | `{ default?, success?, destructive? }` | Dot colors per variant |
|
|
171
|
+
|
|
172
|
+
### `useToast()`
|
|
173
|
+
|
|
174
|
+
Returns:
|
|
175
|
+
|
|
176
|
+
| Key | Type | Description |
|
|
177
|
+
|---|---|---|
|
|
178
|
+
| `toast(options)` | `function` | Trigger a toast |
|
|
179
|
+
| `dismiss(id)` | `function` | Programmatically dismiss a toast by id |
|
|
180
|
+
|
|
181
|
+
### `toast(options)`
|
|
182
|
+
|
|
183
|
+
| Option | Type | Default | Description |
|
|
184
|
+
|---|---|---|---|
|
|
185
|
+
| `message` | `string` | — | The notification text **(required)** |
|
|
186
|
+
| `variant` | `"default" \| "success" \| "destructive"` | `"default"` | Visual style |
|
|
187
|
+
| `duration` | `number` | `3000` | Time in ms before auto-dismiss |
|
|
188
|
+
|
|
189
|
+
---
|
|
190
|
+
|
|
191
|
+
## Next.js App Router
|
|
192
|
+
|
|
193
|
+
If you're using the App Router, mark your layout as a client component or extract the provider:
|
|
194
|
+
|
|
195
|
+
```tsx
|
|
196
|
+
// components/providers.tsx
|
|
197
|
+
'use client';
|
|
198
|
+
import { ToastProvider } from 'notchify';
|
|
199
|
+
|
|
200
|
+
export function Providers({ children }: { children: React.ReactNode }) {
|
|
201
|
+
return <ToastProvider mode="dark">{children}</ToastProvider>;
|
|
202
|
+
}
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
```tsx
|
|
206
|
+
// app/layout.tsx
|
|
207
|
+
import { Providers } from '@/components/providers';
|
|
208
|
+
|
|
209
|
+
export default function RootLayout({ children }) {
|
|
210
|
+
return (
|
|
211
|
+
<html>
|
|
212
|
+
<body>
|
|
213
|
+
<Providers>{children}</Providers>
|
|
214
|
+
</body>
|
|
215
|
+
</html>
|
|
216
|
+
);
|
|
217
|
+
}
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
---
|
|
221
|
+
|
|
222
|
+
## License
|
|
223
|
+
|
|
224
|
+
MIT © [Raushan Kumar](https://github.com/iryanraushan)
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import * as ToastPrimitives from '@radix-ui/react-toast';
|
|
3
|
+
|
|
4
|
+
type ToastVariant = "default" | "destructive" | "success";
|
|
5
|
+
type ToastMode = "dark" | "light";
|
|
6
|
+
interface ToastTheme {
|
|
7
|
+
background?: string;
|
|
8
|
+
border?: string;
|
|
9
|
+
textColor?: string;
|
|
10
|
+
dotColors?: Partial<Record<ToastVariant, string>>;
|
|
11
|
+
boxShadow?: string;
|
|
12
|
+
defaultDuration?: number;
|
|
13
|
+
}
|
|
14
|
+
interface ToastOptions {
|
|
15
|
+
message: string;
|
|
16
|
+
variant?: ToastVariant;
|
|
17
|
+
duration?: number;
|
|
18
|
+
}
|
|
19
|
+
interface ToastItem extends ToastOptions {
|
|
20
|
+
id: string;
|
|
21
|
+
}
|
|
22
|
+
interface ToastContextValue {
|
|
23
|
+
toast: (options: ToastOptions) => void;
|
|
24
|
+
dismiss: (id: string) => void;
|
|
25
|
+
theme: ToastTheme;
|
|
26
|
+
mode: ToastMode;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
declare const ToastViewport: React.ForwardRefExoticComponent<Omit<ToastPrimitives.ToastViewportProps & React.RefAttributes<HTMLOListElement>, "ref"> & React.RefAttributes<HTMLOListElement>>;
|
|
30
|
+
interface ToastRootProps extends React.ComponentPropsWithoutRef<typeof ToastPrimitives.Root> {
|
|
31
|
+
variant?: ToastVariant;
|
|
32
|
+
message: string;
|
|
33
|
+
onDismiss?: () => void;
|
|
34
|
+
theme?: ToastTheme;
|
|
35
|
+
mode?: ToastMode;
|
|
36
|
+
}
|
|
37
|
+
declare const Toast: React.ForwardRefExoticComponent<ToastRootProps & React.RefAttributes<HTMLLIElement>>;
|
|
38
|
+
|
|
39
|
+
interface ToastProviderProps {
|
|
40
|
+
children: React.ReactNode;
|
|
41
|
+
theme?: ToastTheme;
|
|
42
|
+
mode?: ToastMode;
|
|
43
|
+
}
|
|
44
|
+
declare function ToastProvider({ children, theme, mode }: ToastProviderProps): React.JSX.Element;
|
|
45
|
+
|
|
46
|
+
declare function useToast(): ToastContextValue;
|
|
47
|
+
|
|
48
|
+
export { Toast, type ToastContextValue, type ToastItem, type ToastMode, type ToastOptions, ToastProvider, type ToastTheme, type ToastVariant, ToastViewport, useToast };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import * as ToastPrimitives from '@radix-ui/react-toast';
|
|
3
|
+
|
|
4
|
+
type ToastVariant = "default" | "destructive" | "success";
|
|
5
|
+
type ToastMode = "dark" | "light";
|
|
6
|
+
interface ToastTheme {
|
|
7
|
+
background?: string;
|
|
8
|
+
border?: string;
|
|
9
|
+
textColor?: string;
|
|
10
|
+
dotColors?: Partial<Record<ToastVariant, string>>;
|
|
11
|
+
boxShadow?: string;
|
|
12
|
+
defaultDuration?: number;
|
|
13
|
+
}
|
|
14
|
+
interface ToastOptions {
|
|
15
|
+
message: string;
|
|
16
|
+
variant?: ToastVariant;
|
|
17
|
+
duration?: number;
|
|
18
|
+
}
|
|
19
|
+
interface ToastItem extends ToastOptions {
|
|
20
|
+
id: string;
|
|
21
|
+
}
|
|
22
|
+
interface ToastContextValue {
|
|
23
|
+
toast: (options: ToastOptions) => void;
|
|
24
|
+
dismiss: (id: string) => void;
|
|
25
|
+
theme: ToastTheme;
|
|
26
|
+
mode: ToastMode;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
declare const ToastViewport: React.ForwardRefExoticComponent<Omit<ToastPrimitives.ToastViewportProps & React.RefAttributes<HTMLOListElement>, "ref"> & React.RefAttributes<HTMLOListElement>>;
|
|
30
|
+
interface ToastRootProps extends React.ComponentPropsWithoutRef<typeof ToastPrimitives.Root> {
|
|
31
|
+
variant?: ToastVariant;
|
|
32
|
+
message: string;
|
|
33
|
+
onDismiss?: () => void;
|
|
34
|
+
theme?: ToastTheme;
|
|
35
|
+
mode?: ToastMode;
|
|
36
|
+
}
|
|
37
|
+
declare const Toast: React.ForwardRefExoticComponent<ToastRootProps & React.RefAttributes<HTMLLIElement>>;
|
|
38
|
+
|
|
39
|
+
interface ToastProviderProps {
|
|
40
|
+
children: React.ReactNode;
|
|
41
|
+
theme?: ToastTheme;
|
|
42
|
+
mode?: ToastMode;
|
|
43
|
+
}
|
|
44
|
+
declare function ToastProvider({ children, theme, mode }: ToastProviderProps): React.JSX.Element;
|
|
45
|
+
|
|
46
|
+
declare function useToast(): ToastContextValue;
|
|
47
|
+
|
|
48
|
+
export { Toast, type ToastContextValue, type ToastItem, type ToastMode, type ToastOptions, ToastProvider, type ToastTheme, type ToastVariant, ToastViewport, useToast };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var React = require('react');
|
|
4
|
+
var ToastPrimitives2 = require('@radix-ui/react-toast');
|
|
5
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
6
|
+
|
|
7
|
+
function _interopNamespace(e) {
|
|
8
|
+
if (e && e.__esModule) return e;
|
|
9
|
+
var n = Object.create(null);
|
|
10
|
+
if (e) {
|
|
11
|
+
Object.keys(e).forEach(function (k) {
|
|
12
|
+
if (k !== 'default') {
|
|
13
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
14
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: function () { return e[k]; }
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
n.default = e;
|
|
22
|
+
return Object.freeze(n);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
26
|
+
var ToastPrimitives2__namespace = /*#__PURE__*/_interopNamespace(ToastPrimitives2);
|
|
27
|
+
|
|
28
|
+
var __defProp = Object.defineProperty;
|
|
29
|
+
var __defProps = Object.defineProperties;
|
|
30
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
31
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
32
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
33
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
34
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
35
|
+
var __spreadValues = (a, b) => {
|
|
36
|
+
for (var prop in b || (b = {}))
|
|
37
|
+
if (__hasOwnProp.call(b, prop))
|
|
38
|
+
__defNormalProp(a, prop, b[prop]);
|
|
39
|
+
if (__getOwnPropSymbols)
|
|
40
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
41
|
+
if (__propIsEnum.call(b, prop))
|
|
42
|
+
__defNormalProp(a, prop, b[prop]);
|
|
43
|
+
}
|
|
44
|
+
return a;
|
|
45
|
+
};
|
|
46
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
47
|
+
var __objRest = (source, exclude) => {
|
|
48
|
+
var target = {};
|
|
49
|
+
for (var prop in source)
|
|
50
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
51
|
+
target[prop] = source[prop];
|
|
52
|
+
if (source != null && __getOwnPropSymbols)
|
|
53
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
54
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
55
|
+
target[prop] = source[prop];
|
|
56
|
+
}
|
|
57
|
+
return target;
|
|
58
|
+
};
|
|
59
|
+
var ToastContext = React__namespace.createContext(null);
|
|
60
|
+
function ToastProvider({ children, theme = {}, mode = "dark" }) {
|
|
61
|
+
const [toasts, setToasts] = React__namespace.useState([]);
|
|
62
|
+
const toast = React__namespace.useCallback((options) => {
|
|
63
|
+
const id = Math.random().toString(36).slice(2);
|
|
64
|
+
setToasts((prev) => [...prev, __spreadValues({ id }, options)]);
|
|
65
|
+
}, []);
|
|
66
|
+
const dismiss = React__namespace.useCallback((id) => {
|
|
67
|
+
setToasts((prev) => prev.filter((t) => t.id !== id));
|
|
68
|
+
}, []);
|
|
69
|
+
return /* @__PURE__ */ jsxRuntime.jsx(ToastContext.Provider, { value: { toast, dismiss, theme, mode }, children: /* @__PURE__ */ jsxRuntime.jsxs(ToastPrimitives2__namespace.Provider, { swipeDirection: "right", children: [
|
|
70
|
+
children,
|
|
71
|
+
toasts.map((t) => {
|
|
72
|
+
var _a, _b;
|
|
73
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
74
|
+
Toast,
|
|
75
|
+
{
|
|
76
|
+
open: true,
|
|
77
|
+
variant: t.variant,
|
|
78
|
+
duration: (_b = (_a = t.duration) != null ? _a : theme.defaultDuration) != null ? _b : 3e3,
|
|
79
|
+
message: t.message,
|
|
80
|
+
onDismiss: () => dismiss(t.id)
|
|
81
|
+
},
|
|
82
|
+
t.id
|
|
83
|
+
);
|
|
84
|
+
}),
|
|
85
|
+
/* @__PURE__ */ jsxRuntime.jsx(ToastViewport, {})
|
|
86
|
+
] }) });
|
|
87
|
+
}
|
|
88
|
+
var defaultDotColors = {
|
|
89
|
+
default: "#3b82f6",
|
|
90
|
+
destructive: "#ef4444",
|
|
91
|
+
success: "#22c55e"
|
|
92
|
+
};
|
|
93
|
+
var defaultDark = {
|
|
94
|
+
background: "#0c0b0b",
|
|
95
|
+
border: "#1a1a1a",
|
|
96
|
+
textColor: "#f5f5f5",
|
|
97
|
+
boxShadow: "0 4px 24px rgba(0,0,0,0.28), 0 1px 4px rgba(0,0,0,0.14)"};
|
|
98
|
+
var defaultLight = {
|
|
99
|
+
background: "#ffffff",
|
|
100
|
+
border: "#e5e5e5",
|
|
101
|
+
textColor: "#111111",
|
|
102
|
+
boxShadow: "0 4px 24px rgba(0,0,0,0.08), 0 1px 4px rgba(0,0,0,0.06)"};
|
|
103
|
+
var CloseIcon = ({ color }) => /* @__PURE__ */ jsxRuntime.jsxs("svg", { width: "7", height: "7", viewBox: "0 0 10 10", fill: "none", "aria-hidden": "true", children: [
|
|
104
|
+
/* @__PURE__ */ jsxRuntime.jsx("line", { x1: "1", y1: "1", x2: "9", y2: "9", stroke: color, strokeWidth: "2", strokeLinecap: "round" }),
|
|
105
|
+
/* @__PURE__ */ jsxRuntime.jsx("line", { x1: "9", y1: "1", x2: "1", y2: "9", stroke: color, strokeWidth: "2", strokeLinecap: "round" })
|
|
106
|
+
] });
|
|
107
|
+
var ToastViewport = React__namespace.forwardRef((_a, ref) => {
|
|
108
|
+
var _b = _a, { style } = _b, props = __objRest(_b, ["style"]);
|
|
109
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
110
|
+
ToastPrimitives2__namespace.Viewport,
|
|
111
|
+
__spreadValues({
|
|
112
|
+
ref,
|
|
113
|
+
style: __spreadValues({
|
|
114
|
+
position: "fixed",
|
|
115
|
+
top: 16,
|
|
116
|
+
right: 16,
|
|
117
|
+
zIndex: 9999,
|
|
118
|
+
display: "flex",
|
|
119
|
+
flexDirection: "column",
|
|
120
|
+
gap: 8,
|
|
121
|
+
maxWidth: 420,
|
|
122
|
+
width: "calc(100vw - 32px)",
|
|
123
|
+
padding: 8,
|
|
124
|
+
pointerEvents: "none"
|
|
125
|
+
}, style)
|
|
126
|
+
}, props)
|
|
127
|
+
);
|
|
128
|
+
});
|
|
129
|
+
ToastViewport.displayName = "ToastViewport";
|
|
130
|
+
var Toast = React__namespace.forwardRef(
|
|
131
|
+
(_a, ref) => {
|
|
132
|
+
var _b = _a, { variant = "default", duration = 3e3, message, onDismiss, style, theme, mode } = _b, props = __objRest(_b, ["variant", "duration", "message", "onDismiss", "style", "theme", "mode"]);
|
|
133
|
+
var _a2, _b2, _c, _d, _e, _f, _g, _h;
|
|
134
|
+
const ctx = React__namespace.useContext(ToastContext);
|
|
135
|
+
const resolvedMode = (_a2 = mode != null ? mode : ctx == null ? void 0 : ctx.mode) != null ? _a2 : "dark";
|
|
136
|
+
const resolvedTheme = (_b2 = theme != null ? theme : ctx == null ? void 0 : ctx.theme) != null ? _b2 : {};
|
|
137
|
+
const base = resolvedMode === "light" ? defaultLight : defaultDark;
|
|
138
|
+
const dotColor = (_d = (_c = resolvedTheme.dotColors) == null ? void 0 : _c[variant]) != null ? _d : defaultDotColors[variant];
|
|
139
|
+
const bg = (_e = resolvedTheme.background) != null ? _e : base.background;
|
|
140
|
+
const border = (_f = resolvedTheme.border) != null ? _f : base.border;
|
|
141
|
+
const textColor = (_g = resolvedTheme.textColor) != null ? _g : base.textColor;
|
|
142
|
+
const shadow = (_h = resolvedTheme.boxShadow) != null ? _h : base.boxShadow;
|
|
143
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
144
|
+
ToastPrimitives2__namespace.Root,
|
|
145
|
+
__spreadProps(__spreadValues({
|
|
146
|
+
ref,
|
|
147
|
+
duration,
|
|
148
|
+
onOpenChange: (open) => !open && (onDismiss == null ? void 0 : onDismiss()),
|
|
149
|
+
style: __spreadValues({
|
|
150
|
+
display: "flex",
|
|
151
|
+
alignItems: "center",
|
|
152
|
+
gap: 10,
|
|
153
|
+
padding: "10px 14px",
|
|
154
|
+
borderRadius: 12,
|
|
155
|
+
border: `1px solid ${border}`,
|
|
156
|
+
background: bg,
|
|
157
|
+
boxShadow: shadow,
|
|
158
|
+
pointerEvents: "auto",
|
|
159
|
+
fontSize: 14,
|
|
160
|
+
color: textColor,
|
|
161
|
+
lineHeight: 1.5
|
|
162
|
+
}, style)
|
|
163
|
+
}, props), {
|
|
164
|
+
children: [
|
|
165
|
+
/* @__PURE__ */ jsxRuntime.jsx(ToastPrimitives2__namespace.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
166
|
+
"button",
|
|
167
|
+
{
|
|
168
|
+
"aria-label": "Dismiss",
|
|
169
|
+
style: {
|
|
170
|
+
width: 14,
|
|
171
|
+
height: 14,
|
|
172
|
+
borderRadius: "50%",
|
|
173
|
+
background: dotColor,
|
|
174
|
+
border: "none",
|
|
175
|
+
cursor: "pointer",
|
|
176
|
+
flexShrink: 0,
|
|
177
|
+
display: "flex",
|
|
178
|
+
alignItems: "center",
|
|
179
|
+
justifyContent: "center",
|
|
180
|
+
padding: 1
|
|
181
|
+
},
|
|
182
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(CloseIcon, { color: "#ffffff" })
|
|
183
|
+
}
|
|
184
|
+
) }),
|
|
185
|
+
/* @__PURE__ */ jsxRuntime.jsx(ToastPrimitives2__namespace.Description, { style: { flex: 1, color: textColor, fontSize: 14 }, children: message })
|
|
186
|
+
]
|
|
187
|
+
})
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
);
|
|
191
|
+
Toast.displayName = "Toast";
|
|
192
|
+
function useToast() {
|
|
193
|
+
const ctx = React.useContext(ToastContext);
|
|
194
|
+
if (!ctx) throw new Error("useToast must be used within a ToastProvider");
|
|
195
|
+
return ctx;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
exports.Toast = Toast;
|
|
199
|
+
exports.ToastProvider = ToastProvider;
|
|
200
|
+
exports.ToastViewport = ToastViewport;
|
|
201
|
+
exports.useToast = useToast;
|
|
202
|
+
//# sourceMappingURL=index.js.map
|
|
203
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/ToastProvider.tsx","../src/components/Toast.tsx","../src/hooks/useToast.ts"],"names":["React","jsx","jsxs","ToastPrimitives","React2","ToastPrimitives2","_a","_b","useContext"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKO,IAAM,YAAA,GAAqBA,+BAAwC,IAAI,CAAA;AAQvE,SAAS,aAAA,CAAc,EAAE,QAAA,EAAU,KAAA,GAAQ,EAAC,EAAG,IAAA,GAAO,QAAO,EAAuB;AACzF,EAAA,MAAM,CAAC,MAAA,EAAQ,SAAS,CAAA,GAAUA,gBAAA,CAAA,QAAA,CAAsB,EAAE,CAAA;AAE1D,EAAA,MAAM,KAAA,GAAcA,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EAAO,SAAA,EAAW,QAAA,EAAU,EAAA,IACxE,QAAA,EAAA,OAAA,EACH;AAAA;AAAA,OAAA;AAAA,KACF;AAAA,EAEJ;AACF;AACA,KAAA,CAAM,WAAA,GAAc,OAAA;AC/Hb,SAAS,QAAA,GAAW;AACzB,EAAA,MAAM,GAAA,GAAMG,iBAAW,YAAY,CAAA;AACnC,EAAA,IAAI,CAAC,GAAA,EAAK,MAAM,IAAI,MAAM,8CAA8C,CAAA;AACxE,EAAA,OAAO,GAAA;AACT","file":"index.js","sourcesContent":["import * as React from \"react\";\nimport * as ToastPrimitives from \"@radix-ui/react-toast\";\nimport { Toast, ToastViewport } from \"./Toast\";\nimport { ToastItem, ToastOptions, ToastContextValue, ToastTheme, ToastMode } from \"../types\";\n\nexport const ToastContext = React.createContext<ToastContextValue | null>(null);\n\ninterface ToastProviderProps {\n children: React.ReactNode;\n theme?: ToastTheme;\n mode?: ToastMode;\n}\n\nexport function ToastProvider({ children, theme = {}, mode = \"dark\" }: ToastProviderProps) {\n const [toasts, setToasts] = React.useState<ToastItem[]>([]);\n\n const toast = React.useCallback((options: ToastOptions) => {\n const id = Math.random().toString(36).slice(2);\n setToasts((prev) => [...prev, { id, ...options }]);\n }, []);\n\n const dismiss = React.useCallback((id: string) => {\n setToasts((prev) => prev.filter((t) => t.id !== id));\n }, []);\n\n return (\n <ToastContext.Provider value={{ toast, dismiss, theme, mode }}>\n <ToastPrimitives.Provider swipeDirection=\"right\">\n {children}\n {toasts.map((t) => (\n <Toast\n key={t.id}\n open\n variant={t.variant}\n duration={t.duration ?? theme.defaultDuration ?? 3000}\n message={t.message}\n onDismiss={() => dismiss(t.id)}\n />\n ))}\n <ToastViewport />\n </ToastPrimitives.Provider>\n </ToastContext.Provider>\n );\n}\n","import * as React from \"react\";\nimport * as ToastPrimitives from \"@radix-ui/react-toast\";\nimport { ToastVariant, ToastTheme, ToastMode } from \"../types\";\nimport { ToastContext } from \"./ToastProvider\";\n\nconst defaultDotColors: Record<ToastVariant, string> = {\n default: \"#3b82f6\",\n destructive: \"#ef4444\",\n success: \"#22c55e\",\n};\n\nconst defaultDark: Required<Omit<ToastTheme, \"dotColors\">> = {\n background: \"#0c0b0b\",\n border: \"#1a1a1a\",\n textColor: \"#f5f5f5\",\n boxShadow: \"0 4px 24px rgba(0,0,0,0.28), 0 1px 4px rgba(0,0,0,0.14)\",\n defaultDuration: 3000,\n};\n\nconst defaultLight: Required<Omit<ToastTheme, \"dotColors\">> = {\n background: \"#ffffff\",\n border: \"#e5e5e5\",\n textColor: \"#111111\",\n boxShadow: \"0 4px 24px rgba(0,0,0,0.08), 0 1px 4px rgba(0,0,0,0.06)\",\n defaultDuration: 3000,\n};\n\nconst CloseIcon = ({ color }: { color: string }) => (\n <svg width=\"7\" height=\"7\" viewBox=\"0 0 10 10\" fill=\"none\" aria-hidden=\"true\">\n <line x1=\"1\" y1=\"1\" x2=\"9\" y2=\"9\" stroke={color} strokeWidth=\"2\" strokeLinecap=\"round\" />\n <line x1=\"9\" y1=\"1\" x2=\"1\" y2=\"9\" stroke={color} strokeWidth=\"2\" strokeLinecap=\"round\" />\n </svg>\n);\n\nexport const ToastViewport = React.forwardRef<\n React.ElementRef<typeof ToastPrimitives.Viewport>,\n React.ComponentPropsWithoutRef<typeof ToastPrimitives.Viewport>\n>(({ style, ...props }, ref) => (\n <ToastPrimitives.Viewport\n ref={ref}\n style={{\n position: \"fixed\",\n top: 16,\n right: 16,\n zIndex: 9999,\n display: \"flex\",\n flexDirection: \"column\",\n gap: 8,\n maxWidth: 420,\n width: \"calc(100vw - 32px)\",\n padding: 8,\n pointerEvents: \"none\",\n ...style,\n }}\n {...props}\n />\n));\nToastViewport.displayName = \"ToastViewport\";\n\ninterface ToastRootProps extends React.ComponentPropsWithoutRef<typeof ToastPrimitives.Root> {\n variant?: ToastVariant;\n message: string;\n onDismiss?: () => void;\n theme?: ToastTheme;\n mode?: ToastMode;\n}\n\nexport const Toast = React.forwardRef<React.ElementRef<typeof ToastPrimitives.Root>, ToastRootProps>(\n ({ variant = \"default\", duration = 3000, message, onDismiss, style, theme, mode, ...props }, ref) => {\n const ctx = React.useContext(ToastContext);\n const resolvedMode = mode ?? ctx?.mode ?? \"dark\";\n const resolvedTheme = theme ?? ctx?.theme ?? {};\n\n const base = resolvedMode === \"light\" ? defaultLight : defaultDark;\n const dotColor = resolvedTheme.dotColors?.[variant] ?? defaultDotColors[variant];\n const bg = resolvedTheme.background ?? base.background;\n const border = resolvedTheme.border ?? base.border;\n const textColor = resolvedTheme.textColor ?? base.textColor;\n const shadow = resolvedTheme.boxShadow ?? base.boxShadow;\n\n return (\n <ToastPrimitives.Root\n ref={ref}\n duration={duration}\n onOpenChange={(open) => !open && onDismiss?.()}\n style={{\n display: \"flex\",\n alignItems: \"center\",\n gap: 10,\n padding: \"10px 14px\",\n borderRadius: 12,\n border: `1px solid ${border}`,\n background: bg,\n boxShadow: shadow,\n pointerEvents: \"auto\",\n fontSize: 14,\n color: textColor,\n lineHeight: 1.5,\n ...style,\n }}\n {...props}\n >\n <ToastPrimitives.Close asChild>\n <button\n aria-label=\"Dismiss\"\n style={{\n width: 14,\n height: 14,\n borderRadius: \"50%\",\n background: dotColor,\n border: \"none\",\n cursor: \"pointer\",\n flexShrink: 0,\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n padding: 1,\n }}\n >\n <CloseIcon color={\"#ffffff\"} />\n </button>\n </ToastPrimitives.Close>\n\n <ToastPrimitives.Description style={{ flex: 1, color: textColor, fontSize: 14 }}>\n {message}\n </ToastPrimitives.Description>\n </ToastPrimitives.Root>\n );\n }\n);\nToast.displayName = \"Toast\";\n","import { useContext } from \"react\";\nimport { ToastContext } from \"../components/ToastProvider\";\n\nexport function useToast() {\n const ctx = useContext(ToastContext);\n if (!ctx) throw new Error(\"useToast must be used within a ToastProvider\");\n return ctx;\n}\n"]}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { useContext } from 'react';
|
|
3
|
+
import * as ToastPrimitives2 from '@radix-ui/react-toast';
|
|
4
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
5
|
+
|
|
6
|
+
var __defProp = Object.defineProperty;
|
|
7
|
+
var __defProps = Object.defineProperties;
|
|
8
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
9
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
10
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
11
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
12
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
13
|
+
var __spreadValues = (a, b) => {
|
|
14
|
+
for (var prop in b || (b = {}))
|
|
15
|
+
if (__hasOwnProp.call(b, prop))
|
|
16
|
+
__defNormalProp(a, prop, b[prop]);
|
|
17
|
+
if (__getOwnPropSymbols)
|
|
18
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
19
|
+
if (__propIsEnum.call(b, prop))
|
|
20
|
+
__defNormalProp(a, prop, b[prop]);
|
|
21
|
+
}
|
|
22
|
+
return a;
|
|
23
|
+
};
|
|
24
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
25
|
+
var __objRest = (source, exclude) => {
|
|
26
|
+
var target = {};
|
|
27
|
+
for (var prop in source)
|
|
28
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
29
|
+
target[prop] = source[prop];
|
|
30
|
+
if (source != null && __getOwnPropSymbols)
|
|
31
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
32
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
33
|
+
target[prop] = source[prop];
|
|
34
|
+
}
|
|
35
|
+
return target;
|
|
36
|
+
};
|
|
37
|
+
var ToastContext = React.createContext(null);
|
|
38
|
+
function ToastProvider({ children, theme = {}, mode = "dark" }) {
|
|
39
|
+
const [toasts, setToasts] = React.useState([]);
|
|
40
|
+
const toast = React.useCallback((options) => {
|
|
41
|
+
const id = Math.random().toString(36).slice(2);
|
|
42
|
+
setToasts((prev) => [...prev, __spreadValues({ id }, options)]);
|
|
43
|
+
}, []);
|
|
44
|
+
const dismiss = React.useCallback((id) => {
|
|
45
|
+
setToasts((prev) => prev.filter((t) => t.id !== id));
|
|
46
|
+
}, []);
|
|
47
|
+
return /* @__PURE__ */ jsx(ToastContext.Provider, { value: { toast, dismiss, theme, mode }, children: /* @__PURE__ */ jsxs(ToastPrimitives2.Provider, { swipeDirection: "right", children: [
|
|
48
|
+
children,
|
|
49
|
+
toasts.map((t) => {
|
|
50
|
+
var _a, _b;
|
|
51
|
+
return /* @__PURE__ */ jsx(
|
|
52
|
+
Toast,
|
|
53
|
+
{
|
|
54
|
+
open: true,
|
|
55
|
+
variant: t.variant,
|
|
56
|
+
duration: (_b = (_a = t.duration) != null ? _a : theme.defaultDuration) != null ? _b : 3e3,
|
|
57
|
+
message: t.message,
|
|
58
|
+
onDismiss: () => dismiss(t.id)
|
|
59
|
+
},
|
|
60
|
+
t.id
|
|
61
|
+
);
|
|
62
|
+
}),
|
|
63
|
+
/* @__PURE__ */ jsx(ToastViewport, {})
|
|
64
|
+
] }) });
|
|
65
|
+
}
|
|
66
|
+
var defaultDotColors = {
|
|
67
|
+
default: "#3b82f6",
|
|
68
|
+
destructive: "#ef4444",
|
|
69
|
+
success: "#22c55e"
|
|
70
|
+
};
|
|
71
|
+
var defaultDark = {
|
|
72
|
+
background: "#0c0b0b",
|
|
73
|
+
border: "#1a1a1a",
|
|
74
|
+
textColor: "#f5f5f5",
|
|
75
|
+
boxShadow: "0 4px 24px rgba(0,0,0,0.28), 0 1px 4px rgba(0,0,0,0.14)"};
|
|
76
|
+
var defaultLight = {
|
|
77
|
+
background: "#ffffff",
|
|
78
|
+
border: "#e5e5e5",
|
|
79
|
+
textColor: "#111111",
|
|
80
|
+
boxShadow: "0 4px 24px rgba(0,0,0,0.08), 0 1px 4px rgba(0,0,0,0.06)"};
|
|
81
|
+
var CloseIcon = ({ color }) => /* @__PURE__ */ jsxs("svg", { width: "7", height: "7", viewBox: "0 0 10 10", fill: "none", "aria-hidden": "true", children: [
|
|
82
|
+
/* @__PURE__ */ jsx("line", { x1: "1", y1: "1", x2: "9", y2: "9", stroke: color, strokeWidth: "2", strokeLinecap: "round" }),
|
|
83
|
+
/* @__PURE__ */ jsx("line", { x1: "9", y1: "1", x2: "1", y2: "9", stroke: color, strokeWidth: "2", strokeLinecap: "round" })
|
|
84
|
+
] });
|
|
85
|
+
var ToastViewport = React.forwardRef((_a, ref) => {
|
|
86
|
+
var _b = _a, { style } = _b, props = __objRest(_b, ["style"]);
|
|
87
|
+
return /* @__PURE__ */ jsx(
|
|
88
|
+
ToastPrimitives2.Viewport,
|
|
89
|
+
__spreadValues({
|
|
90
|
+
ref,
|
|
91
|
+
style: __spreadValues({
|
|
92
|
+
position: "fixed",
|
|
93
|
+
top: 16,
|
|
94
|
+
right: 16,
|
|
95
|
+
zIndex: 9999,
|
|
96
|
+
display: "flex",
|
|
97
|
+
flexDirection: "column",
|
|
98
|
+
gap: 8,
|
|
99
|
+
maxWidth: 420,
|
|
100
|
+
width: "calc(100vw - 32px)",
|
|
101
|
+
padding: 8,
|
|
102
|
+
pointerEvents: "none"
|
|
103
|
+
}, style)
|
|
104
|
+
}, props)
|
|
105
|
+
);
|
|
106
|
+
});
|
|
107
|
+
ToastViewport.displayName = "ToastViewport";
|
|
108
|
+
var Toast = React.forwardRef(
|
|
109
|
+
(_a, ref) => {
|
|
110
|
+
var _b = _a, { variant = "default", duration = 3e3, message, onDismiss, style, theme, mode } = _b, props = __objRest(_b, ["variant", "duration", "message", "onDismiss", "style", "theme", "mode"]);
|
|
111
|
+
var _a2, _b2, _c, _d, _e, _f, _g, _h;
|
|
112
|
+
const ctx = React.useContext(ToastContext);
|
|
113
|
+
const resolvedMode = (_a2 = mode != null ? mode : ctx == null ? void 0 : ctx.mode) != null ? _a2 : "dark";
|
|
114
|
+
const resolvedTheme = (_b2 = theme != null ? theme : ctx == null ? void 0 : ctx.theme) != null ? _b2 : {};
|
|
115
|
+
const base = resolvedMode === "light" ? defaultLight : defaultDark;
|
|
116
|
+
const dotColor = (_d = (_c = resolvedTheme.dotColors) == null ? void 0 : _c[variant]) != null ? _d : defaultDotColors[variant];
|
|
117
|
+
const bg = (_e = resolvedTheme.background) != null ? _e : base.background;
|
|
118
|
+
const border = (_f = resolvedTheme.border) != null ? _f : base.border;
|
|
119
|
+
const textColor = (_g = resolvedTheme.textColor) != null ? _g : base.textColor;
|
|
120
|
+
const shadow = (_h = resolvedTheme.boxShadow) != null ? _h : base.boxShadow;
|
|
121
|
+
return /* @__PURE__ */ jsxs(
|
|
122
|
+
ToastPrimitives2.Root,
|
|
123
|
+
__spreadProps(__spreadValues({
|
|
124
|
+
ref,
|
|
125
|
+
duration,
|
|
126
|
+
onOpenChange: (open) => !open && (onDismiss == null ? void 0 : onDismiss()),
|
|
127
|
+
style: __spreadValues({
|
|
128
|
+
display: "flex",
|
|
129
|
+
alignItems: "center",
|
|
130
|
+
gap: 10,
|
|
131
|
+
padding: "10px 14px",
|
|
132
|
+
borderRadius: 12,
|
|
133
|
+
border: `1px solid ${border}`,
|
|
134
|
+
background: bg,
|
|
135
|
+
boxShadow: shadow,
|
|
136
|
+
pointerEvents: "auto",
|
|
137
|
+
fontSize: 14,
|
|
138
|
+
color: textColor,
|
|
139
|
+
lineHeight: 1.5
|
|
140
|
+
}, style)
|
|
141
|
+
}, props), {
|
|
142
|
+
children: [
|
|
143
|
+
/* @__PURE__ */ jsx(ToastPrimitives2.Close, { asChild: true, children: /* @__PURE__ */ jsx(
|
|
144
|
+
"button",
|
|
145
|
+
{
|
|
146
|
+
"aria-label": "Dismiss",
|
|
147
|
+
style: {
|
|
148
|
+
width: 14,
|
|
149
|
+
height: 14,
|
|
150
|
+
borderRadius: "50%",
|
|
151
|
+
background: dotColor,
|
|
152
|
+
border: "none",
|
|
153
|
+
cursor: "pointer",
|
|
154
|
+
flexShrink: 0,
|
|
155
|
+
display: "flex",
|
|
156
|
+
alignItems: "center",
|
|
157
|
+
justifyContent: "center",
|
|
158
|
+
padding: 1
|
|
159
|
+
},
|
|
160
|
+
children: /* @__PURE__ */ jsx(CloseIcon, { color: "#ffffff" })
|
|
161
|
+
}
|
|
162
|
+
) }),
|
|
163
|
+
/* @__PURE__ */ jsx(ToastPrimitives2.Description, { style: { flex: 1, color: textColor, fontSize: 14 }, children: message })
|
|
164
|
+
]
|
|
165
|
+
})
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
);
|
|
169
|
+
Toast.displayName = "Toast";
|
|
170
|
+
function useToast() {
|
|
171
|
+
const ctx = useContext(ToastContext);
|
|
172
|
+
if (!ctx) throw new Error("useToast must be used within a ToastProvider");
|
|
173
|
+
return ctx;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export { Toast, ToastProvider, ToastViewport, useToast };
|
|
177
|
+
//# sourceMappingURL=index.mjs.map
|
|
178
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/ToastProvider.tsx","../src/components/Toast.tsx","../src/hooks/useToast.ts"],"names":["ToastPrimitives","jsxs","jsx","React2","_a","_b","useContext"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKO,IAAM,YAAA,GAAqB,oBAAwC,IAAI,CAAA;AAQvE,SAAS,aAAA,CAAc,EAAE,QAAA,EAAU,KAAA,GAAQ,EAAC,EAAG,IAAA,GAAO,QAAO,EAAuB;AACzF,EAAA,MAAM,CAAC,MAAA,EAAQ,SAAS,CAAA,GAAU,KAAA,CAAA,QAAA,CAAsB,EAAE,CAAA;AAE1D,EAAA,MAAM,KAAA,GAAc,KAAA,CAAA,WAAA,CAAY,CAAC,OAAA,KAA0B;AACz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H;AAAA;AAAA,OAAA;AAAA,KACF;AAAA,EAEJ;AACF;AACA,KAAA,CAAM,WAAA,GAAc,OAAA;AC/Hb,SAAS,QAAA,GAAW;AACzB,EAAA,MAAM,GAAA,GAAMI,WAAW,YAAY,CAAA;AACnC,EAAA,IAAI,CAAC,GAAA,EAAK,MAAM,IAAI,MAAM,8CAA8C,CAAA;AACxE,EAAA,OAAO,GAAA;AACT","file":"index.mjs","sourcesContent":["import * as React from \"react\";\nimport * as ToastPrimitives from \"@radix-ui/react-toast\";\nimport { Toast, ToastViewport } from \"./Toast\";\nimport { ToastItem, ToastOptions, ToastContextValue, ToastTheme, ToastMode } from \"../types\";\n\nexport const ToastContext = React.createContext<ToastContextValue | null>(null);\n\ninterface ToastProviderProps {\n children: React.ReactNode;\n theme?: ToastTheme;\n mode?: ToastMode;\n}\n\nexport function ToastProvider({ children, theme = {}, mode = \"dark\" }: ToastProviderProps) {\n const [toasts, setToasts] = React.useState<ToastItem[]>([]);\n\n const toast = React.useCallback((options: ToastOptions) => {\n const id = Math.random().toString(36).slice(2);\n setToasts((prev) => [...prev, { id, ...options }]);\n }, []);\n\n const dismiss = React.useCallback((id: string) => {\n setToasts((prev) => prev.filter((t) => t.id !== id));\n }, []);\n\n return (\n <ToastContext.Provider value={{ toast, dismiss, theme, mode }}>\n <ToastPrimitives.Provider swipeDirection=\"right\">\n {children}\n {toasts.map((t) => (\n <Toast\n key={t.id}\n open\n variant={t.variant}\n duration={t.duration ?? theme.defaultDuration ?? 3000}\n message={t.message}\n onDismiss={() => dismiss(t.id)}\n />\n ))}\n <ToastViewport />\n </ToastPrimitives.Provider>\n </ToastContext.Provider>\n );\n}\n","import * as React from \"react\";\nimport * as ToastPrimitives from \"@radix-ui/react-toast\";\nimport { ToastVariant, ToastTheme, ToastMode } from \"../types\";\nimport { ToastContext } from \"./ToastProvider\";\n\nconst defaultDotColors: Record<ToastVariant, string> = {\n default: \"#3b82f6\",\n destructive: \"#ef4444\",\n success: \"#22c55e\",\n};\n\nconst defaultDark: Required<Omit<ToastTheme, \"dotColors\">> = {\n background: \"#0c0b0b\",\n border: \"#1a1a1a\",\n textColor: \"#f5f5f5\",\n boxShadow: \"0 4px 24px rgba(0,0,0,0.28), 0 1px 4px rgba(0,0,0,0.14)\",\n defaultDuration: 3000,\n};\n\nconst defaultLight: Required<Omit<ToastTheme, \"dotColors\">> = {\n background: \"#ffffff\",\n border: \"#e5e5e5\",\n textColor: \"#111111\",\n boxShadow: \"0 4px 24px rgba(0,0,0,0.08), 0 1px 4px rgba(0,0,0,0.06)\",\n defaultDuration: 3000,\n};\n\nconst CloseIcon = ({ color }: { color: string }) => (\n <svg width=\"7\" height=\"7\" viewBox=\"0 0 10 10\" fill=\"none\" aria-hidden=\"true\">\n <line x1=\"1\" y1=\"1\" x2=\"9\" y2=\"9\" stroke={color} strokeWidth=\"2\" strokeLinecap=\"round\" />\n <line x1=\"9\" y1=\"1\" x2=\"1\" y2=\"9\" stroke={color} strokeWidth=\"2\" strokeLinecap=\"round\" />\n </svg>\n);\n\nexport const ToastViewport = React.forwardRef<\n React.ElementRef<typeof ToastPrimitives.Viewport>,\n React.ComponentPropsWithoutRef<typeof ToastPrimitives.Viewport>\n>(({ style, ...props }, ref) => (\n <ToastPrimitives.Viewport\n ref={ref}\n style={{\n position: \"fixed\",\n top: 16,\n right: 16,\n zIndex: 9999,\n display: \"flex\",\n flexDirection: \"column\",\n gap: 8,\n maxWidth: 420,\n width: \"calc(100vw - 32px)\",\n padding: 8,\n pointerEvents: \"none\",\n ...style,\n }}\n {...props}\n />\n));\nToastViewport.displayName = \"ToastViewport\";\n\ninterface ToastRootProps extends React.ComponentPropsWithoutRef<typeof ToastPrimitives.Root> {\n variant?: ToastVariant;\n message: string;\n onDismiss?: () => void;\n theme?: ToastTheme;\n mode?: ToastMode;\n}\n\nexport const Toast = React.forwardRef<React.ElementRef<typeof ToastPrimitives.Root>, ToastRootProps>(\n ({ variant = \"default\", duration = 3000, message, onDismiss, style, theme, mode, ...props }, ref) => {\n const ctx = React.useContext(ToastContext);\n const resolvedMode = mode ?? ctx?.mode ?? \"dark\";\n const resolvedTheme = theme ?? ctx?.theme ?? {};\n\n const base = resolvedMode === \"light\" ? defaultLight : defaultDark;\n const dotColor = resolvedTheme.dotColors?.[variant] ?? defaultDotColors[variant];\n const bg = resolvedTheme.background ?? base.background;\n const border = resolvedTheme.border ?? base.border;\n const textColor = resolvedTheme.textColor ?? base.textColor;\n const shadow = resolvedTheme.boxShadow ?? base.boxShadow;\n\n return (\n <ToastPrimitives.Root\n ref={ref}\n duration={duration}\n onOpenChange={(open) => !open && onDismiss?.()}\n style={{\n display: \"flex\",\n alignItems: \"center\",\n gap: 10,\n padding: \"10px 14px\",\n borderRadius: 12,\n border: `1px solid ${border}`,\n background: bg,\n boxShadow: shadow,\n pointerEvents: \"auto\",\n fontSize: 14,\n color: textColor,\n lineHeight: 1.5,\n ...style,\n }}\n {...props}\n >\n <ToastPrimitives.Close asChild>\n <button\n aria-label=\"Dismiss\"\n style={{\n width: 14,\n height: 14,\n borderRadius: \"50%\",\n background: dotColor,\n border: \"none\",\n cursor: \"pointer\",\n flexShrink: 0,\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n padding: 1,\n }}\n >\n <CloseIcon color={\"#ffffff\"} />\n </button>\n </ToastPrimitives.Close>\n\n <ToastPrimitives.Description style={{ flex: 1, color: textColor, fontSize: 14 }}>\n {message}\n </ToastPrimitives.Description>\n </ToastPrimitives.Root>\n );\n }\n);\nToast.displayName = \"Toast\";\n","import { useContext } from \"react\";\nimport { ToastContext } from \"../components/ToastProvider\";\n\nexport function useToast() {\n const ctx = useContext(ToastContext);\n if (!ctx) throw new Error(\"useToast must be used within a ToastProvider\");\n return ctx;\n}\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@iryanraushan/notchify",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "A minimal dark-themed toast notification library for React and Next.js",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"toast",
|
|
7
|
+
"notification",
|
|
8
|
+
"react",
|
|
9
|
+
"nextjs",
|
|
10
|
+
"ui"
|
|
11
|
+
],
|
|
12
|
+
"author": "Raushan Kumar",
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"main": "./dist/index.js",
|
|
15
|
+
"module": "./dist/index.mjs",
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"import": "./dist/index.mjs",
|
|
21
|
+
"require": "./dist/index.js"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"dist"
|
|
26
|
+
],
|
|
27
|
+
"sideEffects": false,
|
|
28
|
+
"scripts": {
|
|
29
|
+
"build": "tsup",
|
|
30
|
+
"dev": "tsup --watch",
|
|
31
|
+
"prepublishOnly": "npm run build",
|
|
32
|
+
"preview": "vite"
|
|
33
|
+
},
|
|
34
|
+
"peerDependencies": {
|
|
35
|
+
"react": ">=17",
|
|
36
|
+
"react-dom": ">=17"
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"@radix-ui/react-toast": "^1.2.0",
|
|
40
|
+
"class-variance-authority": "^0.7.0",
|
|
41
|
+
"clsx": "^2.0.0"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@types/react": "^18",
|
|
45
|
+
"@types/react-dom": "^18",
|
|
46
|
+
"@vitejs/plugin-react": "^6.0.2",
|
|
47
|
+
"tsup": "^8.0.0",
|
|
48
|
+
"typescript": "^5",
|
|
49
|
+
"vite": "^8.0.16"
|
|
50
|
+
}
|
|
51
|
+
}
|