DEV Community

Naxrul Ahmed
Naxrul Ahmed

Posted on

I Built a Zero-Dependency React Color Picker with Gradient Support

Color pickers are a common part of modern web applications. Whether you're building a design tool, dashboard, page builder, theme editor, or visual customization interface, you'll probably need one eventually.

I wanted a React color picker that could handle more than just HEX values.

So I built color-zone — a flexible, zero-dependency React color picker with gradient editing, multiple color formats, and a headless hook for building completely custom interfaces.

Website: https://color-zone.devnax.com/

GitHub: https://github.com/devnax/color-zone

What's included?

1. Interactive HSV Color Picker

An intuitive saturation/value canvas with smooth dragging, alongside dedicated hue and opacity sliders.

2. Multiple Color Formats

Switch between HEX, RGB, and HSL directly inside the picker.

Supported formats include:

  • HEX / HEXA
  • RGB / RGBA
  • HSL / HSLA

3. Linear and Radial Gradients

This is one of the main features I wanted.

You can pass a CSS gradient directly as the value prop. The picker automatically switches to gradient mode.

import { useState } from "react";
import { ColorPicker } from "color-zone";

export default function App() {
  const [color, setColor] = useState(
    "linear-gradient(90deg, #e52d27 0%, #b31217 100%)"
  );

  return (
    <ColorPicker
      value={color}
      onChange={setColor}
    />
  );
}
Enter fullscreen mode Exit fullscreen mode

Users can add, move, and remove gradient stops interactively.

4. Headless useColorPicker Hook

Don't need the default UI?

You can use the hook to build your own color picker interface.

import { useState } from "react";
import { useColorPicker } from "color-zone";

function CustomPicker() {
  const [color, setColor] = useState("#e74c3c");
  const picker = useColorPicker(color, setColor);

  return (
    <div>
      <p>HEX: {picker.valueToHex()}</p>
      <p>HSL: {picker.valueToHSL()}</p>

      <button onClick={() => picker.setLinear()}>
        Create Gradient
      </button>
    </div>
  );
}
Enter fullscreen mode Exit fullscreen mode

The hook exposes color channel setters, gradient controls, conversion methods, and more.

5. EyeDropper API

On supported Chromium browsers, users can sample colors directly from their screens using the native EyeDropper API.

6. Additional Features

  • Fully controlled React component
  • Customizable component styles
  • Exported color conversion utilities
  • Full TypeScript definitions
  • React 17+ peer dependency
  • Zero runtime dependencies

Installation

npm install color-zone
Enter fullscreen mode Exit fullscreen mode

Or:

yarn add color-zone
Enter fullscreen mode Exit fullscreen mode

Why another color picker?

I wanted something that works as both a ready-to-use component and a foundation for building custom color interfaces.

The headless hook makes it useful beyond the default UI, while native CSS gradient support makes it suitable for more advanced design tools.

Try it out

It's open source and available under the MIT license.

If you're building something with React, give it a try. Feedback, suggestions, and contributions are welcome!

Built by Devnax.

Top comments (0)