Component API

<ui-button>

Open live example

Button (or link styled as one) with an optional leading icon, in three
visual weights. Set href to render an <a> instead of a <button>
same styling either way — for cross-page navigation that should look like
an action button; a disabled/busy link stays a real <a> with
aria-disabled + pointer-events: none rather than losing its href.
Put the icon in the icon slot and the label in the default slot.

Form-associated (type="submit"/"reset"): the actual <button> lives in
this element's shadow root, which native HTML form association does not
cross into from an ancestor light-DOM <form>. type="submit"/"reset"
is instead wired through ElementInternals.form — the same mechanism
address-autocomplete uses to associate with an ancestor form.

Install

import "@f-ewald/components/ui-button.js";

Usage

<ui-button variant="primary">
  <span slot="icon">...</span>
  New property
</ui-button>
<ui-button variant="danger">Delete</ui-button>
<ui-button variant="secondary" href="/properties?edit=42">Edit</ui-button>

Attributes / properties

PropertyAttributeTypeDefaultDescription
variantvariantButtonVariant"primary"Visual weight.
hrefhrefstring | nullnullRenders an <a href="..."> instead of a <button> when set.
typetype"button" | "submit" | "reset""button"Native button type. Ignored when href is set.
disableddisabledbooleanfalseDisables the control and dims it.
busybusybooleanfalseShows a spinner in place of the icon slot and disables the control.

Events

None.

Slots

SlotDescription
(default)Button label.
iconOptional leading icon (e.g. an inline SVG).

CSS custom properties

Custom property
--ui-border
--ui-danger
--ui-danger-hover
--ui-focus-ring
--ui-font
--ui-font-size-sm
--ui-font-weight-medium
--ui-line-height-tight
--ui-on-accent
--ui-primary
--ui-primary-hover
--ui-radius-sm
--ui-text
--ui-text-muted