Button constructor

Button({
  1. Object? child,
  2. List<Object?> children = const [],
  3. String? className,
  4. Map<String, Object?> props = const {},
  5. Map<String, Object?> style = const {},
  6. DartStyle? dartStyle,
  7. ButtonVariant variant = ButtonVariant.solid,
  8. Tone tone = Tone.primary,
  9. ComponentSize size = ComponentSize.md,
  10. bool loading = false,
  11. bool disabled = false,
  12. void onPressed(
    1. Object event
    )?,
})

Creates a button with optional child content and click handling.

Implementation

Button({
  Object? child,
  List<Object?> children = const [],
  String? className,
  Map<String, Object?> props = const {},
  Map<String, Object?> style = const {},
  DartStyle? dartStyle,
  ButtonVariant variant = ButtonVariant.solid,
  Tone tone = Tone.primary,
  ComponentSize size = ComponentSize.md,
  bool loading = false,
  bool disabled = false,
  void Function(Object event)? onPressed,
}) : super(
        'button',
        props: mergeComponentProps(
          {
            ...props,
            'type': props['type'] ?? 'button',
            if (disabled || loading) 'disabled': true,
            if (loading) 'aria-busy': 'true',
            if (onPressed != null && !disabled && !loading)
              'onClick': onPressed,
          },
          className: className,
          dartStyle: buttonComponentStyle(
            variant: variant,
            tone: tone,
            size: size,
            disabled: disabled,
            loading: loading,
          ).merge(dartStyle),
          style: style,
        ),
        children: [
          if (loading) Spinner(size: ComponentSize.xs, tone: tone),
          ...normalizeChildren(child, children),
        ],
      );