Skip to content

Commit

Permalink
Tidy up documentation and expose more fields on button (#33)
Browse files Browse the repository at this point in the history
* Tidy up documentation and expose more fields on button

* Commit from GitHub Actions (Forui Example Presubmit)

* Commit from GitHub Actions (Forui Presubmit)

* Fix failing lint

* Remove unnecessary imports from FTappable

---------

Co-authored-by: Pante <[email protected]>
  • Loading branch information
Pante and Pante authored Jun 4, 2024
1 parent ed60e07 commit 1285fd6
Show file tree
Hide file tree
Showing 38 changed files with 244 additions and 177 deletions.
3 changes: 3 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,7 @@ class Foo extends StatelessWidget {

## Conventions

* Avoid [double negatives](https://en.wikipedia.org/wiki/Double_negative) when naming things, i.e. a boolean field should
be named `enabled` instead of `disabled`.

* Prefix all publicly exported widgets and styles with `F`, i.e. `FScaffold`.
1 change: 1 addition & 0 deletions forui/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ class ExampleWidget extends StatelessWidget {
FButton(
text: 'Button',
icon: FAssets.icons.airplay,
onPress: () {},
)
],
);
Expand Down
2 changes: 1 addition & 1 deletion forui/lib/forui.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export 'src/theme/themes.dart';
// Widgets
export 'src/widgets/box.dart';
export 'src/widgets/badge/badge.dart' hide FBadgeContent;
export 'src/widgets/button/tappable.dart' hide FTappable;
export 'src/foundation/tappable.dart' hide FTappable;
export 'src/widgets/button/button.dart' hide FButtonContent;
export 'src/widgets/card/card.dart' hide FCardContent;
export 'src/widgets/separator.dart';
Expand Down
File renamed without changes.
7 changes: 6 additions & 1 deletion forui/lib/src/theme/color_scheme.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart';

/// A set of colors that can be used to configure the color properties of most components.
import 'package:forui/forui.dart';

/// A set of colors that can be used to configure the colors of most widgets.
///
/// See the pre-defined themes' color schemes in [FThemes].
final class FColorScheme with Diagnosticable {

/// The background color.
Expand Down Expand Up @@ -124,4 +128,5 @@ final class FColorScheme with Diagnosticable {
destructive.hashCode ^
destructiveForeground.hashCode ^
border.hashCode;

}
37 changes: 19 additions & 18 deletions forui/lib/src/theme/font.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@ import 'package:sugar/core.dart';

import 'package:forui/forui.dart';

// TODO: replace with nullable number operations in Sugar 4.
double? _scale(double? value, double factor) => value == null ? null : value * factor;

/// A Forui font that used to configure the [TextStyle]s of Forui widgets.
/// A Forui font used to configure the Forui widgets' [TextStyle]s.
///
/// It is usually inherited from a ancestor [FTheme]. Besides the typical font information, a [FFont] also contains
/// scalar values used to scale a [TextStyle]'s corresponding properties. This ensures that various fonts are scaled
/// consistently throughout an application.
/// It is usually inherited from an ancestor [FTheme]. Besides the typical font information, a [FFont] also contains
/// scalar values used to scale a [TextStyle]'s corresponding properties. This ensures that various [TextStyle]s with the
/// same font are scaled consistently throughout a project.
final class FFont with Diagnosticable {

/// The font family. Defaults to `packages/forui/Inter`.
/// The font family. Defaults to [`packages/forui/Inter`](https://fonts.google.com/specimen/Inter).
///
/// ## Contract:
/// Throws an [AssertionError] if blank.
Expand Down Expand Up @@ -310,18 +311,18 @@ final class FFont with Diagnosticable {
..add(DoubleProperty('letterSpacingScalar', letterSpacingScalar, defaultValue: 1))
..add(DoubleProperty('wordSpacingScalar', wordSpacingScalar, defaultValue: 1))
..add(DoubleProperty('heightScalar', heightScalar, defaultValue: 1))
..add(DoubleProperty('xs', xs))
..add(DoubleProperty('sm', sm))
..add(DoubleProperty('base', base))
..add(DoubleProperty('lg', lg))
..add(DoubleProperty('xl', xl))
..add(DoubleProperty('xl2', xl2))
..add(DoubleProperty('xl3', xl3))
..add(DoubleProperty('xl4', xl4))
..add(DoubleProperty('xl5', xl5))
..add(DoubleProperty('xl6', xl6))
..add(DoubleProperty('xl7', xl7))
..add(DoubleProperty('xl8', xl8));
..add(DoubleProperty('xs', xs, defaultValue: 12))
..add(DoubleProperty('sm', sm, defaultValue: 14))
..add(DoubleProperty('base', base, defaultValue: 16))
..add(DoubleProperty('lg', lg, defaultValue: 18))
..add(DoubleProperty('xl', xl, defaultValue: 20))
..add(DoubleProperty('xl2', xl2, defaultValue: 22))
..add(DoubleProperty('xl3', xl3, defaultValue: 30))
..add(DoubleProperty('xl4', xl4, defaultValue: 36))
..add(DoubleProperty('xl5', xl5, defaultValue: 48))
..add(DoubleProperty('xl6', xl6, defaultValue: 60))
..add(DoubleProperty('xl7', xl7, defaultValue: 72))
..add(DoubleProperty('xl8', xl8, defaultValue: 96));
}

@override
Expand Down Expand Up @@ -371,7 +372,7 @@ final class FFont with Diagnosticable {
/// Provides functions for working with [FFont]s.
extension FontTextStyle on TextStyle {

/// Returns a [TextStyle] scaled using the given [font].
/// Returns a [TextStyle] with the given [font], scaled using it.
///
/// ```dart
/// final font = FFont(
Expand Down
2 changes: 1 addition & 1 deletion forui/lib/src/theme/style.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart';

/// The overarching style that is used to configure the properties of widget-specific styles if they are not provided.
/// The fallback global style is used to configure the widget-specific styles if they are not provided.
final class FStyle with Diagnosticable {

/// The border radius.
Expand Down
6 changes: 3 additions & 3 deletions forui/lib/src/theme/theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ class FTheme extends StatelessWidget {
/// The theme data.
final FThemeData data;

/// The child widget.
final Widget child;

/// The text direction.
///
/// If none is provided, the text direction is inherited from the context.
final TextDirection? textDirection;

/// The child widget.
final Widget child;

/// Creates a [FTheme].
const FTheme({
required this.data,
Expand Down
6 changes: 4 additions & 2 deletions forui/lib/src/theme/theme_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:forui/forui.dart';

/// The color scheme, fonts, overarching style, and widget specific styles used to configure child Forui widgets.
class FThemeData with Diagnosticable {

/// The color scheme.
final FColorScheme colorScheme;

Expand Down Expand Up @@ -44,15 +45,15 @@ class FThemeData with Diagnosticable {
required this.switchStyle,
});

/// Creates a [FThemeData] that inherits the given arguments' properties.
/// Creates a [FThemeData] that inherits the given properties.
FThemeData.inherit({
required this.colorScheme,
required this.font,
required this.style,
}):
badgeStyles = FBadgeStyles.inherit(colorScheme: colorScheme, font: font, style: style),
boxStyle = FBoxStyle.inherit(colorScheme: colorScheme),
buttonStyles = FButtonStyles.inherit(colorScheme: colorScheme, font: font, style: style, ),
buttonStyles = FButtonStyles.inherit(colorScheme: colorScheme, font: font, style: style),
cardStyle = FCardStyle.inherit(colorScheme: colorScheme, font: font, style: style),
separatorStyles = FSeparatorStyles.inherit(colorScheme: colorScheme, style: style),
switchStyle = FSwitchStyle.inherit(colorScheme: colorScheme);
Expand Down Expand Up @@ -121,4 +122,5 @@ class FThemeData with Diagnosticable {
cardStyle.hashCode ^
separatorStyles.hashCode ^
switchStyle.hashCode;

}
1 change: 1 addition & 0 deletions forui/lib/src/theme/themes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,5 @@ extension FThemes on Never {
style: FStyle(),
),
);

}
34 changes: 10 additions & 24 deletions forui/lib/src/widgets/badge/badge.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,13 @@ import 'package:meta/meta.dart';
import 'package:forui/forui.dart';

part 'badge_content.dart';

part 'badge_styles.dart';

/// A badge, or a component that looks like a badge.
class FBadge extends StatelessWidget {
/// The design.
final FBadgeDesign design;

/// A callback for when the badge is pressed.
final void Function(BuildContext)? onPressed;

/// A callback for when the badge is long pressed.
final void Function(BuildContext)? onLongPressed;
/// The design. Defaults to [FBadgeVariant.primary].
final FBadgeDesign design;

/// The builder.
final Widget Function(BuildContext, FBadgeStyle) builder;
Expand All @@ -28,13 +22,11 @@ class FBadge extends StatelessWidget {
FBadge({
required String label,
this.design = FBadgeVariant.primary,
this.onPressed,
this.onLongPressed,
super.key,
}) : builder = ((context, style) => FBadgeContent(label: label, style: style));

/// Creates a [FBadge].
const FBadge.raw({required this.design, required this.builder, this.onPressed, this.onLongPressed, super.key});
const FBadge.raw({required this.design, required this.builder, super.key});

@override
Widget build(BuildContext context) {
Expand All @@ -46,7 +38,7 @@ class FBadge extends StatelessWidget {
FBadgeVariant.destructive => context.theme.badgeStyles.destructive,
};

final badge = IntrinsicWidth(
return IntrinsicWidth(
child: IntrinsicHeight(
child: DecoratedBox(
decoration: BoxDecoration(
Expand All @@ -61,24 +53,16 @@ class FBadge extends StatelessWidget {
),
),
);

if (onPressed == null && onLongPressed == null) {
return badge;
}

// TODO: Wrap in FTappable when it's ready.
return badge;
}

@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties
..add(DiagnosticsProperty<FBadgeDesign>('design', design))
..add(DiagnosticsProperty<void Function(BuildContext)?>('onPressed', onPressed, defaultValue: null))
..add(DiagnosticsProperty<void Function(BuildContext)?>('onLongPressed', onLongPressed, defaultValue: null))
..add(DiagnosticsProperty<Widget Function(BuildContext, FBadgeStyle)>('builder', builder, defaultValue: null));
..add(DiagnosticsProperty('design', design, defaultValue: FBadgeVariant.primary))
..add(DiagnosticsProperty('builder', builder, defaultValue: null));
}

}

/// The badge design. Either a pre-defined [FBadgeVariant], or a custom [FBadgeStyle].
Expand All @@ -101,6 +85,7 @@ enum FBadgeVariant implements FBadgeDesign {

/// A [FBadge]'s style.
final class FBadgeStyle with Diagnosticable implements FBadgeDesign {

/// The background color.
final Color background;

Expand Down Expand Up @@ -161,7 +146,7 @@ final class FBadgeStyle with Diagnosticable implements FBadgeDesign {
properties
..add(ColorProperty('background', background))
..add(ColorProperty('border', border))
..add(DiagnosticsProperty<BorderRadius>('borderRadius', borderRadius))
..add(DiagnosticsProperty<BorderRadius>('borderRadius', borderRadius, defaultValue: BorderRadius.circular(100)))
..add(DoubleProperty('borderWidth', borderWidth))
..add(DiagnosticsProperty<FBadgeContentStyle>('content', content));
}
Expand All @@ -180,4 +165,5 @@ final class FBadgeStyle with Diagnosticable implements FBadgeDesign {
@override
int get hashCode =>
background.hashCode ^ border.hashCode ^ borderRadius.hashCode ^ borderWidth.hashCode ^ content.hashCode;

}
18 changes: 9 additions & 9 deletions forui/lib/src/widgets/badge/badge_content.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ part of 'badge.dart';

@internal final class FBadgeContent extends StatelessWidget {

final String label;
final FBadgeStyle style;
final String label;

const FBadgeContent({required this.label, required this.style, super.key});
const FBadgeContent({required this.style, required this.label, super.key});

@override
Widget build(BuildContext context) => Center(
Expand All @@ -19,21 +19,21 @@ part of 'badge.dart';
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties
..add(DiagnosticsProperty<FBadgeStyle>('style', style))
..add(StringProperty('text', label));
..add(DiagnosticsProperty('style', style))
..add(StringProperty('label', label));
}

}

/// A badge content's style.
final class FBadgeContentStyle with Diagnosticable {

/// The padding.
final EdgeInsets padding;

/// The text.
final TextStyle label;

/// The padding.
final EdgeInsets padding;

/// Creates a [FBadgeContentStyle].
FBadgeContentStyle({required this.label, this.padding = const EdgeInsets.symmetric(horizontal: 14, vertical: 2)});

Expand All @@ -47,8 +47,8 @@ final class FBadgeContentStyle with Diagnosticable {
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties
..add(DiagnosticsProperty('padding', padding))
..add(DiagnosticsProperty('text', label));
..add(DiagnosticsProperty('label', label))
..add(DiagnosticsProperty('padding', padding, defaultValue: const EdgeInsets.symmetric(horizontal: 14, vertical: 2)));
}

@override
Expand Down
Loading

0 comments on commit 1285fd6

Please sign in to comment.