Skip to content

Commit 5ee74fc

Browse files
authored
Merge pull request #12 from pheralb/next
📚 Fix documentation - Next.js Guide + toast & toaster.
2 parents 799d4aa + 7ef287a commit 5ee74fc

File tree

3 files changed

+35
-33
lines changed

3 files changed

+35
-33
lines changed

website/src/docs/dark-mode.mdx

+28-28
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
2-
title: 'Dark Mode'
3-
description: 'This page shows examples of how to use next-themes (Next.js) or remix-themes (Remix) libraries'
4-
category: 'Customization'
2+
title: "Dark Mode"
3+
description: "This page shows examples of how to set up the dark mode theme for the Toaster component. Using Vite, Next.js (with next-themes) or Remix (with remix-themes)."
4+
category: "Customization"
55
---
66

77
> 💡 If you need to activate the dark mode directly, you can use the `theme` property: [`show`](/toaster#theme)
@@ -14,9 +14,9 @@ category: 'Customization'
1414
- Snippet from [`shadcn/ui` Dark Mode documentation](https://ui.shadcn.com/docs/dark-mode/vite#dark-mode).
1515

1616
```tsx
17-
import { createContext, useContext, useEffect, useState } from 'react';
17+
import { createContext, useContext, useEffect, useState } from "react";
1818

19-
export type Theme = 'dark' | 'light' | 'system';
19+
export type Theme = "dark" | "light" | "system";
2020

2121
type ThemeProviderProps = {
2222
children: React.ReactNode;
@@ -30,16 +30,16 @@ type ThemeProviderState = {
3030
};
3131

3232
const initialState: ThemeProviderState = {
33-
theme: 'system',
33+
theme: "system",
3434
setTheme: () => null,
3535
};
3636

3737
const ThemeProviderContext = createContext<ThemeProviderState>(initialState);
3838

3939
export function ThemeProvider({
4040
children,
41-
defaultTheme = 'system',
42-
storageKey = 'my-ui-theme',
41+
defaultTheme = "system",
42+
storageKey = "my-ui-theme",
4343
...props
4444
}: ThemeProviderProps) {
4545
const [theme, setTheme] = useState<Theme>(
@@ -49,13 +49,13 @@ export function ThemeProvider({
4949
useEffect(() => {
5050
const root = window.document.documentElement;
5151

52-
root.classList.remove('light', 'dark');
52+
root.classList.remove("light", "dark");
5353

54-
if (theme === 'system') {
55-
const systemTheme = window.matchMedia('(prefers-color-scheme: dark)')
54+
if (theme === "system") {
55+
const systemTheme = window.matchMedia("(prefers-color-scheme: dark)")
5656
.matches
57-
? 'dark'
58-
: 'light';
57+
? "dark"
58+
: "light";
5959

6060
root.classList.add(systemTheme);
6161
root.style.colorScheme = systemTheme;
@@ -85,7 +85,7 @@ export const useTheme = () => {
8585
const context = useContext(ThemeProviderContext);
8686

8787
if (context === undefined)
88-
throw new Error('useTheme must be used within a ThemeProvider');
88+
throw new Error("useTheme must be used within a ThemeProvider");
8989

9090
return context;
9191
};
@@ -101,10 +101,10 @@ export const useTheme = () => {
101101
```tsx
102102
// 📄 components/ToasterProvider.tsx
103103

104-
import type { ToasterProperties } from '@pheralb/toast';
105-
import { Toaster } from '@pheralb/toast';
104+
import type { ToasterProperties } from "@pheralb/toast";
105+
import { Toaster } from "@pheralb/toast";
106106

107-
import { useTheme } from './themeProvider';
107+
import { useTheme } from "./themeProvider";
108108

109109
const ToasterProvider = (props: ToasterProperties) => {
110110
const { theme } = useTheme();
@@ -116,12 +116,12 @@ export default ToasterProvider;
116116

117117
2. Import the `ToasterProvider` component in the `main.tsx` file:
118118

119-
```tsx
119+
```tsx {3, 9}
120120
// 📄 main.tsx
121121

122-
import ToasterProvider from './providers/toasterProvider';
122+
import ToasterProvider from "./providers/toasterProvider";
123123

124-
ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render(
124+
ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render(
125125
<React.StrictMode>
126126
<ThemeProvider defaultTheme="system" storageKey="my-ui-theme">
127127
<App />
@@ -143,31 +143,31 @@ ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render(
143143
```tsx
144144
// 📄 components/ToasterNextTheme.tsx
145145

146-
'use client';
146+
"use client";
147147

148148
import {
149149
Toaster,
150150
type ToastTheme,
151151
type ToasterProperties,
152-
} from '@pheralb/toast';
152+
} from "@pheralb/toast";
153153

154-
import { useTheme } from 'next-themes';
154+
import { useTheme } from "next-themes";
155155

156156
const ToasterNextTheme = (props: ToasterProperties) => {
157157
const { theme } = useTheme();
158-
return (
159-
<Toaster toastFont="font-sans" theme={theme as ToastTheme} {...props} />
160-
);
158+
return <Toaster theme={theme as ToastTheme} {...props} />;
161159
};
162160

163161
export default ToasterNextTheme;
164162
```
165163

166164
2. Import the `ToasterNextTheme` component in the `layout/app.tsx` file:
167165

168-
```tsx
166+
```tsx {3, 20}
169167
// 📄 layout/app.tsx
170168

169+
import ToasterNextTheme from "@/components/ToasterNextTheme";
170+
171171
export default function RootLayout({
172172
children,
173173
}: Readonly<{
@@ -197,7 +197,7 @@ export default function RootLayout({
197197
198198
Import the `useTheme` hook from `remix-themes` and change the theme value:
199199

200-
```tsx
200+
```tsx {4, 19}
201201
// 📄 app/root.tsx
202202

203203
import clsx from 'clsx';

website/src/docs/toast.mdx

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ toast.default({
1818

1919
Show a toast with a specific variant:
2020

21-
<ToastVariantExamples client:only="react" />
21+
<ToastVariantExamples />
2222

2323
## toast.variant with action
2424

2525
Show a button and execute a custom function when clicked. The default text for the button is `Action`:
2626

27-
<ToastActionsExamples client:only="react" />
27+
<ToastActionsExamples />
2828

2929
```tsx {3-8}
3030
toast.default({
@@ -42,7 +42,7 @@ toast.default({
4242

4343
Show a toast with loading state and will update automatically after the promise resolves or fails:
4444

45-
<ToastLoadingExample client:only="react" />
45+
<ToastLoadingExample />
4646

4747
```tsx {4-18}
4848
toast.loading({

website/src/docs/toaster.mdx

+4-2
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@ import { Toaster } from "@pheralb/toast";
1414

1515
By default, the position is `bottom-right`. You can customize the position of the toasts by using the `position` prop of the `Toaster` component:
1616

17-
<Positions client:only="react" />
17+
<Positions />
1818

1919
## Theme
2020

2121
You can set the theme of the toasts using the `theme` prop, which accepts the values: `light`, `dark`, and `system`:
2222

23-
<ThemeExamples client:only="react" />
23+
<ThemeExamples />
24+
25+
> 💡 If you want to configure the theme automatically, read [`Dark Mode` guide](/dark-mode).
2426
2527
## MaxToasts
2628

0 commit comments

Comments
 (0)