-
Notifications
You must be signed in to change notification settings - Fork 10
feat: add Sonner toast notifications and integrate into UI components #64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,244 @@ | ||
| import type { Meta, StoryObj } from "@storybook/react"; | ||
| import { toast } from "sonner"; | ||
| import { Toaster } from "./sonner"; | ||
| import { Button } from "./button"; | ||
|
|
||
| const meta = { | ||
| title: "UI/Sonner", | ||
| component: Toaster, | ||
| parameters: { layout: "centered" }, | ||
| tags: ["autodocs"], | ||
| } satisfies Meta<typeof Toaster>; | ||
|
|
||
| export default meta; | ||
| type Story = StoryObj<typeof meta>; | ||
|
|
||
| export const Default: Story = { | ||
| render: () => ( | ||
| <> | ||
| <div className="flex flex-wrap gap-2"> | ||
| <Button | ||
| variant="outline" | ||
| onClick={() => toast("Event has been created.")} | ||
| > | ||
| Default | ||
| </Button> | ||
| <Button | ||
| variant="outline" | ||
| onClick={() => | ||
| toast("Event has been created", { | ||
| description: "Sunday, December 03, 2023 at 9:00 AM", | ||
| }) | ||
| } | ||
| > | ||
| With Description | ||
| </Button> | ||
| <Button | ||
| variant="outline" | ||
| onClick={() => toast.success("Event has been created.")} | ||
| > | ||
| Success | ||
| </Button> | ||
| <Button | ||
| variant="outline" | ||
| onClick={() => | ||
| toast.info("Be at the area 10 minutes before the event time.") | ||
| } | ||
| > | ||
| Info | ||
| </Button> | ||
| <Button | ||
| variant="outline" | ||
| onClick={() => | ||
| toast.warning("Event start time cannot be earlier than 8am.") | ||
| } | ||
| > | ||
| Warning | ||
| </Button> | ||
| <Button | ||
| variant="outline" | ||
| onClick={() => toast.error("Event has not been created.")} | ||
| > | ||
| Error | ||
| </Button> | ||
| <Button | ||
| variant="outline" | ||
| onClick={() => toast.loading("Loading data...")} | ||
| > | ||
| Loading | ||
| </Button> | ||
| <Button | ||
| variant="outline" | ||
| onClick={() => | ||
| toast("Event has been created", { | ||
| action: { | ||
| label: "Undo", | ||
| onClick: () => console.log("Undo"), | ||
| }, | ||
| }) | ||
| } | ||
| > | ||
| With Action | ||
| </Button> | ||
| <Button | ||
| variant="outline" | ||
| onClick={() => | ||
| toast("Event has been created", { | ||
| cancel: { | ||
| label: "Cancel", | ||
| onClick: () => console.log("Cancel"), | ||
| }, | ||
| }) | ||
| } | ||
| > | ||
| With Cancel | ||
| </Button> | ||
| <Button | ||
| variant="outline" | ||
| onClick={() => { | ||
| toast.promise( | ||
| () => | ||
| new window.Promise<{ name: string }>((resolve) => | ||
| setTimeout(() => resolve({ name: "Sonner" }), 2000) | ||
| ), | ||
| { | ||
| loading: "Loading...", | ||
| success: (data) => `${data.name} toast has been added`, | ||
| error: "Error", | ||
| } | ||
| ); | ||
| }} | ||
| > | ||
| Promise | ||
| </Button> | ||
| <Button | ||
| variant="outline" | ||
| onClick={() => | ||
| toast( | ||
| <div className="flex flex-col gap-1"> | ||
| <span className="font-semibold">Custom Toast</span> | ||
| <span className="text-sm text-muted-foreground"> | ||
| This is a toast with{" "} | ||
| <a href="#" className="underline font-medium"> | ||
| custom JSX | ||
| </a>{" "} | ||
| content. | ||
| </span> | ||
| </div> | ||
| ) | ||
| } | ||
| > | ||
| Custom JSX | ||
| </Button> | ||
| </div> | ||
| <Toaster /> | ||
| </> | ||
| ), | ||
| }; | ||
|
|
||
| export const Positions: Story = { | ||
| render: () => { | ||
| const positions = [ | ||
| "top-left", | ||
| "top-center", | ||
| "top-right", | ||
| "bottom-left", | ||
| "bottom-center", | ||
| "bottom-right", | ||
| ] as const; | ||
|
|
||
| return ( | ||
| <> | ||
| <div className="flex flex-wrap gap-2"> | ||
| {positions.map((position) => ( | ||
| <Button | ||
| key={position} | ||
| variant="outline" | ||
| onClick={() => | ||
| toast("Event has been created", { | ||
| description: `Position: ${position}`, | ||
| position, | ||
| }) | ||
| } | ||
| > | ||
| {position} | ||
| </Button> | ||
| ))} | ||
| </div> | ||
| <Toaster /> | ||
| </> | ||
| ); | ||
| }, | ||
| }; | ||
|
|
||
| export const RichColors: Story = { | ||
| render: () => ( | ||
| <> | ||
| <div className="flex flex-wrap gap-2"> | ||
| <Button | ||
| variant="outline" | ||
| onClick={() => toast.success("Event has been created")} | ||
| > | ||
| Success | ||
| </Button> | ||
| <Button | ||
| variant="outline" | ||
| onClick={() => toast.info("Be at the area 10 minutes before")} | ||
| > | ||
| Info | ||
| </Button> | ||
| <Button | ||
| variant="outline" | ||
| onClick={() => | ||
| toast.warning("Event time cannot be earlier than 8am") | ||
| } | ||
| > | ||
| Warning | ||
| </Button> | ||
| <Button | ||
| variant="outline" | ||
| onClick={() => toast.error("Event has not been created")} | ||
| > | ||
| Error | ||
| </Button> | ||
| </div> | ||
| <Toaster richColors /> | ||
| </> | ||
| ), | ||
| }; | ||
|
|
||
| export const CloseButton: Story = { | ||
| render: () => ( | ||
| <> | ||
| <Button | ||
| variant="outline" | ||
| onClick={() => | ||
| toast("Event has been created", { | ||
| description: "This toast has a close button.", | ||
| }) | ||
| } | ||
| > | ||
| With Close Button | ||
| </Button> | ||
| <Toaster closeButton /> | ||
| </> | ||
| ), | ||
| }; | ||
|
|
||
| export const Expanded: Story = { | ||
| render: () => ( | ||
| <> | ||
| <Button | ||
| variant="outline" | ||
| onClick={() => { | ||
| toast("First notification"); | ||
| setTimeout(() => toast.success("Second notification"), 300); | ||
| setTimeout(() => toast.info("Third notification"), 600); | ||
| }} | ||
| > | ||
| Show Expanded Toasts | ||
| </Button> | ||
| <Toaster expand /> | ||
| </> | ||
| ), | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| import { | ||
| CircleCheckIcon, | ||
| InfoIcon, | ||
| Loader2Icon, | ||
| OctagonXIcon, | ||
| TriangleAlertIcon, | ||
| } from "lucide-react"; | ||
| import { useThemeOptional } from "@/providers"; | ||
| import { Toaster as Sonner, type ToasterProps } from "sonner"; | ||
|
|
||
| const Toaster = ({ ...props }: ToasterProps) => { | ||
| const theme = useThemeOptional(); | ||
| const mode = theme?.mode ?? "system"; | ||
|
|
||
| return ( | ||
| <Sonner | ||
| theme={mode as ToasterProps["theme"]} | ||
| className="toaster group" | ||
| icons={{ | ||
| success: <CircleCheckIcon className="size-4" />, | ||
| info: <InfoIcon className="size-4" />, | ||
| warning: <TriangleAlertIcon className="size-4" />, | ||
| error: <OctagonXIcon className="size-4" />, | ||
| loading: <Loader2Icon className="size-4 animate-spin" />, | ||
| }} | ||
| style={ | ||
| { | ||
| "--normal-bg": "var(--popover)", | ||
| "--normal-text": "var(--popover-foreground)", | ||
| "--normal-border": "var(--border)", | ||
| "--border-radius": "var(--radius)", | ||
| } as React.CSSProperties | ||
| } | ||
| {...props} | ||
| /> | ||
| ); | ||
| }; | ||
|
|
||
| export { Toaster }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: getdokan/plugin-ui
Length of output: 295
Update peerDependencies to reflect Sonner's React 18+ requirement.
Sonner 2.0.7 requires
react@^18.0.0 || ^19.0.0andreact-dom@^18.0.0 || ^19.0.0, but the current peer ranges declare>=17.0.0. This mismatch creates install conflicts for consumers using React 17. Update peer ranges to>=18.0.0:Proposed fix
"peerDependencies": { - "react": ">=17.0.0", - "react-dom": ">=17.0.0" + "react": ">=18.0.0", + "react-dom": ">=18.0.0" },🤖 Prompt for AI Agents