DocsComponentsTemplatesThemesGitHub

ThemeProvider

Sets `data-theme` on <html> (light, dark or system) and wraps the app in the .fd-root base.

Code

import * as React from 'react';
import { Switch, useTheme } from '@fruit-labs/design';

export default function Demo() {
  const [t, set] = useTheme();
  return (
    <div
      style={{
        display: 'flex',
        alignItems: 'center',
        gap: 12,
      }}
    >
      <Switch
        label="Dark mode"
        showLabel
        checked={t === 'dark'}
        onChange={(v) => set(v ? 'dark' : 'light')}
      />
    </div>
  );
}

Install

From npm:

npm install @fruit-labs/design

import { ThemeProvider } from '@fruit-labs/design';

Or copy the TypeScript source into your project:

npx shadcn@latest add https://design.fruitlabs.online/r/theme-provider.json

Guidelines

  • Mount once at the app root. theme="system" follows the OS and updates live.
  • Use useTheme() to read/toggle the theme from a settings control.
  • Without React: set <html data-theme="dark"> yourself; tokens.css also honours prefers-color-scheme when no attribute is set.

Props

PropTypeRequired
theme'light' | 'dark' | 'system'No
classNamestringNo
styleReact.CSSPropertiesNo
childrenReact.ReactNodeNo

Edit this example on GitHub