Skip to content

Label color list

A person's own short list of labels, each a word with one of eight series colors as a dot.

<ul class="cap-color-label-list" aria-label="Stages, in order">
  <li><span class="cap-pill" data-series="1"><span class="cap-pill-dot" aria-hidden="true"></span>Idea</span></li>
  <li><span class="cap-pill" data-series="2"><span class="cap-pill-dot" aria-hidden="true"></span>Outlined</span></li>
  <li><span class="cap-pill" data-series="3"><span class="cap-pill-dot" aria-hidden="true"></span>Drafting</span></li>
  <li><span class="cap-pill" data-series="4"><span class="cap-pill-dot" aria-hidden="true"></span>First draft</span></li>
  <li><span class="cap-pill" data-series="5"><span class="cap-pill-dot" aria-hidden="true"></span>Revised</span></li>
  <li><span class="cap-pill" data-series="6"><span class="cap-pill-dot" aria-hidden="true"></span>In review</span></li>
  <li><span class="cap-pill" data-series="7"><span class="cap-pill-dot" aria-hidden="true"></span>Final</span></li>
  <li><span class="cap-pill" data-series="8"><span class="cap-pill-dot" aria-hidden="true"></span>Archived</span></li>
</ul>

Installation

// package.json: "capsomer": "github:DrDustinEdwards/capsomer#v0.152.2"
import "capsomer/tokens.css";
import "capsomer/base.css";
import "capsomer/label-color-list.css";
import { seriesOf, colorLabels, labelFor } from "capsomer/behavior/label-color-list";

Usage

<ul class="cap-color-label-list" aria-label="Stages, in order">
  <li><span class="cap-color-label" data-color="3"><span class="cap-color-label-dot" aria-hidden="true"></span>Drafting</span></li>
</ul>

<ol class="cap-color-label-edit">
  <li>
    <div class="cap-field"><label class="cap-field-label" for="l1">Label 1</label><input class="cap-input" id="l1" name="label" value="Idea" maxlength="40"></div>
    <div class="cap-field"><label class="cap-field-label" for="c1">Color 1</label><select class="cap-select" id="c1" name="color">...</select></div>
    <span class="cap-color-label" data-color="1" aria-hidden="true"><span class="cap-color-label-dot"></span></span>
  </li>
</ol>
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

PropTypeRequiredDoes
labelsreadonly ColorLabel[]Yes
valuestringYesThe value to show: a scene's status: as written. Matched to a label ignoring case.
unknownNotestringSaid after a value the list does not carry: " (not on the list)".

LabelColorList

PropTypeRequiredDoes
labelsreadonly ColorLabel[]Yes
labelstring

Functions

FunctionSignatureDoes
seriesOf(color: number): 2 | 1 | 5 | 8 | 3 | 4 | 6 | 7A 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.
labelFor(labels: readonly ColorLabel[], value: string): ColorLabel | nullThe label a value names, ignoring case and the space around it; null for an empty or unknown one.
cleanLabels(rows: readonly { label: string; color: string | number; }[], { max, maxLength }?: { max?: number | undefined; maxLength?: number | undefined; }): { ok: true; labels: ColorLabel[]; } | { ok: false; error: string; }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.
rowsFromForm(labels: readonly unknown[], colors: readonly unknown[]): { label: string; color: string; }[]The rows a form posted: label and color repeated, paired by position.

Parts and data attributes

ClassIs
.cap-color-label-editits own class
.cap-color-label-listthe root

Accessibility

KeyDoes
TabEach row's name, then its color
Arrow keys, Enter or Space on a colorThe select's own keys
  • The list is a ul named by its aria-label ("Stages, in order").
  • Each editor field has its own numbered label ("Label 2", "Color 2").
  • The dot is aria-hidden; the preview beside a row's color is too, because the select names the color.