James Shopland

Color Pickers [react-aria-components]

Buttons

About

Examples of combining the Primitives to create a full color picker The following are examples of how you can combine the Primitives to create a full color picker.

Built with React and Tailwind. Copy the prompt and paste it into Claude Code, Cursor or Lovable: your agent adds Color Pickers [react-aria-components] to your project and fits it to your theme.

Code

How Color Pickers [react-aria-components] is used: the demo's code. The component's own source comes with a free account.

Usage.tsx

"use client"

import React from "react"
import { parseColor } from "react-aria-components"

import { Button } from "@/components/ui/button"
import {
  ColorArea,
  ColorField,
  ColorPicker,
  ColorSlider,
  ColorSwatch,
  ColorSwatchPicker,
  ColorSwatchPickerItem,
  ColorThumb,
  SliderTrack,
} from "@/components/ui/color"
import { Dialog, DialogTrigger } from "@/components/ui/dialog"
import { Label } from "@/components/ui/field"
import { Popover } from "@/components/ui/popover"
import { Input } from "@/components/ui/textfield"

function HexPicker() {
  let [color, setColor] = React.useState(parseColor("#f00"))

  return (
    <ColorPicker value={color} onChange={setColor}>
      <DialogTrigger>
        <Button variant="ghost" className="flex h-fit items-center gap-2 p-1">
          <ColorSwatch className="size-8 rounded-md border-2" />
          Hex Color
        </Button>
        <Popover placement="bottom start" className="w-fit">
          <Dialog className="flex flex-col gap-4 p-3 outline-none">
            <div>
              <ColorArea
                colorSpace="hsb"
                xChannel="saturation"
                yChannel="brightness"
                className="h-[164px] rounded-b-none border-b-0"
              >
                <ColorThumb className="z-50" />
              </ColorArea>
              <ColorSlider colorSpace="hsb" channel="hue">
                <SliderTrack className="rounded-t-none border-t-0">
                  <ColorThumb className="top-1/2" />
                </SliderTrack>
              </ColorSlider>
            </div>
            <ColorField colorSpace="hsb" className="w-[192px]">
              <Label>Hex</Label>
              <Input className="" />
            </ColorField>
            <ColorSwatchPicker className="w-[192px]">
              <ColorSwatchPickerItem color="#F00">
                <ColorSwatch />
              </ColorSwatchPickerItem>
              <ColorSwatchPickerItem color="#f90">
                <ColorSwatch />
              </ColorSwatchPickerItem>
              <ColorSwatchPickerItem color="#0F0">
                <ColorSwatch />
              </ColorSwatchPickerItem>
              <ColorSwatchPickerItem color="#08f">
                <ColorSwatch />
              </ColorSwatchPickerItem>
              <ColorSwatchPickerItem color="#00f">
                <ColorSwatch />
              </ColorSwatchPickerItem>
            </ColorSwatchPicker>
          </Dialog>
        </Popover>
      </DialogTrigger>
    </ColorPicker>
  )
}

export { HexPicker }

Dependencies

More by James Shopland

View all
  • Tag Group [react-aria-components]

    Tag Group [react-aria-components]

    91
  • Date Range Picker [react-aria-components]

    Date Range Picker [react-aria-components]

    85
  • Grid List [react-aria-components]

    Grid List [react-aria-components]

    70
  • Switch [react-aria-components]

    Switch [react-aria-components]

    68
  • Select [react-aria-components]

    Select [react-aria-components]

    46
  • Range Calendar [react-aria-components]

    Range Calendar [react-aria-components]

    38
  • Popover

    Popover

    35
  • Slider [react-aria-components]

    Slider [react-aria-components]

    34

More in Buttons

View all
  • Button

    Button

    5
  • App Store Button

    App Store Button

    453
  • Button

    Button

    47
  • Eclipse Button

    Eclipse Button

    39
  • Texture Button

    Texture Button

    92
  • Split Button

    Split Button

    14
  • Button

    Button

    4
  • Button

    Button

    32