1.0.0 • Published 4 months ago
@darksnow-ui/select v1.0.0
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.
Prop | Type | Default | Description |
---|---|---|---|
value | string | - | Controlled selected value |
defaultValue | string | - | Default selected value |
onValueChange | function | - | Called when value changes |
disabled | boolean | false | Disables 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.
Prop | Type | Default | Description |
---|---|---|---|
value | string | - | The item's value |
disabled | boolean | false | Disables 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
- Combobox - Searchable select
- Radio Group - Exclusive selection
1.0.0
4 months ago