ZaidanHomeDocsComponentsBlocksChartsTypesetCreate

Command Palette

Search for a command to run...

GitHub
New
Sections
  • Introduction
  • Components
  • Blocks
  • Installation
  • Customization
  • Dark Mode
  • Typeset
  • Zaidan Skills
  • FAQ
  • Roadmap
  • Changelog
Installation
  • Astro
  • Manual
  • Solid Start
  • TanStack Router
  • TanStack Start
  • Vite
Blocks
  • Data Grid
  • Event Calendar
  • Filters
  • Gantt
  • Image Crop
  • Kanban
  • Message Scroller
  • Questionnaire
  • Sortable
Components
  • Accordion
  • Alert
  • Alert Dialog
  • Aspect Ratio
  • Attachment
  • Avatar
  • Badge
  • Breadcrumb
  • Bubble
  • Button
  • Button Group
  • Calendar
  • Card
  • Carousel
  • Chart
  • Checkbox
  • Collapsible
  • Combobox
  • Command
  • Context Menu
  • Dialog
  • Drawer
  • Dropdown Menu
  • Empty
  • Field
  • Hover Card
  • Input
  • Input Group
  • Input OTP
  • Item
  • Kbd
  • Label
  • Marker
  • Menubar
  • Message
  • Native Select
  • Navigation Menu
  • Pagination
  • Popover
  • Progress
  • Radio Group
  • Resizable
  • Scroll Area
  • Select
  • Separator
  • Sheet
  • Sidebar
  • Skeleton
  • Slider
  • Spinner
  • Switch
  • Table
  • Tabs
  • Textarea
  • Toast
  • Toggle
  • Toggle Group
  • Tooltip

Dark Mode

Zaidan shipped with dark mode support out of the box. All the tools are included in the registry, let's see how to enable it in your app.

Quick Start

To start using the dark mode feature, you first need to add the items to your project:

pnpm dlx shadcn@latest add @zaidan/color-mode
npx shadcn@latest add @zaidan/color-mode
yarn dlx shadcn@latest add @zaidan/color-mode
bunx --bun shadcn@latest add @zaidan/color-mode

Then, you need to wrap your applications in the ColorModeProvider and set the initial mode (we will show you later how to detect it automatically):

1
import { ColorModeProvider } from "@components/color-mode";
2
3
function RootComponent() {
4
const colorMode = "light";
5
6
return (
7
<html lang="en" class={colorMode}>
8
<head>{/* ... */}</head>
9
<body>
10
<ColorModeProvider initialColorMode={colorMode}>
11
{/* Your app */}
12
</ColorModeProvider>
13
</body>
14
</html>
15
);
16
}

Then use the useColorMode hook to access the current mode or toggle it from anywhere in your app:

1
import { useColorMode } from "@components/color-mode";
2
3
function ThemeToggle() {
4
const { colorMode, toggleColorMode } = useColorMode();
5
6
return (
7
<button onClick={toggleColorMode}>
8
{colorMode() === "light" ? "Switch to Dark" : "Switch to Light"}
9
</button>
10
);
11
}

That's it! You now have a working dark mode toggle in your app. You can define dark: modifiers in your Tailwind CSS classes to style elements based on the current mode.

Automatic Detection & SSR

Zaidan provides client-side utility to automatically detect the user's preferred color mode either from the cookie or from the system preference

On the server side (SSR), you'll need to come up with your own solution, since it's depends on your framework and setup. We will show you how we did it on Zaidan with Tanstack Start:

__root.tsx
1
import { createIsomorphicFn } from "@tanstack/solid-start";
2
import { getCookie } from "@tanstack/solid-start/server";
3
import { getClientColorMode, ZAIDAN_COLOR_MODE_COOKIE_KEY } from "@components/color-mode";
4
5
// Tanstack Start provides powerful utilities to create function that work on server & client
6
const getColorMode = createIsomorphicFn()
7
.server(() => getCookie(ZAIDAN_COLOR_MODE_COOKIE_KEY) ?? "light") // Use your framework's cookie parsing utility to read the color mode from cookies
8
.client(() => getClientColorMode());
9
10
function RootComponent() {
11
const colorMode = getColorMode();
12
13
return (
14
<html lang="en" class={colorMode}>
15
<head>{/* ... */}</head>
16
<body>
17
<ColorModeProvider initialColorMode={colorMode}>
18
{/* Your app */}
19
</ColorModeProvider>
20
</body>
21
</html>
22
);
23
}

On This Page

  • Quick Start
  • Automatic Detection & SSR
Built by Kevin Abatan. The source code is available on GitHub.