Layout
Box
A div replacement for layout, using theme values.
Example
CrBox replaces a div: spacing, flex and grid are set with properties, and children stay direct children, so flex and grid apply to them properly.
import { CrBox, CrButton } from '@cristal-ui/react';
export default function BoxLayout() {
return (
<CrBox display="flex" direction="column" gap="lg" padding="xl" background="muted" radius="l" border style={{ width: '100%' }}>
<CrBox display="flex" justify="space-between" align="center" wrap gap="sm">
<strong>Projects</strong>
<CrButton size="s">New project</CrButton>
</CrBox>
<CrBox display="grid" columns="160px" gap="sm">
{['Marketing site', 'Mobile app', 'Dashboard', 'Online store'].map((name) => (
<CrBox key={name} padding="lg" background="surface" radius="m" shadow>
{name}
</CrBox>
))}
</CrBox>
</CrBox>
);
}Values
| Property | Values |
|---|---|
display | block (default), flex, grid, inline-flex, inline-block, none |
direction | row, column (and their reverses) |
gap, padding | xs 4px, sm 8px, lg 16px, xl 24px, 2xl 32px, 3xl 48px, or any CSS value; padding="sm xl" gives vertical then horizontal |
align, justify | like align-items and justify-content: center, space-between… |
wrap | wraps to the next line when space runs out |
columns | grid: 3 equal columns, or 220px for as many columns of at least 220px as space allows |
background | surface, muted, subtle, primary (with matching text), or any CSS color |
radius | m, l, full, or any CSS value |
border, shadow | thin border, soft shadow |
maxWidth | maximum width, centered |
CrBox has no role: like a div, it tells screen readers nothing. For an area with meaning (navigation, list, article), keep the appropriate HTML element.
API
Properties
| Property | Type | Default | Description |
|---|---|---|---|
align | string | — | Alignement sur l'axe secondaire (align-items) : start, center, end, stretch, baseline. |
background | string | — | Fond : surface, subtle, muted, primary, ou toute couleur CSS. |
border | boolean | false | Ajoute une bordure fine. |
columns | string | — | Grille : un nombre de colonnes égales (« 3 ») ou une largeur minimale de colonne (« 220px »). |
direction | "column" | "column-reverse" | "row" | "row-reverse" | — | Sens des éléments en flex : row (en ligne) ou column (empilés). |
display | "block" | "flex" | "grid" | "inline-block" | "inline-flex" | "none" | 'block' | Type d'affichage. |
gap | string | — | Espace entre les enfants (flex et grille). |
justify | string | — | Répartition sur l'axe principal (justify-content) : start, center, end, space-between… |
maxWidth | string | — | Largeur maximale (« 640px », « 60ch »…), centrée. |
padding | string | — | Marge intérieure : une valeur, ou deux (« sm xl » : vertical puis horizontal). |
radius | string | — | Arrondi : m, l, full, ou toute valeur CSS. |
shadow | boolean | false | Ajoute une ombre douce. |
wrap | boolean | false | Passe à la ligne quand la place manque (flex). |
CSS parts
To style it from outside: cr-box::part(name) { … }
| Part | Description |
|---|