@molecule/app-color-picker-vue
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-vueHow it works
@molecule/app-color-picker-vue 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 { createApp, defineComponent, h, ref } from 'vue'
import { ColorPicker } from '@molecule/app-color-picker-vue'
const StrokeColorField = defineComponent({
setup() {
const color = ref('#3366ff')
return () => h(ColorPicker, { value: color.value, onChange: (v) => (color.value = v) })
},
})
createApp(StrokeColorField).mount('#app')Works with: @molecule/app-i18n, @molecule/app-ui, @molecule/app-ui-vue, @molecule/app-vue
Reference
Vue controlled HSV + RGB + HEX color picker — design canvases, photo editors, animation tools, brand editors.
The Vue 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.tsJSDoc, not this file.
Quick Start
import { createApp, defineComponent, h, ref } from 'vue'
import { ColorPicker } from '@molecule/app-color-picker-vue'
const StrokeColorField = defineComponent({
setup() {
const color = ref('#3366ff')
return () => h(ColorPicker, { value: color.value, onChange: (v) => (color.value = v) })
},
})
createApp(StrokeColorField).mount('#app')
Type
feature
Installation
npm install @molecule/app-color-picker-vue @molecule/app-i18n @molecule/app-ui @molecule/app-ui-vue @molecule/app-vue vue
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
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.
Constants
ColorPicker
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 Vue 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.
const ColorPicker: DefineComponent<
ExtractPropTypes<{
value: StringConstructor
onChange: { type: PropType<ColorPickerProps['onChange']>; required: true }
dataMolId: StringConstructor
className: StringConstructor
}>,
() => VNode,
{},
{},
{},
ComponentOptionsMixin,
ComponentOptionsMixin,
{},
string,
PublicProps,
Readonly<
ExtractPropTypes<{
value: StringConstructor
onChange: { type: PropType<ColorPickerProps['onChange']>; required: true }
dataMolId: StringConstructor
className: StringConstructor
}>
> &
Readonly<{}>,
{},
{},
{},
{},
string,
ComponentProvideOptions,
true,
{},
any
>
Injection Notes
Requirements
Peer dependencies:
@molecule/app-i18n^1.0.1@molecule/app-ui^1.0.1@molecule/app-ui-vue^1.1.0@molecule/app-vue^3.5.0 || ^4.0.0vue^3.4.0
Runtime Dependencies
-
@molecule/app-i18n -
@molecule/app-ui -
@molecule/app-ui-vue -
@molecule/app-vue -
vue -
Requires a bonded ClassMap (
getClassMap()) and the binding's i18n plugin for the translatedaria-labels — rendering throws without a ClassMap. -
Controlled: the parent owns
valueand receives every change throughonChange. Pure UI — render it inside whatever popover you prefer.
Translations
Translation strings are provided by @molecule/app-locales-color-picker.