Grid List Controlled

PreviousNext

grid-list-controlled-demo

Docs
intentuipage

Preview

Loading preview…
components/docs/collections/grid-list/grid-list-controlled-demo.tsx
"use client"

import { useState } from "react"
import type { Selection } from "react-aria-components"
import { Description } from "@/components/ui/field"
import { GridList, GridListItem } from "@/components/ui/grid-list"

export default function GridListControlledDemo() {
  const [selectedKeys, setSelectedKeys] = useState<Selection>(new Set([]))
  return (
    <div>
      <GridList
        selectedKeys={selectedKeys}
        onSelectionChange={setSelectedKeys}
        items={items}
        aria-label="Select items"
        selectionMode="multiple"
        className="min-w-64"
      >
        {(item) => <GridListItem id={item.id}>{item.name}</GridListItem>}
      </GridList>
      <Description className="mt-2 block text-muted-fg [&>strong]:text-fg">
        You have selected: <strong>{Array.from(selectedKeys).join(", ")}</strong>
      </Description>
    </div>
  )
}

const items = [
  { id: "1", name: "The Beatles" },
  { id: "2", name: "Led Zeppelin" },
  { id: "3", name: "Pink Floyd" },
  { id: "4", name: "Queen" },
  { id: "5", name: "The Rolling Stones" },
]

Installation

npx shadcn@latest add @intentui/grid-list-controlled-demo

Usage

Usage varies by registry entry. Refer to the registry docs or source files below for details.