ColorInput
Accepts hex, rgb() and hsl(), emits hex, and shows the contrast ratio against a colour you nominate. minContrast raises a warning, not an error — an unreadable brand colour is a legal value and blocking the form over it is the wrong call.
$ npx shadcn@latest add https://input-cn.vercel.app/r/color-input.jsonHand this to Claude Code
Most people reach this component through an agent rather than by reading the page. Pick how you want it wired and take a prompt that already carries the canonical value, the real prop names and the mistakes worth avoiding.
Nothing runs on its own. The link opens the tool with the prompt typed into the box; you read it and press Enter. If the button does nothing, Claude Code is not installed on this machine — use Copy prompt instead.
Live demo
1.28:1below AA against #FFFFFF
Paste rgb(205, 242, 92) — it converts.
value = #CDF25C · hex
Constraints
Validation rules, declared as props. Each one produces its own message and its own data-rule value, so a test can assert the rule rather than the sentence.
Props
Shared props
Implemented identically by all eleven components. These tables are generated from the source interfaces at build time, so a renamed prop changes this page rather than quietly making it wrong.
With react-hook-form
import { useForm, Controller } from "react-hook-form"
import { zodResolver } from "@hookform/resolvers/zod"
import { colorSchema } from "@inputcn/color/schema"
import { ColorInput } from "@/components/ui/color-input"
import { z } from "zod"
// The companion schema validates the CANONICAL value, so the resolver and the
// field can never disagree about what "valid" means.
const schema = z.object({ brand: colorSchema() })
export function Example() {
const { control } = useForm({ resolver: zodResolver(schema) })
return (
<Controller
name="brand"
control={control}
render={({ field, fieldState }) => (
<ColorInput
label="Brand colour"
{...field}
aria-invalid={fieldState.invalid}
/>
)}
/>
)
}With a Server Action
import { ColorInput } from "@/components/ui/color-input"
export default function Page() {
return (
<form action={save}>
<ColorInput name="brand" label="Brand colour" />
<button>Save</button>
</form>
)
}
async function save(data: FormData) {
"use server"
// The hidden canonical input carries the real value, not the display text.
const brand = data.get("brand") // "#CDF25C"
}Keyboard
Worth knowing
HSL round-trips are lossy by ±1 in each channel because the conversion rounds to integers. Hex in, hex out is stable; hex → HSL → hex may move by one.
Emits string, for example "#CDF25C". Keyboard operation is covered by automated tests; screen readers have not been verified yet.