@molecule/app-color-swatch-picker-svelte
Feature · color-swatch-picker · App (browser) · v1.1.3 · Apache-2.0
Grid of colored circle swatches with single-select state, for tag colors / labels / themes
npm install @molecule/app-color-swatch-picker-svelteHow it works
@molecule/app-color-swatch-picker-svelte 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.
<script lang="ts">
import { ColorSwatchPicker } from '@molecule/app-color-swatch-picker-svelte'
let selected = $state('red')
const swatches = [
{ value: 'red', color: '#ef4444', label: 'Red' },
{ value: 'blue', color: '#3b82f6', label: 'Blue' },
{ value: 'green', color: '#22c55e', label: 'Green' },
]
</script>
<ColorSwatchPicker
{swatches}
value={selected}
onChange={(value) => (selected = value)}
ariaLabel="Tag color"
>
{#snippet preview()}
<div>Live preview</div>
{/snippet}
</ColorSwatchPicker>Works with: @molecule/app-svelte, @molecule/app-ui, @molecule/app-ui-svelte
Reference
Svelte color-swatch picker — the Svelte counterpart of
@molecule/app-color-swatch-picker-react, with the same props (React
names) and the same DOM for the same input.
Exports ColorSwatchPicker — grid of colored circles with single-select
state. 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.tsJSDoc, not this file.
Quick Start
<script lang="ts">
import { ColorSwatchPicker } from '@molecule/app-color-swatch-picker-svelte'
let selected = $state('red')
const swatches = [
{ value: 'red', color: '#ef4444', label: 'Red' },
{ value: 'blue', color: '#3b82f6', label: 'Blue' },
{ value: 'green', color: '#22c55e', label: 'Green' },
]
</script>
<ColorSwatchPicker
{swatches}
value={selected}
onChange={(value) => (selected = value)}
ariaLabel="Tag color"
>
{#snippet preview()}
<div>Live preview</div>
{/snippet}
</ColorSwatchPicker>
Type
feature
Installation
npm install @molecule/app-color-swatch-picker-svelte @molecule/app-svelte @molecule/app-ui @molecule/app-ui-svelte svelte
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. preview is node-valued:
in Svelte it is a snippet prop.
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), as a snippet. */
preview?: Snippet
/** Extra classes. */
className?: string
/** `aria-label` for the group. */
ariaLabel?: string
}
Constants
ColorSwatchPicker
const ColorSwatchPicker: LegacyComponentType
Injection Notes
Requirements
Peer dependencies:
@molecule/app-svelte^3.5.0 || ^4.0.0@molecule/app-ui^1.1.0@molecule/app-ui-svelte^1.1.0svelte^5.0.0
Runtime Dependencies
@molecule/app-svelte@molecule/app-ui@molecule/app-ui-sveltesvelte
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.
The node-valued preview prop is a snippet.