Ir al contenido
Español

Cómo funciona

Each variant sets only a few private variables (text colour, fill, hover fill, resting shadow), so adding a variant needs no new state rules. Filled variants carry a faint top sheen and a shadow tinted with their own colour; pressing deepens the fill, tucks the shadow in and scales to 0.98 (icon-only buttons to 0.92). The secondary button is a raised surface with a hairline ring rather than a grey border. Loading does not use disabled, which would drop keyboard focus and hide the busy state from screen readers; instead it keeps focus, sets aria-busy and aria-disabled, and blocks clicks in onClick. The spinner (a bright arc on a faint track) replaces a leading icon, or sits centred over hidden text, so the width never changes.

Úsalo para

  • Any press-to-run action on a page, dialog, form or table row.
  • One ink or primary button per area; use secondary, soft or ghost buttons for the rest.
  • Destructive actions: danger-soft when it sits beside other content, solid danger for the final confirmation.
  • The main action at the bottom of a mobile page: size lg plus block.

Busca otra opción cuando

  • Navigation to another page: use a link (<a>) so assistive tech and “open in new tab” work.
  • Switching between two states (on / off): use a switch.

Uso

import { BaseButton } from './BaseButton.jsx'

export function AlbumActions({ sharing, onShare, onDownload, onDelete }) {
  return (
    <div style={{ display: 'flex', gap: 8 }}>
      <BaseButton variant="secondary" size="lg" icon={<DownloadIcon />} aria-label="Download all photos" onClick={onDownload} />
      <BaseButton variant="ink" size="lg" block loading={sharing} onClick={onShare}>
        Share album
      </BaseButton>
    </div>
  )
}

// A quiet destructive action beside other content
// <BaseButton variant="danger-soft" size="sm" icon={<TrashIcon />} onClick={onDelete}>Delete album</BaseButton>

// Icon only: square, and it must have an aria-label
// <BaseButton variant="ghost" icon={<MoreIcon />} aria-label="More actions" />

// Landing page call to action: large, accent and fully round
// <BaseButton variant="primary" size="lg" pill>Start free trial</BaseButton>

Propiedades

PropiedadTipoPor defectoQué hace
variant'primary' | 'ink' | 'secondary' | 'soft' | 'text' | 'ghost' | 'danger' | 'danger-soft''secondary'Style: accent-filled primary, ink-filled (text colour, inverts in dark), raised secondary with a hairline ring, grey-filled soft, accent text, quiet ghost (for icon buttons), solid red danger, or red-tinted danger-soft.
size'sm' | 'md' | 'lg''md'Height 28 / 36 / 44px, radius 10 / 12 / 14px, font size 13 / 14 / 15px (large is semibold with 18px icons).
iconReactNode—Icon before the label (16px). With no label the button is square and needs an aria-label.
iconAfterReactNode—Icon after the label (16px), such as “View details ›”.
loadingbooleanfalseShows a spinner without changing the width; clicks are ignored and focus is kept.
loadingLabelstring'Loading'Text announced to screen readers when loading starts.
blockbooleanfalseFills the parent width; several block buttons in a flex row share it equally.
pillbooleanfalseFully round ends instead of the size's corner radius.
disabledbooleanfalseNative disabled: opacity 0.45, no shadow, no hover, no clicks.
type'button' | 'submit' | 'reset''button'Native type. Defaults to button so it never submits a form by accident.
refRef<HTMLButtonElement>—Forwarded to the native <button>.
...restButtonHTMLAttributes—Other attributes, such as className, style, onClick and aria-*, go to the <button>.

Accesibilidad

  • A native <button>: Tab to focus, Enter or Space to activate, with a visible focus ring (an outline in high-contrast mode).
  • Icon-only buttons need an aria-label; a console warning appears without one, and the icon itself is aria-hidden. Toggle buttons pass aria-pressed and keep their hover fill while on.
  • Loading sets aria-busy and aria-disabled, keeps focus and announces the loading label.
  • On touch screens the tap area of small and medium buttons grows to 44 × 44px without changing their look.
  • In forced-colors (high contrast) mode, where shadows vanish, every button draws a real 1px border.
  • Reduced motion removes the press scale and fades; the spinner slows down but keeps running.

Movimiento

Hover fill 160ms standard; a trailing icon nudges 2px forward on hover with a slight spring; press scale 0.98 (icon-only 0.92) in 100ms with the shadow tucked in; content fades out 100ms when loading; spinner 700ms linear (1.4s with reduced motion).

Añádelo a tu proyecto

Copia la instrucción en Codex o Claude Code. El agente lee el código publicado, te muestra lo que va a escribir y añade el componente junto a los tuyos.

BaseButton.jsxbase-button.csstokens.cssREADME.md

Los dos archivos se instalan juntos. La hoja de estilos lee las variables de tokens.css y lleva valores de reserva, así que también funciona sola.

Botones
Botón de borde aurora viene con Pro. La vista previa aparece al desbloquearlo.
Botón con mordiscos viene con Pro. La vista previa aparece al desbloquearlo.