Configurare
Setări globale pentru fiecare componentă Zephora — învelește-ți aplicația o singură dată cu ZephoraConfigProvider și configurează locale-ul, straturile z-index pentru overlay, containerul portal și valoarea implicită headless.
Configurare
import { ZephoraConfigProvider } from "@zephora/react";
export default function App() {
return (
<ZephoraConfigProvider
locale="tr"
zIndex={{ modal: 2000, toast: 2100 }}
appendTo={typeof document !== "undefined" ? document.body : null}
unstyled={false}
>
<YourApp />
</ZephoraConfigProvider>
);
}ZephoraConfigProvider props
| Prop | Tip | Implicit | Descriere |
|---|---|---|---|
locale | string | "en" | Active locale for component UI strings. Only "en" is embedded; load others from @zephora/theme/locales/* (module or JSON) and register with addLocale(). |
zIndex | { dropdown?, overlay?, modal?, popover?, toast?, tooltip?: number } | — | Overrides the layering of floating elements. Written as --z-index-* CSS variables on the root element. |
appendTo | HTMLElement | null | document.body | Container that Portal-based overlays (Dialog, Select menus, Tooltip…) render into. |
unstyled | boolean | false | Makes every component headless by default for Tailwind-first apps. A per-component unstyled prop still wins. |
Citirea configurației
import { useZephoraConfig, useLocale } from "@zephora/react";
function MyField() {
const config = useZephoraConfig(); // { locale, zIndex, appendTo, unstyled }
const { t, messages, locale } = useLocale();
return <button aria-label={t("close")} />;
}Straturi z-index
Componentele își iau ordinea de stivuire din variabile CSS cu fallback-uri încorporate, astfel încât atât provider-ul, cât și CSS-ul simplu le pot ajusta:
:root {
--z-index-dropdown: 1000;
--z-index-overlay: 1040;
--z-index-modal: 1050;
--z-index-popover: 1060;
--z-index-toast: 1070;
--z-index-tooltip: 1080;
}Mod întunecat
@zephora/theme include helper-e automate pentru modul întunecat. Hook-ul useColorScheme rezolvă o schemă (cu mode: "system" urmează live preferința sistemului de operare) și implicit aplică global tema rezolvată:
import { useColorScheme } from "@zephora/theme";
function App() {
// mode: "light" | "dark" | "system" (default "system")
const { scheme, theme } = useColorScheme({ mode: "system" });
return <span>Active scheme: {scheme}</span>;
}useColorScheme(options) props
| Prop | Tip | Implicit | Descriere |
|---|---|---|---|
mode | "light" | "dark" | "system" | "system" | "system" follows the OS preference live; "light"/"dark" force a scheme. |
light / dark | Theme | lightTheme / darkTheme | Theme objects used for each scheme. |
apply | boolean | true | Write the resolved theme to document.documentElement via applyTheme. |
→ returns | { scheme: "light" | "dark"; theme: Theme } | — | The resolved scheme and the theme object in effect. |
Primitivele de nivel mai jos sunt și ele exportate:
import { getSystemColorScheme, watchSystemColorScheme } from "@zephora/theme";
// Reads the OS color scheme (SSR-safe; defaults to "light").
const scheme = getSystemColorScheme(); // "light" | "dark"
// Subscribes to OS changes. Returns an unsubscribe function.
const stop = watchSystemColorScheme((next) => console.log(next));
stop();SSR fără FOUC
Pentru randare pe server, colorSchemeCss(light?, dark?) construiește o foaie de stil statică ce schimbă temele după preferința sistemului de operare — fără flash-ul temei greșite, fără JavaScript necesar înainte de paint. Setarea data-zephora-scheme pe <html> suprascrie media query-ul (leag-o de un comutator al utilizatorului):
import { colorSchemeCss } from "@zephora/theme";
// Next.js app router — app/layout.tsx
export default function RootLayout({ children }: { children: React.ReactNode }) {
return (
<html lang="en">
<head>
<style dangerouslySetInnerHTML={{ __html: colorSchemeCss() }} />
</head>
<body>{children}</body>
</html>
);
}Slot classNames
Componentele multi-slot (Dialog, Sheet, Tabs, Card, Popover, Tooltip…) expun un contract de clase per slot: root-ul acceptă classNames tipizat ca Partial<Record<<Name>Slot, string>> (uniunile de nume de slot precum DialogSlot sunt exportate). Clasele de slot se adaugă după clasele modulului și nu sunt condiționate de unstyled — funcționează atât în modul stilizat, cât și în cel unstyled; în modul unstyled ele sunt singurele clase. classNames.root se îmbină alături de prop-ul className existent, care continuă să țintească root-ul și se aplică ultimul. Pentru componentele compuse, classNames se setează o singură dată pe root și se transmite părților prin context.
Componente server
Bundle-ul publicat @zephora/react este livrat cu o directivă "use client", așa că poți importa componentele direct în arbori de React Server Component (Next.js app router) fără să adaugi tu directiva — fiecare componentă Zephora este o componentă client.