Kumo Svelte
  • Home
  • Installation
  • Colors
  • Accessibility
  • Changelog
  • Autocomplete
  • Badge
  • Banner
  • Breadcrumbs
  • Button
  • Checkbox
  • Clipboard Text
  • Cloudflare Logo
  • CodeHighlighted
  • Collapsible
  • Combobox
  • Command Palette
  • Date Picker
  • Dialog
  • Dropdown
  • Empty
  • Flow
  • Grid
  • Input
  • InputArea
  • InputGroup
  • Label
  • Layer Card
  • Link
  • Loader
  • MenuBar
  • Meter
  • Pagination
  • Popover
  • Radio
  • Select
  • Sensitive Input
  • Sidebar
  • Skeleton Line
  • Switch
  • Table
  • Table of Contents
  • Tabs
  • Text
  • Toast
  • Toolbar
  • Tooltip
  • Charts
  • Colors
  • Timeseries
  • Maps
  • Sankey
  • Custom Chart
  • Page Header
  • Resource List
  • Delete Resource
Grid
kumo-svelte

Grid

A responsive grid layout component for organizing content into columns.

Item 1

First grid item

Item 2

Second grid item

<script lang="ts">
  import { Grid, GridItem } from "kumo-svelte/components/grid";
  import { Surface } from "kumo-svelte/components/surface";
  import { Text } from "kumo-svelte/components/text";
</script>

<Grid variant="2up" gap="base">
  <GridItem>
    <Surface class="rounded-lg p-4">
      <Text bold>Item 1</Text>
      <div class="mt-1"><Text variant="secondary">First grid item</Text></div>
    </Surface>
  </GridItem>
  <GridItem>
    <Surface class="rounded-lg p-4">
      <Text bold>Item 2</Text>
      <div class="mt-1"><Text variant="secondary">Second grid item</Text></div>
    </Surface>
  </GridItem>
</Grid>

Import

import { Grid, GridItem } from "kumo-svelte/components/grid";

Usage

<script lang="ts">
  import { Grid, GridItem } from "kumo-svelte/components/grid";
</script>

<Grid variant="2up" gap="base">
  <GridItem>Item 1</GridItem>
  <GridItem>Item 2</GridItem>
</Grid>

Grid Variants

The Grid component supports multiple column layouts that adapt responsively across breakpoints.

variant="2up"

1

2

variant="3up"

1

2

3

variant="4up"

1

2

3

4

<script lang="ts">
  import { Grid, GridItem } from "kumo-svelte/components/grid";
  import { Surface } from "kumo-svelte/components/surface";
  import { Text } from "kumo-svelte/components/text";
  const variants = [
    { name: "2up", count: 2 },
    { name: "3up", count: 3 },
    { name: "4up", count: 4 },
  ] as const;
</script>

<div class="flex flex-col gap-8">
  {#each variants as variant}
    <div>
      <p class="mb-2 text-kumo-subtle">variant="{variant.name}"</p>
      <Grid variant={variant.name} gap="sm">
        {#each Array.from({ length: variant.count }, (_, index) => index + 1) as item}
          <GridItem>
            <Surface class="rounded-lg p-4 text-center">
              <Text>{item}</Text>
            </Surface>
          </GridItem>
        {/each}
      </Grid>
    </div>
  {/each}
</div>

Asymmetric Layouts

Use asymmetric variants for sidebar/main content layouts.

variant="2-1" (66% / 33%)

Main Content

Two-thirds width

Sidebar

One-third width

variant="1-2" (33% / 66%)

Sidebar

One-third width

Main Content

Two-thirds width

<script lang="ts">
  import { Grid, GridItem } from "kumo-svelte/components/grid";
  import { Surface } from "kumo-svelte/components/surface";
  import { Text } from "kumo-svelte/components/text";
</script>

<div class="flex flex-col gap-8">
  <div>
    <p class="mb-2 text-kumo-subtle">variant="2-1" (66% / 33%)</p>
    <Grid variant="2-1" gap="sm">
      <GridItem>
        <Surface class="rounded-lg p-4">
          <Text bold>Main Content</Text>
          <div class="mt-1"><Text variant="secondary">Two-thirds width</Text></div>
        </Surface>
      </GridItem>
      <GridItem>
        <Surface class="rounded-lg p-4">
          <Text bold>Sidebar</Text>
          <div class="mt-1"><Text variant="secondary">One-third width</Text></div>
        </Surface>
      </GridItem>
    </Grid>
  </div>
  <div>
    <p class="mb-2 text-kumo-subtle">variant="1-2" (33% / 66%)</p>
    <Grid variant="1-2" gap="sm">
      <GridItem>
        <Surface class="rounded-lg p-4">
          <Text bold>Sidebar</Text>
          <div class="mt-1"><Text variant="secondary">One-third width</Text></div>
        </Surface>
      </GridItem>
      <GridItem>
        <Surface class="rounded-lg p-4">
          <Text bold>Main Content</Text>
          <div class="mt-1"><Text variant="secondary">Two-thirds width</Text></div>
        </Surface>
      </GridItem>
    </Grid>
  </div>
</div>

Gap Sizes

Control the spacing between grid items with the gap prop.

gap="none"

1

2

gap="sm"

1

2

gap="base"

1

2

gap="lg"

1

2

<script lang="ts">
  import { Grid, GridItem } from "kumo-svelte/components/grid";
  import { Surface } from "kumo-svelte/components/surface";
  import { Text } from "kumo-svelte/components/text";
  const gaps = ["none", "sm", "base", "lg"] as const;
</script>

<div class="flex flex-col gap-8">
  {#each gaps as gap}
    <div>
      <p class="mb-2 text-kumo-subtle">gap="{gap}"</p>
      <Grid variant="side-by-side" {gap}>
        <GridItem>
          <Surface class="rounded-lg p-4 text-center"><Text>1</Text></Surface>
        </GridItem>
        <GridItem>
          <Surface class="rounded-lg p-4 text-center"><Text>2</Text></Surface>
        </GridItem>
      </Grid>
    </div>
  {/each}
</div>

Mobile Dividers

Add dividers between items on mobile with the mobileDivider prop. Mobile dividers only apply to the 4up variant.

Item 1

Has divider on mobile

Item 2

Has divider on mobile

Item 3

Has divider on mobile

Item 4

Has divider on mobile

<script lang="ts">
  import { Grid, GridItem } from "kumo-svelte/components/grid";
  import { Surface } from "kumo-svelte/components/surface";
  import { Text } from "kumo-svelte/components/text";
</script>

<Grid variant="4up" gap="base" mobileDivider>
  {#each [1, 2, 3, 4] as item}
    <GridItem>
      <Surface class="rounded-lg p-4">
        <Text bold>Item {item}</Text>
        <div class="mt-1"><Text variant="secondary">Has divider on mobile</Text></div>
      </Surface>
    </GridItem>
  {/each}
</Grid>

All Variants

Reference for all available grid variants:

VariantDescription
2up1 column mobile, 2 columns medium+.
side-by-sideAlways 2 columns.
2-166%/33% split on medium+.
1-233%/66% split on medium+.
1-3up1 column mobile, 3 columns large+.
3up1 mobile, 2 medium, 3 large.
4upProgressive: 1 → 2 → 3 → 4 columns.
6up2 mobile, up to 6 on XL.
1-2-4up1 mobile, 2 medium, 4 large.

API Reference

Grid

PropTypeDefault
childrenSnippet—
classstring—
gapKumoGridGapKUMO_GRID_DEFAULT_VARIANTS.gap
mobileDividerbooleanfalse
variantKumoGridVariant—

GridItem

PropTypeDefault
childrenSnippet—
classstring—

On this page

  • Import
  • Usage
  • Grid Variants
  • Asymmetric Layouts
  • Gap Sizes
  • Mobile Dividers
  • All Variants
  • API Reference
    • Grid
    • GridItem