brumate/ui

Button

A button that presses with a mouse, a touch, a pen, Enter, Space, or a screen reader. Each way calls the same handlers.

Pressed 0 times.

<script>
  import { $signal } from 'brumate/signals';
  import Button from '@brumate/ui/Button.brm';

  let presses = $signal(0);
  let last = $signal('');
</script>

<Button
  class="ui-button"
  onPress=((event) => {
    presses++;
    last = event.pointerType;
  })
>Press me</Button>
<Button class="ui-button" isPending>Saving</Button>
<Button class="ui-button" isDisabled>Disabled</Button>
<p>Pressed {presses === 1 ? 'once' : `${presses} times`}{last ? `, last with ${last}` : ''}.</p>

Attributes

Attribute When
data-pressed A pointer or a key holds it down.
data-hovered A mouse or a pen is over it.
data-focused It has focus.
data-focus-visible Its focus shows as a ring.
data-disabled It is disabled.
data-pending It is pending.

In other parts

Many parts give the Button inside them its role, its state and its handlers through a context, such as the trigger of a Disclosure, of a DialogTrigger or of a TooltipTrigger. slot picks the button that a part means, such as slot="close" in a Dialog. The handlers of the part run first, then yours.