Personalizar los tokens
Cambia colores, radio, espaciado y fuentes, añade un tema con nombre y cambia de tema sin proveedor.
Los tokens de diseño son propiedades personalizadas CSS como --neshel-primary y
--neshel-radius-base. Los componentes solo leen tokens, así que cambiar un token cambia el estilo de
todo lo que lo usa.
Cambiar los temas incorporados
import { defineConfig } from "@neshel-ui/config";
export default defineConfig({
radius: { base: "0.5rem" },
spacing: { unit: "0.25rem" },
themes: {
light: {
colors: {
primary: "#5b2a86",
primaryForeground: "#ffffff",
accent: "#e0a526",
accentForeground: "#1f1300",
},
},
dark: {
colors: { primary: "#cfb3ff", primaryForeground: "#1b0a33" },
},
// A named theme for a marketing section, based on the light theme.
sunrise: {
extends: "light",
colors: { background: "#fff7ed", foreground: "#3b1d00", primary: "#c2410c" },
},
},
output: "./src/neshel.generated.css",
});Ejecuta neshel generate. Se comprueba el contraste de cada par primer plano/fondo que cambies; los
fallos son avisos por defecto y errores con --strict o contrast: "error".
Cambiar de tema
Los temas se seleccionan con el atributo data-neshel-theme, sin proveedor de React:
<div data-neshel-theme="dark">
<Button>Dark button</Button>
<section data-neshel-theme="sunrise">
<Button>Sunrise button inside a dark page</Button>
</section>
</div>| Valor del atributo | Resultado |
|---|---|
| ausente | claro |
light / dark | forzado, sea cual sea la preferencia del sistema |
system | sigue prefers-color-scheme |
| un tema con nombre | tu tema de neshel.config.ts |
Para que el usuario elija, establece el atributo en <html> desde tu propio estado y guárdalo (una
cookie leída en el servidor evita un parpadeo con el tema equivocado).
Theme “light”
Same components, different tokens.
Theme “dark”
Same components, different tokens.
Theme “evergreen”
Same components, different tokens.
Theme “aurora”
Same components, different tokens.
import {
Badge,
Button,
Card,
CardContent,
CardFooter,
CardHeader,
CardTitle,
} from "@neshel-ui/components";
import { Grid } from "@neshel-ui/layout";
import { Paragraph } from "@neshel-ui/typography";
/**
* Nested theme scopes: any element can set data-neshel-theme. "evergreen" and "aurora" are named
* themes from this site's neshel.config.ts (generated by `neshel generate`).
*/
const themes = ["light", "dark", "evergreen", "aurora"] as const;
export default function ThemeScopes() {
return (
<Grid columns={{ base: 1, md: 2 }} space="4">
{themes.map((theme) => (
<div
key={theme}
data-neshel-theme={theme}
className="rounded-xl bg-[var(--neshel-background)] p-4"
>
<Card>
<CardHeader>
<CardTitle>Theme “{theme}”</CardTitle>
</CardHeader>
<CardContent>
<Paragraph size="sm" tone="muted">
Same components, different tokens.
</Paragraph>
</CardContent>
<CardFooter>
<Button size="sm">Primary</Button>
<Badge variant="accent">Accent</Badge>
</CardFooter>
</Card>
</div>
))}
</Grid>
);
}El azul marino y el dorado de Neshel son solo los valores predeterminados. Consulta la guía de temas para los 25 roles de color, los pares de contraste, las fuentes y la cascada. Siguiente: Desplegar una aplicación.