---
title: "Grid List · Base UI — StyleX Blocks"
description: "Interactive row lists with a sticky header, hover states, and rounded rows."
url: "https://stylexblocks.com/components/base-ui/grid-list/"
agent:
  instructions: "Use this search API to find relevant components and blocks across this site with keywords or natural-language queries, instead of crawling individual pages. Results are returned in Markdown."
  endpoint: "https://stylexblocks.com/.well-known/search?q={query}"
  method: "GET"
  documentation: "https://developers.cloudflare.com/ai-search/how-to/search-for-agents/"
---

# Grid List

Interactive row lists with a sticky header, hover states, and rounded rows.

- Behavior engine: Base UI
- Also available for: [Ark UI](https://stylexblocks.com/components/ark-ui/grid-list.md), [UI SDK](https://stylexblocks.com/components/ui-sdk/grid-list.md)
- Category: Display
- Variants: rounded
- Sizes: sm, md
- HTML page: https://stylexblocks.com/components/base-ui/grid-list/

## Install

Configure the project once (sets the behavior engine and import aliases):

```sh
npx stylexblocks init --style base-ui
```

Then add the item as source you own:

```sh
npx stylexblocks add grid-list
```

Equivalent: `npx shadcn add @stylexblocks/grid-list`. Registry item JSON: https://stylexblocks.com/r/base-ui/grid-list.json

## Usage

```tsx
import { GridList } from "#components/ui/base-ui/grid-list.tsx";

const deployments = [
  ["web-app", "2m ago"],
  ["docs-site", "1h ago"],
];

export function Example() {
  return (
    // variant/size resolve once on Root; parts inherit them via context and
    // expose data-* attributes. Items is a reset <ul>; rows are <li> and are
    // interactive (hover/active) by default — pass interactive={false} to
    // opt out.
    <GridList.Root variant="rounded" size="md">
      <GridList.Header>Recent deployments</GridList.Header>
      <GridList.Items>
        {deployments.map(([name, meta]) => (
          <GridList.Item key={name} onClick={() => open(name)}>
            <GridList.Cell>{name}</GridList.Cell>
            <GridList.Cell>{meta}</GridList.Cell>
          </GridList.Item>
        ))}
      </GridList.Items>
    </GridList.Root>
  );
}

// composition works per part — e.g. render a row as a link:
// <GridList.Item render={<a href="/deploys/web-app" />}>…</GridList.Item>
```

## Source

`components/ui/base-ui/grid-list.tsx`

```tsx
import * as stylex from "@stylexjs/stylex";
import { createSlotRecipeContext } from "#lib/base-ui/create-slot-recipe-context.tsx";
import { defineSlotRecipe } from "#lib/recipe-props.ts";
import { cursor } from '@stylexblocks/ui/tokens/cursor.stylex.ts'
import { durations } from '@stylexblocks/ui/tokens/durations.stylex.ts'
import { fontSizes } from '@stylexblocks/ui/tokens/font-sizes.stylex.ts'
import { fontWeights } from '@stylexblocks/ui/tokens/font-weights.stylex.ts'
import { lineHeights } from '@stylexblocks/ui/tokens/line-heights.stylex.ts'
import { radii } from '@stylexblocks/ui/tokens/radii.stylex.ts'
import { semanticColors } from '@stylexblocks/ui/semantic-tokens/colors.stylex.ts'
import { semanticShadows } from '@stylexblocks/ui/semantic-tokens/shadows.stylex.ts'
import { spacing } from '@stylexblocks/ui/tokens/spacing.stylex.ts'

const gridListRoot = stylex.create({
  base: {
    position: 'relative',
  },
})

const gridListRootSizes = stylex.create({
  sm: {
    fontSize: fontSizes.sm,
    lineHeight: lineHeights.sm,
    paddingBlock: spacing._0_5,
  },
  md: {
    fontSize: fontSizes.md,
    lineHeight: lineHeights.md,
    paddingBlock: spacing._1,
  },
})

const gridListItem = stylex.create({
  base: {
    display: 'flex',
    flexDirection: 'row',
    alignItems: 'center',
    justifyContent: 'space-between',
    flex: 1,
    userSelect: 'none',
    borderRadius: 'inherit',
    outline: 'none',
    boxShadow: {
      default: null,
      ':focus-visible': `0 0 0 2px ${semanticColors.accentFocusRing}`,
    },
    cursor: {
      default: null,
      ':is(:disabled, [disabled], [data-disabled])': cursor.disabled,
    },
    opacity: {
      default: null,
      ':is(:disabled, [disabled], [data-disabled])': 0.5,
    },
    backgroundColor: {
      default: null,
      ':is(:disabled, [disabled], [data-disabled])': {
        default: null,
        ':hover': {
          default: 'transparent',
          '@media (prefers-color-scheme: dark)': 'transparent',
        },
        ':active': {
          default: 'transparent',
          '@media (prefers-color-scheme: dark)': 'transparent',
        },
      },
    },
  },
})

const gridListItemSizes = stylex.create({
  sm: {
    paddingBlock: spacing._1,
    paddingInline: spacing._2,
    gap: spacing._1,
  },
  md: {
    paddingBlock: spacing._2,
    paddingInline: spacing._3,
    gap: spacing._2,
  },
})

const gridListItemVariants = stylex.create({
  rounded: {
    borderRadius: radii.md,
    marginBottom: spacing._0_5,
  },
})

const gridListItemInteractives = stylex.create({
  true: {
    cursor: {
      default: cursor.button,
      ':is(:disabled, [disabled], [data-disabled])': cursor.disabled,
    },
    transitionProperty: 'bg',
    transitionDuration: durations.fast,
    backgroundColor: {
      default: null,
      ':is(:disabled, [disabled], [data-disabled])': {
        default: null,
        ':hover': {
          default: 'transparent',
          '@media (prefers-color-scheme: dark)': 'transparent',
        },
        ':active': {
          default: 'transparent',
          '@media (prefers-color-scheme: dark)': 'transparent',
        },
      },
      ':hover': semanticColors.bgSubtle,
      ':active': semanticColors.bgSubtle,
    },
  },
})

const gridListHeader = stylex.create({
  base: {
    display: 'flex',
    flexDirection: 'row',
    position: 'sticky',
    fontWeight: fontWeights.medium,
    color: semanticColors.fgSubtle,
  },
})

const gridListHeaderSizes = stylex.create({
  sm: {
    paddingBlock: spacing._0_5,
    paddingInline: spacing._2,
  },
  md: {
    paddingBlock: spacing._1,
    paddingInline: spacing._3,
  },
})

const gridListCell = stylex.create({
  base: {
    flexShrink: 0,
  },
})

export type GridListInteractive = keyof typeof gridListItemInteractives

export type GridListVariant = keyof typeof gridListItemVariants

export type GridListSize = keyof typeof gridListRootSizes

// Rows render as real <li> inside a GridList.Items <ul>; the reset lives
// here because the recipe styles only the rows themselves.
const gridListLocal = stylex.create({
  items: { listStyle: "none", marginBlock: 0, paddingInlineStart: 0 },
});

// defineSlotRecipe validates the shape at compile time: default values must
// exist in the axis maps, and slot keys must be `styles` or a declared axis.
// (The generated recipe's own default is the unstyled "simple" variant, which
// has no map entry — "rounded" is the only styled variant, so it is the
// component default.)
const gridListSlotRecipe = defineSlotRecipe({
  slots: {
    root: { styles: gridListRoot, sizes: gridListRootSizes },
    header: { styles: gridListHeader, sizes: gridListHeaderSizes },
    item: { styles: gridListItem, sizes: gridListItemSizes, variants: gridListItemVariants },
    cell: { styles: gridListCell },
  },
  defaultVariants: { variant: "rounded", size: "md" },
});

/**
 * GridList — recipe and component colocated in one file. `<GridList.Root
 * variant size>` resolves the recipe once and every part inherits it through
 * context; each part composes via `render`. `GridList.Item` takes a boolean
 * `interactive` prop (default true) that layers the hover/active row styles
 * from the recipe's interactive map.
 */
const { withProvider, withContext } = createSlotRecipeContext(gridListSlotRecipe);

const GridListItemBase = withContext(
  "li",
  (v) => [
    gridListItem.base,
    gridListItemSizes[v.size],
    v.variant === "rounded" && gridListItemVariants.rounded,
  ],
  "GridListItem",
);

function GridListItem({
  interactive = true,
  style,
  ...props
}: React.ComponentProps<typeof GridListItemBase> & {
  /** Cursor, hover, and active row treatment from the recipe. */
  interactive?: boolean;
}) {
  return (
    <GridListItemBase
      {...props}
      style={[interactive && gridListItemInteractives.true, style] as never}
    />
  );
}

export const GridList = {
  Root: withProvider("div", "root", "GridListRoot"),
  Header: withContext("div", "header", "GridListHeader"),
  Items: withContext("ul", () => [gridListLocal.items], "GridListItems"),
  Item: GridListItem,
  Cell: withContext("span", "cell", "GridListCell"),
};
```
