import { ColorLabelPill, LabelColorList } from "capsomer/react/label-color-list";
import { LabelColorEditor } from "capsomer/react/label-color-editor";
import { cleanLabels, rowsFromForm } from "capsomer/behavior/label-color-list";
<LabelColorList labels={labels} label="Statuses, in order" />
<ColorLabelPill labels={labels} value={scene.status} />
<Form method="post"><LabelColorEditor labels={labels} /><Button type="submit">Save the list</Button></Form>
// In the action:
const result = cleanLabels(rowsFromForm(form.getAll("label"), form.getAll("color")));
Examples
A value the list does not carry, shown as written
<div data-mount="unknown"></div>
The editor: each label's name and color, with two empty rows to add to it
<div data-mount="editor"></div>
API reference
ColorLabelPill
Prop
Type
Required
Does
labels
readonly ColorLabel[]
Yes
value
string
Yes
The value to show: a scene's status: as written. Matched to a label ignoring case.
unknownNote
string
Said after a value the list does not carry: " (not on the list)".
LabelColorList
Prop
Type
Required
Does
labels
readonly ColorLabel[]
Yes
label
string
Functions
Function
Signature
Does
seriesOf
(color: number): 2 | 1 | 5 | 8 | 3 | 4 | 6 | 7
A label's color as the series number a pill's dot takes (Pill's series): 1 to 8, a color past 8 round again, and anything that is not a number the first.
colorLabels
(...labels: string[]): ColorLabel[]
A starting list: each label takes the next color, round the eight.
A list as a person submitted it: blank rows dropped, labels trimmed and their spaces closed up, a label twice (ignoring case) refused, a color outside 1 to 8 given the next one round. Returns the clean list or the sentence that says why it was refused.
editRows
(labels: readonly ColorLabel[], { spare, max }?: { spare?: number | undefined; max?: number | undefined; }): ColorLabel[]
The editor's rows: the list, then up to spare empty rows to add to it, never past max. An empty row's color is the one it would take next.