@molecule/app-color-picker-react 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +210 -0
- package/package.json +17 -10
package/README.md
ADDED
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
AUTO-GENERATED — DO NOT EDIT THIS FILE.
|
|
3
|
+
Generated by `mlcl sync-docs` from the package's src/index.ts JSDoc + mlcl/registry.json.
|
|
4
|
+
Edits here are overwritten on the next commit (molecule's pre-commit hook regenerates).
|
|
5
|
+
To change this document, edit the module-level JSDoc in src/index.ts.
|
|
6
|
+
Generated: 2026-08-04T01:50:20.623Z
|
|
7
|
+
-->
|
|
8
|
+
|
|
9
|
+
# @molecule/app-color-picker-react
|
|
10
|
+
|
|
11
|
+
> **Auto-generated, AI-first package reference** for the [molecule.dev](https://molecule.dev) ecosystem.
|
|
12
|
+
> It is written to be read by coding agents as much as by people, and is generated from this
|
|
13
|
+
> package's source — edit `src/index.ts` JSDoc, not this file.
|
|
14
|
+
|
|
15
|
+
Controlled HSV + RGB + HEX color picker — design canvases, photo editors,
|
|
16
|
+
animation tools, brand editors.
|
|
17
|
+
|
|
18
|
+
## Quick Start
|
|
19
|
+
|
|
20
|
+
```tsx
|
|
21
|
+
import { ColorPicker } from '@molecule/app-color-picker-react'
|
|
22
|
+
|
|
23
|
+
function StrokeColorField() {
|
|
24
|
+
const [color, setColor] = useState('#3366ff')
|
|
25
|
+
return <ColorPicker value={color} onChange={setColor} />
|
|
26
|
+
}
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Type
|
|
30
|
+
|
|
31
|
+
`feature`
|
|
32
|
+
|
|
33
|
+
## Installation
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
npm install @molecule/app-color-picker-react @molecule/app-i18n @molecule/app-react @molecule/app-ui react
|
|
37
|
+
npm install -D @types/react
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## API
|
|
41
|
+
|
|
42
|
+
### Interfaces
|
|
43
|
+
|
|
44
|
+
#### `ColorPickerProps`
|
|
45
|
+
|
|
46
|
+
Props for {@link ColorPicker}.
|
|
47
|
+
|
|
48
|
+
```typescript
|
|
49
|
+
interface ColorPickerProps {
|
|
50
|
+
/** Current color as a 6-character HEX string with leading `#`. */
|
|
51
|
+
value: string
|
|
52
|
+
/** Called whenever the user picks a new color. Receives a `#rrggbb` string. */
|
|
53
|
+
onChange: (hex: string) => void
|
|
54
|
+
/** `data-mol-id` attribute for AI-agent selectors. */
|
|
55
|
+
dataMolId?: string
|
|
56
|
+
/** Extra classes appended via the ClassMap `cn()` helper. */
|
|
57
|
+
className?: string
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
#### `HsvColor`
|
|
62
|
+
|
|
63
|
+
HSV color, hue degrees + saturation/value 0–1.
|
|
64
|
+
|
|
65
|
+
```typescript
|
|
66
|
+
interface HsvColor {
|
|
67
|
+
/** Hue in degrees (0–360). */
|
|
68
|
+
h: number
|
|
69
|
+
/** Saturation (0–1). */
|
|
70
|
+
s: number
|
|
71
|
+
/** Value / brightness (0–1). */
|
|
72
|
+
v: number
|
|
73
|
+
}
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
#### `RgbColor`
|
|
77
|
+
|
|
78
|
+
RGB color, 8-bit components (0–255).
|
|
79
|
+
|
|
80
|
+
```typescript
|
|
81
|
+
interface RgbColor {
|
|
82
|
+
/** Red (0–255). */
|
|
83
|
+
r: number
|
|
84
|
+
/** Green (0–255). */
|
|
85
|
+
g: number
|
|
86
|
+
/** Blue (0–255). */
|
|
87
|
+
b: number
|
|
88
|
+
}
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### Functions
|
|
92
|
+
|
|
93
|
+
#### `clamp(n, lo, hi)`
|
|
94
|
+
|
|
95
|
+
Clamp a number to the inclusive range `[lo, hi]`.
|
|
96
|
+
|
|
97
|
+
```typescript
|
|
98
|
+
function clamp(n: number, lo: number, hi: number): number
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
- `n` — Input value.
|
|
102
|
+
- `lo` — Lower bound.
|
|
103
|
+
- `hi` — Upper bound.
|
|
104
|
+
|
|
105
|
+
**Returns:** The clamped value.
|
|
106
|
+
|
|
107
|
+
#### `ColorPicker(props)`
|
|
108
|
+
|
|
109
|
+
Controlled color picker — HSV (hue + saturation + value) sliders, RGB
|
|
110
|
+
sliders, and a HEX text input. All four representations stay in lockstep
|
|
111
|
+
with the controlling `value`.
|
|
112
|
+
|
|
113
|
+
Designed for design canvases, photo editors, animation tools, and brand
|
|
114
|
+
editors. Pure UI — no popover/anchor logic; parents render this inside
|
|
115
|
+
whatever portal/popover they prefer.
|
|
116
|
+
|
|
117
|
+
Styling is delegated to `getClassMap()`; only inline styles are used for
|
|
118
|
+
the live swatch background and slider track gradients.
|
|
119
|
+
|
|
120
|
+
```typescript
|
|
121
|
+
function ColorPicker({ value, onChange, dataMolId, className }: ColorPickerProps): JSX.Element
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
- `props` — Component props.
|
|
125
|
+
|
|
126
|
+
**Returns:** The rendered picker element.
|
|
127
|
+
|
|
128
|
+
#### `hexToRgb(hex)`
|
|
129
|
+
|
|
130
|
+
Parse a `#rgb`/`#rrggbb` hex string into an RGB color. Falls back to black
|
|
131
|
+
for unparseable input rather than throwing — pickers shouldn't crash on
|
|
132
|
+
a stray empty string.
|
|
133
|
+
|
|
134
|
+
```typescript
|
|
135
|
+
function hexToRgb(hex: string): RgbColor
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
- `hex` — Color string (with or without the leading `#`).
|
|
139
|
+
|
|
140
|
+
**Returns:** The parsed RGB color.
|
|
141
|
+
|
|
142
|
+
#### `hsvToRgb(hsv)`
|
|
143
|
+
|
|
144
|
+
Convert HSV (h: 0–360, s/v: 0–1) to RGB (0–255).
|
|
145
|
+
|
|
146
|
+
```typescript
|
|
147
|
+
function hsvToRgb({ h, s, v }: HsvColor): RgbColor
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
- `hsv` — Color to convert.
|
|
151
|
+
|
|
152
|
+
**Returns:** The equivalent RGB color.
|
|
153
|
+
|
|
154
|
+
#### `isValidHex(hex)`
|
|
155
|
+
|
|
156
|
+
Whether `hex` parses to a 6-character hex color.
|
|
157
|
+
|
|
158
|
+
```typescript
|
|
159
|
+
function isValidHex(hex: string): boolean
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
- `hex` — Candidate hex string (with or without `#`).
|
|
163
|
+
|
|
164
|
+
**Returns:** `true` when the string parses cleanly.
|
|
165
|
+
|
|
166
|
+
#### `rgbToHex(rgb)`
|
|
167
|
+
|
|
168
|
+
Format an RGB color as a `#rrggbb` hex string (lowercase).
|
|
169
|
+
|
|
170
|
+
```typescript
|
|
171
|
+
function rgbToHex({ r, g, b }: RgbColor): string
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
- `rgb` — Color to format.
|
|
175
|
+
|
|
176
|
+
**Returns:** The hex string.
|
|
177
|
+
|
|
178
|
+
#### `rgbToHsv(rgb)`
|
|
179
|
+
|
|
180
|
+
Convert RGB (0–255) to HSV (h: 0–360, s/v: 0–1).
|
|
181
|
+
|
|
182
|
+
```typescript
|
|
183
|
+
function rgbToHsv({ r, g, b }: RgbColor): HsvColor
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
- `rgb` — Color to convert.
|
|
187
|
+
|
|
188
|
+
**Returns:** The equivalent HSV color.
|
|
189
|
+
|
|
190
|
+
## Injection Notes
|
|
191
|
+
|
|
192
|
+
### Requirements
|
|
193
|
+
|
|
194
|
+
Peer dependencies:
|
|
195
|
+
|
|
196
|
+
- `@molecule/app-i18n` ^1.0.1
|
|
197
|
+
- `@molecule/app-react` ^1.0.1
|
|
198
|
+
- `@molecule/app-ui` ^1.0.1
|
|
199
|
+
- `react` ^18.0.0 || ^19.0.0
|
|
200
|
+
|
|
201
|
+
### Runtime Dependencies
|
|
202
|
+
|
|
203
|
+
- `@molecule/app-i18n`
|
|
204
|
+
- `@molecule/app-react`
|
|
205
|
+
- `@molecule/app-ui`
|
|
206
|
+
- `react`
|
|
207
|
+
|
|
208
|
+
## Translations
|
|
209
|
+
|
|
210
|
+
Translation strings are provided by `@molecule/app-locales-color-picker`.
|
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@molecule/app-color-picker-react",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "HSV slider + RGB sliders + HEX input — controlled color picker for design canvases, photo editors, animation tools",
|
|
5
|
+
"homepage": "https://www.molecule.dev/packages/app-color-picker-react",
|
|
5
6
|
"type": "module",
|
|
6
7
|
"main": "dist/index.js",
|
|
7
8
|
"types": "dist/index.d.ts",
|
|
@@ -17,7 +18,8 @@
|
|
|
17
18
|
}
|
|
18
19
|
},
|
|
19
20
|
"files": [
|
|
20
|
-
"dist"
|
|
21
|
+
"dist",
|
|
22
|
+
"README.md"
|
|
21
23
|
],
|
|
22
24
|
"keywords": [
|
|
23
25
|
"molecule",
|
|
@@ -28,17 +30,22 @@
|
|
|
28
30
|
"react"
|
|
29
31
|
],
|
|
30
32
|
"license": "Apache-2.0",
|
|
33
|
+
"repository": {
|
|
34
|
+
"type": "git",
|
|
35
|
+
"url": "https://github.com/molecule-dev/molecule.git",
|
|
36
|
+
"directory": "packages/app/features/color-picker-react"
|
|
37
|
+
},
|
|
31
38
|
"peerDependencies": {
|
|
32
|
-
"@molecule/app-i18n": "^1.0.
|
|
33
|
-
"@molecule/app-react": "^1.0.
|
|
34
|
-
"@molecule/app-ui": "^1.0.
|
|
39
|
+
"@molecule/app-i18n": "^1.0.1",
|
|
40
|
+
"@molecule/app-react": "^1.0.1",
|
|
41
|
+
"@molecule/app-ui": "^1.0.1",
|
|
35
42
|
"react": "^18.0.0 || ^19.0.0"
|
|
36
43
|
},
|
|
37
44
|
"devDependencies": {
|
|
38
|
-
"@molecule/app-i18n": "1.0.
|
|
39
|
-
"@molecule/app-react": "1.
|
|
40
|
-
"@molecule/app-ui": "1.
|
|
41
|
-
"@molecule/app-ui-tailwind": "1.
|
|
45
|
+
"@molecule/app-i18n": "1.0.2",
|
|
46
|
+
"@molecule/app-react": "1.5.1",
|
|
47
|
+
"@molecule/app-ui": "1.1.1",
|
|
48
|
+
"@molecule/app-ui-tailwind": "1.1.3",
|
|
42
49
|
"@testing-library/dom": "10.4.1",
|
|
43
50
|
"@testing-library/react": "16.3.2",
|
|
44
51
|
"@types/node": "26.1.2",
|
|
@@ -48,6 +55,6 @@
|
|
|
48
55
|
"react": "19.2.8",
|
|
49
56
|
"react-dom": "19.2.8",
|
|
50
57
|
"typescript": "6.0.3",
|
|
51
|
-
"vitest": "4.1.
|
|
58
|
+
"vitest": "4.1.11"
|
|
52
59
|
}
|
|
53
60
|
}
|