# Controls

> The components of songstress/ui for controls, each as Songstress draws it, with its props and an example.

Page: https://songstress.app/docs/develop/components/controls/

What a person presses, switches, slides, picks and types. Each takes its value and tells your handler what the person chose: an action anywhere, a function in client code (see [State and handlers](/docs/develop/state/)).

Each picture is the SDK’s own test tree for the component, drawn by the web app; every app draws the same tree with its own controls, the phones natively. Each example is the one in the SDK’s doc comment, which its tests compile, and the props are read from its types.

## Button [#button]

<Shot name="gallery/button" alt="Buttons: primary, secondary, quiet and danger, one busy and one disabled" />

A button: a `button` node, `onPress` its `action`.

```tsx
import { Button, Text, useState } from 'songstress/ui'

function Counter() {
  const [count, setCount] = useState(0)
  return (
    <>
      <Text>{`Pressed ${count} times`}</Text>
      <Button title="Add one" icon="add" emphasis="primary" onPress={() => setCount((was) => was + 1)} />
    </>
  )
}
```

A `Button`'s props. Its look is `emphasis`; vocabulary 2's `style` is
left out.

| Field | Type | Description |
|---|---|---|
| `onPress` | `Handler<void>` | What pressing it does. |
| `grow?` | `boolean \| undefined` | In a horizontal stack, it takes the room left over. Elsewhere it does nothing. |
| `width?` | `Width \| undefined` | Across its parent, or as wide as what it holds. Left out, the block's own way. |
| `title` | `string` | The button's label. |
| `icon?` | `IconName \| undefined` | An icon from Songstress's icon set. |
| `emphasis?` | `Emphasis \| undefined` | How much it asks to be seen. Left out, from `style`, else "secondary". A page has at most one primary button. |
| `busy?` | `boolean \| undefined` | Work it started is going on: it shows a spinner and cannot be chosen. |
| `disabled?` | `boolean \| undefined` | Shown, but it cannot be chosen. |

## IconButton [#iconbutton]

<Shot name="gallery/icon-button" alt="Two icon buttons, Like and Delete" />

A button that shows an icon alone: an `icon-button` node, `onPress` its
`action`.

```tsx
import { IconButton } from 'songstress/ui'

const reload = <IconButton icon="refresh" label="Look again" onPress={{ type: 'refresh' }} />
```

An `IconButton`'s props.

| Field | Type | Description |
|---|---|---|
| `onPress` | `Handler<void>` | What pressing it does. |
| `grow?` | `boolean \| undefined` | In a horizontal stack, it takes the room left over. Elsewhere it does nothing. |
| `width?` | `Width \| undefined` | Across its parent, or as wide as what it holds. Left out, the block's own way. |
| `icon` | `IconName` | An icon from Songstress's icon set. |
| `label` | `string` | What it does, for people who do not see the icon; also its tooltip. |
| `emphasis?` | `Emphasis \| undefined` | How much it asks to be seen. Left out, "quiet". |
| `disabled?` | `boolean \| undefined` | Shown, but it cannot be chosen. |
| `busy?` | `boolean \| undefined` | Work it started is going on. |

## Menu [#menu]

<Shot name="gallery/menu" alt="A button titled More that opens a menu" />

A button that opens a menu: a `menu` node, its entries its `MenuOption`
children.

```tsx
import { Menu, MenuOption } from 'songstress/ui'

const more = (
  <Menu title="More" icon="settings">
    <MenuOption title="Look again" icon="refresh" onSelect={{ type: 'refresh' }} />
    <MenuOption title="Say hello" onSelect={() => ({ type: 'toast', message: 'Hello' })} />
  </Menu>
)
```

A `Menu`'s props: its entries are its children, each a `MenuOption`.

| Field | Type | Description |
|---|---|---|
| `children?` | `UiNode` | Its entries: `MenuOption` elements. |
| `grow?` | `boolean \| undefined` | In a horizontal stack, it takes the room left over. Elsewhere it does nothing. |
| `width?` | `Width \| undefined` | Across its parent, or as wide as what it holds. Left out, the block's own way. |
| `title` | `string` | The menu button's label. |
| `icon?` | `IconName \| undefined` | The menu button's icon. |

### MenuOption [#menuoption]

A menu item: one entry of a `Menu`, or of a `ListItem`'s, a
`TreeItem`'s or a `MediaCard`'s menu. `onSelect` is what choosing it does.

```tsx
import { confirmed, Menu, MenuOption } from 'songstress/ui'

const more = (
  <Menu title="More">
    <MenuOption title="Forget every play" icon="trash" destructive onSelect={confirmed({ title: 'Forget every play?' }, { type: 'invoke', command: 'forget' })} />
  </Menu>
)
```

A `MenuOption`'s props.

| Field | Type | Description |
|---|---|---|
| `onSelect` | `Handler<void>` | What choosing it does. |
| `title` | `string` | Its label. |
| `icon?` | `IconName \| undefined` | An icon from Songstress's icon set. |
| `destructive?` | `boolean \| undefined` | It deletes or cannot be undone: drawn as such. |

## Switch [#switch]

<Shot name="gallery/switch" alt="A switch labelled Scrobble, on" />

On or off, as a switch: a `switch` node, told a boolean.

```tsx
import { Switch, useState } from 'songstress/ui'

function Loud() {
  const [loud, setLoud] = useState(false)
  return <Switch label="Loud" help="Plays the next song louder." value={loud} onChange={setLoud} />
}
```

A `Switch`'s props.

| Field | Type | Description |
|---|---|---|
| `onChange?` | `Handler<boolean> \| undefined` | Told whether it is now on. |
| `grow?` | `boolean \| undefined` | In a horizontal stack, it takes the room left over. Elsewhere it does nothing. |
| `width?` | `Width \| undefined` | Across its parent, or as wide as what it holds. Left out, the block's own way. |
| `label` | `string` | What it sets, said beside it. |
| `help?` | `string \| undefined` | A line of help under it. |
| `disabled?` | `boolean \| undefined` | Shown, but it cannot be used. |
| `value` | `boolean` | Whether it is on. |

## Checkbox [#checkbox]

<Shot name="gallery/checkbox" alt="A checkbox labelled Only loved songs" />

On or off, as a checkbox: a `checkbox` node, told a boolean.

```tsx
import { Checkbox, useState } from 'songstress/ui'

function Intros() {
  const [skip, setSkip] = useState(true)
  return <Checkbox label="Skip intros" value={skip} onChange={setSkip} />
}
```

A `Checkbox`'s props.

| Field | Type | Description |
|---|---|---|
| `onChange?` | `Handler<boolean> \| undefined` | Told whether it is now ticked. |
| `grow?` | `boolean \| undefined` | In a horizontal stack, it takes the room left over. Elsewhere it does nothing. |
| `width?` | `Width \| undefined` | Across its parent, or as wide as what it holds. Left out, the block's own way. |
| `label` | `string` | What it sets, said beside it. |
| `help?` | `string \| undefined` | A line of help under it. |
| `disabled?` | `boolean \| undefined` | Shown, but it cannot be used. |
| `value` | `boolean` | Whether it is ticked. |

## Slider [#slider]

<Shot name="gallery/slider" alt="A slider labelled Volume" />

A number in a range: a `slider` node, told a number.

```tsx
import { Slider, useState } from 'songstress/ui'

function Fade() {
  const [seconds, setSeconds] = useState(4)
  return <Slider label="Fade" value={seconds} minimum={0} maximum={12} step={1} onChange={setSeconds} />
}
```

A `Slider`'s props.

| Field | Type | Description |
|---|---|---|
| `onChange?` | `Handler<number> \| undefined` | Told where it now stands. |
| `grow?` | `boolean \| undefined` | In a horizontal stack, it takes the room left over. Elsewhere it does nothing. |
| `width?` | `Width \| undefined` | Across its parent, or as wide as what it holds. Left out, the block's own way. |
| `label` | `string` | What it sets, said beside it. |
| `help?` | `string \| undefined` | A line of help under it. |
| `disabled?` | `boolean \| undefined` | Shown, but it cannot be used. |
| `value` | `number` | Where it stands, held between `minimum` and `maximum`. |
| `minimum` | `number` | Its lowest value. Each of a slider's numbers is one a 32-bit float carries, as the phones hold it: a slider with a number past that, or with bounds a float makes one, is left out. |
| `maximum` | `number` | Its highest value, above `minimum`. |
| `step?` | `number \| undefined` | How far one move goes, above 0 and no longer than the range (else it is left out, as is a step a float makes nothing). Left out, the app picks one: a hundredth of the range rounded down to a power of ten, never more than 1. Any count of steps is kept: an app draws a tick for each only when there are few. |

## Select [#select]

<Shot name="gallery/select" alt="A select labelled Service" />

One of a list, in a menu: a `select` node, told the option's `value`.

```tsx
import { Select, useState } from 'songstress/ui'

const ORDERS = [
  { value: 'recent', title: 'Most recent' },
  { value: 'plays', title: 'Most played' },
]

function Order() {
  const [order, setOrder] = useState('recent')
  return <Select label="Sort by" options={ORDERS} value={order} onChange={setOrder} />
}
```

A `Select`'s props.

| Field | Type | Description |
|---|---|---|
| `onChange?` | `Handler<string> \| undefined` | Told the `value` of the option chosen. |
| `grow?` | `boolean \| undefined` | In a horizontal stack, it takes the room left over. Elsewhere it does nothing. |
| `width?` | `Width \| undefined` | Across its parent, or as wide as what it holds. Left out, the block's own way. |
| `label` | `string` | What it sets, said beside it. |
| `help?` | `string \| undefined` | A line of help under it. |
| `disabled?` | `boolean \| undefined` | Shown, but it cannot be used. |
| `options` | `{ value: string; title: string; }[]` | The choices, at most 100. |
| `value?` | `string \| undefined` | The `value` of the option chosen. Left out, nothing is chosen. |
| `placeholder?` | `string \| undefined` | What it says while nothing is chosen. Left out, "Choose one". |

## Segmented [#segmented]

<Shot name="gallery/segmented" alt="A segmented control labelled Range" />

One of a few, side by side: a `segmented` node, told the option's
`value`.

```tsx
import { Segmented, useState } from 'songstress/ui'

function Span() {
  const [span, setSpan] = useState('week')
  return (
    <Segmented
      label="Over"
      options={[{ value: 'week', title: 'Week' }, { value: 'year', title: 'Year' }]}
      value={span}
      onChange={setSpan}
    />
  )
}
```

A `Segmented`'s props.

| Field | Type | Description |
|---|---|---|
| `onChange?` | `Handler<string> \| undefined` | Told the `value` of the option chosen. |
| `grow?` | `boolean \| undefined` | In a horizontal stack, it takes the room left over. Elsewhere it does nothing. |
| `width?` | `Width \| undefined` | Across its parent, or as wide as what it holds. Left out, the block's own way. |
| `label` | `string` | What it sets, said beside it. |
| `disabled?` | `boolean \| undefined` | Shown, but it cannot be used. |
| `options` | `{ value: string; title: string; }[]` | The choices, two to five; one whose `value` or `title` repeats an earlier one's is left out. A title is at most 40 characters. |
| `value` | `string` | The `value` of the option chosen. |

## TextInput [#textinput]

<Shot name="gallery/text-input" alt="Two text fields: Name on one line, and Notes on several" />

A line of text, or several: a `text-field` node, told what it holds.

```tsx
import { TextInput, useState } from 'songstress/ui'

function MixName() {
  const [name, setName] = useState('')
  return (
    <TextInput
      label="Name"
      placeholder="A name for the mix"
      value={name}
      onChange={setName}
      onSubmit={(value) => ({ type: 'toast', message: `Saved ${value}` })}
    />
  )
}
```

A `TextInput`'s props: the `text-field` node.

| Field | Type | Description |
|---|---|---|
| `onChange?` | `Handler<string> \| undefined` | Told what it holds as the person types. |
| `onSubmit?` | `Handler<string> \| undefined` | Told what it holds when the person presses Return in a single line. |
| `grow?` | `boolean \| undefined` | In a horizontal stack, it takes the room left over. Elsewhere it does nothing. |
| `width?` | `Width \| undefined` | Across its parent, or as wide as what it holds. Left out, the block's own way. |
| `label` | `string` | What it sets, said beside it. |
| `help?` | `string \| undefined` | A line of help under it. |
| `disabled?` | `boolean \| undefined` | Shown, but it cannot be used. |
| `value` | `string` | What it holds. |
| `placeholder?` | `string \| undefined` | The hint while it is empty. |
| `multiline?` | `boolean \| undefined` | Several lines. |
| `maxLength?` | `number \| undefined` | The most characters it takes, from 1 to 2,000. |

## SearchField [#searchfield]

<Shot name="gallery/search-field" alt="A search field: Search plays" />

The app's search field: a `search-field` node, told what it holds.

```tsx
import { SearchField, useState } from 'songstress/ui'

function Find() {
  const [term, setTerm] = useState('')
  return <SearchField placeholder="Search your plays" value={term} onChange={setTerm} />
}
```

A `SearchField`'s props.

| Field | Type | Description |
|---|---|---|
| `onChange?` | `Handler<string> \| undefined` | Told what it holds as the person types. |
| `onSubmit?` | `Handler<string> \| undefined` | Told what it holds when the person submits it. |
| `grow?` | `boolean \| undefined` | In a horizontal stack, it takes the room left over. Elsewhere it does nothing. |
| `width?` | `Width \| undefined` | Across its parent, or as wide as what it holds. Left out, the block's own way. |
| `value` | `string` | What it holds. |
| `label?` | `string \| undefined` | What it searches, said to screen readers. Left out, "Search". |
| `placeholder?` | `string \| undefined` | The hint while it is empty. Left out, "Search". |

## DatePicker [#datepicker]

<Shot name="gallery/date-picker" alt="A date picker labelled Since" />

A day: a `date-picker` node, told the day as YYYY-MM-DD.

```tsx
import { DatePicker, useState } from 'songstress/ui'

function Since() {
  const [since, setSince] = useState('2026-11-01')
  return <DatePicker label="Since" value={since} maximum="2026-12-31" onChange={setSince} />
}
```

A `DatePicker`'s props.

| Field | Type | Description |
|---|---|---|
| `onChange?` | `Handler<string> \| undefined` | Told the day chosen, as YYYY-MM-DD. |
| `grow?` | `boolean \| undefined` | In a horizontal stack, it takes the room left over. Elsewhere it does nothing. |
| `width?` | `Width \| undefined` | Across its parent, or as wide as what it holds. Left out, the block's own way. |
| `label` | `string` | What it sets, said beside it. |
| `help?` | `string \| undefined` | A line of help under it. |
| `disabled?` | `boolean \| undefined` | Shown, but it cannot be used. |
| `value?` | `string \| undefined` | The day chosen, as YYYY-MM-DD. Left out, none. A day that is no real day of the calendar (`2026-02-30`, `9999-99-99`) is left out, here and in `minimum` and `maximum`. |
| `minimum?` | `string \| undefined` | The earliest day it takes, as YYYY-MM-DD. |
| `maximum?` | `string \| undefined` | The latest day it takes, as YYYY-MM-DD. |
