Skip to content

An open source design system that's fully customizable and agent ready

TypeScript
4.2 KB
Raw Blame

Selector — Dropdown Selector Component

A dropdown selector for choosing from a list of options. Supports simple strings, rich options with icons/descriptions, sections, and dividers.

Import

import {Selector, SelectorOption} from '@astryxdesign/core';

Basic Usage

// Simple string options
<Selector
  label="Fruit"
  options={['Apple', 'Banana', 'Orange']}
  value={fruit}
  onChange={setFruit}
  placeholder="Select a fruit..."
/>

// Rich options with icons and descriptions
<Selector
  label="Status"
  options={[
    { value: 'active', label: 'Active', icon: 'checkCircle' },
    { value: 'paused', label: 'Paused', icon: 'pause' },
    { value: 'archived', label: 'Archived', icon: 'archive' },
  ]}
  value={status}
  onChange={setStatus}
/>

// Sections and dividers
<Selector
  label="Action"
  options={[
    { type: 'section', title: 'Edit', options: [
      { value: 'cut', label: 'Cut' },
      { value: 'copy', label: 'Copy' },
    ]},
    { type: 'divider' },
    { type: 'section', title: 'View', options: [
      { value: 'zoom-in', label: 'Zoom In' },
      { value: 'zoom-out', label: 'Zoom Out' },
    ]},
  ]}
  value={action}
  onChange={setAction}
/>

Custom Option Rendering

<Selector
  label="User"
  options={users.map(u => ({value: u.id, label: u.name, icon: 'user'}))}
  value={selectedUser}
  onChange={setSelectedUser}
  renderOption={option => (
    <SelectorOption
      icon={option.icon}
      label={option.label}
      description={option.email}
    />
  )}
/>

Props

Selector

Prop Type Default Description
label string required Label text (always rendered for a11y)
options Array<string | OptionData | Divider | Section> required The options to display
value string — Currently selected value
onChange (value: string) => void — Selection change callback
changeAction (value: string) => Promise — Async action on change
placeholder string 'Select...' Placeholder when nothing selected
size 'sm' | 'md' | 'lg' 'md' Trigger size
isDisabled boolean false Disabled state
isLabelHidden boolean false Visually hide label
description string — Help text below label
isOptional boolean false Show optional indicator
isRequired boolean false Show required indicator
status { type: 'warning' | 'error' | 'success', message?: string } — Validation status
renderOption (option: OptionData) => ReactNode — Custom option renderer

SelectorOption (for custom rendering)

Prop Type Description
icon IconType Leading icon
label ReactNode Primary text
description ReactNode Secondary text
children ReactNode Additional content

Option Types

type OptionData = {
  value: string;
  label?: string;
  disabled?: boolean;
  icon?: IconType;
};
type Divider = {type: 'divider'};
type Section = {type: 'section'; title?: string; options: OptionData[]};