Label Picker

Coloured repository labels, picked from a searchable list. Chip text is derived from the fill by luminance, since a label set imported from a forge only gives you a background colour.

src/components/ui/label-picker.tsx

About

From the component's own source, where it was written.

Repository labels: coloured chips, picked from a searchable list.

Each label carries its own colour, so the chip is styled from data rather than from a variant — which is why this is not just a Badge with a prop. The text colour is derived from the fill rather than stored, since a label set imported from a forge only gives you the background.

Install

npx astralyx-ui add label-picker

Usage

import { LabelPicker } from '@/components/ui/label-picker'

<LabelPicker labels={labels} selected={selected} onSelectedChange={setSelected} />

Composer

Change the props and the source below follows.

bug
Props
tsx
<LabelPicker
  labels={labels}
  selected={selected}
  onSelectedChange={setSelected}
/>

Examples

Picker

API

Generated from the source, so it cannot fall behind the code. One table per exported component, then hooks, functions and types.

LabelChip

The chip on its own, for rendering labels outside the picker.

Extends ComponentProps<'span'>.

PropTypeDefaultDescription
labelLabelOptionrequired—

LabelPicker

Extends Omit<ComponentProps<'div'>, 'onSelect'>.

PropTypeDefaultDescription
labelsLabelOption[]required{ id, name, color, description? } where colour is any CSS colour.
selectedstring[]requiredControlled selection by id.
onSelectedChange(ids: string[]) => voidrequiredControlled selection by id.
triggerLabelstring'Labels'—
searchPlaceholderstring'Filter labels'—
searchLabelstring'Filter labels'Accessible name for the filter field.
listLabelstring'Labels'Accessible name for the option list.
emptyMessageReactNode'No labels match.'—

Functions

FunctionSignatureDescription
readableInk(color: string) => 'white' | 'black'Exported helper. Picks black or white from Rec. 709 luma — color-mix cannot answer "is this light or dark", and relative oklch() cannot branch.

Types

LabelOption

Repository labels: coloured chips, picked from a searchable list.

FieldTypeDescription
idstring—
namestring—
colorstringAny CSS colour.
description?string—