Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added FButton.icon for a single icon button #138

Merged
merged 40 commits into from
Aug 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
af29913
Added FButton.icon for a single icon button
Aug 3, 2024
3487e11
Added sample and docs for FButton.icon
Aug 3, 2024
30d6b16
Added FButton.icon for a single icon button
Aug 3, 2024
f78b1b8
Added sample and docs for FButton.icon
Aug 3, 2024
8bd0fd2
Commit from GitHub Actions (Forui Samples Presubmit)
Pante Aug 4, 2024
7edd519
Commit from GitHub Actions (Forui Presubmit)
Pante Aug 4, 2024
16fc755
Merge remote-tracking branch 'origin/icon-button' into icon-button
sommye-ctr Aug 4, 2024
9ab4805
Added golden images
sommye-ctr Aug 10, 2024
e484a3d
Commit from GitHub Actions (Forui Presubmit)
sommye-ctr Aug 10, 2024
c51dfb6
Commit from GitHub Actions (Forui Samples Presubmit)
sommye-ctr Aug 10, 2024
d59b46c
Update docs/pages/docs/button.mdx
sommye-ctr Aug 11, 2024
c825216
Update forui/lib/src/widgets/button/button.dart
sommye-ctr Aug 11, 2024
4b505e5
Update forui/lib/src/widgets/divider.dart
sommye-ctr Aug 11, 2024
1b4cbb6
Renamed icon to child in FButton.icon(...)
sommye-ctr Aug 11, 2024
d40dff4
Merge remote-tracking branch 'origin/icon-button' into icon-button
sommye-ctr Aug 11, 2024
88ce938
Renamed icon to child in FButton.icon(...)
sommye-ctr Aug 11, 2024
a0c46d9
Commit from GitHub Actions (Forui Presubmit)
sommye-ctr Aug 11, 2024
8e3294d
Updated forui/lib/src/widgets/button/button.dart
sommye-ctr Aug 11, 2024
fbd8bb4
Merge remote-tracking branch 'origin/icon-button' into icon-button
sommye-ctr Aug 11, 2024
0b66c57
Added FButtonIconContentStyle
sommye-ctr Aug 13, 2024
52182c6
Commit from GitHub Actions (Forui Presubmit)
sommye-ctr Aug 13, 2024
537f33c
Commit from GitHub Actions (Forui Samples Presubmit)
sommye-ctr Aug 13, 2024
c25995a
Added FButtonIconContentStyle to FButtonCustomStyle
sommye-ctr Aug 14, 2024
17f1374
Merge remote-tracking branch 'origin/icon-button' into icon-button
sommye-ctr Aug 14, 2024
be7ac55
Added FButtonIconContentStyle to FButtonCustomStyle
sommye-ctr Aug 15, 2024
399ba33
Commit from GitHub Actions (Forui Presubmit)
sommye-ctr Aug 15, 2024
57ae4bb
Merge branch 'main' into icon-button
Pante Aug 15, 2024
094a11b
Commit from GitHub Actions (Forui Samples Presubmit)
Pante Aug 15, 2024
c9cac75
Merge branch 'main' into icon-button
Pante Aug 15, 2024
70b886a
Minor Changes
sommye-ctr Aug 15, 2024
4045bdb
Removed FButtonIconStyle from FButton
sommye-ctr Aug 15, 2024
a5e783e
Merge remote-tracking branch 'origin/icon-button' into icon-button
sommye-ctr Aug 15, 2024
2462171
Resolved changes
sommye-ctr Aug 15, 2024
1b8736d
Commit from GitHub Actions (Forui Presubmit)
sommye-ctr Aug 15, 2024
dd55aed
Resolved errors
sommye-ctr Aug 15, 2024
c784e14
Merge remote-tracking branch 'origin/icon-button' into icon-button
sommye-ctr Aug 15, 2024
3e449db
Commit from GitHub Actions (Forui Presubmit)
sommye-ctr Aug 15, 2024
5f0da01
Added default value to FCustomButtonStyle.iconContent
sommye-ctr Aug 16, 2024
38d117f
Merge remote-tracking branch 'origin/icon-button' into icon-button
sommye-ctr Aug 16, 2024
fe6d682
Commit from GitHub Actions (Forui Presubmit)
sommye-ctr Aug 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions docs/pages/docs/button.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ FButton.raw(
</Tabs.Tab>
</Tabs>

### With Icon
### With Text and Icon
<Tabs items={['Preview', 'Code']}>
<Tabs.Tab>
<Widget name='button' variant='icon' query={{}}/>
Expand All @@ -123,4 +123,20 @@ FButton.raw(
),
```
</Tabs.Tab>
</Tabs>
</Tabs>

### With Only Icon
<Tabs items={['Preview', 'Code']}>
<Tabs.Tab>
<Widget name='button' variant='only-icon' query={{}}/>
</Tabs.Tab>
<Tabs.Tab>
```dart {2}
FButton.icon(
icon: FButtonIcon(icon: FAssets.icons.chevronRight),
onPress: () {},
),
```
</Tabs.Tab>
</Tabs>

31 changes: 28 additions & 3 deletions forui/lib/src/widgets/button/button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,18 @@ class FButton extends StatelessWidget {
label: label,
);

/// Creates a [FButton] that contains only an icon.
FButton.icon({
required this.onPress,
required Widget child,
this.style = Variant.outline,
this.onLongPress,
this.autofocus = false,
this.focusNode,
this.onFocusChange,
super.key,
}) : child = _FButtonIconContent(child: child);

/// Creates a [FButton] with custom content.
const FButton.raw({
required this.onPress,
Expand Down Expand Up @@ -200,12 +212,16 @@ class FButtonCustomStyle extends FButtonStyle with Diagnosticable {
/// The icon's style.
final FButtonIconStyle icon;

/// The icon content's style.
final FButtonIconContentStyle iconContent;

/// Creates a [FButtonCustomStyle].
FButtonCustomStyle({
required this.enabledBoxDecoration,
required this.disabledBoxDecoration,
required this.content,
required this.icon,
this.iconContent = const FButtonIconContentStyle(),
});

/// Returns a copy of this [FButtonCustomStyle] with the given properties replaced.
Expand All @@ -230,12 +246,14 @@ class FButtonCustomStyle extends FButtonStyle with Diagnosticable {
BoxDecoration? disabledBoxDecoration,
FButtonContentStyle? content,
FButtonIconStyle? icon,
FButtonIconContentStyle? iconContent,
}) =>
FButtonCustomStyle(
enabledBoxDecoration: enabledBoxDecoration ?? this.enabledBoxDecoration,
disabledBoxDecoration: disabledBoxDecoration ?? this.disabledBoxDecoration,
content: content ?? this.content,
icon: icon ?? this.icon,
iconContent: iconContent ?? this.iconContent,
);

@override
Expand All @@ -245,7 +263,8 @@ class FButtonCustomStyle extends FButtonStyle with Diagnosticable {
..add(DiagnosticsProperty('enabledBoxDecoration', enabledBoxDecoration))
..add(DiagnosticsProperty('disabledBoxDecoration', disabledBoxDecoration))
..add(DiagnosticsProperty('content', content))
..add(DiagnosticsProperty('icon', icon));
..add(DiagnosticsProperty('icon', icon))
..add(DiagnosticsProperty('iconContent', iconContent));
}

@override
Expand All @@ -256,10 +275,16 @@ class FButtonCustomStyle extends FButtonStyle with Diagnosticable {
enabledBoxDecoration == other.enabledBoxDecoration &&
disabledBoxDecoration == other.disabledBoxDecoration &&
content == other.content &&
icon == other.icon;
icon == other.icon &&
iconContent == other.iconContent;

@override
int get hashCode => enabledBoxDecoration.hashCode ^ disabledBoxDecoration.hashCode ^ content.hashCode ^ icon.hashCode;
int get hashCode =>
enabledBoxDecoration.hashCode ^
disabledBoxDecoration.hashCode ^
content.hashCode ^
icon.hashCode ^
iconContent.hashCode;
}

typedef _Data = ({FButtonCustomStyle style, bool enabled});
Expand Down
53 changes: 53 additions & 0 deletions forui/lib/src/widgets/button/button_content.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,59 @@ final class _FButtonContent extends StatelessWidget {
}
}

final class _FButtonIconContent extends StatelessWidget {
final Widget child;

const _FButtonIconContent({required this.child});

@override
Widget build(BuildContext context) {
final (:style, enabled: _) = FButton._of(context);
sommye-ctr marked this conversation as resolved.
Show resolved Hide resolved

return Padding(
padding: style.iconContent.padding,
child: child,
);
}
}

/// [FButton] icon content's style.
class FButtonIconContentStyle with Diagnosticable {
/// The padding.
final EdgeInsets padding;

/// Creates a [FButtonIconContentStyle].
const FButtonIconContentStyle({
this.padding = const EdgeInsets.symmetric(
horizontal: 16,
vertical: 12.5,
),
});

/// Returns a copy of this [FButtonIconContentStyle] with the given properties replaced.
@useResult
FButtonIconContentStyle copyWith({
EdgeInsets? padding,
}) =>
FButtonIconContentStyle(
padding: padding ?? this.padding,
);

@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties.add(DiagnosticsProperty('padding', padding));
}

@override
bool operator ==(Object other) =>
identical(this, other) ||
other is FButtonIconContentStyle && runtimeType == other.runtimeType && padding == other.padding;

@override
int get hashCode => padding.hashCode;
sommye-ctr marked this conversation as resolved.
Show resolved Hide resolved
}

/// [FButton] content's style.
class FButtonContentStyle with Diagnosticable {
/// The [TextStyle] when this button is enabled.
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
50 changes: 50 additions & 0 deletions forui/test/src/widgets/button/button_golden_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,56 @@ void main() {
matchesGoldenFile('button/$name-$variant-disabled-raw-button.png'),
);
});

testWidgets('$name with enabled icon', (tester) async {
await tester.pumpWidget(
TestScaffold(
data: theme,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: FButton.icon(
onPress: () {},
style: variant,
child: FButtonIcon(
icon: FAssets.icons.chevronRight,
),
),
),
),
);

await expectLater(
find.byType(TestScaffold),
matchesGoldenFile(
'button/$name-$variant-icon-enabled-button.png',
),
);
});

testWidgets('$name with disabled icon', (tester) async {
await tester.pumpWidget(
TestScaffold(
data: theme,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: FButton.icon(
onPress: null,
style: variant,
child: FButtonIcon(
icon: FAssets.icons.chevronRight,
),
),
),
),
);

await expectLater(
find.byType(TestScaffold),
matchesGoldenFile(
'button/$name-$variant-icon-disabled-button.png',
),
);
});
}
}
});
Expand Down
4 changes: 4 additions & 0 deletions samples/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ class _AppRouter extends RootStackRouter {
path: '/button/icon',
page: ButtonIconRoute.page,
),
AutoRoute(
path: '/button/only-icon',
page: ButtonOnlyIconRoute.page,
),
AutoRoute(
path: '/calendar/default',
page: CalendarRoute.page,
Expand Down
15 changes: 15 additions & 0 deletions samples/lib/widgets/button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,18 @@ class ButtonIconPage extends SampleScaffold {
),
);
}

@RoutePage()
class ButtonOnlyIconPage extends SampleScaffold {
ButtonOnlyIconPage({
@queryParam super.theme,
});

@override
Widget child(BuildContext context) => IntrinsicWidth(
child: FButton.icon(
child: FButtonIcon(icon: FAssets.icons.chevronRight),
onPress: () {},
),
);
}
24 changes: 12 additions & 12 deletions samples/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -367,18 +367,18 @@ packages:
dependency: transitive
description:
name: leak_tracker
sha256: "3f87a60e8c63aecc975dda1ceedbc8f24de75f09e4856ea27daf8958f2f0ce05"
sha256: "7f0df31977cb2c0b88585095d168e689669a2cc9b97c309665e3386f3e9d341a"
url: "https://pub.dev"
source: hosted
version: "10.0.5"
version: "10.0.4"
leak_tracker_flutter_testing:
dependency: transitive
description:
name: leak_tracker_flutter_testing
sha256: "932549fb305594d82d7183ecd9fa93463e9914e1b67cacc34bc40906594a1806"
sha256: "06e98f569d004c1315b991ded39924b21af84cf14cc94791b8aea337d25b57f8"
url: "https://pub.dev"
source: hosted
version: "3.0.5"
version: "3.0.3"
leak_tracker_testing:
dependency: transitive
description:
Expand Down Expand Up @@ -407,18 +407,18 @@ packages:
dependency: transitive
description:
name: material_color_utilities
sha256: f7142bb1154231d7ea5f96bc7bde4bda2a0945d2806bb11670e30b850d56bdec
sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a"
url: "https://pub.dev"
source: hosted
version: "0.11.1"
version: "0.8.0"
meta:
dependency: transitive
description:
name: meta
sha256: bdb68674043280c3428e9ec998512fb681678676b3c54e773629ffe74419f8c7
sha256: "7687075e408b093f36e6bbf6c91878cc0d4cd10f409506f7bc996f68220b9136"
url: "https://pub.dev"
source: hosted
version: "1.15.0"
version: "1.12.0"
mime:
dependency: transitive
description:
Expand Down Expand Up @@ -652,10 +652,10 @@ packages:
dependency: transitive
description:
name: test_api
sha256: "5b8a98dafc4d5c4c9c72d8b31ab2b23fc13422348d2997120294d3bac86b4ddb"
sha256: "9955ae474176f7ac8ee4e989dadfb411a58c30415bcfb648fa04b2b8a03afa7f"
url: "https://pub.dev"
source: hosted
version: "0.7.2"
version: "0.7.0"
timing:
dependency: transitive
description:
Expand Down Expand Up @@ -708,10 +708,10 @@ packages:
dependency: transitive
description:
name: vm_service
sha256: f652077d0bdf60abe4c1f6377448e8655008eef28f128bc023f7b5e8dfeb48fc
sha256: "3923c89304b715fb1eb6423f017651664a03bf5f4b29983627c4da791f74a4ec"
url: "https://pub.dev"
source: hosted
version: "14.2.4"
version: "14.2.1"
watcher:
dependency: transitive
description:
Expand Down
Loading