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 22 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 @@ -103,7 +103,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 @@ -117,4 +117,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>

88 changes: 88 additions & 0 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 @@ -262,6 +274,82 @@ class FButtonCustomStyle extends FButtonStyle with Diagnosticable {
int get hashCode => enabledBoxDecoration.hashCode ^ disabledBoxDecoration.hashCode ^ content.hashCode ^ icon.hashCode;
}

/// [FButton] style for icon-button.
class FButtonIconStyle extends FButtonStyle with Diagnosticable {
sommye-ctr marked this conversation as resolved.
Show resolved Hide resolved
/// The box decoration for an enabled button.
final BoxDecoration enabledBoxDecoration;

/// The box decoration for a disabled button.
final BoxDecoration disabledBoxDecoration;

/// The content's style.
final FButtonContentStyle content;

/// The icon's style.
final FButtonIconStyle icon;

/// Creates a [FButtonIconStyle].
FButtonIconStyle({
required this.enabledBoxDecoration,
required this.disabledBoxDecoration,
required this.content,
required this.icon,
});

/// Returns a copy of this [FButtonIconStyle] with the given properties replaced.
///
/// ```dart
/// final style = FButtonIconStyle(
/// enabledBoxDecoration: ...,
/// disabledBoxDecoration: ...,
/// // other properties omitted for brevity
/// );
///
/// final copy = style.copyWith(
/// disabledBoxDecoration: ...,
/// );
///
/// print(copy.background); // Colors.blue
/// print(copy.border); // Colors.black
/// ```
@useResult
FButtonIconStyle copyWith({
BoxDecoration? enabledBoxDecoration,
BoxDecoration? disabledBoxDecoration,
FButtonContentStyle? content,
FButtonIconStyle? icon,
}) =>
FButtonIconStyle(
enabledBoxDecoration: enabledBoxDecoration ?? this.enabledBoxDecoration,
disabledBoxDecoration: disabledBoxDecoration ?? this.disabledBoxDecoration,
content: content ?? this.content,
icon: icon ?? this.icon,
);

@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties
..add(DiagnosticsProperty('enabledBoxDecoration', enabledBoxDecoration))
..add(DiagnosticsProperty('disabledBoxDecoration', disabledBoxDecoration))
..add(DiagnosticsProperty('content', content))
..add(DiagnosticsProperty('icon', icon));
}

@override
bool operator ==(Object other) =>
identical(this, other) ||
other is FButtonCustomStyle &&
runtimeType == other.runtimeType &&
enabledBoxDecoration == other.enabledBoxDecoration &&
disabledBoxDecoration == other.disabledBoxDecoration &&
content == other.content &&
icon == other.icon;

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

sommye-ctr marked this conversation as resolved.
Show resolved Hide resolved
typedef _Data = ({FButtonCustomStyle style, bool enabled});

class _InheritedData extends InheritedWidget {
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 FButtonIconContentStyle contentStyle = FButtonIconContentStyle();

return Padding(
padding: contentStyle.padding,
child: child,
);
}
}

/// [FButton] icon's style.
sommye-ctr marked this conversation as resolved.
Show resolved Hide resolved
class FButtonIconContentStyle with Diagnosticable {
/// The padding.
final EdgeInsets padding;

/// Creates a [FButtonIconContentStyle].
FButtonIconContentStyle({
sommye-ctr marked this conversation as resolved.
Show resolved Hide resolved
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
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

@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties.add(DiagnosticsProperty<EdgeInsets>('padding', padding));
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.
52 changes: 52 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,7 +136,59 @@ 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',
),
);
});
}
}
});
}

//flutter test --update-goldens /Users/somyemahajan/Projects/forui/forui/test/src/widgets/button/button_golden_test.dart
sommye-ctr marked this conversation as resolved.
Show resolved Hide resolved
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: () {},
),
);
}