Button constructor

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

Creates a button with optional child content and click handling.

Implementation

Button({
  Object? child,
  String? label,
  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,
  Function? onClick,
}) : super(
        'button',
        props: mergeComponentProps(
          {
            ...props,
            'type': props['type'] ?? 'button',
            if (disabled || loading) 'disabled': true,
            if (loading) 'aria-busy': 'true',
            if ((onPressed != null || onClick != null) &&
                !disabled &&
                !loading)
              'onClick': onPressed ?? _normalizeClickHandler(onClick),
          },
          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 ?? label, children),
        ],
      );