From f6b029a8431104a6969581a5b9ccbd613e341eb5 Mon Sep 17 00:00:00 2001 From: javayhu Date: Thu, 20 Feb 2025 01:02:01 +0800 Subject: [PATCH] feat: add component sonner --- package.json | 2 ++ pnpm-lock.yaml | 28 ++++++++++++++++++++++++++++ src/components/ui/sonner.tsx | 31 +++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+) create mode 100644 src/components/ui/sonner.tsx diff --git a/package.json b/package.json index 519e388..6585664 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,7 @@ "lucide-react": "^0.475.0", "motion": "^12.4.3", "next": "15.1.7", + "next-themes": "^0.4.4", "react": "^19.0.0", "react-dom": "^19.0.0", "rehype-autolink-headings": "^7.1.0", @@ -37,6 +38,7 @@ "remark-code-import": "^1.2.0", "remark-gfm": "^4.0.1", "shiki": "^2.4.2", + "sonner": "^2.0.0", "tailwind-merge": "^3.0.1", "tailwindcss-animate": "^1.0.7" }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 26e3774..8e8b700 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -68,6 +68,9 @@ importers: next: specifier: 15.1.7 version: 15.1.7(react-dom@19.0.0(react@19.0.0))(react@19.0.0) + next-themes: + specifier: ^0.4.4 + version: 0.4.4(react-dom@19.0.0(react@19.0.0))(react@19.0.0) react: specifier: ^19.0.0 version: 19.0.0 @@ -92,6 +95,9 @@ importers: shiki: specifier: ^2.4.2 version: 2.4.2 + sonner: + specifier: ^2.0.0 + version: 2.0.0(react-dom@19.0.0(react@19.0.0))(react@19.0.0) tailwind-merge: specifier: ^3.0.1 version: 3.0.1 @@ -1897,6 +1903,12 @@ packages: engines: {node: ^10 || ^12 || ^13.7 || ^14 || >=15.0.1} hasBin: true + next-themes@0.4.4: + resolution: {integrity: sha512-LDQ2qIOJF0VnuVrrMSMLrWGjRMkq+0mpgl6e0juCLqdJ+oo8Q84JRWT6Wh11VDQKkMMe+dVzDKLWs5n87T+PkQ==} + peerDependencies: + react: ^16.8 || ^17 || ^18 || ^19 || ^19.0.0-rc + react-dom: ^16.8 || ^17 || ^18 || ^19 || ^19.0.0-rc + next@15.1.7: resolution: {integrity: sha512-GNeINPGS9c6OZKCvKypbL8GTsT5GhWPp4DM0fzkXJuXMilOO2EeFxuAY6JZbtk6XIl6Ws10ag3xRINDjSO5+wg==} engines: {node: ^18.18.0 || ^19.8.0 || >= 20.0.0} @@ -2216,6 +2228,12 @@ packages: simple-swizzle@0.2.2: resolution: {integrity: sha512-JA//kQgZtbuY83m+xT+tXJkmJncGMTFT+C+g2h2R9uxkYIrE2yy9sgmcLhCnw57/WSD+Eh3J97FPEDFnbXnDUg==} + sonner@2.0.0: + resolution: {integrity: sha512-3WeSl3WrEdhmdiTniT8JsCiVRVDOdn7k+4MG2drqzSMOeqrExm03HIwDBPKuq52JBqL7wRLG17QBIiSleUbljw==} + peerDependencies: + react: ^18.0.0 || ^19.0.0 || ^19.0.0-rc + react-dom: ^18.0.0 || ^19.0.0 || ^19.0.0-rc + source-map-js@1.2.1: resolution: {integrity: sha512-UXWMKhLOwVKb728IUtQPXxfYU+usdybtUrK/8uGE8CQMvrhOpwvzDBwj0QhSL7MQc7vIsISBG8VQ8+IDQxpfQA==} engines: {node: '>=0.10.0'} @@ -4481,6 +4499,11 @@ snapshots: nanoid@3.3.8: {} + next-themes@0.4.4(react-dom@19.0.0(react@19.0.0))(react@19.0.0): + dependencies: + react: 19.0.0 + react-dom: 19.0.0(react@19.0.0) + next@15.1.7(react-dom@19.0.0(react@19.0.0))(react@19.0.0): dependencies: '@next/env': 15.1.7 @@ -4891,6 +4914,11 @@ snapshots: is-arrayish: 0.3.2 optional: true + sonner@2.0.0(react-dom@19.0.0(react@19.0.0))(react@19.0.0): + dependencies: + react: 19.0.0 + react-dom: 19.0.0(react@19.0.0) + source-map-js@1.2.1: {} source-map@0.7.4: {} diff --git a/src/components/ui/sonner.tsx b/src/components/ui/sonner.tsx new file mode 100644 index 0000000..452f4d9 --- /dev/null +++ b/src/components/ui/sonner.tsx @@ -0,0 +1,31 @@ +"use client" + +import { useTheme } from "next-themes" +import { Toaster as Sonner } from "sonner" + +type ToasterProps = React.ComponentProps + +const Toaster = ({ ...props }: ToasterProps) => { + const { theme = "system" } = useTheme() + + return ( + + ) +} + +export { Toaster }