Skip to content

Commit

Permalink
Merge pull request #17 from conceptadev/feat/improve-api-usage
Browse files Browse the repository at this point in the history
Improve API
  • Loading branch information
leoafarias authored Feb 23, 2024
2 parents 13a2b5c + afa83fc commit 8f9d98b
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 45 deletions.
4 changes: 2 additions & 2 deletions demo/lib/components/button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ Widget buildButtonUseCase(BuildContext context) {
initialValue: 'Title',
),
onPressed: () {},
isLoading: context.knobs.boolean(
loading: context.knobs.boolean(
label: 'Is loading',
initialValue: false,
),
loadingLabel: context.knobs.stringOrNull(
label: 'Loading label',
initialValue: 'Loading',
),
isDisabled: context.knobs.boolean(
disabled: context.knobs.boolean(
label: 'Disabled',
initialValue: false,
),
Expand Down
4 changes: 2 additions & 2 deletions demo/lib/components/checkbox.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
),
Expand Down
4 changes: 1 addition & 3 deletions demo/lib/components/list_tile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ Widget buildCheckboxUseCase(BuildContext context) {
),
),
),
child: StyledText(
'LF',
),
child: StyledText('LF'),
),
title: StyledText(
context.knobs.string(
Expand Down
12 changes: 6 additions & 6 deletions lib/components/button/button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand All @@ -44,7 +44,7 @@ class RemixButton extends StatelessWidget
}

List<Widget> _buildChildren(BuildContext context, ButtonStyles style) {
if (isLoading) {
if (loading) {
return _buildLoadingChildren(context, style);
}
return _buildDefaultChildren(style);
Expand Down Expand Up @@ -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),
Expand Down
29 changes: 15 additions & 14 deletions lib/components/button/button.style.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
12 changes: 11 additions & 1 deletion lib/components/card/card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,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
Expand Down
14 changes: 7 additions & 7 deletions lib/components/checkbox/checkbox.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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<bool>? onChanged;
Expand All @@ -41,21 +41,21 @@ 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: [
AnimatedBox(
style: style.innerContainer,
duration: const Duration(milliseconds: 150),
child: StyledIcon(
isChecked ? iconChecked : iconUnchecked,
checked ? iconChecked : iconUnchecked,
style: style.icon,
),
),
Expand Down
4 changes: 2 additions & 2 deletions test/components/button_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void main() {
await tester.pumpWidget(
MaterialApp(
home: RemixButton(
isLoading: true,
loading: true,
loadingLabel: loadingLabel,
onPressed: () {},
),
Expand Down Expand Up @@ -70,7 +70,7 @@ void main() {
onPressed: () {
didCallOnPressed = true;
},
isDisabled: true,
disabled: true,
),
));

Expand Down
15 changes: 7 additions & 8 deletions test/components/checkbox_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ void main() {
await tester.pumpWidget(
MaterialApp(
home: RemixCheckbox(
isChecked: isChecked,
checked: isChecked,
label: 'Checkbox',
onChanged: (value) {
expect(value, !isChecked);
Expand All @@ -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;
},
Expand All @@ -52,16 +52,15 @@ void main() {
for (var isChecked in [true, false]) {
await tester.pumpWidget(MaterialApp(
home: RemixCheckbox(
isChecked: isChecked,
checked: isChecked,
label: 'Checkbox',
onChanged: (value) {},
),
));

expect(
find.byWidgetPredicate(
(widget) =>
widget is RemixCheckbox && widget.isChecked == isChecked,
(widget) => widget is RemixCheckbox && widget.checked == isChecked,
),
findsOneWidget,
);
Expand All @@ -73,7 +72,7 @@ void main() {

await tester.pumpWidget(MaterialApp(
home: RemixCheckbox(
isChecked: false,
checked: false,
label: label,
onChanged: (value) {},
),
Expand All @@ -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',
Expand Down

0 comments on commit 8f9d98b

Please sign in to comment.