Skip to Content
Cristal

Layout

Box

A div replacement for layout, using theme values.

<cr-box>CrBox

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.

ProjectsNew projectMarketing siteMobile appDashboardOnline store
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

PropertyValues
displayblock (default), flex, grid, inline-flex, inline-block, none
directionrow, column (and their reverses)
gap, paddingxs 4px, sm 8px, lg 16px, xl 24px, 2xl 32px, 3xl 48px, or any CSS value; padding="sm xl" gives vertical then horizontal
align, justifylike align-items and justify-content: center, space-between…
wrapwraps to the next line when space runs out
columnsgrid: 3 equal columns, or 220px for as many columns of at least 220px as space allows
backgroundsurface, muted, subtle, primary (with matching text), or any CSS color
radiusm, l, full, or any CSS value
border, shadowthin border, soft shadow
maxWidthmaximum 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

PropertyTypeDefaultDescription
alignstring—Alignement sur l'axe secondaire (align-items) : start, center, end, stretch, baseline.
backgroundstring—Fond : surface, subtle, muted, primary, ou toute couleur CSS.
borderbooleanfalseAjoute une bordure fine.
columnsstring—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.
gapstring—Espace entre les enfants (flex et grille).
justifystring—Répartition sur l'axe principal (justify-content) : start, center, end, space-between…
maxWidthstring—Largeur maximale (« 640px », « 60ch »…), centrée.
paddingstring—Marge intérieure : une valeur, ou deux (« sm xl » : vertical puis horizontal).
radiusstring—Arrondi : m, l, full, ou toute valeur CSS.
shadowbooleanfalseAjoute une ombre douce.
wrapbooleanfalsePasse à la ligne quand la place manque (flex).

CSS parts

To style it from outside: cr-box::part(name) { … }

PartDescription

On this page