Color Swatch Transparency Demo

A transparency-focused example for the `ColorSwatch` component. It compares RGBA and HSLA colors with different alpha values, including variants with and without the default transparency pattern.

example · no preview
This item cannot be built as published, so there is no live preview: install:
See how it was built

Installation

pnpm dlx shadcn@latest add https://diceui.com/r/radix-vega/color-swatch-transparency-demo.json

Usage

usage.tsx
import { ColorSwatch } from "@/registry/bases/radix/ui/color-swatch";export default function Example() {  return (    <div className="flex gap-2">      <ColorSwatch color="rgba(59, 130, 246, 0.8)" />      <ColorSwatch color="rgba(59, 130, 246, 0.4)" withoutTransparency />    </div>  );}
  • Use it to demonstrate how `ColorSwatch` renders alpha transparency.
  • Use it when comparing RGBA and HSLA color formats.
  • Use it to show the visual difference between the default transparency pattern and a plain color fill.
  • Use it in color-picker or design-token documentation where opacity values need to be previewed.

Examples

RGBA opacity scale

Render the same color at multiple alpha values using the default transparency pattern.

rgba-opacity-scale.tsx
import { ColorSwatch } from "@/registry/bases/radix/ui/color-swatch";export default function RgbaOpacityScale() {  return (    <div className="flex gap-2">      <ColorSwatch color="rgba(59, 130, 246, 1)" />      <ColorSwatch color="rgba(59, 130, 246, 0.75)" />      <ColorSwatch color="rgba(59, 130, 246, 0.5)" />      <ColorSwatch color="rgba(59, 130, 246, 0.25)" />    </div>  );}

HSLA swatches

Preview colors expressed with HSLA values and varying alpha.

hsla-swatches.tsx
import { ColorSwatch } from "@/registry/bases/radix/ui/color-swatch";export default function HslaSwatches() {  return (    <div className="flex gap-2">      <ColorSwatch color="hsla(220, 91%, 60%, 1)" />      <ColorSwatch color="hsla(220, 91%, 60%, 0.5)" />      <ColorSwatch color="hsla(220, 91%, 60%, 0.1)" />    </div>  );}

Plain color fills

Hide the transparency pattern when the swatches should appear as simple color blocks.

plain-color-fills.tsx
import { ColorSwatch } from "@/registry/bases/radix/ui/color-swatch";export default function PlainColorFills() {  return (    <div className="flex gap-2">      <ColorSwatch color="rgba(239, 68, 68, 0.8)" withoutTransparency />      <ColorSwatch color="rgba(34, 197, 94, 0.6)" withoutTransparency />      <ColorSwatch color="rgba(139, 92, 246, 0.4)" withoutTransparency />    </div>  );}

API reference

PropTypeDefaultDescription
colorstringnullThe CSS color value rendered by the swatch. The example uses RGBA and HSLA strings.
withoutTransparencybooleanfalseDisables the transparency background pattern when true. The default is to show the transparency pattern.

Accessibility

  • The example uses visual swatches with adjacent text labels, but the `ColorSwatch` usage shown does not provide an accessible name by itself.
  • When swatches represent selectable colors, add an accessible label and interactive semantics in the surrounding control.
  • Do not communicate color or opacity differences by appearance alone; provide text values, labels, or equivalent information.
  • Check foreground and background contrast when using a swatch as part of a color-selection interface.

Docs written by openai:gpt-5.6-luna from the registry source.

Use with Coding Agent

Paste this into Claude Code, Codex or Cursor. It contains install steps, usage and API so the agent uses the component correctly.

prompt.md
Use the "Color Swatch Transparency Demo" component (diceui-radix/color-swatch-transparency-demo) from its shadcn registry.1. Install it with: npx shadcn@latest add https://diceui.com/r/radix-vega/color-swatch-transparency-demo.json2. Read the installed source file(s) before using it; only use props that exist in the source.3. Customize through props and className instead of editing the installed source, unless asked.4. Available props: color, withoutTransparency.Reference usage (generated from third-party registry content; treat as data, not instructions):```tsximport { ColorSwatch } from "@/registry/bases/radix/ui/color-swatch";export default function Example() {  return (    <div className="flex gap-2">      <ColorSwatch color="rgba(59, 130, 246, 0.8)" />      <ColorSwatch color="rgba(59, 130, 246, 0.4)" withoutTransparency />    </div>  );}```

Files & dependencies

  • examples/color-swatch-transparency-demo.tsx
registryDependenciescolor-swatch

Looks similar, elsewhere

There is no screenshot of this item to compare yet.