Bonusway design system

Forms

IconToggle

A two-state icon action — favourite a store, follow, flag. Manages aria-pressed, which is the difference between this and an IconButton you re-render with a different glyph.

import IconToggle from '@/components/ui/IconToggle';

Source: src/components/ui/IconToggle.tsx

Examples

Pressed states

Uncontrolled by default (`defaultPressed`), controlled when you pass `pressed`. The `activeIcon` is the filled variant shown while pressed.

interactive

Props

<IconToggle> props

PropTypeDefaultDescription
iconrequiredIconName——
activeIconIconName—

The filled variant shown while pressed (defaults to `icon` if the font has no pair).

colorIconButtonColor'red'—
sizeIconButtonSize'md'—
pressedboolean——
defaultPressedbooleanfalse—
onPressedChange(pressed: boolean) => void——

Also accepts everything in Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'color' | 'onToggle'> — so native attributes (id, onClick, aria-*, data-*) pass straight through.

Accessibility

  • aria-pressed carries the state, so the label stays constant and the state is announced separately.

Usage

Do

  • Give it an aria-label that names the ACTION, not the state — “Favourite”, not “Favourited”.

Don’t

  • Don’t build one out of IconButton. You would have to manage aria-pressed yourself, and a toggle that only changes its icon tells a screen-reader user nothing.

Tämä verkkosivusto käyttää evästeitä

Käytämme evästeitä parantaaksemme käyttökokemustasi sivustollamme ja mukauttaaksemme sinulle tarjoamaamme sisältöä. Tärkeät evästeet ovat välttämättömiä jotta palvelumme toimii oikein. Jos suostut siihen, että keräämme tietoja sinusta käyttämällä välttämättömiä evästeitä ja markkinointievästeitä, valitse "Hyväksy kaikki". Voit aina muuttaa valintaasi evästeasetuksista.

Evästeasetukset