From 4e7b84523b99406083f431853c94719e3a55d63d Mon Sep 17 00:00:00 2001 From: Hugo Pointcheval Date: Mon, 13 Feb 2023 17:07:39 +0100 Subject: [PATCH] refactor(ui_component): merge flat and outline buttons in only one style --- .../entities/buttons/button_component.dart | 31 +++++++--- .../domain/entities/buttons/button_style.dart | 12 ++++ .../src/domain/entities/buttons/buttons.dart | 2 - .../buttons/flat_button_component.dart | 22 ++++++- .../buttons/flat_button_component.g.dart | 16 +++-- .../entities/buttons/flat_button_style.dart | 10 +++- .../buttons/outlined_button_component.dart | 42 -------------- .../buttons/outlined_button_component.g.dart | 26 --------- .../buttons/outlined_button_style.dart | 58 ------------------- 9 files changed, 75 insertions(+), 144 deletions(-) delete mode 100644 packages/wyatt_ui_components/lib/src/domain/entities/buttons/outlined_button_component.dart delete mode 100644 packages/wyatt_ui_components/lib/src/domain/entities/buttons/outlined_button_component.g.dart delete mode 100644 packages/wyatt_ui_components/lib/src/domain/entities/buttons/outlined_button_style.dart 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 f87c19e7..ee8f3473 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 @@ -15,24 +15,39 @@ // along with this program. If not, see . import 'package:flutter/widgets.dart'; -import 'package:wyatt_ui_components/src/core/enums/control_state.dart'; import 'package:wyatt_ui_components/src/domain/entities/buttons/button_style.dart'; import 'package:wyatt_ui_components/src/domain/entities/component.dart'; abstract class ButtonComponent extends Component { const ButtonComponent({ - this.state = ControlState.normal, this.mainAxisSize = MainAxisSize.min, - this.style, + this.disabledStyle, + this.normalStyle, + this.hoveredStyle, + this.focusedStyle, + this.tappedStyle, + this.onPressed, super.key, }); - /// Actual state of the button - final ControlState? state; - /// Main axis size final MainAxisSize? mainAxisSize; - /// Style of this button - final ButtonStyle? style; + /// Style of this button in disabled state + final ButtonStyle? disabledStyle; + + /// Style of this button in normal state + final ButtonStyle? normalStyle; + + /// Style of this button in hovered state + final ButtonStyle? hoveredStyle; + + /// Style of this button in focused state + final ButtonStyle? focusedStyle; + + /// Style of this button in tapped state + final ButtonStyle? tappedStyle; + + /// Callback on button press + final VoidCallback? onPressed; } diff --git a/packages/wyatt_ui_components/lib/src/domain/entities/buttons/button_style.dart b/packages/wyatt_ui_components/lib/src/domain/entities/buttons/button_style.dart index 362ecb8d..22620337 100644 --- a/packages/wyatt_ui_components/lib/src/domain/entities/buttons/button_style.dart +++ b/packages/wyatt_ui_components/lib/src/domain/entities/buttons/button_style.dart @@ -21,7 +21,10 @@ abstract class ButtonStyle { const ButtonStyle({ this.radius = 15, this.padding = 10, + this.foregroundColors, this.backgroundColors, + this.borderColors, + this.stroke = 2, this.shadow = const BoxShadow( blurRadius: 30, offset: Offset(0, 5), @@ -35,9 +38,18 @@ abstract class ButtonStyle { /// Padding and gaps of this card final double? padding; + /// Button foreground gradient colors (from left to right) + final MultiColor? foregroundColors; + /// Button background gradient colors (from left to right) final MultiColor? backgroundColors; + /// Border colors (from left to right). + final MultiColor? borderColors; + + /// Stroke of the border + final double? stroke; + /// Drop shadow final BoxShadow? shadow; 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 c3c58180..940eb03a 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,5 +18,3 @@ export './button_component.dart'; export './button_style.dart'; export './flat_button_component.dart'; export './flat_button_style.dart'; -export './outlined_button_component.dart'; -export './outlined_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 33cdbb7f..29156d3c 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 @@ -27,14 +27,30 @@ abstract class FlatButtonComponent extends ButtonComponent this.prefix, this.suffix, this.label, - super.state, - super.style, + super.disabledStyle, + super.normalStyle, + super.hoveredStyle, + super.focusedStyle, + super.tappedStyle, + super.onPressed, super.mainAxisSize, super.key, }); @override - FlatButtonStyle? get style; + FlatButtonStyle? get disabledStyle; + + @override + FlatButtonStyle? get normalStyle; + + @override + FlatButtonStyle? get hoveredStyle; + + @override + FlatButtonStyle? get focusedStyle; + + @override + FlatButtonStyle? get tappedStyle; final Widget? prefix; final Widget? suffix; 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 2d54e3ca..7b6dac39 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 @@ -10,16 +10,24 @@ abstract class $FlatButtonComponentCWProxy { FlatButtonComponent prefix(Widget? prefix); FlatButtonComponent suffix(Widget? suffix); FlatButtonComponent label(TextWrapper? label); - FlatButtonComponent state(ControlState? state); - FlatButtonComponent style(ButtonStyle? style); + FlatButtonComponent disabledStyle(ButtonStyle? disabledStyle); + FlatButtonComponent normalStyle(ButtonStyle? normalStyle); + FlatButtonComponent hoveredStyle(ButtonStyle? hoveredStyle); + FlatButtonComponent focusedStyle(ButtonStyle? focusedStyle); + FlatButtonComponent tappedStyle(ButtonStyle? tappedStyle); + FlatButtonComponent onPressed(void Function()? onPressed); FlatButtonComponent mainAxisSize(MainAxisSize? mainAxisSize); FlatButtonComponent key(Key? key); FlatButtonComponent call({ Widget? prefix, Widget? suffix, TextWrapper? label, - ControlState? state, - ButtonStyle? style, + ButtonStyle? disabledStyle, + ButtonStyle? normalStyle, + ButtonStyle? hoveredStyle, + ButtonStyle? focusedStyle, + ButtonStyle? tappedStyle, + void Function()? onPressed, MainAxisSize? mainAxisSize, Key? key, }); diff --git a/packages/wyatt_ui_components/lib/src/domain/entities/buttons/flat_button_style.dart b/packages/wyatt_ui_components/lib/src/domain/entities/buttons/flat_button_style.dart index aca7e5a2..355965ab 100644 --- a/packages/wyatt_ui_components/lib/src/domain/entities/buttons/flat_button_style.dart +++ b/packages/wyatt_ui_components/lib/src/domain/entities/buttons/flat_button_style.dart @@ -22,7 +22,10 @@ class FlatButtonStyle extends ButtonStyle { const FlatButtonStyle({ 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), @@ -34,14 +37,19 @@ class FlatButtonStyle extends ButtonStyle { FlatButtonStyle copyWith({ double? radius, double? padding, + MultiColor? foregroundColors, MultiColor? backgroundColors, - BoxShadow? shadow, + MultiColor? borderColors, double? stroke, + BoxShadow? shadow, }) => FlatButtonStyle( 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, ); } diff --git a/packages/wyatt_ui_components/lib/src/domain/entities/buttons/outlined_button_component.dart b/packages/wyatt_ui_components/lib/src/domain/entities/buttons/outlined_button_component.dart deleted file mode 100644 index 36ebac09..00000000 --- a/packages/wyatt_ui_components/lib/src/domain/entities/buttons/outlined_button_component.dart +++ /dev/null @@ -1,42 +0,0 @@ -// 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 'outlined_button_component.g.dart'; - -@ComponentProxyExtension() -abstract class OutlinedButtonComponent extends ButtonComponent - with CopyWithMixin<$OutlinedButtonComponentCWProxy> { - const OutlinedButtonComponent({ - this.prefix, - this.suffix, - this.label, - super.state, - super.style, - super.mainAxisSize, - super.key, - }); - - @override - OutlinedButtonStyle? get style; - - final Widget? prefix; - final Widget? suffix; - final TextWrapper? label; -} diff --git a/packages/wyatt_ui_components/lib/src/domain/entities/buttons/outlined_button_component.g.dart b/packages/wyatt_ui_components/lib/src/domain/entities/buttons/outlined_button_component.g.dart deleted file mode 100644 index f2471b16..00000000 --- a/packages/wyatt_ui_components/lib/src/domain/entities/buttons/outlined_button_component.g.dart +++ /dev/null @@ -1,26 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'outlined_button_component.dart'; - -// ************************************************************************** -// ComponentProxyGenerator -// ************************************************************************** - -abstract class $OutlinedButtonComponentCWProxy { - OutlinedButtonComponent prefix(Widget? prefix); - OutlinedButtonComponent suffix(Widget? suffix); - OutlinedButtonComponent label(TextWrapper? label); - OutlinedButtonComponent state(ControlState? state); - OutlinedButtonComponent style(ButtonStyle? style); - OutlinedButtonComponent mainAxisSize(MainAxisSize? mainAxisSize); - OutlinedButtonComponent key(Key? key); - OutlinedButtonComponent call({ - Widget? prefix, - Widget? suffix, - TextWrapper? label, - ControlState? state, - ButtonStyle? style, - MainAxisSize? mainAxisSize, - Key? key, - }); -} diff --git a/packages/wyatt_ui_components/lib/src/domain/entities/buttons/outlined_button_style.dart b/packages/wyatt_ui_components/lib/src/domain/entities/buttons/outlined_button_style.dart deleted file mode 100644 index 7ba8de93..00000000 --- a/packages/wyatt_ui_components/lib/src/domain/entities/buttons/outlined_button_style.dart +++ /dev/null @@ -1,58 +0,0 @@ -// 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 OutlinedButtonStyle extends ButtonStyle { - const OutlinedButtonStyle({ - super.radius = 15, - super.padding = 10, - super.backgroundColors, - super.shadow = const BoxShadow( - blurRadius: 30, - offset: Offset(0, 5), - color: Color.fromRGBO(0, 0, 0, 0.05), - ), - this.borderColors, - this.stroke = 2, - }); - - /// Border colors (from left to right). - final MultiColor? borderColors; - - /// Stroke of the border - final double? stroke; - - @override - OutlinedButtonStyle copyWith({ - double? radius, - double? padding, - MultiColor? borderColors, - MultiColor? backgroundColors, - BoxShadow? shadow, - double? stroke, - }) => - OutlinedButtonStyle( - radius: radius ?? this.radius, - padding: padding ?? this.padding, - borderColors: borderColors ?? this.borderColors, - backgroundColors: backgroundColors ?? this.backgroundColors, - shadow: shadow ?? this.shadow, - stroke: stroke ?? this.stroke, - ); -}