button function
HTMLButtonElement
button(})
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;
}