1.0.0 • Published 4 months ago

@darksnow-ui/select v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

Select

Displays a list of options for the user to pick from—triggered by a button. Built on top of Radix UI Select primitive.

Installation

npm install @darksnow-ui/select

Peer Dependencies

npm install react react-dom

Usage

import {
  Select,
  SelectContent,
  SelectItem,
  SelectTrigger,
  SelectValue,
} from "@darksnow-ui/select"

export function SelectExample() {
  return (
    <Select>
      <SelectTrigger className="w-[180px]">
        <SelectValue placeholder="Select a fruit" />
      </SelectTrigger>
      <SelectContent>
        <SelectItem value="apple">Apple</SelectItem>
        <SelectItem value="banana">Banana</SelectItem>
        <SelectItem value="blueberry">Blueberry</SelectItem>
        <SelectItem value="grapes">Grapes</SelectItem>
        <SelectItem value="pineapple">Pineapple</SelectItem>
      </SelectContent>
    </Select>
  )
}

Components

Select

The root container component.

PropTypeDefaultDescription
valuestring-Controlled selected value
defaultValuestring-Default selected value
onValueChangefunction-Called when value changes
disabledbooleanfalseDisables the select

SelectTrigger

The button that opens the select dropdown.

SelectValue

Displays the selected value or placeholder.

SelectContent

The dropdown content container.

SelectItem

A selectable item within the dropdown.

PropTypeDefaultDescription
valuestring-The item's value
disabledbooleanfalseDisables the item

Examples

Basic Select

<Select>
  <SelectTrigger className="w-[180px]">
    <SelectValue placeholder="Theme" />
  </SelectTrigger>
  <SelectContent>
    <SelectItem value="light">Light</SelectItem>
    <SelectItem value="dark">Dark</SelectItem>
    <SelectItem value="system">System</SelectItem>
  </SelectContent>
</Select>

Controlled Select

function ControlledSelect() {
  const [value, setValue] = useState("")

  return (
    <Select value={value} onValueChange={setValue}>
      <SelectTrigger>
        <SelectValue placeholder="Select option" />
      </SelectTrigger>
      <SelectContent>
        <SelectItem value="option1">Option 1</SelectItem>
        <SelectItem value="option2">Option 2</SelectItem>
      </SelectContent>
    </Select>
  )
}

With Groups

<Select>
  <SelectTrigger>
    <SelectValue placeholder="Select timezone" />
  </SelectTrigger>
  <SelectContent>
    <SelectGroup>
      <SelectLabel>North America</SelectLabel>
      <SelectItem value="est">Eastern Standard Time (EST)</SelectItem>
      <SelectItem value="cst">Central Standard Time (CST)</SelectItem>
      <SelectItem value="mst">Mountain Standard Time (MST)</SelectItem>
      <SelectItem value="pst">Pacific Standard Time (PST)</SelectItem>
    </SelectGroup>
  </SelectContent>
</Select>

Accessibility

  • Full keyboard navigation support
  • Screen reader accessible
  • Focus management
  • Arrow key navigation
  • Type-ahead search

Styling

Uses DarkSnow UI design tokens for consistent theming.

Related Components