Skip to content
IzzyBlazor

Enter all results ↑ ↓ move Esc close

Swatch

Since 0.1.0-alpha.31
Shows a color with its name.

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

Brand--ib-color-primary Brand soft--ib-color-primary-soft Brand text--ib-color-primary-text Promo--ib-color-promo Background--ib-color-background Surface--ib-color-surface Sunken--ib-color-surface-sunken Fill strong--ib-color-fill-strong

Code

Usage.razor
@* 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:

bash
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

Success--ib-color-success Success soft--ib-color-success-soft--ib-color-success-text Danger--ib-color-danger Danger soft--ib-color-danger-soft--ib-color-danger-text

Code

Pairs.razor
@* 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

What works in each mode, Swatch
FeatureStaticInteractive
EverythingYesYes

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 Label when 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

Swatch parameters
PropTypeDefault
ColorThe color, such as Color.Primary, Color.Token("promo") or Color.Of("#0f766e").ColorRequired
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?

See 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.

Connection lost

Rejoining the server…