From a46712e7637196de7d3b4923623ab9598e5066c4 Mon Sep 17 00:00:00 2001 From: Hugo Pointcheval Date: Thu, 16 Feb 2023 15:12:40 +0100 Subject: [PATCH] feat(ui_component): add loader component and style --- .../lib/src/domain/entities/entities.dart | 2 + .../src/domain/entities/loader_component.dart | 50 +++++++++++ .../domain/entities/loader_component.g.dart | 27 ++++++ .../lib/src/domain/entities/loader_style.dart | 86 +++++++++++++++++++ 4 files changed, 165 insertions(+) create mode 100644 packages/wyatt_ui_components/lib/src/domain/entities/loader_component.dart create mode 100644 packages/wyatt_ui_components/lib/src/domain/entities/loader_component.g.dart create mode 100644 packages/wyatt_ui_components/lib/src/domain/entities/loader_style.dart diff --git a/packages/wyatt_ui_components/lib/src/domain/entities/entities.dart b/packages/wyatt_ui_components/lib/src/domain/entities/entities.dart index 39ae2f65..f04375b8 100644 --- a/packages/wyatt_ui_components/lib/src/domain/entities/entities.dart +++ b/packages/wyatt_ui_components/lib/src/domain/entities/entities.dart @@ -20,5 +20,7 @@ export './buttons/buttons.dart'; export './cards/cards.dart'; export './component.dart'; export './error_widget_component.dart'; +export './loader_component.dart'; +export './loader_style.dart'; export './loading_widget_component.dart'; export './theme_style.dart'; diff --git a/packages/wyatt_ui_components/lib/src/domain/entities/loader_component.dart b/packages/wyatt_ui_components/lib/src/domain/entities/loader_component.dart new file mode 100644 index 00000000..9d26ba10 --- /dev/null +++ b/packages/wyatt_ui_components/lib/src/domain/entities/loader_component.dart @@ -0,0 +1,50 @@ +// 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 'loader_component.g.dart'; + +@ComponentProxyExtension() +abstract class LoaderComponent extends Component + with CopyWithMixin<$LoaderComponentCWProxy> { + const LoaderComponent({ + this.colors, + this.radius, + this.stroke, + this.duration, + this.flip, + super.themeResolver, + super.key, + }); + + /// Gradient colors from start to end. + final MultiColor? colors; + + /// Loader radius + final double? radius; + + /// Loader stroke width + final double? stroke; + + /// Animation duration + final Duration? duration; + + /// Flip the animation + final bool? flip; +} diff --git a/packages/wyatt_ui_components/lib/src/domain/entities/loader_component.g.dart b/packages/wyatt_ui_components/lib/src/domain/entities/loader_component.g.dart new file mode 100644 index 00000000..61b302b2 --- /dev/null +++ b/packages/wyatt_ui_components/lib/src/domain/entities/loader_component.g.dart @@ -0,0 +1,27 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'loader_component.dart'; + +// ************************************************************************** +// ComponentProxyGenerator +// ************************************************************************** + +abstract class $LoaderComponentCWProxy { + LoaderComponent colors(MultiColor? colors); + LoaderComponent radius(double? radius); + LoaderComponent stroke(double? stroke); + LoaderComponent duration(Duration? duration); + LoaderComponent flip(bool? flip); + LoaderComponent themeResolver( + ThemeResolver? themeResolver); + LoaderComponent key(Key? key); + LoaderComponent call({ + MultiColor? colors, + double? radius, + double? stroke, + Duration? duration, + bool? flip, + ThemeResolver? themeResolver, + Key? key, + }); +} diff --git a/packages/wyatt_ui_components/lib/src/domain/entities/loader_style.dart b/packages/wyatt_ui_components/lib/src/domain/entities/loader_style.dart new file mode 100644 index 00000000..43c3253c --- /dev/null +++ b/packages/wyatt_ui_components/lib/src/domain/entities/loader_style.dart @@ -0,0 +1,86 @@ +// 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 'dart:ui'; + +import 'package:wyatt_ui_components/wyatt_wyatt_ui_components.dart'; + +class LoaderStyle extends ThemeStyle { + const LoaderStyle({ + this.colors, + this.stroke, + }); + + /// Merges non-null `b` attributes in `a` + static LoaderStyle? merge( + LoaderStyle? a, + LoaderStyle? b, + ) { + if (b == null) { + return a?.copyWith(); + } + if (a == null) { + return b.copyWith(); + } + + return a.copyWith( + colors: b.colors, + stroke: b.stroke, + ); + } + + /// Used for interpolation. + static LoaderStyle? lerp( + LoaderStyle? a, + LoaderStyle? b, + double t, + ) { + if (a == null || b == null) { + return null; + } + // b.copyWith to return b attributes even if they are not lerped + return b.copyWith( + colors: MultiColor.lerp(a.colors, b.colors, t), + stroke: lerpDouble(a.stroke, b.stroke, t), + ); + } + + /// Gradient colors from start to end. + final MultiColor? colors; + + /// Loader stroke width + final double? stroke; + + @override + LoaderStyle mergeWith(LoaderStyle? other) => LoaderStyle.merge(this, other)!; + + @override + LoaderStyle? lerpWith(LoaderStyle? other, double t) => + LoaderStyle.lerp(this, other, t); + + @override + LoaderStyle copyWith({ + MultiColor? colors, + double? stroke, + }) => + LoaderStyle( + colors: colors ?? this.colors, + stroke: stroke ?? this.stroke, + ); + + @override + String toString() => 'LoaderStyle($colors, $stroke)'; +}