A named color
import { ColorSwatch } from "@senvenli/react/color";
export default function Example() {
return <ColorSwatch color="#1E63D0" name="Ocean" />;
}import { ColorSwatch } from "@senvenli/react/color";Examples
Beside its value
A small palette, each color with its name and hex.import { ColorSwatch } from "@senvenli/react/color";
import { Text } from "@senvenli/react/display";
import { Stack } from "@senvenli/react/layout";
const PALETTE = [
{ name: "Ocean", value: "#1E63D0" },
{ name: "Pine", value: "#0F766E" },
{ name: "Plum", value: "#7C3AED" },
{ name: "Chalk", value: "#F4F4F2" },
];
export default function Example() {
return (
<Stack direction="horizontal" space="space-300">
{PALETTE.map((color) => (
<Stack direction="horizontal" key={color.value} space="space-100">
<ColorSwatch color={color.value} name={color.name} />
<Stack>
<Text size="body-small">{color.name}</Text>
<Text size="code" tone="subtle">{color.value}</Text>
</Stack>
</Stack>
))}
</Stack>
);
}Guidelines
When to use it
- Showing a color next to its name or value.
Use something else when
- People pick one of the colors. Color swatch picker
- The color marks a status that also needs words. Badge
Accessibility
Built in
- The name is the accessible label; without one, the color is described.
You provide
- A name when the color carries meaning.
API reference
ColorSwatch
| Prop | Type | Default | Description |
|---|---|---|---|
colorRequired | string | – | The color shown ("#1E63D0"). |
name | string | – | Its name ("Ocean"): the accessible label. |
className | string | – |
colorRequiredstringThe color shown ("#1E63D0").
namestringIts name ("Ocean"): the accessible label.
classNamestring