Skip to content
Klarhimmel UI

Colour field

Darkened a little so text on it reads on white

npx shadcn add @klarhimmel/theme-parts
DetailsAbout, usage, props and more

A brand colour: a hex field, the browser's own picker and up to eight swatches. It sends a normalised #rrggbb only, and a line under it says what the colour did or why it was refused.

Preview

Colour field
color-field.tsx
import { Theme } from '@/components/klarhimmel/theme/style';
import { ColorField } from '@/components/klarhimmel/ui/theme-parts';

export default function Example() {
  return (
    <Theme theme="brand">
      <ColorField label="Brand colour" value="#1d4ed8" onChange={(hex) => console.log(hex)} swatches={['#1d4ed8', '#b45309', '#0f766e']} />
    </Theme>
  );
}

Import

Import

import { ColorField } from '@/components/klarhimmel/ui/theme-parts';
Files
theme-parts.tsx, in components/klarhimmel/ui/. With it: input, theme, utils.
Render in
Render it inside <Theme>, once near the root of your app. Tokens and fonts are scoped to it, so outside it the component is unstyled.

Props

PropTypeDefaultDescription
labelReactNoderequiredThe field's words.
descriptionReactNode-The field's words.
valuestringrequiredThe colour as hex.
onChange(hex: string) => voidrequiredGets a normalised #rrggbb; a bad hex is held and marked, never sent.
swatchesstring[][]Up to eight colours to pick from.
notesReactNode-A calm line on what the colour did, or a refusal in the danger tone.
problemReactNode-A calm line on what the colour did, or a refusal in the danger tone.
pickerLabelstring'Pick a colour'
invalidLabelstring'Write a colour as #rrggbb'
disabledboolean-
classNamestring-Extra classes, merged after the component's own.