Color Picker

Form

Visual color picker with hex input.

Preview

#000000

Usage

example.jsx
import { ColorPicker } from "@/components/ui/color-picker";

export default function Example() {
  return <ColorPicker />;
}

Source Code

Copy this file into components/ui/color-picker.jsx in your project.

color-picker.jsx
"use client";

import { forwardRef } from "react";
import { cn } from "@/lib/utils";

const ColorPicker = forwardRef(({ className, value, onValueChange, ...props }, ref) => {
  return (
    <div className={cn("flex items-center gap-3", className)}>
      <input
        ref={ref}
        type="color"
        value={value || "#000000"}
        onChange={(e) => onValueChange?.(e.target.value)}
        className="h-9 w-9 cursor-pointer rounded-md border border-input p-0.5"
        {...props}
      />
      <span className="text-sm font-mono text-muted-foreground">{value || "#000000"}</span>
    </div>
  );
});
ColorPicker.displayName = "ColorPicker";

export { ColorPicker };

Quick Install

Make sure you have the cn() utility set up. It requires clsx and tailwind-merge.

npm install clsx tailwind-merge