Skip to content

Commit 209dd75

Browse files
authored
Merge pull request #9 from CQCL/expose-react-form-deps
fix(): expose react-hook-form as a nested module
2 parents cfe5fb3 + afcd8ee commit 209dd75

File tree

4 files changed

+52
-34
lines changed

4 files changed

+52
-34
lines changed

package-lock.json

+3-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@
115115
"lucide-react": "^0.298.0",
116116
"next-themes": "^0.2.1",
117117
"react-day-picker": "^8.10.0",
118-
"react-hook-form": "^7.50.1",
119118
"react-resizable-panels": "^1.0.5",
119+
"sonner": "^1.3.1",
120120
"tailwind-merge": "^2.1.0",
121121
"vaul": "^0.8.0",
122122
"zod": "^3.22.4"
@@ -125,8 +125,8 @@
125125
"@tailwindcss/typography": "^0.5.10",
126126
"react": "^18.2.0",
127127
"react-dom": "^18.2.0",
128-
"sonner": "^1.3.1",
129128
"tailwindcss": "^3.3.6",
130-
"tailwindcss-animate": "^1.0.7"
129+
"tailwindcss-animate": "^1.0.7",
130+
"react-hook-form": "^7.50.1"
131131
}
132132
}

src/shadcn/ui/sonner.tsx

+23-14
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,38 @@
22

33
import { useTheme } from "next-themes"
44
import { Toaster as Sonner} from "sonner"
5+
import { cn } from "src/utils"
6+
export * as sonner from "sonner"
57

68
type ToasterProps = React.ComponentProps<typeof Sonner>
79

8-
export const SonnerToast = ({ ...props }: ToasterProps) => {
9-
const { theme = "system" } = useTheme()
10-
10+
export const SonnerToast = ({ theme, className, toastOptions, ...props }: ToasterProps) => {
11+
const { theme: defaultTheme = "system" } = useTheme()
1112
return (
1213
<Sonner
13-
theme={theme as ToasterProps["theme"]}
14-
className="toaster group"
14+
theme={theme ?? defaultTheme as ToasterProps["theme"]}
15+
className={cn("toaster group", className)}
1516
toastOptions={{
17+
...toastOptions,
1618
classNames: {
17-
toast:
18-
"group toast group-[.toaster]:bg-background group-[.toaster]:text-foreground group-[.toaster]:border-border group-[.toaster]:shadow-lg",
19-
description: "group-[.toast]:text-muted-foreground",
20-
actionButton:
19+
toast: cn(
20+
"group toast group-[.toaster]:bg-background group-[.toaster]:text-foreground group-[.toaster]:border-border group-[.toaster]:shadow-lg",
21+
toastOptions?.classNames?.toast
22+
),
23+
description: cn("group-[.toast]:text-muted-foreground", toastOptions?.classNames?.description),
24+
actionButton: cn(
2125
"group-[.toast]:bg-primary group-[.toast]:text-primary-foreground",
22-
cancelButton:
26+
toastOptions?.classNames?.actionButton
27+
),
28+
cancelButton: cn(
2329
"group-[.toaster]:bg-muted group-[.toaster]:text-muted-foreground bg-red",
24-
25-
closeButton:
26-
"group-[.toaster]:bg-muted group-[.toaster]:border-border group-[.toaster]:text-foreground bg-red group-[.toaster]:hover:text-background",
27-
},
30+
toastOptions?.classNames?.cancelButton
31+
),
32+
closeButton:cn(
33+
"group-[.toaster]:bg-muted group-[.toaster]:border-border group-[.toaster]:text-foreground bg-red group-[.toaster]:hover:text-muted-foreground",
34+
toastOptions?.classNames?.closeButton
35+
),
36+
},
2837
}}
2938
{...props}
3039
/>

stories/shadcn/sonner.stories.tsx

+23-15
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,31 @@ import type { Meta, StoryObj } from "@storybook/react";
22
import React from "react";
33
import { Button, SonnerToast } from "src";
44
import * as sonner from 'sonner'
5-
const SonnerDemo = () => {
6-
return (
7-
<div>
8-
<SonnerToast closeButton duration={9000000}>
95

6+
const SonnerDemo = (props: {defaultStyles: Boolean}) => {
7+
return props.defaultStyles ? (
8+
<div>
9+
<SonnerToast closeButton duration={9000000}>
10+
</SonnerToast>
11+
<Button onClick={() => sonner.toast.success('Success!')}>Show Toast</Button>
12+
</div>
13+
) : (
14+
<div>
15+
<SonnerToast closeButton duration={9000000} toastOptions={{classNames: {toast: 'group-[.toaster]:bg-green-500 group-[.toaster]:border-green-700'}}}>
1016
</SonnerToast>
11-
<Button onClick={() => sonner.toast.success('Success!')}>Show Toast</Button> </div>
12-
);
17+
<Button onClick={() => sonner.toast.info('Info: this toast has overriden styles.')}>
18+
Show Styled Toast
19+
</Button>
20+
</div>
21+
)
1322
}
1423

1524
const meta: Meta<typeof SonnerDemo> = {
16-
component: SonnerDemo,
17-
};
18-
19-
export default meta;
20-
21-
export const Default: StoryObj<typeof SonnerDemo> = {
22-
args: {},
23-
};
24-
25+
component: SonnerDemo,
26+
};
27+
28+
export default meta;
29+
30+
export const Default: StoryObj<typeof SonnerDemo> = {
31+
args: {defaultStyles: true},
32+
};

0 commit comments

Comments
 (0)