# Picker

A command palette at popover scale: search, groups, hints and a footer.

Section: Components / Overlays
Page: https://ui.heyramzi.com/components/picker
Import path: `@heyramzi/ui/components/picker`

## Import

```ts
import { Picker, pickerTriggerClass } from "@heyramzi/ui/components/picker";
```

## Usage

```svelte
<Picker
  options={[{ value: "high", label: "High", hint: "P1" }]}
  {value}
  onSelect={(next) => (value = next)}
  triggerClass={pickerTriggerClass()}
>
  {#snippet trigger()}
    {selected?.label ?? "Priority"}
  {/snippet}
</Picker>
```

## Demo

```svelte
<script lang="ts">
	import { CaretDown } from "phosphor-svelte";
	import { Picker, pickerTriggerClass } from "@heyramzi/ui/components/picker";

	const options = [
		{ value: "urgent", label: "Urgent", hint: "P0" },
		{ value: "high", label: "High", hint: "P1" },
		{ value: "normal", label: "Normal", hint: "P2" },
		{ value: "low", label: "Low", hint: "P3" },
	];

	let value = $state<string | null>("normal");
	let selected = $derived(options.find((option) => option.value === value));
</script>

<Picker {options} {value} onSelect={(next) => (value = next)} triggerClass={pickerTriggerClass()}>
	{#snippet trigger()}
		<span>{selected?.label ?? "Priority"}</span>
		<CaretDown aria-hidden="true" class="size-3 text-muted-foreground" />
	{/snippet}
</Picker>
```

## API

### Picker

| Prop | Type | Default | Notes |
| --- | --- | --- | --- |
| `options` | `PickerOption<V>[]` |  | Flat list. Mutually exclusive with `groups`. |
| `groups` | `PickerGroup<V>[]` |  | Titled runs, when the menu has a shape worth naming. |
| `value` | `V \| V[] \| null` |  | required. An array checks each row in it, and a pick leaves the menu open for the next one. |
| `onSelect` | `(value: V) => void` |  | required |
| `trigger` | `Snippet` |  | required. The control that opens the menu. Rendered inside `Popover.Trigger`. |
| `triggerClass` | `string` |  | Class for the trigger. Use `pickerTriggerClass` to build it. |
| `triggerLabel` | `string` |  |  |
| `lead` | `Snippet<[PickerOption<V>]>` |  | A mark drawn at the head of a row when the option carries no icon: an avatar, a client logo, a colour swatch. |
| `footer` | `Snippet<[{ close: () => void }]>` |  | Pinned under the list: a clear action, a hint, a secondary surface. |
| `searchable` | `boolean \| "auto"` | `"auto"` | Search field. `auto` shows it from seven rows, the point at which the eye stops finding a name faster than the fingers can type it. |
| `searchPlaceholder` | `string` |  |  |
| `emptyLabel` | `string` | `"No matches"` |  |
| `open` | `boolean` | `false` | bindable |
| `align` | `"start" \| "center" \| "end"` | `"start"` |  |
| `width` | `"sm" \| "default" \| "lg"` | `"default"` | `sm` fits a word, `default` a name, `lg` a name and a date. |
| `disabled` | `boolean` | `false` |  |

### MarkPicker

| Prop | Type | Default | Notes |
| --- | --- | --- | --- |
| `options` | `PickerOption<V>[]` |  | required |
| `value` | `V \| null` |  | required |
| `onSelect` | `(value: V) => void` |  | required |
| `ariaLabel` | `string` |  | required |
| `placeholder` | `string` | `"Select"` | Said by the trigger when nothing in the list is the current value. |
| `searchPlaceholder` | `string` | `"Search"` | The search field's own prompt, on a list long enough to show one. |
| `shape` | `"square" \| "circle"` | `"square"` | `circle` for a face or an avatar, `square` for a logo. |
| `width` | `"sm" \| "default" \| "lg"` | `"lg"` |  |
| `class` | `string` |  |  |
