@mijn-ui/react-sonner 0.0.0-stage → 0.1.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 +72 -2
- package/dist/index.d.ts +94 -0
- package/dist/index.js +94 -0
- package/dist/metafile-esm.json +1 -0
- package/package.json +62 -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,73 @@
|
|
|
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. With `richColors`, success, warning and error use
|
|
50
|
+
their status tiers and info uses the categorical blue tier — not the brand, so
|
|
51
|
+
info stays distinct from success whatever the brand colour is. Pass `unstyled` to drop that mapping entirely and
|
|
52
|
+
supply your own `classNames`.
|
|
53
|
+
|
|
54
|
+
### Overriding a slot
|
|
55
|
+
|
|
56
|
+
Sonner injects its own stylesheet at runtime, outside any CSS cascade layer.
|
|
57
|
+
Unlayered rules beat every Tailwind utility (those live in `@layer utilities`)
|
|
58
|
+
regardless of specificity, so the toaster's slot classes are `!important`
|
|
59
|
+
wherever sonner sets the same property. Do the same in your own `classNames`
|
|
60
|
+
when you override one of those properties:
|
|
61
|
+
|
|
62
|
+
```tsx
|
|
63
|
+
<Toaster classNames={{ title: "font-bold!", actionButton: "rounded-full!" }} />
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Properties sonner leaves alone (`uppercase`, `py-2`, …) need no `!`. The
|
|
67
|
+
toast's own background, text and border colours are the exception: they come
|
|
68
|
+
from the variables above, so set those variables (or use `richColors`) rather
|
|
69
|
+
than classes.
|
|
70
|
+
|
|
71
|
+
## License
|
|
72
|
+
|
|
73
|
+
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,94 @@
|
|
|
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
|
+
/**
|
|
10
|
+
* Why so many `!`: sonner injects its own stylesheet at runtime, outside any
|
|
11
|
+
* cascade layer, and unlayered rules beat everything in Tailwind's
|
|
12
|
+
* `@layer utilities` whatever their specificity. So a class here only applies
|
|
13
|
+
* if sonner does not set the same property — or if it is `!important`. Every
|
|
14
|
+
* class below that competes with a sonner property carries `!`; the rest
|
|
15
|
+
* (`py-1`, `group`) do not need it. `sonner.test.tsx` checks this against
|
|
16
|
+
* sonner's actual stylesheet.
|
|
17
|
+
*
|
|
18
|
+
* The same goes for your own `classNames`: to override a property sonner
|
|
19
|
+
* sets, add `!` (`title: "font-bold!"`).
|
|
20
|
+
*/
|
|
21
|
+
declare const sonnerStyles: tailwind_variants.TVReturnType<{
|
|
22
|
+
[key: string]: {
|
|
23
|
+
[key: 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
|
+
[x: string]: {
|
|
35
|
+
[x: string]: tailwind_merge.ClassNameValue | {
|
|
36
|
+
toast?: tailwind_merge.ClassNameValue;
|
|
37
|
+
title?: tailwind_merge.ClassNameValue;
|
|
38
|
+
description?: tailwind_merge.ClassNameValue;
|
|
39
|
+
actionButton?: tailwind_merge.ClassNameValue;
|
|
40
|
+
cancelButton?: tailwind_merge.ClassNameValue;
|
|
41
|
+
closeButton?: tailwind_merge.ClassNameValue;
|
|
42
|
+
icon?: tailwind_merge.ClassNameValue;
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
} | {}, {
|
|
46
|
+
toast: string;
|
|
47
|
+
title: string;
|
|
48
|
+
description: string;
|
|
49
|
+
actionButton: string;
|
|
50
|
+
cancelButton: string;
|
|
51
|
+
closeButton: string;
|
|
52
|
+
icon: string;
|
|
53
|
+
}, undefined, {
|
|
54
|
+
[key: string]: {
|
|
55
|
+
[key: string]: tailwind_merge.ClassNameValue | {
|
|
56
|
+
toast?: tailwind_merge.ClassNameValue;
|
|
57
|
+
title?: tailwind_merge.ClassNameValue;
|
|
58
|
+
description?: tailwind_merge.ClassNameValue;
|
|
59
|
+
actionButton?: tailwind_merge.ClassNameValue;
|
|
60
|
+
cancelButton?: tailwind_merge.ClassNameValue;
|
|
61
|
+
closeButton?: tailwind_merge.ClassNameValue;
|
|
62
|
+
icon?: tailwind_merge.ClassNameValue;
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
} | {}, {
|
|
66
|
+
toast: string;
|
|
67
|
+
title: string;
|
|
68
|
+
description: string;
|
|
69
|
+
actionButton: string;
|
|
70
|
+
cancelButton: string;
|
|
71
|
+
closeButton: string;
|
|
72
|
+
icon: string;
|
|
73
|
+
}, tailwind_variants.TVReturnType<unknown, {
|
|
74
|
+
toast: string;
|
|
75
|
+
title: string;
|
|
76
|
+
description: string;
|
|
77
|
+
actionButton: string;
|
|
78
|
+
cancelButton: string;
|
|
79
|
+
closeButton: string;
|
|
80
|
+
icon: string;
|
|
81
|
+
}, undefined, unknown, unknown, undefined>>;
|
|
82
|
+
type SonnerVariantProps = VariantProps<typeof sonnerStyles>;
|
|
83
|
+
type SonnerSlots = keyof ReturnType<typeof sonnerStyles>;
|
|
84
|
+
|
|
85
|
+
type MijnToasterProps = UnstyledComponentWithSlots<SonnerSlots> & ToasterProps;
|
|
86
|
+
/**
|
|
87
|
+
* A `sonner` <Toaster /> dressed in the mijn-ui theme.
|
|
88
|
+
*
|
|
89
|
+
* Mount it once, near the root of the app. Every `toast()` call anywhere in the
|
|
90
|
+
* tree renders through this one instance.
|
|
91
|
+
*/
|
|
92
|
+
declare const Toaster: ({ unstyled, classNames, className, style, toastOptions, ...props }: MijnToasterProps) => react_jsx_runtime.JSX.Element;
|
|
93
|
+
|
|
94
|
+
export { type MijnToasterProps, type SonnerSlots, type SonnerVariantProps, Toaster, sonnerStyles };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
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
|
+
// The toast's colours are the exception: they reach sonner through its
|
|
15
|
+
// --normal-* variables (TOASTER_THEME below), not through `!`, so that
|
|
16
|
+
// `richColors` can still recolour a success or error toast. These three
|
|
17
|
+
// classes are the fallback for a toast sonner leaves unstyled.
|
|
18
|
+
toast: "group border-outline-secondary bg-bg-default-alt text-fg-default rounded-(--mijn-radius-lg)! border! shadow-(--mijn-shadow-lg)! focus-visible:ring-outline-brand focus-visible:mijn-focus-ring!",
|
|
19
|
+
// No colour: sonner makes the title inherit the toast's, which is what
|
|
20
|
+
// lets `richColors` tint it.
|
|
21
|
+
title: "text-sm! font-semibold!",
|
|
22
|
+
description: "text-fg-secondary! text-sm!",
|
|
23
|
+
actionButton: "bg-bg-brand! text-on-bg-brand! rounded-md! px-2.5! py-1 text-xs! font-medium!",
|
|
24
|
+
cancelButton: "bg-bg-secondary! text-fg-secondary! rounded-md! px-2.5! py-1 text-xs! font-medium!",
|
|
25
|
+
closeButton: "border-outline-secondary! bg-bg-default-alt! text-fg-tertiary! hover:bg-bg-secondary! hover:text-fg-default!",
|
|
26
|
+
icon: "shrink-0!"
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
var TOASTER_THEME = {
|
|
30
|
+
"--normal-bg": "var(--color-bg-default-alt)",
|
|
31
|
+
"--normal-text": "var(--color-fg-default)",
|
|
32
|
+
"--normal-border": "var(--color-outline-secondary)",
|
|
33
|
+
"--success-bg": "var(--color-bg-success-subtle)",
|
|
34
|
+
"--success-text": "var(--color-on-bg-success-subtle)",
|
|
35
|
+
"--success-border": "var(--color-outline-success-subtle)",
|
|
36
|
+
"--error-bg": "var(--color-bg-danger-subtle)",
|
|
37
|
+
"--error-text": "var(--color-on-bg-danger-subtle)",
|
|
38
|
+
"--error-border": "var(--color-outline-danger-subtle)",
|
|
39
|
+
"--warning-bg": "var(--color-bg-warning-subtle)",
|
|
40
|
+
"--warning-text": "var(--color-on-bg-warning-subtle)",
|
|
41
|
+
"--warning-border": "var(--color-outline-warning-subtle)",
|
|
42
|
+
// Info gets the categorical blue tier, not brand: with a green brand (as in
|
|
43
|
+
// PicoAI) brand-subtle is success-subtle, and info toasts looked like
|
|
44
|
+
// success ones.
|
|
45
|
+
"--info-bg": "var(--color-bg-blue-subtle)",
|
|
46
|
+
"--info-text": "var(--color-on-bg-blue-subtle)",
|
|
47
|
+
"--info-border": "var(--color-outline-blue-subtle)"
|
|
48
|
+
};
|
|
49
|
+
var Toaster = ({
|
|
50
|
+
unstyled,
|
|
51
|
+
classNames,
|
|
52
|
+
className,
|
|
53
|
+
style,
|
|
54
|
+
toastOptions,
|
|
55
|
+
...props
|
|
56
|
+
}) => {
|
|
57
|
+
const slots = createTVUnstyledSlots(sonnerStyles(), unstyled);
|
|
58
|
+
return /* @__PURE__ */ jsx(
|
|
59
|
+
SonnerToaster,
|
|
60
|
+
{
|
|
61
|
+
"data-slot": "toaster",
|
|
62
|
+
className: cn("toaster group", className),
|
|
63
|
+
style: { ...unstyled ? void 0 : TOASTER_THEME, ...style },
|
|
64
|
+
toastOptions: {
|
|
65
|
+
...toastOptions,
|
|
66
|
+
classNames: {
|
|
67
|
+
toast: slots.toast({ className: classNames?.toast }),
|
|
68
|
+
title: slots.title({ className: classNames?.title }),
|
|
69
|
+
description: slots.description({
|
|
70
|
+
className: classNames?.description
|
|
71
|
+
}),
|
|
72
|
+
actionButton: slots.actionButton({
|
|
73
|
+
className: classNames?.actionButton
|
|
74
|
+
}),
|
|
75
|
+
cancelButton: slots.cancelButton({
|
|
76
|
+
className: classNames?.cancelButton
|
|
77
|
+
}),
|
|
78
|
+
closeButton: slots.closeButton({
|
|
79
|
+
className: classNames?.closeButton
|
|
80
|
+
}),
|
|
81
|
+
icon: slots.icon({ className: classNames?.icon }),
|
|
82
|
+
...toastOptions?.classNames
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
...props
|
|
86
|
+
}
|
|
87
|
+
);
|
|
88
|
+
};
|
|
89
|
+
export {
|
|
90
|
+
Toaster,
|
|
91
|
+
sonnerStyles,
|
|
92
|
+
toast,
|
|
93
|
+
useSonner
|
|
94
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"inputs":{"src/sonner.tsx":{"bytes":5494,"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":3467},"src/index.ts":{"bytesInOutput":0}},"bytes":3560}}}
|
package/package.json
CHANGED
|
@@ -1,6 +1,65 @@
|
|
|
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.1",
|
|
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.7.0",
|
|
32
|
+
"@mijn-ui/react-core": "0.6.0",
|
|
33
|
+
"eslint-config-custom": "0.0.1",
|
|
34
|
+
"tsconfig": "0.0.0",
|
|
35
|
+
"tsup-config": "0.0.0",
|
|
36
|
+
"test-utils": "0.0.0"
|
|
37
|
+
},
|
|
38
|
+
"peerDependencies": {
|
|
39
|
+
"@mijn-ui/react-core": "^0.6.0",
|
|
40
|
+
"react": "^19.0",
|
|
41
|
+
"react-dom": "^19.0",
|
|
42
|
+
"sonner": "^2.0.0",
|
|
43
|
+
"tailwind-merge": "^3.0.0",
|
|
44
|
+
"tailwind-variants": "^3.0.0"
|
|
45
|
+
},
|
|
46
|
+
"publishConfig": {
|
|
47
|
+
"access": "public"
|
|
48
|
+
},
|
|
49
|
+
"keywords": [
|
|
50
|
+
"sonner",
|
|
51
|
+
"toast",
|
|
52
|
+
"toaster",
|
|
53
|
+
"notification",
|
|
54
|
+
"react",
|
|
55
|
+
"nextjs"
|
|
56
|
+
],
|
|
57
|
+
"scripts": {
|
|
58
|
+
"clean": "rimraf dist .turbo",
|
|
59
|
+
"build": "tsup",
|
|
60
|
+
"test": "vitest run",
|
|
61
|
+
"lint": "eslint .",
|
|
62
|
+
"lint:fix": "eslint . --fix",
|
|
63
|
+
"types:check": "tsc --noEmit"
|
|
64
|
+
}
|
|
6
65
|
}
|