From afa83fcf101cc9761dc8d8cfd759314552e228fd Mon Sep 17 00:00:00 2001 From: Lucas Oliveira <62367544+tilucasoli@users.noreply.github.com> Date: Wed, 7 Feb 2024 14:01:54 -0300 Subject: [PATCH] api usage refinement --- demo/lib/components/button.dart | 4 ++-- demo/lib/components/checkbox.dart | 4 ++-- demo/lib/components/list_tile.dart | 4 +--- lib/components/button/button.dart | 12 +++++----- lib/components/button/button.style.dart | 29 +++++++++++++------------ lib/components/card/card.dart | 12 +++++++++- lib/components/checkbox/checkbox.dart | 14 ++++++------ test/components/button_test.dart | 4 ++-- test/components/checkbox_test.dart | 15 ++++++------- 9 files changed, 53 insertions(+), 45 deletions(-) diff --git a/demo/lib/components/button.dart b/demo/lib/components/button.dart index 91aa4a6..f9967e1 100644 --- a/demo/lib/components/button.dart +++ b/demo/lib/components/button.dart @@ -15,7 +15,7 @@ Widget buildButtonUseCase(BuildContext context) { initialValue: 'Title', ), onPressed: () {}, - isLoading: context.knobs.boolean( + loading: context.knobs.boolean( label: 'Is loading', initialValue: false, ), @@ -23,7 +23,7 @@ Widget buildButtonUseCase(BuildContext context) { label: 'Loading label', initialValue: 'Loading', ), - isDisabled: context.knobs.boolean( + disabled: context.knobs.boolean( label: 'Disabled', initialValue: false, ), diff --git a/demo/lib/components/checkbox.dart b/demo/lib/components/checkbox.dart index 9c43555..0208627 100644 --- a/demo/lib/components/checkbox.dart +++ b/demo/lib/components/checkbox.dart @@ -15,11 +15,11 @@ Widget buildCheckboxUseCase(BuildContext context) { initialValue: 'Title', ), onChanged: (value) {}, - isChecked: context.knobs.boolean( + checked: context.knobs.boolean( label: 'Checked', initialValue: false, ), - isDisabled: context.knobs.boolean( + disabled: context.knobs.boolean( label: 'Disabled', initialValue: false, ), diff --git a/demo/lib/components/list_tile.dart b/demo/lib/components/list_tile.dart index 8afe174..c846d39 100644 --- a/demo/lib/components/list_tile.dart +++ b/demo/lib/components/list_tile.dart @@ -22,9 +22,7 @@ Widget buildCheckboxUseCase(BuildContext context) { ), ), ), - child: StyledText( - 'LF', - ), + child: StyledText('LF'), ), title: StyledText( context.knobs.string( diff --git a/lib/components/button/button.dart b/lib/components/button/button.dart index 06f8c18..29e19e8 100644 --- a/lib/components/button/button.dart +++ b/lib/components/button/button.dart @@ -10,8 +10,8 @@ class RemixButton extends StatelessWidget const RemixButton({ super.key, this.label, - this.isDisabled = false, - this.isLoading = false, + this.disabled = false, + this.loading = false, this.iconLeft, this.iconRight, this.type = ButtonType.primary, @@ -23,8 +23,8 @@ class RemixButton extends StatelessWidget }); final String? label; - final bool isDisabled; - final bool isLoading; + final bool disabled; + final bool loading; final String? loadingLabel; final IconData? iconLeft; final IconData? iconRight; @@ -44,7 +44,7 @@ class RemixButton extends StatelessWidget } List _buildChildren(BuildContext context, ButtonStyles style) { - if (isLoading) { + if (loading) { return _buildLoadingChildren(context, style); } return _buildDefaultChildren(style); @@ -88,7 +88,7 @@ class RemixButton extends StatelessWidget final style = buildStyle([size, type, ...variants]); return PressableBox( - onPressed: isDisabled || isLoading ? null : onPressed, + onPressed: disabled || loading ? null : onPressed, child: HBox( style: style.container, children: _buildChildren(context, style), diff --git a/lib/components/button/button.style.dart b/lib/components/button/button.style.dart index 94db268..3892b43 100644 --- a/lib/components/button/button.style.dart +++ b/lib/components/button/button.style.dart @@ -86,39 +86,40 @@ Style _container() => Style( box.padding.vertical(10), ), ButtonType.primary( - box.decoration.color.black(), + box.color.black(), onHover( - box.decoration.color.black87(), + box.color.black87(), ), ), ButtonType.secondary( - box.decoration.color.grey.shade200(), + box.color.grey.shade200(), onHover( - box.decoration.color.grey.shade100(), + box.color.grey.shade100(), ), ), ButtonType.destructive( - box.decoration.color.redAccent(), + box.color.redAccent(), onHover( - box.decoration.color.redAccent.shade200(), + box.color.redAccent.shade200(), ), ), ButtonType.outline( - box.decoration.color.white(), - box.decoration.border(width: 1.5, color: Colors.black12), - box.decoration.boxShadow.color(Colors.black12.withOpacity(0.1)), - box.decoration.boxShadow.blurRadius(1), + box.color.white(), + box.border.width(1.5), + box.border.color.black12(), + box.shadow.color(Colors.black12.withOpacity(0.1)), + box.shadow.blurRadius(1), ), ButtonType.ghost( - box.decoration.color(Colors.transparent), + box.color.transparent(), onHover( - box.decoration.color(Colors.black12), + box.color.black12(), ), ), ButtonType.link( - box.decoration.color(Colors.transparent), + box.color.transparent(), ), - box.decoration.borderRadius(6), + box.borderRadius(6), ); Style _icon() => Style( diff --git a/lib/components/card/card.dart b/lib/components/card/card.dart index 72f5e12..60a8e2b 100644 --- a/lib/components/card/card.dart +++ b/lib/components/card/card.dart @@ -6,9 +6,19 @@ class PresableRemixCard extends RemixCard { const PresableRemixCard({ super.key, required super.child, - void Function()? onTap, + this.onTap, super.style, }); + + final void Function()? onTap; + + @override + Widget build(BuildContext context) { + return Pressable( + onPressed: onTap, + child: super.build(context), + ); + } } class RemixCard extends StatelessWidget { diff --git a/lib/components/checkbox/checkbox.dart b/lib/components/checkbox/checkbox.dart index 01346ae..1071428 100644 --- a/lib/components/checkbox/checkbox.dart +++ b/lib/components/checkbox/checkbox.dart @@ -10,8 +10,8 @@ class RemixCheckbox extends StatelessWidget const RemixCheckbox({ super.key, this.label, - this.isDisabled = false, - this.isChecked = false, + this.disabled = false, + this.checked = false, this.onChanged, this.iconChecked = Icons.check_rounded, this.iconUnchecked, @@ -20,8 +20,8 @@ class RemixCheckbox extends StatelessWidget }); final String? label; - final bool isDisabled; - final bool isChecked; + final bool disabled; + final bool checked; final IconData iconChecked; final IconData? iconUnchecked; final ValueChanged? onChanged; @@ -41,13 +41,13 @@ class RemixCheckbox extends StatelessWidget @override Widget build(BuildContext context) { var internalVariants = - isChecked ? CheckboxState.checked : CheckboxState.unchecked; + checked ? CheckboxState.checked : CheckboxState.unchecked; final style = buildStyle([internalVariants, ...variants]); return Pressable( onPressed: - onChanged == null || isDisabled ? null : () => onChanged!(!isChecked), + onChanged == null || disabled ? null : () => onChanged!(!checked), child: HBox( style: style.flexContainer, children: [ @@ -55,7 +55,7 @@ class RemixCheckbox extends StatelessWidget style: style.innerContainer, duration: const Duration(milliseconds: 150), child: StyledIcon( - isChecked ? iconChecked : iconUnchecked, + checked ? iconChecked : iconUnchecked, style: style.icon, ), ), diff --git a/test/components/button_test.dart b/test/components/button_test.dart index 3a74276..bf9461e 100644 --- a/test/components/button_test.dart +++ b/test/components/button_test.dart @@ -28,7 +28,7 @@ void main() { await tester.pumpWidget( MaterialApp( home: RemixButton( - isLoading: true, + loading: true, loadingLabel: loadingLabel, onPressed: () {}, ), @@ -70,7 +70,7 @@ void main() { onPressed: () { didCallOnPressed = true; }, - isDisabled: true, + disabled: true, ), )); diff --git a/test/components/checkbox_test.dart b/test/components/checkbox_test.dart index c907299..c2fa04f 100644 --- a/test/components/checkbox_test.dart +++ b/test/components/checkbox_test.dart @@ -12,7 +12,7 @@ void main() { await tester.pumpWidget( MaterialApp( home: RemixCheckbox( - isChecked: isChecked, + checked: isChecked, label: 'Checkbox', onChanged: (value) { expect(value, !isChecked); @@ -32,8 +32,8 @@ void main() { await tester.pumpWidget(MaterialApp( home: Scaffold( body: RemixCheckbox( - isChecked: false, - isDisabled: true, + checked: false, + disabled: true, onChanged: (value) { didCallOnChanged = true; }, @@ -52,7 +52,7 @@ void main() { for (var isChecked in [true, false]) { await tester.pumpWidget(MaterialApp( home: RemixCheckbox( - isChecked: isChecked, + checked: isChecked, label: 'Checkbox', onChanged: (value) {}, ), @@ -60,8 +60,7 @@ void main() { expect( find.byWidgetPredicate( - (widget) => - widget is RemixCheckbox && widget.isChecked == isChecked, + (widget) => widget is RemixCheckbox && widget.checked == isChecked, ), findsOneWidget, ); @@ -73,7 +72,7 @@ void main() { await tester.pumpWidget(MaterialApp( home: RemixCheckbox( - isChecked: false, + checked: false, label: label, onChanged: (value) {}, ), @@ -95,7 +94,7 @@ void main() { for (var isChecked in [true, false]) { await tester.pumpWidget(MaterialApp( home: RemixCheckbox( - isChecked: isChecked, + checked: isChecked, iconChecked: iconChecked, iconUnchecked: iconUnchecked, label: 'Checkbox',