@stackshift-ui/toast 1.0.0-beta.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 +373 -0
- package/README.md +24 -0
- package/dist/chunk-3EYN2AKU.mjs +1 -0
- package/dist/chunk-6CMUX5YF.mjs +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -0
- package/dist/index.mjs +2 -0
- package/dist/setupTests.d.ts +2 -0
- package/dist/setupTests.js +51 -0
- package/dist/setupTests.mjs +51 -0
- package/dist/toast.d.ts +6 -0
- package/dist/toast.js +2 -0
- package/dist/toast.mjs +2 -0
- package/package.json +64 -0
- package/src/index.ts +4 -0
- package/src/setupTests.ts +4 -0
- package/src/toast.test.tsx +44 -0
- package/src/toast.tsx +32 -0
package/package.json
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@stackshift-ui/toast",
|
|
3
|
+
"description": "An opinionated toast component for React.",
|
|
4
|
+
"version": "1.0.0-beta.1",
|
|
5
|
+
"private": false,
|
|
6
|
+
"sideEffects": false,
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"module": "./dist/index.mjs",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"files": [
|
|
11
|
+
"dist/**",
|
|
12
|
+
"src"
|
|
13
|
+
],
|
|
14
|
+
"author": "WebriQ <info@webriq.com>",
|
|
15
|
+
"devDependencies": {
|
|
16
|
+
"@testing-library/jest-dom": "^6.5.0",
|
|
17
|
+
"@testing-library/react": "^16.0.1",
|
|
18
|
+
"@testing-library/user-event": "^14.6.1",
|
|
19
|
+
"@types/node": "^22.7.0",
|
|
20
|
+
"@types/react": "^18.3.9",
|
|
21
|
+
"@types/react-dom": "^18.3.0",
|
|
22
|
+
"@vitejs/plugin-react": "^4.3.1",
|
|
23
|
+
"@vitest/coverage-v8": "^2.1.1",
|
|
24
|
+
"esbuild-plugin-rdi": "^0.0.0",
|
|
25
|
+
"esbuild-plugin-react18": "^0.2.5",
|
|
26
|
+
"esbuild-plugin-react18-css": "^0.0.4",
|
|
27
|
+
"jsdom": "^25.0.1",
|
|
28
|
+
"react": "^18.3.1",
|
|
29
|
+
"react-dom": "^18.3.1",
|
|
30
|
+
"tsup": "^8.3.0",
|
|
31
|
+
"typescript": "^5.6.2",
|
|
32
|
+
"vite-tsconfig-paths": "^5.0.1",
|
|
33
|
+
"vitest": "^2.1.1",
|
|
34
|
+
"@stackshift-ui/eslint-config": "6.0.10",
|
|
35
|
+
"@stackshift-ui/typescript-config": "6.0.10"
|
|
36
|
+
},
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"classnames": "^2.5.1",
|
|
39
|
+
"next-themes": "^0.4.6",
|
|
40
|
+
"sonner": "^2.0.5",
|
|
41
|
+
"@stackshift-ui/scripts": "6.1.0-beta.0",
|
|
42
|
+
"@stackshift-ui/system": "6.1.0-beta.0"
|
|
43
|
+
},
|
|
44
|
+
"peerDependencies": {
|
|
45
|
+
"@stackshift-ui/system": ">=6.1.0-beta.0",
|
|
46
|
+
"@types/react": "16.8 - 19",
|
|
47
|
+
"next": "10 - 14",
|
|
48
|
+
"react": "16.8 - 19",
|
|
49
|
+
"react-dom": "16.8 - 19"
|
|
50
|
+
},
|
|
51
|
+
"peerDependenciesMeta": {
|
|
52
|
+
"next": {
|
|
53
|
+
"optional": true
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
"scripts": {
|
|
57
|
+
"build": "tsup && tsc -p tsconfig-build.json",
|
|
58
|
+
"clean": "rm -rf dist",
|
|
59
|
+
"dev": "tsup --watch && tsc -p tsconfig-build.json -w",
|
|
60
|
+
"typecheck": "tsc --noEmit",
|
|
61
|
+
"lint": "eslint src/",
|
|
62
|
+
"test": "vitest run --coverage"
|
|
63
|
+
}
|
|
64
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { cleanup, render, screen } from "@testing-library/react";
|
|
2
|
+
import { afterEach, describe, test, vi } from "vitest";
|
|
3
|
+
import { toast, Toaster } from "./toast";
|
|
4
|
+
|
|
5
|
+
// Object.defineProperty(window, "matchMedia", {
|
|
6
|
+
// writable: true,
|
|
7
|
+
// value: query => ({
|
|
8
|
+
// matches: false,
|
|
9
|
+
// media: query,
|
|
10
|
+
// onchange: null,
|
|
11
|
+
// addListener: () => {},
|
|
12
|
+
// removeListener: () => {},
|
|
13
|
+
// addEventListener: () => {},
|
|
14
|
+
// removeEventListener: () => {},
|
|
15
|
+
// dispatchEvent: () => false,
|
|
16
|
+
// }),
|
|
17
|
+
// });
|
|
18
|
+
|
|
19
|
+
window.matchMedia = vi.fn().mockImplementation(query => ({
|
|
20
|
+
matches: false,
|
|
21
|
+
media: query,
|
|
22
|
+
onchange: null,
|
|
23
|
+
addListener: vi.fn(),
|
|
24
|
+
removeListener: vi.fn(),
|
|
25
|
+
addEventListener: vi.fn(),
|
|
26
|
+
removeEventListener: vi.fn(),
|
|
27
|
+
dispatchEvent: vi.fn(),
|
|
28
|
+
}));
|
|
29
|
+
|
|
30
|
+
// TODO: Proper test for Toaster component
|
|
31
|
+
describe.concurrent("toast", () => {
|
|
32
|
+
afterEach(() => {
|
|
33
|
+
cleanup();
|
|
34
|
+
vi.clearAllMocks();
|
|
35
|
+
vi.resetAllMocks();
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
test("Dummy test - test if renders without errors", ({ expect }) => {
|
|
39
|
+
const clx = "my-class";
|
|
40
|
+
const { unmount } = render(<Toaster data-testid="toast" className={clx} />);
|
|
41
|
+
expect(screen.getByLabelText("Notifications alt+T")).toBeInTheDocument();
|
|
42
|
+
unmount();
|
|
43
|
+
});
|
|
44
|
+
});
|
package/src/toast.tsx
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useTheme } from "next-themes";
|
|
4
|
+
import { Toaster as Sonner, ToasterProps, toast } from "sonner";
|
|
5
|
+
|
|
6
|
+
import { DefaultComponent, useStackShiftUIComponents } from "@stackshift-ui/system";
|
|
7
|
+
|
|
8
|
+
const displayName = "Toaster";
|
|
9
|
+
|
|
10
|
+
const Toaster = ({ ...props }: ToasterProps) => {
|
|
11
|
+
const { [displayName]: Component = DefaultComponent } = useStackShiftUIComponents();
|
|
12
|
+
const { theme = "system" } = useTheme();
|
|
13
|
+
|
|
14
|
+
return (
|
|
15
|
+
<Component
|
|
16
|
+
as={Sonner}
|
|
17
|
+
theme={theme as ToasterProps["theme"]}
|
|
18
|
+
className="toaster group"
|
|
19
|
+
style={
|
|
20
|
+
{
|
|
21
|
+
"--normal-bg": "var(--popover)",
|
|
22
|
+
"--normal-text": "var(--popover-foreground)",
|
|
23
|
+
"--normal-border": "var(--border)",
|
|
24
|
+
} as React.CSSProperties
|
|
25
|
+
}
|
|
26
|
+
{...props}
|
|
27
|
+
/>
|
|
28
|
+
);
|
|
29
|
+
};
|
|
30
|
+
Toaster.displayName = displayName;
|
|
31
|
+
|
|
32
|
+
export { Toaster, toast, type ToasterProps };
|