-
Notifications
You must be signed in to change notification settings - Fork 440
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4e4d409
commit aaefa32
Showing
4 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 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 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,31 @@ | ||
"use client"; | ||
|
||
import { useTheme } from "next-themes"; | ||
import { Toaster as Sonner } from "sonner"; | ||
|
||
type ToasterProps = React.ComponentProps<typeof Sonner>; | ||
|
||
const Toaster = ({ ...props }: ToasterProps) => { | ||
const { theme = "system" } = useTheme(); | ||
|
||
return ( | ||
<Sonner | ||
theme={theme as ToasterProps["theme"]} | ||
className="toaster group" | ||
toastOptions={{ | ||
classNames: { | ||
toast: | ||
"group toast group-[.toaster]:bg-background group-[.toaster]:text-foreground group-[.toaster]:border-border group-[.toaster]:shadow-lg data-[button]:bg-button-primary-background gap-2", | ||
description: "group-[.toast]:text-foreground-secondary", | ||
actionButton: | ||
"group-[.toast]:!bg-button-primary-background group-[.toast]:!text-button-primary-foreground", | ||
closeButton: | ||
"group-[.toast]:bg-background group-[.toast]:text-foreground group-[.toast]:border-border", | ||
}, | ||
}} | ||
{...props} | ||
/> | ||
); | ||
}; | ||
|
||
export { Toaster }; |
This file contains 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,56 @@ | ||
import { Button } from "@/components/ui/Button"; | ||
import { Toaster } from "@/components/ui/Toaster"; | ||
import type { Meta, StoryObj } from "@storybook/react"; | ||
import { toast } from "sonner"; | ||
|
||
type ToastExampleProps = { | ||
title: string; | ||
description?: string; | ||
action?: boolean; | ||
closeButton?: boolean; | ||
}; | ||
const ToastExample = ({ | ||
title = "Toast example", | ||
description, | ||
action, | ||
closeButton, | ||
}: ToastExampleProps) => { | ||
return ( | ||
<> | ||
<Button | ||
onClick={() => | ||
toast(title, { | ||
description, | ||
action: action ? ( | ||
<Button size="xs" className="ml-auto"> | ||
Action | ||
</Button> | ||
) : undefined, | ||
closeButton, | ||
}) | ||
} | ||
> | ||
Show toast! | ||
</Button> | ||
<Toaster /> | ||
</> | ||
); | ||
}; | ||
|
||
const meta: Meta<typeof ToastExample> = { | ||
title: "Design system/Toast", | ||
component: ToastExample, | ||
}; | ||
|
||
export default meta; | ||
|
||
type Story = StoryObj<typeof ToastExample>; | ||
|
||
export const Default: Story = { | ||
args: { | ||
title: "Toast example", | ||
description: "", | ||
action: false, | ||
closeButton: false, | ||
}, | ||
}; |