@pbroom/color-kit/driverMulti color

addMultiColorEntry

Appends an entry (string colors are parsed). Selects it only when nothing was selected. No-op when id already exists.

functionimport { addMultiColorEntry } from '@pbroom/color-kit/driver';multi-color-state.ts:550
function addMultiColorEntry(
  model: MultiColorModel,
  id: string,
  color: string | Color,
  source?: ColorSource,
): MultiColorModel;

Parameters

idstring
colorstring | Color
source?ColorSourcedefault 'programmatic'
Source of the new entry.

Returns

MultiColorModel

Throws

  • When color is neither a string nor an object.
  • When color is a string that cannot be parsed (from parse).

Example

TypeScript
import { addMultiColorEntry, createMultiColorModel } from '@pbroom/color-kit/driver';

const model = createMultiColorModel({ colors: { bg: '#ffffff', fg: '#3b82f6' } });
const next = addMultiColorEntry(model, 'accent', '#f97316');
next.order; // → ['bg', 'fg', 'accent']
next.selectedId; // → 'bg'
addMultiColorEntry(next, 'accent', '#000') === next; // → true