DlGrid

Lay out named content items in a responsive grid

The DlGrid block component places named slots into a responsive grid.

Features

  • #️⃣ column and row setup
  • 🏷️ one cell per slot, with optional column and row placement
  • 📐 alignment and justification of the content inside each cell
  • 🧩 theme-friendly visual adjustments
  • ⚠️ extensive error reporter

Usage

Use ::dl-grid as a block component defining the grid with grid-cols and, when you need a fixed row count, grid-rows.

Each cell is a named slot. The name is #item-{n}, starting at 1. Slots are ordered by that number, so #item-10 stays after #item-2. Append a position to place the cell on the grid. The slot body is normal Markdown and can include other content components.

::dl-grid{grid-cols="lg:grid-cols-3"}#item-1Grid item 1#item-2Grid item 2#item-3Grid item 3::

Result:

Grid item 1

Grid item 2

Grid item 3

Class generation

grid-cols and grid-rows accept lg:grid-cols-1 through lg:grid-cols-12, and the same range for rows. Other values are not generated.

If you need grid classes at another breakpoint, such as md:grid-cols-3, add them in your CSS (for example with @apply) so Tailwind can detect them and include in the final bundle.

With custom item content alignment

Each item is a vertical flex container that fills its cell.

align / justifyjustify class appliedalign class applied
start

justify-start

items-start

center

justify-center

items-center

end

justify-end

items-end

Both align and justify accept start, center, and end. Like this:

::dl-grid{grid-cols="lg:grid-cols-3" align="start" justify="start"}<!-- Grid items -->::

With custom item positions

The position is part of the slot name, after |. The numbers are grid lines: the start line, then the end line. Two numbers place the item across columns. Four numbers place it across columns and then rows.

slotplacement
#item-1|1-3

Columns only, from line 1 to line 3.

#item-1|1-3-1-2

Columns from line 1 to line 3, and rows from line 1 to 2.

Placement applies from the large breakpoint. Smaller screens keep a single column.

::dl-grid{grid-cols="lg:grid-cols-4" grid-rows="lg:grid-rows-2"}#item-1|1-4Grid item 1#item-2|4-5-1-3Grid item 2::

Result:

Grid item 1

Grid item 2

Props

Here are the properties you can use with the DlGrid component. Each property should be set on an individual component instance; they do not affect the global configuration. More about defining properties in MDC components you can read here.

nametypedefaultdescription
lazybooleantrue

Whether to lazy load the component.

gridCols'{breakpoint}:grid-cols-${n}''lg:grid-cols-2'

Grid columns at the large breakpoint. Smaller screens use a single column.

gridRows'{breakpoint}:grid-rows-${n}'undefined

Grid rows at the large breakpoint. Omit it and the row count follows the items.

align'start' | 'center' | 'end''start'

Cross-axis alignment of the content inside each item.

justify'start' | 'center' | 'end''start'

Main-axis justification of the content inside each item.

Slots

namedescription
#item-{n}|{c-c}-{r-r}?

One grid cell, {n} is its number. See placement for column and row lines. The {c-c} and {r-r} represents the column and row positions.

ui

Dedicated slot for defining the component’s ui object. More about styling MDC components you can read here.

Styling

Styling from Markdown

Every DocLayer component can be styled directly within your Markdown file using dedicated slot/property configuration. This allows you to customize the appearance of the component's markup elements without modifying global styles. More about components styling you can read here.

Below you'll find the default set of Tailwind classes for the component's dedicated markup elements. base is the grid, item is each cell.

<script lang="ts">const ui = defineDoclayerComponentUi({  base: ['u-space-mb', 'grid', 'grid-cols-1', 'gap-4', 'md:gap-6', 'w-full'],  item: ['flex', 'flex-col', 'min-w-0', 'w-full', 'h-full'],});</script>