Skip to content
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

Remix dark mode docs #4840

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 31 additions & 18 deletions apps/www/content/docs/dark-mode/remix.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,25 @@ npm install remix-themes

```tsx title="app/sessions.server.tsx"
import { createThemeSessionResolver } from "remix-themes"
import { createCookieSessionStorage } from "@remix-run/node";

// You can default to 'development' if process.env.NODE_ENV is not set
const isProduction = process.env.NODE_ENV === "production"

const sessionStorage = createCookieSessionStorage({
cookie: {
name: "theme",
path: "/",
httpOnly: true,
sameSite: "lax",
secrets: ["s3cr3t"],
// Set domain and secure only if in production
...(isProduction
? { domain: "your-production-domain.com", secure: true }
: {}),
},
})

export const themeSessionResolver = createThemeSessionResolver(sessionStorage)
export const themeSessionResolver = createThemeSessionResolver(
createCookieSessionStorage({
cookie: {
name: "__theme",
path: "/",
httpOnly: true,
sameSite: "lax",
secrets: ["s3cr3t"],
...(isProduction
? { domain: "your-production-domain", secure: true }
: {}),
},
})
);
```

### Set up Remix Themes
Expand All @@ -58,6 +58,7 @@ Add the `ThemeProvider` to your root layout.
```tsx {1-3,6-11,15-22,25-26,28,33} title="app/root.tsx"
import clsx from "clsx"
import { PreventFlashOnWrongTheme, ThemeProvider, useTheme } from "remix-themes"
import { type LoaderFunctionArgs } from "@remix-run/node";

import { themeSessionResolver } from "./sessions.server"

Expand All @@ -75,7 +76,9 @@ export default function AppWithProviders() {
const data = useLoaderData<typeof loader>()
return (
<ThemeProvider specifiedTheme={data.theme} themeAction="/action/set-theme">
<App />
<Layout>
<App />
</Layout>
</ThemeProvider>
)
}
Expand All @@ -93,14 +96,19 @@ export function App() {
<Links />
</head>
<body>
<Outlet />
<ScrollRestoration />
<Scripts />
<LiveReload />
</body>
</html>
)
}

function App() {
return (
<Outlet />
)
}
```

### Add an action route
Expand All @@ -112,7 +120,12 @@ import { createThemeAction } from "remix-themes"

import { themeSessionResolver } from "./sessions.server"

export const action = createThemeAction(themeSessionResolver)
import type { ActionFunctionArgs } from "@remix-run/node";


export const action = async (args: ActionFunctionArgs) => {
return createThemeAction(themeSessionResolver)(args);
};
```

### Add a mode toggle
Expand Down