@molecule/app-color-swatch-picker-solid

Feature · color-swatch-picker · App (browser) · v1.1.2 · Apache-2.0

Grid of colored circle swatches with single-select state, for tag colors / labels / themes

npm install @molecule/app-color-swatch-picker-solid

npm · Source on GitHub

How it works

@molecule/app-color-swatch-picker-solid is a ready-made color-swatch-picker feature for the app (browser) side. It composes the core interfaces it needs, so it works with whichever providers your app has bonded.

import { createSignal } from 'solid-js'
import { ColorSwatchPicker } from '@molecule/app-color-swatch-picker-solid'

const swatches = [
  { value: 'red', color: '#ef4444', label: 'Red' },
  { value: 'blue', color: '#3b82f6', label: 'Blue' },
  { value: 'green', color: '#22c55e', label: 'Green' },
]

export function TagColorPicker() {
  const [selected, setSelected] = createSignal('red')
  return (
    <ColorSwatchPicker
      swatches={swatches}
      value={selected()}
      onChange={setSelected}
      ariaLabel="Tag color"
    />
  )
}

Works with: @molecule/app-solid, @molecule/app-ui, @molecule/app-ui-solid

Reference

Solid color-swatch picker.

Exports ColorSwatchPicker — grid of colored circles with single-select state. It is the Solid counterpart of @molecule/app-color-swatch-picker-react: same props (React names) and the same DOM for the same input. Apps switching framework change only the package name in their imports.

Auto-generated, AI-first package reference for the molecule.dev ecosystem. It is written to be read by coding agents as much as by people, and is generated from this package's source — edit src/index.ts JSDoc, not this file.

Quick Start

import { createSignal } from 'solid-js'
import { ColorSwatchPicker } from '@molecule/app-color-swatch-picker-solid'

const swatches = [
  { value: 'red', color: '#ef4444', label: 'Red' },
  { value: 'blue', color: '#3b82f6', label: 'Blue' },
  { value: 'green', color: '#22c55e', label: 'Green' },
]

export function TagColorPicker() {
  const [selected, setSelected] = createSignal('red')
  return (
    <ColorSwatchPicker
      swatches={swatches}
      value={selected()}
      onChange={setSelected}
      ariaLabel="Tag color"
    />
  )
}

Type

feature

Installation

npm install @molecule/app-color-swatch-picker-solid @molecule/app-solid @molecule/app-ui @molecule/app-ui-solid solid-js

API

Interfaces

ColorSwatch

A single color option in the swatch picker with its value, CSS color, and optional label.

interface ColorSwatch {
  /** Value stored in state (can be the raw color or a semantic id). */
  value: string
  /** CSS color (any valid color string). */
  color: string
  /** Optional label shown as tooltip / aria-label. */
  label?: string
}

ColorSwatchPickerProps

Props accepted by the ColorSwatchPicker component — the same props @molecule/app-color-swatch-picker-react accepts.

interface ColorSwatchPickerProps {
  /** Swatch definitions. */
  swatches: ColorSwatch[]
  /** Currently selected swatch value. */
  value: string
  /** Called when a swatch is picked. */
  onChange: (value: string) => void
  /** Swatch diameter in pixels. Defaults to 28. */
  size?: number
  /** Gap between swatches. */
  gap?: 'xs' | 'sm' | 'md'
  /** Optional child rendered below (e.g. a live preview). */
  preview?: JSX.Element
  /** Extra classes. */
  className?: string
  /** `aria-label` for the group. */
  ariaLabel?: string
}

Functions

ColorSwatchPicker(props)

Grid of colored circles with single-select state. Each swatch renders as a role="radio" button sized by size (default 28) and painted with its own color — the one inline style that is the caller's data, not a design token; a cm.button() fill would hide it. The style object uses kebab-case keys because Solid's style runtime applies each key with setProperty, which only reads kebab-case property names.

function ColorSwatchPicker(props: ColorSwatchPickerProps): JSX.Element
  • props — Component props (see ColorSwatchPickerProps).

Returns: The rendered swatch picker.

Injection Notes

Requirements

Peer dependencies:

  • @molecule/app-solid ^3.5.0 || ^4.0.0
  • @molecule/app-ui ^1.1.0
  • @molecule/app-ui-solid ^1.1.0
  • solid-js ^1.8.0

Runtime Dependencies

  • @molecule/app-solid
  • @molecule/app-ui
  • @molecule/app-ui-solid
  • solid-js

All text (label per swatch, ariaLabel for the group) is consumer-provided — pass translated strings via t(); the component has no built-in copy. Selection is fully controlled: persist onChange(value) and re-render with the new value. Swatches render as role="radio" buttons sized by the size prop (default 28px) with the CSS color you provide.