Skip to Content
Cristal

Actions

Icon button

A button reduced to an icon, named by its label and explained by a tooltip.

<cr-icon-button>CrIconButton

Variants

label is required: it gives the button its name for screen readers and shows in a tooltip on hover and keyboard focus. The default, ghost (no background), suits toolbars; secondary, outline and primary follow the button hierarchy. shape="round" makes it round.

import { CrIconButton } from '@cristal-ui/react';
import { Pencil, Settings, Share2, Trash2 } from 'lucide-react';

export default function IconButtonVariants() {
  return (
    <>
      <CrIconButton label="Edit">
        <Pencil aria-hidden="true" />
      </CrIconButton>
      <CrIconButton label="Share" variant="secondary">
        <Share2 aria-hidden="true" />
      </CrIconButton>
      <CrIconButton label="Settings" variant="outline" shape="round">
        <Settings aria-hidden="true" />
      </CrIconButton>
      <CrIconButton label="Delete" variant="primary">
        <Trash2 aria-hidden="true" />
      </CrIconButton>
    </>
  );
}

Sizes

A 30, 36, 40 or 48px square (xs, s, m, l), with a 20px icon in xs and 24px otherwise.

import { CrIconButton } from '@cristal-ui/react';
import { Plus } from 'lucide-react';

export default function IconButtonSizes() {
  return (
    <>
      {(['xs', 's', 'm', 'l'] as const).map((size) => (
        <CrIconButton key={size} label={`Add (${size.toUpperCase()})`} size={size} variant="secondary">
          <Plus aria-hidden="true" />
        </CrIconButton>
      ))}
    </>
  );
}

Toggle

With toggle, each click flips pressed: the button is announced as pressed or not, fills when active and bounces slightly. onCrToggle gives the new state.

'use client';

import { useState } from 'react';
import { CrIconButton } from '@cristal-ui/react';
import { Bold, Heart, Italic, Underline } from 'lucide-react';

export default function IconButtonToggle() {
  const [liked, setLiked] = useState(false);
  return (
    <>
      <div role="toolbar" aria-label="Formatting" style={{ display: 'flex', gap: 4 }}>
        <CrIconButton label="Bold" size="s" toggle>
          <Bold aria-hidden="true" />
        </CrIconButton>
        <CrIconButton label="Italic" size="s" toggle>
          <Italic aria-hidden="true" />
        </CrIconButton>
        <CrIconButton label="Underline" size="s" toggle>
          <Underline aria-hidden="true" />
        </CrIconButton>
      </div>
      <CrIconButton label="Add to favorites" variant="outline" shape="round" toggle pressed={liked} onCrToggle={(event) => setLiked(event.detail)}>
        <Heart aria-hidden="true" fill={liked ? 'currentColor' : 'none'} />
      </CrIconButton>
    </>
  );
}

Badge and loading

badge shows a number or a short text, added to the accessible name: "Notifications (3)". The badge bounces when its value changes. loading replaces the icon with the indicator and blocks clicks.

New notification
'use client';

import { useState } from 'react';
import { CrButton, CrIconButton } from '@cristal-ui/react';
import { Bell, Loader, Mail } from 'lucide-react';

export default function IconButtonBadge() {
  const [unread, setUnread] = useState(3);
  return (
    <>
      <CrIconButton label="Notifications" variant="secondary" badge={unread || undefined} onClick={() => setUnread(0)}>
        <Bell aria-hidden="true" />
      </CrIconButton>
      <CrIconButton label="Messages" variant="secondary" badge="99+">
        <Mail aria-hidden="true" />
      </CrIconButton>
      <CrIconButton label="Syncing" loading>
        <Loader aria-hidden="true" />
      </CrIconButton>
      <CrButton size="s" variant="outline" onClick={() => setUnread((count) => count + 1)}>
        New notification
      </CrButton>
    </>
  );
}

Tooltip

tooltipPlacement picks the side: top (default), bottom, start or end. Escape hides it; tooltip={false} removes it.

import { CrIconButton } from '@cristal-ui/react';
import { ArrowDown, ArrowLeft, ArrowRight, ArrowUp } from 'lucide-react';

export default function IconButtonTooltip() {
  return (
    <>
      <CrIconButton label="Above" variant="outline" tooltipPlacement="top">
        <ArrowUp aria-hidden="true" />
      </CrIconButton>
      <CrIconButton label="Below" variant="outline" tooltipPlacement="bottom">
        <ArrowDown aria-hidden="true" />
      </CrIconButton>
      <CrIconButton label="Left" variant="outline" tooltipPlacement="start">
        <ArrowLeft aria-hidden="true" />
      </CrIconButton>
      <CrIconButton label="Right" variant="outline" tooltipPlacement="end">
        <ArrowRight aria-hidden="true" />
      </CrIconButton>
    </>
  );
}

Accessibility

  • Native button named by label: the tooltip is a visual duplicate, ignored by screen readers.
  • The tooltip opens immediately on keyboard focus and after 0.3 s on hover; it can be hovered without disappearing, and Escape closes it (WCAG criterion 1.4.13).
  • No tooltip after a simple tap on a touch screen.
  • Toggle state announced with aria-pressed; the active state changes the fill, not just the hue.
  • Animations disabled with prefers-reduced-motion, and never on load.
  • The icon is decorative: add aria-hidden="true" to it.

API

Properties

PropertyTypeDefaultDescription
badgenumber | string—Pastille (nombre de notifications…), ajoutée au nom lu : « Notifications (3) ».
disabledbooleanfalseDésactive le bouton.
hrefstring—Adresse : le bouton devient un vrai lien (Ctrl+clic, clic molette et « Ouvrir dans un nouvel onglet » natifs).
label (obligatoire)string—Nom du bouton, lu par les lecteurs d'écran et affiché dans l'infobulle (obligatoire).
loadingbooleanfalseRemplace l'icône par l'indicateur de chargement et bloque les clics.
pressedbooleanfalseÉtat de la bascule (avec toggle).
shape"round" | "square"'square'Coins arrondis (square) ou bouton rond (round).
size"l" | "m" | "s" | "xs"'m'Côté : xs 30px, s 36px, m 40px, l 48px.
targetstring—Où ouvrir le lien (avec href), par exemple _blank ; rel="noopener noreferrer" est ajouté pour _blank.
togglebooleanfalseBouton bascule (favori, muet…) : chaque clic inverse pressed, annoncé enfoncé ou non.
tooltipbooleantrueAffiche le libellé en infobulle au survol et au focus.
tooltipPlacement"bottom" | "end" | "start" | "top"'top'Côté où s'ouvre l'infobulle.
type"button" | "reset" | "submit"'button'Comportement dans un formulaire (sans effet avec href).
variant"ghost" | "outline" | "primary" | "secondary"'ghost'Niveau de hiérarchie visuelle ; ghost : sans fond, pour les barres d'outils.

Events

Reactevent.detailDescription
onCrTogglebooleanÉmis quand l'utilisateur inverse la bascule ; detail : le nouvel état pressed.

Slots

SlotDescription
defaultL'icône, avec aria-hidden="true".

CSS parts

To style it from outside: cr-icon-button::part(name) { … }

PartDescription
badgeLa pastille.
buttonLe bouton natif.
spinner
tooltipL'infobulle.

On this page