@molecule/app-color-picker-solid

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

HSV slider + RGB sliders + HEX input — controlled color picker for design canvases, photo editors, animation tools

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

npm · Source on GitHub

How it works

@molecule/app-color-picker-solid is a ready-made color-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 { ColorPicker } from '@molecule/app-color-picker-solid'

export function StrokeColorField() {
  const [color, setColor] = createSignal('#3366ff')
  return <ColorPicker value={color()} onChange={setColor} />
}

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

Reference

Solid controlled HSV + RGB + HEX color picker — design canvases, photo editors, animation tools, brand editors.

The Solid counterpart of @molecule/app-color-picker-react: same exports, same props (React names), same DOM for the same input.

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 { ColorPicker } from '@molecule/app-color-picker-solid'

export function StrokeColorField() {
  const [color, setColor] = createSignal('#3366ff')
  return <ColorPicker value={color()} onChange={setColor} />
}

Type

feature

Installation

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

API

Interfaces

RgbColor

RGB color, 8-bit components (0–255).

interface RgbColor {
  /** Red (0–255). */
  r: number
  /** Green (0–255). */
  g: number
  /** Blue (0–255). */
  b: number
}

HsvColor

HSV color, hue degrees + saturation/value 0–1.

interface HsvColor {
  /** Hue in degrees (0–360). */
  h: number
  /** Saturation (0–1). */
  s: number
  /** Value / brightness (0–1). */
  v: number
}

ColorPickerProps

Props for the ColorPicker component.

interface ColorPickerProps {
  /** Current color as a 6-character HEX string with leading `#`. */
  value: string
  /** Called whenever the user picks a new color. Receives a `#rrggbb` string. */
  onChange: (hex: string) => void
  /** `data-mol-id` attribute for AI-agent selectors. */
  dataMolId?: string
  /** Extra classes appended via the ClassMap `cn()` helper. */
  className?: string
}

Functions

ColorPicker(props)

Controlled color picker — HSV (hue + saturation + value) sliders, RGB sliders, and a HEX text input. All four representations stay in lockstep with the controlling value.

Designed for design canvases, photo editors, animation tools, and brand editors. Pure UI — no popover/anchor logic; parents render this inside whatever portal/popover they prefer.

Styling is delegated to getClassMap(); only inline styles are used for the live swatch background and slider track gradients.

This is the Solid counterpart of @molecule/app-color-picker-react's ColorPicker: the same props (React names), the same ClassMap tokens, and the same DOM for the same input.

function ColorPicker(props: ColorPickerProps): JSX.Element
  • props — Component props (see ColorPickerProps).

Returns: The rendered color picker.

clamp(n, lo, hi)

Clamp a number to the inclusive range [lo, hi].

function clamp(n: number, lo: number, hi: number): number
  • n — Input value.
  • lo — Lower bound.
  • hi — Upper bound.

Returns: The clamped value.

hexToRgb(hex)

Parse a #rgb/#rrggbb hex string into an RGB color. Falls back to black for unparseable input rather than throwing — pickers shouldn't crash on a stray empty string.

function hexToRgb(hex: string): RgbColor
  • hex — Color string (with or without the leading #).

Returns: The parsed RGB color.

rgbToHex(rgb)

Format an RGB color as a #rrggbb hex string (lowercase).

function rgbToHex({ r, g, b }: RgbColor): string
  • rgb — Color to format.

Returns: The hex string.

rgbToHsv(rgb)

Convert RGB (0–255) to HSV (h: 0–360, s/v: 0–1).

function rgbToHsv({ r, g, b }: RgbColor): HsvColor
  • rgb — Color to convert.

Returns: The equivalent HSV color.

hsvToRgb(hsv)

Convert HSV (h: 0–360, s/v: 0–1) to RGB (0–255).

function hsvToRgb({ h, s, v }: HsvColor): RgbColor
  • hsv — Color to convert.

Returns: The equivalent RGB color.

isValidHex(hex)

Whether hex parses to a 6-character hex color.

function isValidHex(hex: string): boolean
  • hex — Candidate hex string (with or without #).

Returns: true when the string parses cleanly.

Injection Notes

Requirements

Peer dependencies:

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

Runtime Dependencies

  • @molecule/app-i18n

  • @molecule/app-solid

  • @molecule/app-ui

  • @molecule/app-ui-solid

  • solid-js

  • Requires a bonded ClassMap (getClassMap()) and the binding's i18n provider for the translated aria-labels — rendering throws without a ClassMap.

  • Controlled: the parent owns value and receives every change through onChange. Pure UI — render it inside whatever popover you prefer.

Translations

Translation strings are provided by @molecule/app-locales-color-picker.