āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā ā š shadcn/directory/sadmann7/diceui/components/color-swatch ā āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā
npx shadcn@latest add "https://diceui.com/r/color-swatch"
```package-install
@radix-ui/react-slot class-variance-authority
```
</Step>
<Step>
Copy and paste the following code into your project.
<ComponentSource name="color-swatch" />
</Step>
</Steps>
Import the component and use it to display color values.
import { ColorSwatch } from "@/components/ui/color-swatch";
<ColorSwatch value="#3b82f6" />
The color swatch component supports three different sizes: sm, default, and lg.
The color swatch automatically detects transparent colors and displays them with a checkerboard background pattern.
<ComponentTabs name="color-swatch-transparency-demo" />A color swatch component that displays a color value with optional transparency support.
<AutoTypeTable path="./types/docs/color-swatch.ts" name="ColorSwatchProps" />
<DataAttributesTable attributes={[ { title: "[data-disabled]", value: "Present when the component is disabled.", }, { title: "[data-slot]", value: "Always set to 'color-swatch' for identification.", }, ]} />
The color swatch component includes proper accessibility features:
aria-label text based on the color valuerole="img" to indicate it's an image representation of a coloraria-label reads "Color swatch: [color-value]"aria-label reads "No color selected"The color swatch component supports various color formats:
#3b82f6rgb(59, 130, 246)rgba(59, 130, 246, 0.5)hsl(217, 91%, 60%)hsla(217, 91%, 60%, 0.5)blue, red, etc.The component automatically detects transparent colors by checking for:
rgba() or hsla() function notationWhen transparency is detected, a checkerboard pattern is displayed behind the color to show the transparency effect. Use the withoutTransparency prop to disable this behavior.
ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā