Zephora UI

Теми

Теми — це звичайні об'єкти TypeScript, що компілюються в CSS custom properties --z-*. Перемикання теми переписує змінні — миттєво, без CSS-in-JS, без витрат на ре-рендер для стилів.

Готові теми

import { lightTheme, darkTheme, auraTheme, materialTheme } from "@zephora/theme";

createTheme

import { createTheme, lightTheme } from "@zephora/theme";

const brand = createTheme(lightTheme, {
  name: "brand",
  colors: {
    primary: "#0f766e",
    primaryHover: "#115e59",
    ring: "#14b8a6",
  },
  radius: "0.75rem",
});

Scoped проти global

// Scoped — wraps a subtree in a themed scope element
<ThemeProvider theme={brand}>...</ThemeProvider>

// Global — writes variables onto <html>, ideal for app-level switching
import { applyTheme } from "@zephora/theme";
applyTheme(brand);

Перевизначення на рівні CSS

Компоненти читають змінні напряму, тож будь-яке правило CSS може змінити тему будь-якого піддерева:

.marketing-section {
  --z-primary: #ea580c;
  --z-radius: 9999px;
}

Темний режим

const [scheme, setScheme] = useState<"light" | "dark">("light");
<ThemeProvider theme={scheme === "dark" ? darkTheme : lightTheme} global>
  <App />
</ThemeProvider>