@mijn-ui/react-sonner 0.0.0-stage → 0.1.0
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 +53 -2
- package/dist/index.d.ts +82 -0
- package/dist/index.js +85 -0
- package/dist/metafile-esm.json +1 -0
- package/package.json +61 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 MijnUI
|
|
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
CHANGED
|
@@ -1,3 +1,54 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @mijn-ui/react-sonner
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A [`sonner`](https://sonner.emilkowal.ski) toaster dressed in the mijn-ui theme.
|
|
4
|
+
|
|
5
|
+
[Documentation](https://mijn-ui.vercel.app/react/docs/components/sonner)
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
`sonner` is a **peer** dependency — install it alongside:
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
npm install @mijn-ui/react-sonner sonner
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
Mount one `<Toaster />` near the root of the app. Every `toast()` call anywhere
|
|
18
|
+
in the tree renders through it.
|
|
19
|
+
|
|
20
|
+
```tsx
|
|
21
|
+
import { Toaster, toast } from "@mijn-ui/react-sonner"
|
|
22
|
+
|
|
23
|
+
export function App() {
|
|
24
|
+
return (
|
|
25
|
+
<>
|
|
26
|
+
<Toaster position="bottom-right" closeButton />
|
|
27
|
+
<button onClick={() => toast.success("Saved")}>Save</button>
|
|
28
|
+
</>
|
|
29
|
+
)
|
|
30
|
+
}
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Why `sonner` is a peer dependency
|
|
34
|
+
|
|
35
|
+
Sonner's queue is module state. If the app bundled a second copy, `toast()`
|
|
36
|
+
calls would land in a store that the mounted `<Toaster />` is not rendering, and
|
|
37
|
+
the toasts would simply never appear — with no error anywhere to explain it. As
|
|
38
|
+
a peer, the app resolves exactly one copy, so importing `toast` from this
|
|
39
|
+
package or straight from `sonner` reaches the same queue either way.
|
|
40
|
+
|
|
41
|
+
This is also why the package is **not** re-exported from the `@mijn-ui/react`
|
|
42
|
+
barrel: that barrel is a single entry with no subpaths, so every app importing
|
|
43
|
+
anything from it would pull sonner's bytes in whether or not it shows a toast.
|
|
44
|
+
|
|
45
|
+
## Theming
|
|
46
|
+
|
|
47
|
+
The toaster maps sonner's surface variables (`--normal-bg`, `--success-bg`, …)
|
|
48
|
+
onto mijn-ui theme tokens, so toasts follow light/dark and any re-themed palette
|
|
49
|
+
without per-app restyling. Pass `unstyled` to drop that mapping entirely and
|
|
50
|
+
supply your own `classNames`.
|
|
51
|
+
|
|
52
|
+
## License
|
|
53
|
+
|
|
54
|
+
This project is licensed under the terms of the [MIT license.](https://github.com/mijn-ui/mijn-ui-react/blob/main/LICENSE)
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import * as tailwind_variants from 'tailwind-variants';
|
|
3
|
+
import { VariantProps } from 'tailwind-variants';
|
|
4
|
+
import * as tailwind_merge from 'tailwind-merge';
|
|
5
|
+
import { UnstyledComponentWithSlots } from '@mijn-ui/react-core';
|
|
6
|
+
import { ToasterProps } from 'sonner';
|
|
7
|
+
export { ToasterProps, toast, useSonner } from 'sonner';
|
|
8
|
+
|
|
9
|
+
declare const sonnerStyles: tailwind_variants.TVReturnType<{
|
|
10
|
+
[key: string]: {
|
|
11
|
+
[key: string]: tailwind_merge.ClassNameValue | {
|
|
12
|
+
toast?: tailwind_merge.ClassNameValue;
|
|
13
|
+
title?: tailwind_merge.ClassNameValue;
|
|
14
|
+
description?: tailwind_merge.ClassNameValue;
|
|
15
|
+
actionButton?: tailwind_merge.ClassNameValue;
|
|
16
|
+
cancelButton?: tailwind_merge.ClassNameValue;
|
|
17
|
+
closeButton?: tailwind_merge.ClassNameValue;
|
|
18
|
+
icon?: tailwind_merge.ClassNameValue;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
} | {
|
|
22
|
+
[x: string]: {
|
|
23
|
+
[x: string]: tailwind_merge.ClassNameValue | {
|
|
24
|
+
toast?: tailwind_merge.ClassNameValue;
|
|
25
|
+
title?: tailwind_merge.ClassNameValue;
|
|
26
|
+
description?: tailwind_merge.ClassNameValue;
|
|
27
|
+
actionButton?: tailwind_merge.ClassNameValue;
|
|
28
|
+
cancelButton?: tailwind_merge.ClassNameValue;
|
|
29
|
+
closeButton?: tailwind_merge.ClassNameValue;
|
|
30
|
+
icon?: tailwind_merge.ClassNameValue;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
} | {}, {
|
|
34
|
+
toast: string;
|
|
35
|
+
title: string;
|
|
36
|
+
description: string;
|
|
37
|
+
actionButton: string;
|
|
38
|
+
cancelButton: string;
|
|
39
|
+
closeButton: string;
|
|
40
|
+
icon: string;
|
|
41
|
+
}, undefined, {
|
|
42
|
+
[key: string]: {
|
|
43
|
+
[key: string]: tailwind_merge.ClassNameValue | {
|
|
44
|
+
toast?: tailwind_merge.ClassNameValue;
|
|
45
|
+
title?: tailwind_merge.ClassNameValue;
|
|
46
|
+
description?: tailwind_merge.ClassNameValue;
|
|
47
|
+
actionButton?: tailwind_merge.ClassNameValue;
|
|
48
|
+
cancelButton?: tailwind_merge.ClassNameValue;
|
|
49
|
+
closeButton?: tailwind_merge.ClassNameValue;
|
|
50
|
+
icon?: tailwind_merge.ClassNameValue;
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
} | {}, {
|
|
54
|
+
toast: string;
|
|
55
|
+
title: string;
|
|
56
|
+
description: string;
|
|
57
|
+
actionButton: string;
|
|
58
|
+
cancelButton: string;
|
|
59
|
+
closeButton: string;
|
|
60
|
+
icon: string;
|
|
61
|
+
}, tailwind_variants.TVReturnType<unknown, {
|
|
62
|
+
toast: string;
|
|
63
|
+
title: string;
|
|
64
|
+
description: string;
|
|
65
|
+
actionButton: string;
|
|
66
|
+
cancelButton: string;
|
|
67
|
+
closeButton: string;
|
|
68
|
+
icon: string;
|
|
69
|
+
}, undefined, unknown, unknown, undefined>>;
|
|
70
|
+
type SonnerVariantProps = VariantProps<typeof sonnerStyles>;
|
|
71
|
+
type SonnerSlots = keyof ReturnType<typeof sonnerStyles>;
|
|
72
|
+
|
|
73
|
+
type MijnToasterProps = UnstyledComponentWithSlots<SonnerSlots> & ToasterProps;
|
|
74
|
+
/**
|
|
75
|
+
* A `sonner` <Toaster /> dressed in the mijn-ui theme.
|
|
76
|
+
*
|
|
77
|
+
* Mount it once, near the root of the app. Every `toast()` call anywhere in the
|
|
78
|
+
* tree renders through this one instance.
|
|
79
|
+
*/
|
|
80
|
+
declare const Toaster: ({ unstyled, classNames, className, style, toastOptions, ...props }: MijnToasterProps) => react_jsx_runtime.JSX.Element;
|
|
81
|
+
|
|
82
|
+
export { type MijnToasterProps, type SonnerSlots, type SonnerVariantProps, Toaster, sonnerStyles };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// src/sonner.tsx
|
|
4
|
+
import {
|
|
5
|
+
cn,
|
|
6
|
+
createTVUnstyledSlots
|
|
7
|
+
} from "@mijn-ui/react-core";
|
|
8
|
+
import { Toaster as SonnerToaster } from "sonner";
|
|
9
|
+
import { tv } from "tailwind-variants";
|
|
10
|
+
import { toast, useSonner } from "sonner";
|
|
11
|
+
import { jsx } from "react/jsx-runtime";
|
|
12
|
+
var sonnerStyles = tv({
|
|
13
|
+
slots: {
|
|
14
|
+
toast: "group border-outline-secondary bg-bg-default-alt text-fg-default rounded-lg border shadow-lg",
|
|
15
|
+
title: "text-fg-default text-sm font-semibold",
|
|
16
|
+
description: "text-fg-secondary! text-sm",
|
|
17
|
+
actionButton: "bg-bg-brand text-on-bg-brand rounded-md px-2.5 py-1 text-xs font-medium",
|
|
18
|
+
cancelButton: "bg-bg-secondary text-fg-secondary rounded-md px-2.5 py-1 text-xs font-medium",
|
|
19
|
+
closeButton: "border-outline-secondary bg-bg-default-alt text-fg-tertiary hover:text-fg-default",
|
|
20
|
+
icon: "shrink-0"
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
var TOASTER_THEME = {
|
|
24
|
+
"--normal-bg": "var(--color-bg-default-alt)",
|
|
25
|
+
"--normal-text": "var(--color-fg-default)",
|
|
26
|
+
"--normal-border": "var(--color-outline-secondary)",
|
|
27
|
+
"--success-bg": "var(--color-bg-success-subtle)",
|
|
28
|
+
"--success-text": "var(--color-on-bg-success-subtle)",
|
|
29
|
+
"--success-border": "var(--color-outline-success-subtle)",
|
|
30
|
+
"--error-bg": "var(--color-bg-danger-subtle)",
|
|
31
|
+
"--error-text": "var(--color-on-bg-danger-subtle)",
|
|
32
|
+
"--error-border": "var(--color-outline-danger-subtle)",
|
|
33
|
+
"--warning-bg": "var(--color-bg-warning-subtle)",
|
|
34
|
+
"--warning-text": "var(--color-on-bg-warning-subtle)",
|
|
35
|
+
"--warning-border": "var(--color-outline-warning-subtle)",
|
|
36
|
+
"--info-bg": "var(--color-bg-brand-subtle)",
|
|
37
|
+
"--info-text": "var(--color-on-bg-brand-subtle)",
|
|
38
|
+
"--info-border": "var(--color-outline-brand-subtle)"
|
|
39
|
+
};
|
|
40
|
+
var Toaster = ({
|
|
41
|
+
unstyled,
|
|
42
|
+
classNames,
|
|
43
|
+
className,
|
|
44
|
+
style,
|
|
45
|
+
toastOptions,
|
|
46
|
+
...props
|
|
47
|
+
}) => {
|
|
48
|
+
const slots = createTVUnstyledSlots(sonnerStyles(), unstyled);
|
|
49
|
+
return /* @__PURE__ */ jsx(
|
|
50
|
+
SonnerToaster,
|
|
51
|
+
{
|
|
52
|
+
"data-slot": "toaster",
|
|
53
|
+
className: cn("toaster group", className),
|
|
54
|
+
style: { ...unstyled ? void 0 : TOASTER_THEME, ...style },
|
|
55
|
+
toastOptions: {
|
|
56
|
+
...toastOptions,
|
|
57
|
+
classNames: {
|
|
58
|
+
toast: slots.toast({ className: classNames?.toast }),
|
|
59
|
+
title: slots.title({ className: classNames?.title }),
|
|
60
|
+
description: slots.description({
|
|
61
|
+
className: classNames?.description
|
|
62
|
+
}),
|
|
63
|
+
actionButton: slots.actionButton({
|
|
64
|
+
className: classNames?.actionButton
|
|
65
|
+
}),
|
|
66
|
+
cancelButton: slots.cancelButton({
|
|
67
|
+
className: classNames?.cancelButton
|
|
68
|
+
}),
|
|
69
|
+
closeButton: slots.closeButton({
|
|
70
|
+
className: classNames?.closeButton
|
|
71
|
+
}),
|
|
72
|
+
icon: slots.icon({ className: classNames?.icon }),
|
|
73
|
+
...toastOptions?.classNames
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
...props
|
|
77
|
+
}
|
|
78
|
+
);
|
|
79
|
+
};
|
|
80
|
+
export {
|
|
81
|
+
Toaster,
|
|
82
|
+
sonnerStyles,
|
|
83
|
+
toast,
|
|
84
|
+
useSonner
|
|
85
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"inputs":{"src/sonner.tsx":{"bytes":4181,"imports":[{"path":"react","kind":"import-statement","external":true},{"path":"@mijn-ui/react-core","kind":"import-statement","external":true},{"path":"sonner","kind":"import-statement","external":true},{"path":"tailwind-variants","kind":"import-statement","external":true},{"path":"sonner","kind":"import-statement","external":true},{"path":"react/jsx-runtime","kind":"import-statement","external":true}],"format":"esm"},"src/index.ts":{"bytes":25,"imports":[{"path":"src/sonner.tsx","kind":"import-statement","original":"./sonner"}],"format":"esm"}},"outputs":{"dist/index.js":{"imports":[{"path":"@mijn-ui/react-core","kind":"import-statement","external":true},{"path":"sonner","kind":"import-statement","external":true},{"path":"tailwind-variants","kind":"import-statement","external":true},{"path":"sonner","kind":"import-statement","external":true},{"path":"react/jsx-runtime","kind":"import-statement","external":true}],"exports":["Toaster","sonnerStyles","toast","useSonner"],"entryPoint":"src/index.ts","inputs":{"src/sonner.tsx":{"bytesInOutput":2766},"src/index.ts":{"bytesInOutput":0}},"bytes":2859}}}
|
package/package.json
CHANGED
|
@@ -1,6 +1,64 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mijn-ui/react-sonner",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"author": "Htet Aung Lin<htetaunglin.coder@gmail.com>",
|
|
4
|
+
"version": "0.1.0",
|
|
5
|
+
"homepage": "https://mijn-ui.vercel.app",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"sideEffects": false,
|
|
9
|
+
"files": [
|
|
10
|
+
"dist"
|
|
11
|
+
],
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "git+https://github.com/mijn-ui/mijn-ui-react.git",
|
|
15
|
+
"directory": "packages/components/sonner"
|
|
16
|
+
},
|
|
17
|
+
"bugs": {
|
|
18
|
+
"url": "https://github.com/mijn-ui/mijn-ui-react/issues"
|
|
19
|
+
},
|
|
20
|
+
"exports": "./dist/index.js",
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@next/eslint-plugin-next": "^15.0.3",
|
|
24
|
+
"@testing-library/react": "^16.1.0",
|
|
25
|
+
"@types/react": "^19.0.0",
|
|
26
|
+
"@types/react-dom": "^19.0.0",
|
|
27
|
+
"jsdom": "^30.1.3",
|
|
28
|
+
"react": "19.0.1",
|
|
29
|
+
"react-dom": "19.0.1",
|
|
30
|
+
"sonner": "^2.0.7",
|
|
31
|
+
"@mijn-ui/react-button": "0.6.0",
|
|
32
|
+
"@mijn-ui/react-core": "0.5.1",
|
|
33
|
+
"eslint-config-custom": "0.0.1",
|
|
34
|
+
"tsconfig": "0.0.0",
|
|
35
|
+
"tsup-config": "0.0.0"
|
|
36
|
+
},
|
|
37
|
+
"peerDependencies": {
|
|
38
|
+
"@mijn-ui/react-core": "^0.5.0",
|
|
39
|
+
"react": "^19.0",
|
|
40
|
+
"react-dom": "^19.0",
|
|
41
|
+
"sonner": "^2.0.0",
|
|
42
|
+
"tailwind-merge": "^3.0.0",
|
|
43
|
+
"tailwind-variants": "^3.0.0"
|
|
44
|
+
},
|
|
45
|
+
"publishConfig": {
|
|
46
|
+
"access": "public"
|
|
47
|
+
},
|
|
48
|
+
"keywords": [
|
|
49
|
+
"sonner",
|
|
50
|
+
"toast",
|
|
51
|
+
"toaster",
|
|
52
|
+
"notification",
|
|
53
|
+
"react",
|
|
54
|
+
"nextjs"
|
|
55
|
+
],
|
|
56
|
+
"scripts": {
|
|
57
|
+
"clean": "rimraf dist .turbo",
|
|
58
|
+
"build": "tsup",
|
|
59
|
+
"test": "vitest run",
|
|
60
|
+
"lint": "eslint .",
|
|
61
|
+
"lint:fix": "eslint . --fix",
|
|
62
|
+
"types:check": "tsc --noEmit"
|
|
63
|
+
}
|
|
6
64
|
}
|