Skip to content

Grid

Grid Props ​

NameTypeDefaultDescription
columnsnumber | GridResponsiveColumns-Column configuration. A number is a fixed count of equal-width columns; an object { minWidth, max?, repeat? } creates responsive columns that reflow with the available width. A missing, zero, or negative value falls back to a single column.
widthnumber | string-Width of the container. Numbers are pixels, strings are used as they are.
heightnumber | string-Height of the container. Numbers are pixels, strings are used as they are.
maxWidthnumber | string-Maximum width of the container. Numbers are pixels, strings are used as they are.
minHeightnumber | string-Minimum height of the container. Numbers are pixels, strings are used as they are.
gapSpacingStep-Spacing between items on both axes, using the Astryx spacing scale.
rowGapSpacingStep-Spacing between rows; overrides gap on that axis.
columnGapSpacingStep-Spacing between columns; overrides gap on that axis. It also takes precedence over gap when the responsive column count is capped.
rowHeightnumber-Height in pixels of each implicit row (grid-auto-rows). Use it together with GridSpan's rows.
alignGridAlignment'stretch'Vertical alignment of items inside their row (align-items): start, center, end, or stretch.
justifyGridAlignment'stretch'Horizontal alignment of items within their row (justify-items): start, center, end, or stretch.

GridResponsiveColumns has this shape:

ts
interface GridResponsiveColumns {
  minWidth: number
  max?: number
  repeat?: 'fill' | 'fit'
}

SpacingStep accepts these values:

ts
type SpacingStep = 0 | 0.5 | 1 | 1.5 | 2 | 3 | 4 | 5 | 6 | 8 | 10

Grid Span Props ​

NameTypeDefaultDescription
columnsnumber | 'full'-Columns to span. 'full' renders grid-column: 1 / -1, which spans the row whatever the column count is.
rowsnumber-Rows to span, rendered as grid-row: span N.

Slots ​

NameDescription
defaultThe items to lay out. Place children directly, or wrap one in GridSpan to change how many columns or rows it occupies.

GridSpan has a single default slot as well:

NameDescription
defaultThe content of the spanning item.

CSS variables ​

Grid writes these variables to its root element. They are an implementation detail, but a theme or an application may override them:

NameDescription
--astryx-grid-template-columnsThe computed column template. It lives in a variable rather than an inline grid-template-columns declaration, so a media query can still override it.
--astryx-grid-auto-rowsThe implicit row height derived from rowHeight.
--astryx-grid-gapThe spacing token for gap, shared by both axes.
--astryx-grid-row-gapThe spacing token for rowGap, which overrides --astryx-grid-gap on the row axis.
--astryx-grid-column-gapThe spacing token for columnGap, which overrides --astryx-grid-gap on the column axis.
--astryx-grid-default-gapA theme token used as the spacing when no gap prop is given. The neutral theme sets it to --astryx-spacing-0, which leaves no space between items.

Native attributes ​

Grid and GridSpan both render a <div> at the root.

The following go to the root element:

  • HTML attributes.
  • aria-* attributes.
  • data-* attributes.
  • class.
  • style.

class is merged with the component's own classes. When style and the size props (width, height, maxWidth, minHeight) are both given, the props win; the same holds for GridSpan's columns and rows.

Grid also writes data-columns (only when columns is a number), data-gap, data-row-gap, data-column-gap, data-align, and data-justify, so a theme can target it by attribute.