A color shown with its name: a theme token such as Color.PrimarySoft, one of your own (Color.Token("promo")) or a raw CSS color. For a page of tokens, a theme preview or a brand kit. A chip as wide as its place, then the name and the variable under it. The chip has an edge, so a color that matches the page still shows.
Tokens and your own colors
Set Color to a token, such as Color.PrimarySoft, one of your own (Color.Token("promo")) or a CSS color (Color.Of("#0f766e")), and name it with Label. Its variable, or the CSS color, shows under the name.
Static
Preview
Code
@* The colors a team's brand page lists: the theme's brand and surfaces, each named with its
variable under it, and the app's own promo token (defined on the Grid here, in theme.css in an
app). *@
<Grid Columns="new() { Base = 2, Sm = 4 }" Gap="4" Grow Style="--ib-color-promo: light-dark(#7c3aed, #a78bfa)">
<Swatch Color="Color.Primary" Label="Brand" />
<Swatch Color="Color.PrimarySoft" Label="Brand soft" />
<Swatch Color="Color.PrimaryText" Label="Brand text" />
<Swatch Color='Color.Token("promo")' Label="Promo" />
<Swatch Color="Color.Background" Label="Background" />
<Swatch Color="Color.Surface" Label="Surface" />
<Swatch Color="Color.SurfaceSunken" Label="Sunken" />
<Swatch Color="Color.FillStrong" Label="Fill strong" />
</Grid>Add this example to a page with the izzy CLI:
izzy add component Swatch --at <file>:<line>Text on a color
To show a pair, set TextColor: the chip shows "Aa" in it, and its variable shows under the chip's. Use it for the soft and text colors that go together, such as Color.SuccessSoft and Color.SuccessText.
Static
Preview
Code
@* The status colors a design page lists: each fill, then its soft color with the status's text on
it, the pair alerts and badges use. *@
<Grid Columns="new() { Base = 2, Sm = 4 }" Gap="4" Grow>
<Swatch Color="Color.Success" Label="Success" />
<Swatch Color="Color.SuccessSoft" TextColor="Color.SuccessText" Label="Success soft" />
<Swatch Color="Color.Danger" Label="Danger" />
<Swatch Color="Color.DangerSoft" TextColor="Color.DangerText" Label="Danger soft" />
</Grid>Mode support
| Feature | Static | Interactive |
|---|---|---|
| Everything | Yes | Yes |
Static: static server-side rendering, with no circuit and no WebAssembly. Interactive: Server, WebAssembly or Auto.
Accessibility
- It renders a
span: the chip is decorative (aria-hidden), and the label is text, so screen readers read the name. - The color itself isn't spoken, so name it in
Labelwhen its value matters, as in "Promo, #7c3aed". - With
TextColor, the chip's "Aa" is decorative too: the variables under the name say which pair it is.
Parameters
| Prop | Type | Default |
|---|---|---|
ColorThe color, such as Color.Primary, Color.Token("promo") or Color.Of("#0f766e"). | Color | Required |
LabelThe color's name, such as "Brand soft", over its variable (--ib-color-primary-soft) or a raw color's CSS. | string? | |
TextColorA text color to show on the chip, as "Aa": for a pair such as Color.SuccessSoft with Color.SuccessText. | Color? |
Plus 17 item props and 4 common props.
Full APISee also
- ColorPicker: a swatch and a hex box; the swatch opens a color panel.
- ThemeScope: themes part of a page: its brand color, density, shape or color scheme.