react-headless-color-picker 1.0.0 → 1.0.1
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 +251 -0
- package/dist/index.d.mts +2 -25
- package/dist/index.d.ts +2 -25
- package/dist/index.js +216 -270
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +209 -260
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1 +1,252 @@
|
|
|
1
1
|
# react-headless-color-picker
|
|
2
|
+
|
|
3
|
+
A lightweight, fully customizable **headless color picker library for React**.
|
|
4
|
+
|
|
5
|
+
Built for developers who need complete control over styling and layout, `react-headless-color-picker` provides only the core logic and interaction primitives — no forced UI, no opinionated design system.
|
|
6
|
+
|
|
7
|
+
Inspired by the excellent **react-colorful**, but redesigned with a **headless-first architecture**.
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## Table of Contents
|
|
12
|
+
|
|
13
|
+
* Overview
|
|
14
|
+
* Why Use It?
|
|
15
|
+
* Features
|
|
16
|
+
* Installation
|
|
17
|
+
* Quick Start
|
|
18
|
+
* Full Example
|
|
19
|
+
* Custom Pointer Rendering
|
|
20
|
+
* Build Your Own UI
|
|
21
|
+
* API Philosophy
|
|
22
|
+
* Inspiration & Credits
|
|
23
|
+
* NPM Package
|
|
24
|
+
* License
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## Overview
|
|
29
|
+
|
|
30
|
+
Most React color pickers ship with predefined styles and component layouts.
|
|
31
|
+
|
|
32
|
+
That works for simple use cases, but becomes limiting when building:
|
|
33
|
+
|
|
34
|
+
* Design systems
|
|
35
|
+
* Internal admin tools
|
|
36
|
+
* CMS editors
|
|
37
|
+
* Theme generators
|
|
38
|
+
* GIS / map styling interfaces
|
|
39
|
+
* White-label products
|
|
40
|
+
* Fully branded SaaS dashboards
|
|
41
|
+
|
|
42
|
+
`react-headless-color-picker` solves that by giving you only the behavior layer, so you can design everything yourself.
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
## Why Use It?
|
|
47
|
+
|
|
48
|
+
Instead of overriding CSS from a prebuilt component, you get complete freedom:
|
|
49
|
+
|
|
50
|
+
✅ Use Tailwind, CSS Modules, styled-components, or plain CSS
|
|
51
|
+
✅ Build sliders, panels, popovers, dialogs, sidebars, or floating pickers
|
|
52
|
+
✅ Match your product branding perfectly
|
|
53
|
+
✅ Reuse primitives across projects
|
|
54
|
+
✅ Keep bundle size small
|
|
55
|
+
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
## Features
|
|
59
|
+
|
|
60
|
+
* Headless architecture
|
|
61
|
+
* Fully customizable UI
|
|
62
|
+
* Built specifically for React
|
|
63
|
+
* TypeScript support
|
|
64
|
+
* Lightweight and fast
|
|
65
|
+
* Reusable low-level primitives
|
|
66
|
+
* Flexible composition model
|
|
67
|
+
* Familiar color-picker behavior
|
|
68
|
+
* Inspired by proven UX patterns
|
|
69
|
+
|
|
70
|
+
---
|
|
71
|
+
|
|
72
|
+
## Installation
|
|
73
|
+
|
|
74
|
+
Install using your preferred package manager.
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
npm install react-headless-color-picker
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
or
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
pnpm add react-headless-color-picker
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
or
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
yarn add react-headless-color-picker
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
---
|
|
93
|
+
|
|
94
|
+
## Full Example
|
|
95
|
+
|
|
96
|
+
```tsx
|
|
97
|
+
import { useState } from "react";
|
|
98
|
+
import {
|
|
99
|
+
Alpha,
|
|
100
|
+
Hue,
|
|
101
|
+
Saturation,
|
|
102
|
+
equalHex,
|
|
103
|
+
hexToHsva,
|
|
104
|
+
hsvaToHex,
|
|
105
|
+
useColorManipulation,
|
|
106
|
+
type ColorModel,
|
|
107
|
+
} from "react-headless-color-picker";
|
|
108
|
+
|
|
109
|
+
export default function App() {
|
|
110
|
+
const [hex, setHex] = useState("#3b82f6");
|
|
111
|
+
|
|
112
|
+
const hexColorModel: ColorModel<string> = {
|
|
113
|
+
defaultColor: "#ff0000",
|
|
114
|
+
toHsva: hexToHsva,
|
|
115
|
+
fromHsva: hsvaToHex,
|
|
116
|
+
equal: equalHex,
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
const [hsva, updateHsva] = useColorManipulation(
|
|
120
|
+
hexColorModel,
|
|
121
|
+
hex,
|
|
122
|
+
setHex
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
return (
|
|
126
|
+
<div>
|
|
127
|
+
<div className="flex items-center gap-2 mb-3">
|
|
128
|
+
<span>Selected:</span>
|
|
129
|
+
|
|
130
|
+
<div
|
|
131
|
+
className="w-4 h-4 rounded-sm border"
|
|
132
|
+
style={{ backgroundColor: hex }}
|
|
133
|
+
/>
|
|
134
|
+
</div>
|
|
135
|
+
|
|
136
|
+
<div className="w-64">
|
|
137
|
+
<div
|
|
138
|
+
className="relative w-full"
|
|
139
|
+
style={{ aspectRatio: "1 / 0.75" }}
|
|
140
|
+
>
|
|
141
|
+
<Saturation
|
|
142
|
+
hsva={hsva}
|
|
143
|
+
onChange={updateHsva}
|
|
144
|
+
className="w-full h-full"
|
|
145
|
+
/>
|
|
146
|
+
</div>
|
|
147
|
+
|
|
148
|
+
<div className="mt-3 relative h-3 rounded-full overflow-hidden">
|
|
149
|
+
<Hue
|
|
150
|
+
hue={hsva.h}
|
|
151
|
+
onChange={updateHsva}
|
|
152
|
+
style={{ width: "100%", height: "100%" }}
|
|
153
|
+
/>
|
|
154
|
+
</div>
|
|
155
|
+
|
|
156
|
+
<div className="mt-3 relative h-3 rounded-full overflow-hidden">
|
|
157
|
+
<Alpha
|
|
158
|
+
hsva={hsva}
|
|
159
|
+
onChange={updateHsva}
|
|
160
|
+
style={{ width: "100%", height: "100%" }}
|
|
161
|
+
/>
|
|
162
|
+
</div>
|
|
163
|
+
</div>
|
|
164
|
+
</div>
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
---
|
|
170
|
+
|
|
171
|
+
## Example Result
|
|
172
|
+
|
|
173
|
+
Customize the UI however you want — modern, minimal, enterprise, branded, playful, or advanced.
|
|
174
|
+
|
|
175
|
+

|
|
176
|
+
|
|
177
|
+
---
|
|
178
|
+
|
|
179
|
+
## Custom Pointer Rendering
|
|
180
|
+
|
|
181
|
+
You can customize the pointer/handle used in:
|
|
182
|
+
|
|
183
|
+
* `Saturation`
|
|
184
|
+
* `Hue`
|
|
185
|
+
* `Alpha`
|
|
186
|
+
|
|
187
|
+
Use the `renderPointer` prop.
|
|
188
|
+
|
|
189
|
+
```tsx
|
|
190
|
+
const SaturationPointer = ({
|
|
191
|
+
left,
|
|
192
|
+
top,
|
|
193
|
+
}: {
|
|
194
|
+
left: number;
|
|
195
|
+
top: number;
|
|
196
|
+
}) => (
|
|
197
|
+
<Pointer left={left} top={top}>
|
|
198
|
+
<div className="w-4 h-4 rounded-full border-2 border-white shadow-[0_1px_6px_rgba(0,0,0,0.5)] pointer-events-none" />
|
|
199
|
+
</Pointer>
|
|
200
|
+
);
|
|
201
|
+
|
|
202
|
+
<Saturation
|
|
203
|
+
hsva={hsva}
|
|
204
|
+
onChange={updateHsva}
|
|
205
|
+
className="w-full h-full"
|
|
206
|
+
renderPointer={({ left, top }) => (
|
|
207
|
+
<SaturationPointer left={left} top={top!} />
|
|
208
|
+
)}
|
|
209
|
+
/>;
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
---
|
|
213
|
+
|
|
214
|
+
## Build Your Own UI
|
|
215
|
+
|
|
216
|
+
This package is intentionally unstyled.
|
|
217
|
+
|
|
218
|
+
You can combine primitives to build:
|
|
219
|
+
|
|
220
|
+
* Popover color pickers
|
|
221
|
+
* Inline editors
|
|
222
|
+
* Theme customization panels
|
|
223
|
+
* Drawing tools
|
|
224
|
+
* Dashboard controls
|
|
225
|
+
* Brand token editors
|
|
226
|
+
* Advanced design system components
|
|
227
|
+
|
|
228
|
+
---
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
## Inspiration & Credits
|
|
232
|
+
|
|
233
|
+
This project is heavily inspired by:
|
|
234
|
+
|
|
235
|
+
**react-colorful**
|
|
236
|
+
[https://github.com/omgovich/react-colorful](https://github.com/omgovich/react-colorful)
|
|
237
|
+
|
|
238
|
+
The original library demonstrated a clean, elegant, and performant approach to color picking.
|
|
239
|
+
|
|
240
|
+
`react-headless-color-picker` extends that concept into a **fully headless developer experience**.
|
|
241
|
+
|
|
242
|
+
---
|
|
243
|
+
|
|
244
|
+
## NPM Package
|
|
245
|
+
|
|
246
|
+
[https://www.npmjs.com/package/react-headless-color-picker](https://www.npmjs.com/package/react-headless-color-picker)
|
|
247
|
+
|
|
248
|
+
---
|
|
249
|
+
|
|
250
|
+
## License
|
|
251
|
+
|
|
252
|
+
MIT
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
1
|
import * as react from 'react';
|
|
3
2
|
import { HTMLAttributes, ReactNode } from 'react';
|
|
3
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
4
4
|
|
|
5
5
|
interface RgbColor {
|
|
6
6
|
r: number;
|
|
@@ -71,29 +71,6 @@ type PointerProps = HTMLAttributes<HTMLDivElement> & {
|
|
|
71
71
|
};
|
|
72
72
|
declare const Pointer: ({ left, top, children, style, ...rest }: PointerProps) => react_jsx_runtime.JSX.Element;
|
|
73
73
|
|
|
74
|
-
interface ColorPickerRenderProps {
|
|
75
|
-
hsva: HsvaColor;
|
|
76
|
-
updateHsva: (params: Partial<HsvaColor>) => void;
|
|
77
|
-
Saturation: typeof Saturation;
|
|
78
|
-
Hue: typeof Hue;
|
|
79
|
-
Alpha: typeof Alpha;
|
|
80
|
-
Pointer: typeof Pointer;
|
|
81
|
-
}
|
|
82
|
-
interface ColorPickerProps<T extends AnyColor> extends Omit<HTMLAttributes<HTMLDivElement>, "onChange" | "children" | "color"> {
|
|
83
|
-
colorModel: ColorModel<T>;
|
|
84
|
-
color: T;
|
|
85
|
-
onChange?: (color: T) => void;
|
|
86
|
-
children?: (renderProps: ColorPickerRenderProps) => ReactNode;
|
|
87
|
-
renderSaturationPointer?: (args: RenderPointerArgs) => ReactNode;
|
|
88
|
-
renderHuePointer?: (args: RenderPointerArgs) => ReactNode;
|
|
89
|
-
}
|
|
90
|
-
declare function ColorPicker<T extends AnyColor>({ colorModel, color, onChange, children, renderSaturationPointer, renderHuePointer, ...rest }: ColorPickerProps<T>): react_jsx_runtime.JSX.Element;
|
|
91
|
-
|
|
92
|
-
interface HexColorPickerProps extends Omit<ColorPickerProps<string>, "colorModel"> {
|
|
93
|
-
}
|
|
94
|
-
declare const hexColorModel: ColorModel<string>;
|
|
95
|
-
declare function HexColorPicker({ color, ...rest }: HexColorPickerProps): react_jsx_runtime.JSX.Element;
|
|
96
|
-
|
|
97
74
|
type Position = {
|
|
98
75
|
left: number;
|
|
99
76
|
top: number;
|
|
@@ -160,4 +137,4 @@ declare const setNonce: (hash: string) => void;
|
|
|
160
137
|
|
|
161
138
|
declare const formatClassName: (names: unknown[]) => string;
|
|
162
139
|
|
|
163
|
-
export { Alpha, type AlphaProps, type AnyColor, type ColorModel,
|
|
140
|
+
export { Alpha, type AlphaProps, type AnyColor, type ColorModel, type HslColor, type HslaColor, type HsvColor, type HsvaColor, Hue, type HueProps, Interactive, type ObjectColor, Pointer, type PointerPosition, type RenderPointerArgs, type RgbColor, type RgbaColor, Saturation, type SaturationProps, clamp, equalColorObjects, equalColorString, equalHex, formatClassName, getNonce, hexToHsva, hexToRgba, hslStringToHsva, hslaStringToHsva, hslaToHsl, hslaToHsva, hsvStringToHsva, hsvaStringToHsva, hsvaToHex, hsvaToHslString, hsvaToHsla, hsvaToHslaString, hsvaToHsv, hsvaToHsvString, hsvaToHsvaString, hsvaToHueHsl, hsvaToRgbString, hsvaToRgba, hsvaToRgbaString, parseHue, rgbStringToHsva, rgbaStringToHsva, rgbaToHex, rgbaToHsva, rgbaToRgb, round, roundHsva, setNonce, useColorManipulation, useEventCallback, validHex };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
1
|
import * as react from 'react';
|
|
3
2
|
import { HTMLAttributes, ReactNode } from 'react';
|
|
3
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
4
4
|
|
|
5
5
|
interface RgbColor {
|
|
6
6
|
r: number;
|
|
@@ -71,29 +71,6 @@ type PointerProps = HTMLAttributes<HTMLDivElement> & {
|
|
|
71
71
|
};
|
|
72
72
|
declare const Pointer: ({ left, top, children, style, ...rest }: PointerProps) => react_jsx_runtime.JSX.Element;
|
|
73
73
|
|
|
74
|
-
interface ColorPickerRenderProps {
|
|
75
|
-
hsva: HsvaColor;
|
|
76
|
-
updateHsva: (params: Partial<HsvaColor>) => void;
|
|
77
|
-
Saturation: typeof Saturation;
|
|
78
|
-
Hue: typeof Hue;
|
|
79
|
-
Alpha: typeof Alpha;
|
|
80
|
-
Pointer: typeof Pointer;
|
|
81
|
-
}
|
|
82
|
-
interface ColorPickerProps<T extends AnyColor> extends Omit<HTMLAttributes<HTMLDivElement>, "onChange" | "children" | "color"> {
|
|
83
|
-
colorModel: ColorModel<T>;
|
|
84
|
-
color: T;
|
|
85
|
-
onChange?: (color: T) => void;
|
|
86
|
-
children?: (renderProps: ColorPickerRenderProps) => ReactNode;
|
|
87
|
-
renderSaturationPointer?: (args: RenderPointerArgs) => ReactNode;
|
|
88
|
-
renderHuePointer?: (args: RenderPointerArgs) => ReactNode;
|
|
89
|
-
}
|
|
90
|
-
declare function ColorPicker<T extends AnyColor>({ colorModel, color, onChange, children, renderSaturationPointer, renderHuePointer, ...rest }: ColorPickerProps<T>): react_jsx_runtime.JSX.Element;
|
|
91
|
-
|
|
92
|
-
interface HexColorPickerProps extends Omit<ColorPickerProps<string>, "colorModel"> {
|
|
93
|
-
}
|
|
94
|
-
declare const hexColorModel: ColorModel<string>;
|
|
95
|
-
declare function HexColorPicker({ color, ...rest }: HexColorPickerProps): react_jsx_runtime.JSX.Element;
|
|
96
|
-
|
|
97
74
|
type Position = {
|
|
98
75
|
left: number;
|
|
99
76
|
top: number;
|
|
@@ -160,4 +137,4 @@ declare const setNonce: (hash: string) => void;
|
|
|
160
137
|
|
|
161
138
|
declare const formatClassName: (names: unknown[]) => string;
|
|
162
139
|
|
|
163
|
-
export { Alpha, type AlphaProps, type AnyColor, type ColorModel,
|
|
140
|
+
export { Alpha, type AlphaProps, type AnyColor, type ColorModel, type HslColor, type HslaColor, type HsvColor, type HsvaColor, Hue, type HueProps, Interactive, type ObjectColor, Pointer, type PointerPosition, type RenderPointerArgs, type RgbColor, type RgbaColor, Saturation, type SaturationProps, clamp, equalColorObjects, equalColorString, equalHex, formatClassName, getNonce, hexToHsva, hexToRgba, hslStringToHsva, hslaStringToHsva, hslaToHsl, hslaToHsva, hsvStringToHsva, hsvaStringToHsva, hsvaToHex, hsvaToHslString, hsvaToHsla, hsvaToHslaString, hsvaToHsv, hsvaToHsvString, hsvaToHsvaString, hsvaToHueHsl, hsvaToRgbString, hsvaToRgba, hsvaToRgbaString, parseHue, rgbStringToHsva, rgbaStringToHsva, rgbaToHex, rgbaToHsva, rgbaToRgb, round, roundHsva, setNonce, useColorManipulation, useEventCallback, validHex };
|