Zephora UI

Chủ đề

Theme là các đối tượng TypeScript thuần được biên dịch thành các CSS custom property --z-*. Đổi theme sẽ ghi lại các biến — tức thì, không CSS-in-JS, không tốn chi phí re-render cho style.

Theme dựng sẵn

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 và 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);

Ghi đè ở cấp CSS

Các component đọc biến trực tiếp, nên bất kỳ quy tắc CSS nào cũng có thể đổi theme cho bất kỳ cây con nào:

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

Chế độ tối

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