button function

HTMLButtonElement button(
  1. String label, {
  2. bool primary = false,
  3. bool loading = false,
  4. bool disabled = false,
  5. String? className,
  6. String? ariaLabel,
  7. void onClick()?,
})

A primary or secondary button. When loading it shows a spinner and is disabled.

Implementation

web.HTMLButtonElement button(
  String label, {
  bool primary = false,
  bool loading = false,
  bool disabled = false,
  String? className,
  String? ariaLabel,
  void Function()? onClick,
}) {
  final classes = [if (primary) 'primary', ?className].join(' ');
  final b =
      el(
            'button',
            classes: classes.isEmpty ? null : classes,
            ariaLabel: ariaLabel,
            onClick: onClick == null ? null : (_) => onClick(),
          )
          as web.HTMLButtonElement;
  b.type = 'button';
  if (loading) {
    b.appendChild(el('span', classes: 'spinner'));
    b.appendChild(textNode(' $label'));
  } else {
    b.textContent = label;
  }
  b.disabled = disabled || loading;
  return b;
}