Zephora UI

Konfigūracija

Globalūs nustatymai kiekvienam Zephora komponentui — vieną kartą apgaubkite savo programą ZephoraConfigProvider ir sukonfigūruokite locale, overlay z-index sluoksnius, portalo konteinerį ir headless numatytąją reikšmę.

Nustatymas

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

PropTipasNumatytojiAprašymas
localestring"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.
appendToHTMLElement | nulldocument.bodyContainer that Portal-based overlays (Dialog, Select menus, Tooltip…) render into.
unstyledbooleanfalseMakes every component headless by default for Tailwind-first apps. A per-component unstyled prop still wins.

Konfigūracijos skaitymas

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 sluoksniai

Komponentai savo dėstymo tvarką (stacking order) ima iš CSS kintamųjų su įtaisytomis atsarginėmis reikšmėmis, todėl tiek provider'is, tiek paprastas CSS gali jas iš naujo suderinti:

: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;
}

Tamsusis režimas

@zephora/theme pristato automatinius tamsiojo režimo pagalbininkus. useColorScheme hook'as išsprendžia schemą (su mode: "system" jis realiu laiku seka OS nuostatą) ir pagal numatymą pritaiko išspręstą temą globaliai:

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

PropTipasNumatytojiAprašymas
mode"light" | "dark" | "system""system""system" follows the OS preference live; "light"/"dark" force a scheme.
light / darkThemelightTheme / darkThemeTheme objects used for each scheme.
applybooleantrueWrite the resolved theme to document.documentElement via applyTheme.
→ returns{ scheme: "light" | "dark"; theme: Theme }The resolved scheme and the theme object in effect.

Žemesnio lygmens primityvai taip pat eksportuojami:

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 be FOUC

Serverio atvaizdavimui colorSchemeCss(light?, dark?) sukuria statinį stilių failą, kuris keičia temas pagal OS nuostatą — jokio neteisingos temos blyksnio, jokio JavaScript nereikia prieš piešimą (paint). data-zephora-scheme nustatymas ant <html> perrašo media užklausą (susiekite jį su vartotojo perjungikliu):

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

Daugiaslotiai komponentai (Dialog, Sheet, Tabs, Card, Popover, Tooltip…) pateikia klasių sutartį kiekvienam slotui: šaknis priima classNames, tipizuotą kaip Partial<Record<<Name>Slot, string>> (slotų pavadinimų union'ai, tokie kaip DialogSlot, yra eksportuojami). Slotų klasės pridedamos po modulio klasių ir nėra ribojamos unstyled — jos veikia tiek stilizuotame, tiek nestilizuotame režime; nestilizuotame režime jos yra vienintelės klasės. classNames.root susilieja su esamu className prop'u, kuris toliau taikosi į šaknį ir pritaikomas paskutinis. Sudėtiniuose komponentuose classNames nustatomas vieną kartą ant šaknies ir per context perduodamas dalims.

Serverio komponentai

Publikuotas @zephora/react paketas pristatomas su "use client" direktyva, todėl komponentus galite importuoti tiesiogiai React Server Component medžiuose (Next.js app router) patys nepridėdami direktyvos — kiekvienas Zephora komponentas yra kliento komponentas.