preskok/ui

Choice Box

Grid or stacked option selector with single or multiple selection modes.

Installation

pnpm dlx @preskok-org/ui@latest add choice-box

Usage

import {
  ChoiceBox,
  ChoiceBoxDescription,
  ChoiceBoxItem,
  ChoiceBoxLabel,
} from "@/registry/preskok/ui/preskok-ui/choice-box"
 
export function ChoiceBoxExample() {
  return (
    <ChoiceBox aria-label="Select car packages" selectionMode="multiple">
      <ChoiceBoxItem
        textValue="sedan"
        label="Sedan"
        description="Comfortable family car with excellent fuel economy."
      />
      <ChoiceBoxItem
        textValue="suv"
        label="SUV"
        description="Versatile vehicle with enhanced cargo space and off-road capability."
      />
      <ChoiceBoxItem
        textValue="luxury"
        label="Luxury"
        description="Premium features with leather interior and advanced technology package."
      />
    </ChoiceBox>
  )
}

Components

ChoiceBox

The root container component for the choice box.

PropTypeDefaultDescription
columns1 | 2 | 3 | 4 | 5 | 61Number of columns for grid layout
gap0 | 1 | 2 | 3 | 4 | 5 | 60Gap between items
selectionMode"single" | "multiple""single"Selection mode
isReadOnlybooleanfalseWhether the choice box is read-only
classNamestring-Additional CSS classes

All standard GridList props from React Aria Components are also supported.

ChoiceBoxItem

An individual choice item within the choice box.

PropTypeDefaultDescription
labelstring-Label text for the item
descriptionstring-Description text displayed below the label
classNamestring-Additional CSS classes

All standard GridListItem props from React Aria Components are also supported.

ChoiceBoxLabel

The label text component for choice items.

PropTypeDefaultDescription
classNamestring-Additional CSS classes

All standard Text props from React Aria Components are also supported.

ChoiceBoxDescription

The description text component for choice items.

PropTypeDefaultDescription
classNamestring-Additional CSS classes

All standard Text props from React Aria Components are also supported.

Examples

Single Selection

<ChoiceBox aria-label="Select plan" selectionMode="single">
  <ChoiceBoxItem textValue="basic" label="Basic" />
  <ChoiceBoxItem textValue="pro" label="Pro" />
  <ChoiceBoxItem textValue="enterprise" label="Enterprise" />
</ChoiceBox>

Multiple Selection

<ChoiceBox aria-label="Select features" selectionMode="multiple">
  <ChoiceBoxItem textValue="feature1" label="Feature 1" />
  <ChoiceBoxItem textValue="feature2" label="Feature 2" />
  <ChoiceBoxItem textValue="feature3" label="Feature 3" />
</ChoiceBox>

Grid Layout

<ChoiceBox aria-label="Select plan" columns={3} gap={4}>
  <ChoiceBoxItem textValue="basic" label="Basic" />
  <ChoiceBoxItem textValue="pro" label="Pro" />
  <ChoiceBoxItem textValue="enterprise" label="Enterprise" />
</ChoiceBox>

With Descriptions

<ChoiceBox aria-label="Select plan">
  <ChoiceBoxItem
    textValue="basic"
    label="Basic"
    description="Perfect for personal projects"
  />
  <ChoiceBoxItem
    textValue="pro"
    label="Pro"
    description="Great for small teams"
  />
</ChoiceBox>

Custom Children

<ChoiceBox aria-label="Select option">
  <ChoiceBoxItem textValue="option1">
    <ChoiceBoxLabel>Option 1</ChoiceBoxLabel>
    <ChoiceBoxDescription>Custom content here</ChoiceBoxDescription>
  </ChoiceBoxItem>
</ChoiceBox>