react ~9 KB 0 deps v0.1.0 ↗ GitHub ↗

@mshafiqyajid/react-color-input

Headless color input hook and styled component. Swatch input with picker popover portalled to body. Hex, RGB, HSL formats, preset colors, copy button.

Playground #

Props
TSX
import { ColorInputStyled } from "@mshafiqyajid/react-color-input/styled";
import "@mshafiqyajid/react-color-input/styles.css";

<ColorInputStyled
  value={value}
  onChange={setValue}
/>

Install #

npm install @mshafiqyajid/react-color-input

Quick start #

import { ColorInputStyled } from "@mshafiqyajid/react-color-input/styled";
import "@mshafiqyajid/react-color-input/styles.css";

const [color, setColor] = useState("#6366f1");
<ColorInputStyled
  value={color}
  onChange={setColor}
  format="hex"
  showCopyButton
  label="Brand color"
/>

API #

PropTypeDefaultDescription
valuestringControlled color value
defaultValuestring"#000000"Uncontrolled initial value
onChange(v) => voidCalled on change
format"hex" | "rgb" | "hsl""hex"Color format for input/output
showCopyButtonbooleantrueShow copy-to-clipboard button
labelstringVisible label
hintstringHelper text below input
errorstringError message (overrides hint)
size"sm" | "md" | "lg""md"Input size
tone"neutral" | "primary" | "danger""neutral"Color tone
disabledbooleanfalseDisable interaction
presetsstring[](built-in 12 colors)Custom preset swatches
showAlphabooleanfalseAlpha channel slider
eyeDropperbooleanfalseEyeDropper API button (Chrome only)
onOpen() => voidPicker open callback
onClose() => voidPicker close callback
Edit this page on GitHub