Color swatch card component for displaying a named color with its hex, RGB, and HSL values, plus an optional one-click copy button.
Designed for design-system documentation pages, theme browsers, and any UI where users need to inspect or copy color values at a glance.
Anatomy
The card is a bordered rounded panel with two regions (top to bottom):
- Swatch block — a solid-color
divwhosebackground-coloris set from thehexattribute via an inline style. Height varies bysize. - Info panel — shows
name, monospacehexbadge, optionalrgb/hsllabels, a copy button (whencopyable={true}), and a:tagsslot.
Size reference
:size | Swatch height |
|---|---|
:sm | h-16 (64px) |
:md | h-24 (96px) |
:lg | h-32 (128px) |
Copy button
When copyable={true} (default), a copy_button/1 is rendered beside the
hex badge. Clicking it writes the hex value to the clipboard and shows a
brief checkmark confirmation via the PhiaCopyButton JS hook.
Examples
<%!-- Minimal — just name and hex --%>
<.color_swatch_card name="Ocean Blue" hex="#1E90FF" />
<%!-- With all color formats and large swatch --%>
<.color_swatch_card
name="Sunset"
hex="#FF6B35"
rgb="rgb(255, 107, 53)"
hsl="hsl(18, 100%, 60%)"
size={:lg}
/>
<%!-- No copy button, with tag slot --%>
<.color_swatch_card name="Forest" hex="#228B22" copyable={false}>
<:tags>
<.badge variant={:secondary}>nature</.badge>
</:tags>
</.color_swatch_card>Design system palette gallery
<div class="grid grid-cols-2 sm:grid-cols-4 gap-4">
<%= for color <- @palette do %>
<.color_swatch_card
name={color.name}
hex={color.hex}
rgb={color.rgb}
/>
<% end %>
</div>
Summary
Functions
Renders a color swatch card displaying a color block with its name and hex value.
Functions
Renders a color swatch card displaying a color block with its name and hex value.
Sizes
:sm— h-16 color block:md— h-24 color block:lg— h-32 color block
Examples
<.color_swatch_card name="Ocean Blue" hex="#1E90FF" />
<.color_swatch_card name="Sunset" hex="#FF6B35" rgb="rgb(255, 107, 53)" size={:lg} />
<.color_swatch_card name="Forest" hex="#228B22" copyable={false}>
<:tags><span class="badge">nature</span></:tags>
</.color_swatch_card>Attributes
name(:string) (required) - Color name (e.g. 'Ocean Blue').hex(:string) (required) - Hex color value (e.g. '#1E90FF').rgb(:string) - Optional RGB representation (e.g. 'rgb(30, 144, 255)'). Defaults tonil.hsl(:string) - Optional HSL representation (e.g. 'hsl(210, 100%, 56%)'). Defaults tonil.copyable(:boolean) - Whether to show a copy button for the hex value. Defaults totrue.size(:atom) - Size variant controlling swatch height. Defaults to:md. Must be one of:sm,:md, or:lg.class(:string) - Additional CSS classes. Defaults tonil.- Global attributes are accepted. HTML attributes forwarded to the wrapper element.
Slots
tags- Optional tags to display below the color info.