Konfiqurasiya
Hər Zephora komponenti üçün qlobal parametrlər — tətbiqinizi bir dəfə ZephoraConfigProvider ilə sarın və locale, overlay z-index qatlarını, portal konteynerini və headless defoltunu konfiqurasiya edin.
Quraşdırma
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 | Defolt | Təsvir |
|---|---|---|---|
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. |
Konfiqurasiyanın oxunması
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")} />;
}z-index qatları
Komponentlər yığılma sırasını daxili fallback-lı CSS dəyişənlərindən götürür, ona görə də həm provider, həm də sadə CSS onları yenidən tənzimləyə bilər:
: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;
}Tünd rejim
@zephora/theme avtomatik tünd rejim köməkçiləri ilə gəlir. useColorScheme hook-u sxem həll edir (mode: "system" ilə əməliyyat sisteminin üstünlüyünü canlı izləyir) və defolt olaraq həll olunmuş temanı qlobal tətbiq edir:
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 | Defolt | Təsvir |
|---|---|---|---|
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. |
Aşağı səviyyəli primitivlər də ixrac olunur:
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();FOUC-suz SSR
Server render üçün colorSchemeCss(light?, dark?) temaları əməliyyat sisteminin üstünlüyü ilə dəyişən statik stil vərəqi qurur — səhv temanın yanıb-sönməsi yoxdur, boyanmadan əvvəl JavaScript lazım deyil. <html> üzərində data-zephora-scheme təyin etmək media sorğusunu override edir (onu istifadəçi keçidinə bağlayın):
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
Çox slotlu komponentlər (Dialog, Sheet, Tabs, Card, Popover, Tooltip…) hər slot üçün sinif müqaviləsi açığa çıxarır: kök Partial<Record<<Name>Slot, string>> kimi tiplənən classNames-i qəbul edir (DialogSlot kimi slot-adı union-ları ixrac olunur). Slot sinifləri modul siniflərindən sonra əlavə olunur və unstyled ilə şərtləndirilmir — həm stilli, həm də stilsiz rejimdə işləyir; stilsiz rejimdə yeganə siniflər onlardır. classNames.root mövcud className prop-u ilə birlikdə birləşir, o kökü hədəfləməyə davam edir və ən sonda tətbiq olunur. Kompaund komponentlər üçün classNames kökdə bir dəfə təyin olunur və context vasitəsilə hissələrə daşınır.
Server komponentləri
Nəşr olunmuş @zephora/react bundle-ı "use client" direktivi ilə gəlir, ona görə də komponentləri React Server Component ağaclarına (Next.js app router) direktivi özünüz əlavə etmədən birbaşa idxal edə bilərsiniz — hər Zephora komponenti client komponentidir.