Grid component lays out direct children in equal-width columns across rows. Consider using the Stack instead when items should keep their width.

Open in new tab
import { Grid } from "@kesko/components";

const box = { border: "1px dashed var(--k-color-border-primary)" };

export default () => (
  <Grid className="k-bg-primary k-rounded-xs k-p-sm">
    <div className="k-bg-base k-px-sm k-py-xs k-text-sm k-font-code" style={box}>Overview</div>
    <div className="k-bg-base k-px-sm k-py-xs k-text-sm k-font-code" style={box}>Orders and deliveries</div>
    <div className="k-bg-base k-px-sm k-py-xs k-text-sm k-font-code" style={box}>Invoices</div>
    <div className="k-bg-base k-px-sm k-py-xs k-text-sm k-font-code" style={box}>Customers</div>
    <div className="k-bg-base k-px-sm k-py-xs k-text-sm k-font-code" style={box}>Settings</div>
    <div className="k-bg-base k-px-sm k-py-xs k-text-sm k-font-code" style={box}>Reports</div>
  </Grid>
);
import { Grid } from "@kesko/components";

const box = { border: "1px dashed var(--k-color-border-primary)" };

export default () => (
  <Grid columns={3} alignment="center" className="k-bg-primary k-rounded-xs k-p-sm">
    <div className="k-bg-base k-px-sm k-py-xs k-text-sm k-font-code" style={box}>Short</div>
    <div className="k-bg-base k-px-sm k-py-xs k-text-sm k-font-code" style={box}>
      Tall
      <br />
      cell
      <br />
      here
    </div>
    <div className="k-bg-base k-px-sm k-py-xs k-text-sm k-font-code" style={box}>Short</div>
  </Grid>
);
import { Grid } from "@kesko/components";

const box = { border: "1px dashed var(--k-color-border-primary)" };

export default () => (
  <Grid columns={3} className="k-bg-primary k-rounded-xs k-p-sm">
    <div className="k-bg-base k-px-sm k-py-xs k-text-sm k-font-code" style={box}>Overview</div>
    <div className="k-bg-base k-px-sm k-py-xs k-text-sm k-font-code" style={box}>Orders and deliveries</div>
    <div className="k-bg-base k-px-sm k-py-xs k-text-sm k-font-code" style={box}>Invoices</div>
    <div className="k-bg-base k-px-sm k-py-xs k-text-sm k-font-code" style={box}>Customers</div>
    <div className="k-bg-base k-px-sm k-py-xs k-text-sm k-font-code" style={box}>Settings</div>
    <div className="k-bg-base k-px-sm k-py-xs k-text-sm k-font-code" style={box}>Reports</div>
  </Grid>
);
import { Grid } from "@kesko/components";

const box = { border: "1px dashed var(--k-color-border-primary)" };

export default () => (
  <Grid columns={2} gap="xs" className="k-bg-primary k-rounded-xs k-p-sm">
    <div className="k-bg-base k-px-sm k-py-xs k-text-sm k-font-code" style={box}>First</div>
    <div className="k-bg-base k-px-sm k-py-xs k-text-sm k-font-code" style={box}>Second</div>
    <div className="k-bg-base k-px-sm k-py-xs k-text-sm k-font-code" style={box}>Third</div>
    <div className="k-bg-base k-px-sm k-py-xs k-text-sm k-font-code" style={box}>Fourth</div>
  </Grid>
);
import { Grid } from "@kesko/components";

const box = { border: "1px dashed var(--k-color-border-primary)" };

export default () => (
  <Grid style={{ "--k-grid-min": "8rem" }} className="k-bg-primary k-rounded-xs k-p-sm">
    <div className="k-bg-base k-px-sm k-py-xs k-text-sm k-font-code" style={box}>Overview</div>
    <div className="k-bg-base k-px-sm k-py-xs k-text-sm k-font-code" style={box}>Orders and deliveries</div>
    <div className="k-bg-base k-px-sm k-py-xs k-text-sm k-font-code" style={box}>Invoices</div>
    <div className="k-bg-base k-px-sm k-py-xs k-text-sm k-font-code" style={box}>Customers</div>
    <div className="k-bg-base k-px-sm k-py-xs k-text-sm k-font-code" style={box}>Settings</div>
    <div className="k-bg-base k-px-sm k-py-xs k-text-sm k-font-code" style={box}>Reports</div>
  </Grid>
);
import { Grid } from "@kesko/components";

const box = { border: "1px dashed var(--k-color-border-primary)" };

export default () => (
  <Grid columns={3} className="k-bg-primary k-rounded-xs k-p-sm">
    <div className="k-bg-base k-px-sm k-py-xs k-text-sm k-font-code" style={{ ...box, gridColumn: "1 / -1" }}>Full width</div>
    <div className="k-bg-base k-px-sm k-py-xs k-text-sm k-font-code" style={{ ...box, gridColumn: "span 2" }}>Two columns</div>
    <div className="k-bg-base k-px-sm k-py-xs k-text-sm k-font-code" style={box}>One</div>
    <div className="k-bg-base k-px-sm k-py-xs k-text-sm k-font-code" style={box}>One</div>
    <div className="k-bg-base k-px-sm k-py-xs k-text-sm k-font-code" style={box}>One</div>
    <div className="k-bg-base k-px-sm k-py-xs k-text-sm k-font-code" style={box}>One</div>
  </Grid>
);

Properties #

NameDescriptionTypeDefault
columns

Number of columns, or "auto" to fit as many as the width allows.

"auto" | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12"auto"
gap

Space between the cells.

"3xs" | "2xs" | "xs" | "sm" | "md" | "lg" | "xl" | "2xl" | "3xl""md"
alignment

Alignment of the cells within each row.

"start" | "center" | "end" | "stretch""stretch"

Styles #

CSS custom properties provide finer-grained control than properties. See Styling API for more details. Prefer the Properties API when it suits your need.

NameDescriptionDefault
--k-grid-gap

Overrides the gap between cells.

var(--k-space-md)
--k-grid-min

Minimum column width when columns is "auto".

16rem

Accessibility #

Grid is layout only. It renders a <k-grid> element with no role, no name and no focus stop, so assistive technologies see only its children.

  • Use a list when the items are a list. Grid adds no semantics. Use <ul> or <ol> elements instead when appropriate.
  • Keep reading order and visual order the same. Screen readers and the Tab key follow DOM order. Do not reorder cells with order, grid-area or negative line numbers, change the source order instead.
  • Size the children, not the grid. Grid does not resize what it holds. When you place buttons, links or inputs in cells, pick their own sizes so each stays at least 24×24 pixels, the minimum touch target size.

See the accessibility guidelines and the A11Y checklist for more details.


Usage #

There are two necessary parts to using the Grid component. The @kesko/components package and the CSS Framework are required. Everything else is optional:

npm install @kesko/components @kesko/css

Once installed, load the CSS Framework in your app’s entry point or root layout:

import "@kesko/css";

Then, you can import the Grid:

import { Grid } from "@kesko/components";

Projects without React can get the same styles from @kesko/css by importing the components stylesheet as well:

@import "@kesko/css";
@import "@kesko/css/components";

Resources #