From aea71fa32c2862eadbab528d482444de05467629 Mon Sep 17 00:00:00 2001 From: Hugo Pointcheval Date: Mon, 13 Feb 2023 21:20:34 +0100 Subject: [PATCH] feat(ui_kit): add symbol button --- .../lib/src/core/enums/control_state.dart | 10 +-- .../entities/buttons/button_component.dart | 18 +++--- .../src/domain/entities/buttons/buttons.dart | 2 + .../buttons/flat_button_component.dart | 3 +- .../buttons/flat_button_component.g.dart | 8 +-- .../buttons/symbol_button_component.dart | 61 +++++++++++++++++++ .../buttons/symbol_button_component.g.dart | 30 +++++++++ .../entities/buttons/symbol_button_style.dart | 55 +++++++++++++++++ 8 files changed, 165 insertions(+), 22 deletions(-) create mode 100644 packages/wyatt_ui_components/lib/src/domain/entities/buttons/symbol_button_component.dart create mode 100644 packages/wyatt_ui_components/lib/src/domain/entities/buttons/symbol_button_component.g.dart create mode 100644 packages/wyatt_ui_components/lib/src/domain/entities/buttons/symbol_button_style.dart diff --git a/packages/wyatt_ui_components/lib/src/core/enums/control_state.dart b/packages/wyatt_ui_components/lib/src/core/enums/control_state.dart index a3c36727..e4629e75 100644 --- a/packages/wyatt_ui_components/lib/src/core/enums/control_state.dart +++ b/packages/wyatt_ui_components/lib/src/core/enums/control_state.dart @@ -28,19 +28,11 @@ enum ControlState { tapped, /// When the control is focused (like pressing tab) - focused, - - /// When the control is selected - selected, - - /// When the control content is invalid - invalid; + focused; bool isDisabled() => this == ControlState.disabled; bool isEnabled() => this != ControlState.disabled; bool isHovered() => this == ControlState.hovered; bool isTapped() => this == ControlState.tapped; bool isFocused() => this == ControlState.focused; - bool isSelected() => this == ControlState.selected; - bool isInvalid() => this == ControlState.invalid; } diff --git a/packages/wyatt_ui_components/lib/src/domain/entities/buttons/button_component.dart b/packages/wyatt_ui_components/lib/src/domain/entities/buttons/button_component.dart index ee8f3473..ffaa015a 100644 --- a/packages/wyatt_ui_components/lib/src/domain/entities/buttons/button_component.dart +++ b/packages/wyatt_ui_components/lib/src/domain/entities/buttons/button_component.dart @@ -14,25 +14,21 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -import 'package:flutter/widgets.dart'; -import 'package:wyatt_ui_components/src/domain/entities/buttons/button_style.dart'; -import 'package:wyatt_ui_components/src/domain/entities/component.dart'; +import 'package:wyatt_ui_components/wyatt_wyatt_ui_components.dart'; abstract class ButtonComponent extends Component { const ButtonComponent({ - this.mainAxisSize = MainAxisSize.min, this.disabledStyle, this.normalStyle, this.hoveredStyle, this.focusedStyle, this.tappedStyle, + this.selectedStyle, + this.invalidStyle, this.onPressed, super.key, }); - /// Main axis size - final MainAxisSize? mainAxisSize; - /// Style of this button in disabled state final ButtonStyle? disabledStyle; @@ -48,6 +44,12 @@ abstract class ButtonComponent extends Component { /// Style of this button in tapped state final ButtonStyle? tappedStyle; + /// Style of this button in selected state + final ButtonStyle? selectedStyle; + + /// Style of this button in invalid state + final ButtonStyle? invalidStyle; + /// Callback on button press - final VoidCallback? onPressed; + final void Function(ControlState state)? onPressed; } diff --git a/packages/wyatt_ui_components/lib/src/domain/entities/buttons/buttons.dart b/packages/wyatt_ui_components/lib/src/domain/entities/buttons/buttons.dart index 940eb03a..f645fbd3 100644 --- a/packages/wyatt_ui_components/lib/src/domain/entities/buttons/buttons.dart +++ b/packages/wyatt_ui_components/lib/src/domain/entities/buttons/buttons.dart @@ -18,3 +18,5 @@ export './button_component.dart'; export './button_style.dart'; export './flat_button_component.dart'; export './flat_button_style.dart'; +export './symbol_button_component.dart'; +export './symbol_button_style.dart'; diff --git a/packages/wyatt_ui_components/lib/src/domain/entities/buttons/flat_button_component.dart b/packages/wyatt_ui_components/lib/src/domain/entities/buttons/flat_button_component.dart index 29156d3c..6f5ecb88 100644 --- a/packages/wyatt_ui_components/lib/src/domain/entities/buttons/flat_button_component.dart +++ b/packages/wyatt_ui_components/lib/src/domain/entities/buttons/flat_button_component.dart @@ -24,6 +24,7 @@ part 'flat_button_component.g.dart'; abstract class FlatButtonComponent extends ButtonComponent with CopyWithMixin<$FlatButtonComponentCWProxy> { const FlatButtonComponent({ + this.mainAxisSize = MainAxisSize.min, this.prefix, this.suffix, this.label, @@ -33,7 +34,6 @@ abstract class FlatButtonComponent extends ButtonComponent super.focusedStyle, super.tappedStyle, super.onPressed, - super.mainAxisSize, super.key, }); @@ -52,6 +52,7 @@ abstract class FlatButtonComponent extends ButtonComponent @override FlatButtonStyle? get tappedStyle; + final MainAxisSize? mainAxisSize; final Widget? prefix; final Widget? suffix; final TextWrapper? label; diff --git a/packages/wyatt_ui_components/lib/src/domain/entities/buttons/flat_button_component.g.dart b/packages/wyatt_ui_components/lib/src/domain/entities/buttons/flat_button_component.g.dart index 7b6dac39..442de52f 100644 --- a/packages/wyatt_ui_components/lib/src/domain/entities/buttons/flat_button_component.g.dart +++ b/packages/wyatt_ui_components/lib/src/domain/entities/buttons/flat_button_component.g.dart @@ -7,6 +7,7 @@ part of 'flat_button_component.dart'; // ************************************************************************** abstract class $FlatButtonComponentCWProxy { + FlatButtonComponent mainAxisSize(MainAxisSize? mainAxisSize); FlatButtonComponent prefix(Widget? prefix); FlatButtonComponent suffix(Widget? suffix); FlatButtonComponent label(TextWrapper? label); @@ -15,10 +16,10 @@ abstract class $FlatButtonComponentCWProxy { FlatButtonComponent hoveredStyle(ButtonStyle? hoveredStyle); FlatButtonComponent focusedStyle(ButtonStyle? focusedStyle); FlatButtonComponent tappedStyle(ButtonStyle? tappedStyle); - FlatButtonComponent onPressed(void Function()? onPressed); - FlatButtonComponent mainAxisSize(MainAxisSize? mainAxisSize); + FlatButtonComponent onPressed(void Function(ControlState)? onPressed); FlatButtonComponent key(Key? key); FlatButtonComponent call({ + MainAxisSize? mainAxisSize, Widget? prefix, Widget? suffix, TextWrapper? label, @@ -27,8 +28,7 @@ abstract class $FlatButtonComponentCWProxy { ButtonStyle? hoveredStyle, ButtonStyle? focusedStyle, ButtonStyle? tappedStyle, - void Function()? onPressed, - MainAxisSize? mainAxisSize, + void Function(ControlState)? onPressed, Key? key, }); } diff --git a/packages/wyatt_ui_components/lib/src/domain/entities/buttons/symbol_button_component.dart b/packages/wyatt_ui_components/lib/src/domain/entities/buttons/symbol_button_component.dart new file mode 100644 index 00000000..a811af66 --- /dev/null +++ b/packages/wyatt_ui_components/lib/src/domain/entities/buttons/symbol_button_component.dart @@ -0,0 +1,61 @@ +// Copyright (C) 2023 WYATT GROUP +// Please see the AUTHORS file for details. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +import 'package:flutter/widgets.dart'; +import 'package:wyatt_component_copy_with_extension/component_copy_with_extension.dart'; +import 'package:wyatt_ui_components/wyatt_wyatt_ui_components.dart'; + +part 'symbol_button_component.g.dart'; + +@ComponentProxyExtension() +abstract class SymbolButtonComponent extends ButtonComponent + with CopyWithMixin<$SymbolButtonComponentCWProxy> { + const SymbolButtonComponent({ + this.mainAxisSize = MainAxisSize.min, + this.label, + this.icon, + super.disabledStyle, + super.normalStyle, + super.hoveredStyle, + super.focusedStyle, + super.tappedStyle, + super.selectedStyle, + super.onPressed, + super.key, + }); + + @override + SymbolButtonStyle? get disabledStyle; + + @override + SymbolButtonStyle? get normalStyle; + + @override + SymbolButtonStyle? get hoveredStyle; + + @override + SymbolButtonStyle? get focusedStyle; + + @override + SymbolButtonStyle? get tappedStyle; + + @override + SymbolButtonStyle? get selectedStyle; + + final MainAxisSize? mainAxisSize; + final Widget? icon; + final TextWrapper? label; +} diff --git a/packages/wyatt_ui_components/lib/src/domain/entities/buttons/symbol_button_component.g.dart b/packages/wyatt_ui_components/lib/src/domain/entities/buttons/symbol_button_component.g.dart new file mode 100644 index 00000000..db10e4fb --- /dev/null +++ b/packages/wyatt_ui_components/lib/src/domain/entities/buttons/symbol_button_component.g.dart @@ -0,0 +1,30 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'symbol_button_component.dart'; + +// ************************************************************************** +// ComponentProxyGenerator +// ************************************************************************** + +abstract class $SymbolButtonComponentCWProxy { + SymbolButtonComponent icon(Widget? icon); + SymbolButtonComponent disabledStyle(ButtonStyle? disabledStyle); + SymbolButtonComponent normalStyle(ButtonStyle? normalStyle); + SymbolButtonComponent hoveredStyle(ButtonStyle? hoveredStyle); + SymbolButtonComponent focusedStyle(ButtonStyle? focusedStyle); + SymbolButtonComponent tappedStyle(ButtonStyle? tappedStyle); + SymbolButtonComponent selectedStyle(ButtonStyle? selectedStyle); + SymbolButtonComponent onPressed(void Function(ControlState)? onPressed); + SymbolButtonComponent key(Key? key); + SymbolButtonComponent call({ + Widget? icon, + ButtonStyle? disabledStyle, + ButtonStyle? normalStyle, + ButtonStyle? hoveredStyle, + ButtonStyle? focusedStyle, + ButtonStyle? tappedStyle, + ButtonStyle? selectedStyle, + void Function(ControlState)? onPressed, + Key? key, + }); +} diff --git a/packages/wyatt_ui_components/lib/src/domain/entities/buttons/symbol_button_style.dart b/packages/wyatt_ui_components/lib/src/domain/entities/buttons/symbol_button_style.dart new file mode 100644 index 00000000..2885b0c5 --- /dev/null +++ b/packages/wyatt_ui_components/lib/src/domain/entities/buttons/symbol_button_style.dart @@ -0,0 +1,55 @@ +// Copyright (C) 2023 WYATT GROUP +// Please see the AUTHORS file for details. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +import 'package:flutter/widgets.dart'; +import 'package:wyatt_ui_components/src/core/utils/multi_color.dart'; +import 'package:wyatt_ui_components/src/domain/entities/buttons/button_style.dart'; + +class SymbolButtonStyle extends ButtonStyle { + const SymbolButtonStyle({ + super.radius = 15, + super.padding = 10, + super.foregroundColors, + super.backgroundColors, + super.borderColors, + super.stroke = 2, + super.shadow = const BoxShadow( + blurRadius: 30, + offset: Offset(0, 5), + color: Color.fromRGBO(0, 0, 0, 0.05), + ), + }); + + @override + SymbolButtonStyle copyWith({ + double? radius, + double? padding, + MultiColor? foregroundColors, + MultiColor? backgroundColors, + MultiColor? borderColors, + double? stroke, + BoxShadow? shadow, + }) => + SymbolButtonStyle( + radius: radius ?? this.radius, + padding: padding ?? this.padding, + foregroundColors: foregroundColors ?? this.foregroundColors, + backgroundColors: backgroundColors ?? this.backgroundColors, + borderColors: borderColors ?? this.borderColors, + stroke: stroke ?? this.stroke, + shadow: shadow ?? this.shadow, + ); +}