Components · engine.button · version 0.1.0

Button

Triggers an action. Renders a native button.

Preview

Every variant in every state, drawn by the same definition that the Figma sync and the tests use.

button in every variant and size and state
variant and sizerestloadingdisableddisabled, loadingfocusfocus, loadinghoverhover, focuspressedpressed, focus
primary · sm
primary · md
primary · lg
secondary · sm
secondary · md
secondary · lg
ghost · sm
ghost · md
ghost · lg
danger · sm
danger · md
danger · lg

Install

npm install @uiuxengine/react

Components come from npm and stay identical to their definition and their Figma component. See Installation.

Usage

import { Button } from "@uiuxengine/react";
import { IconChevronDown } from "@uiuxicons/react/icons/chevron-down";
import { IconPlus } from "@uiuxicons/react/icons/plus";

export function Example() {
  return (
    <Button label="Button" leadingIcon={IconPlus} trailingIcon={IconChevronDown} />
  );
}

Guidelines

  • Use primary for the single most important action in a view, secondary for other actions, ghost in dense toolbars, danger for destructive actions.
  • Labels are short verbs or verb phrases, for example 'Run analysis'.
  • Icon-only buttons need an accessibleLabel that says what the button does.
  • Use loading while the action runs. The button stays focusable and ignores presses.
  • Size is local to the button. Density comes from the surrounding application, never from a prop.

Props

PropTypeDefaultDescription
variant"primary" | "secondary" | "ghost" | "danger"secondaryVisual emphasis.
size"sm" | "md" | "lg"mdSize within the current density.
labeltext, up to 80—Visible text. Also the accessible name.
accessibleLabeltext, up to 160—Accessible name when there is no visible label, or to make the visible label more specific.
disabledbooleanfalsePrevents interaction.
loadingbooleanfalseShows a spinner and ignores presses.

Slots

SlotTakesDescription
leadingIconiconIcon before the label.
trailingIconiconIcon after the label.

Events

press
The button was activated by pointer, keyboard or an authorized agent.

Accessibility

  • Renders a native <button> with the role button.
  • loading is announced as aria-busy.
  • A button needs a label or an accessibleLabel.
  • A button needs a label or an icon.

As a spec

Agents describe interfaces as JSON specs. A spec renders only after it validates against the installed contracts, the approved icons and the host's actions. Edit it to see.

No actions yet.

JSON Schema of the props
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "urn:uiuxengine:component:engine.button@0.1.0",
  "title": "button",
  "description": "Triggers an action. Renders a native button.",
  "type": "object",
  "properties": {
    "variant": {
      "description": "Visual emphasis.",
      "type": "string",
      "enum": [
        "primary",
        "secondary",
        "ghost",
        "danger"
      ],
      "default": "secondary"
    },
    "size": {
      "description": "Size within the current density.",
      "type": "string",
      "enum": [
        "sm",
        "md",
        "lg"
      ],
      "default": "md"
    },
    "label": {
      "description": "Visible text. Also the accessible name.",
      "type": "string",
      "maxLength": 80
    },
    "accessibleLabel": {
      "description": "Accessible name when there is no visible label, or to make the visible label more specific.",
      "type": "string",
      "maxLength": 160
    },
    "disabled": {
      "description": "Prevents interaction.",
      "type": "boolean",
      "default": false
    },
    "loading": {
      "description": "Shows a spinner and ignores presses.",
      "type": "boolean",
      "default": false
    },
    "leadingIcon": {
      "$ref": "#/$defs/iconRef",
      "description": "Icon before the label."
    },
    "trailingIcon": {
      "$ref": "#/$defs/iconRef",
      "description": "Icon after the label."
    }
  },
  "additionalProperties": false,
  "allOf": [
    {
      "anyOf": [
        {
          "required": [
            "label"
          ]
        },
        {
          "required": [
            "accessibleLabel"
          ]
        }
      ]
    },
    {
      "anyOf": [
        {
          "required": [
            "label"
          ]
        },
        {
          "required": [
            "leadingIcon"
          ]
        },
        {
          "required": [
            "trailingIcon"
          ]
        }
      ]
    }
  ],
  "$defs": {
    "iconRef": {
      "type": "object",
      "description": "A reference to an icon in the host's approved catalog.",
      "properties": {
        "type": {
          "const": "icon"
        },
        "id": {
          "type": "string",
          "pattern": "^[a-z0-9]+(?:-[a-z0-9]+)*$"
        },
        "style": {
          "type": "string",
          "pattern": "^[a-z0-9]+(?:-[a-z0-9]+)*$"
        },
        "weight": {
          "type": "string",
          "pattern": "^[a-z0-9]+(?:-[a-z0-9]+)*$"
        }
      },
      "required": [
        "type",
        "id"
      ],
      "additionalProperties": false
    }
  }
}