Skip to content
Porcelana

ThemeProvider

Light, night or system theme for the whole app or one section.

Theming

Example

Night theme

Only this box switches, because global is false.

Example.tsx
import { useState } from "react";
import { Card, CardDescription, CardTitle, Switch, ThemeProvider } from "@porcelana/ui";

export default function Example() {
  const [night, setNight] = useState(true);
  return (
    <ThemeProvider theme={night ? "night" : "light"} global={false} style={{ padding: 20, borderRadius: 28 }}>
      <Card>
        <CardTitle>{night ? "Night" : "Light"} theme</CardTitle>
        <CardDescription>Only this box switches, because global is false.</CardDescription>
        <Switch label="Night theme" checked={night} onCheckedChange={setNight} />
      </Card>
    </ThemeProvider>
  );
}

Import

Import
import { ThemeProvider } from "@porcelana/ui";
import "@porcelana/ui/styles.css"; // once, at your app root

Props

Generated from the TypeScript types. Standard HTML attributes are passed through and not listed.

ThemeProvider

Wraps content in the porcelana root with the chosen theme.

PropTypeDefaultDescription
aria-labelstring–Defines a string value that labels the current element. @see aria-labelledby.
globalbooleantrueAlso set data-theme on <html>, so portalled overlays pick up the theme. Default true.
idstring–Element id. Generated automatically when omitted.
themeThemeNamelight"light", "night", or "system" to follow the OS dark mode.

Accessibility

  • Both themes meet WCAG AA text contrast; focus rings are dark blue in light and yellow in night.
  • theme="system" follows the operating system's dark mode.

Mobile

  • Sets data-theme on <html> by default, so portalled sheets and menus pick up the theme too.