amenui
en·中 github ↗ v0.0.1
01docs 02components 03lab 04works
en·中github ↗
×

docs / components / inputs / button docs / components / inputs /

button

04.1
On this page ▾
  1. Installation
  2. Usage
  3. Examples
  4. API
  5. Keyboard and accessibility

Perform an action.

It fires on press, and Enter or Space fire it too.

drawn by amenuiopen ↗

Installation

Components are distributed as source. Copy it and what it depends on into your project, then change it as you need:

sh
cargo run --release --bin amenui -- add button --to ../my-app

Files copied: src/widgets/button.rs, src/widgets/mod.rs

Usage

rust
use amenui::widgets::{button, button_as};

fn view() -> El<Msg> {
    button_as("b1", "保存", Variant::Default, Msg::Nothing)
}

Examples

Quiet

rust
fn view() -> El<Msg> {
    button_as("b2", "取消", Variant::Quiet, Msg::Nothing)
}

Accent

rust
fn view() -> El<Msg> {
    button_as("b3", "发布", Variant::Accent, Msg::Nothing)
}

Disabled

rust
fn view() -> El<Msg> {
    button_as("b4", "发布", Variant::Accent, Msg::Nothing).disabled(true)
}

Primary

rust
fn view() -> El<Msg> {
    button_as("b5", "Save", Variant::Primary, Msg::Nothing)
}

API

Functionsbutton, button_as
Propskey, label, v: Variant (Default outlined, Quiet, Primary an ink plate, Accent filled), msg.
Filessrc/widgets/button.rs
Depends onbase
Response to frontsnudge (a control: pushed as one piece by fronts, held and condensing at most to Look::legible_cap)
Recompositionkeyed labels recompose when their text changes

Keyboard and accessibility

Statesrest, hovered, focused, pressed (held at the legibility cap, condenses back from it), disabled (.disabled(true)).
Keys and messagessends msg on press, Enter or Space; its front reaches only itself unless .ripplr(..) says otherwise.

On the web every control is mirrored into the page as an element with its role and name, so screen readers and the browser's own focus see it (DESIGN.md §1.14).

Recipes: A form