Colour picker

Hex colour picker with swatch trigger, popover panel, and text input — built on react-colorful and Radix Popover.

Install

npx shadcn@latest add https://substrate.georgedrury.co.uk/r/colour-picker

Examples

Default

#6366f1
"use client"

import { useState } from "react"

Inline

"use client"

import { useState } from "react"

Custom trigger

"use client"

import { useState } from "react"

Components

ComponentDescription
ColourPickerPopover wrapper — renders swatch trigger and picker content in a panel
ColourPickerContentSaturation/hue picker with hex input and preview swatch
ColourSwatchColour preview button sized sm (20px) or md (28px)
ColourInputHex colour text input wrapping HexColorInput from react-colorful

Props

ColourPicker

PropTypeDefaultDescription
valuestring—Current colour, in any CSS format (hex, oklch(), rgb(), named)
onChange(colour: string) => void—Called with the new colour as hex
onStart() => void—Called when a drag or edit begins. Useful for undo snapshots.
childrenReact.ReactNodeSwatchCustom trigger element

ColourPickerContent

PropTypeDefaultDescription
valuestring—Current colour, in any CSS format
onChange(colour: string) => void—Called with the new colour as hex
onStart() => void—Called when a drag or edit begins

ColourSwatch

PropTypeDefaultDescription
colourstring—Any CSS colour to display
size"sm" | "md""md"Swatch size

ColourInput

PropTypeDefaultDescription
valuestring—Current hex colour value
onChange(colour: string) => void—Called when colour changes