Skip to content

Commit

Permalink
Complete implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
kawaijoe committed Jun 23, 2024
1 parent 2a9cba2 commit be16d9e
Show file tree
Hide file tree
Showing 13 changed files with 348 additions and 336 deletions.
5 changes: 4 additions & 1 deletion forui/lib/src/theme/theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,10 @@ class FTheme extends StatelessWidget {
child: Directionality(
textDirection: textDirection ?? Directionality.of(context),
child: DefaultTextStyle(
style: data.typography.base.copyWith(color: data.colorScheme.foreground),
style: data.typography.base.copyWith(
fontFamily: data.typography.defaultFontFamily,
color: data.colorScheme.foreground,
),
child: child,
),
),
Expand Down
44 changes: 27 additions & 17 deletions forui/lib/src/theme/theme_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -70,22 +70,31 @@ final class FThemeData with Diagnosticable {
});

/// Creates a [FThemeData] that configures the widget styles using the given properties.
FThemeData.inherit({
required this.colorScheme,
this.style = const FStyle(),
}) : typography = FTypography.inherit(colorScheme: colorScheme),
badgeStyles = FBadgeStyles.inherit(colorScheme: colorScheme, typography: typography, style: style),
buttonStyles = FButtonStyles.inherit(
colorScheme: colorScheme,
typography: typography,
style: style,
),
cardStyle = FCardStyle.inherit(colorScheme: colorScheme, typography: typography, style: style),
dialogStyle = FDialogStyle.inherit(style: style, colorScheme: colorScheme, typography: typography),
headerStyle = FHeaderStyle.inherit(colorScheme: colorScheme, typography: typography),
textFieldStyle = FTextFieldStyle.inherit(colorScheme: colorScheme, typography: typography, style: style),
separatorStyles = FSeparatorStyles.inherit(colorScheme: colorScheme, style: style),
switchStyle = FSwitchStyle.inherit(colorScheme: colorScheme);
factory FThemeData.inherit({
required FColorScheme colorScheme,
FStyle style = const FStyle(),
FTypography? typography,
}) {
typography ??= FTypography.inherit(colorScheme: colorScheme);

return FThemeData(
colorScheme: colorScheme,
typography: typography,
style: style,
badgeStyles: FBadgeStyles.inherit(colorScheme: colorScheme, typography: typography, style: style),
buttonStyles: FButtonStyles.inherit(
colorScheme: colorScheme,
typography: typography,
style: style,
),
cardStyle: FCardStyle.inherit(colorScheme: colorScheme, typography: typography, style: style),
dialogStyle: FDialogStyle.inherit(style: style, colorScheme: colorScheme, typography: typography),
headerStyle: FHeaderStyle.inherit(colorScheme: colorScheme, typography: typography),
textFieldStyle: FTextFieldStyle.inherit(colorScheme: colorScheme, typography: typography, style: style),
separatorStyles: FSeparatorStyles.inherit(colorScheme: colorScheme, style: style),
switchStyle: FSwitchStyle.inherit(colorScheme: colorScheme),
);
}

/// Returns a copy of this [FThemeData] with the given properties replaced.
///
Expand All @@ -103,7 +112,8 @@ final class FThemeData with Diagnosticable {
/// print(theme.colorScheme == copy.colorScheme); // true
/// print(copy.typography); // bar
/// ```
@useResult FThemeData copyWith({
@useResult
FThemeData copyWith({
FColorScheme? colorScheme,
FTypography? typography,
FStyle? style,
Expand Down
2 changes: 1 addition & 1 deletion forui/lib/src/widgets/badge/badge_content.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ final class FBadgeContent extends StatelessWidget {
child: Padding(
padding: style.content.padding,
child: DefaultTextStyle.merge(
style: style.content.labelTextStyle.scale(context.theme.typography),
style: style.content.labelTextStyle,
child: switch ((label, rawLabel)) {
(final String label, _) => Text(label),
(_, final Widget label) => label,
Expand Down
12 changes: 4 additions & 8 deletions forui/lib/src/widgets/badge/badge_styles.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@ class FBadgeStyles with Diagnosticable {
backgroundColor: colorScheme.primary,
borderColor: colorScheme.primary,
content: FBadgeContentStyle(
labelTextStyle: TextStyle(
labelTextStyle: typography.sm.copyWith(
color: colorScheme.primaryForeground,
fontSize: typography.sm,
fontWeight: FontWeight.w600,
),
),
Expand All @@ -41,9 +40,8 @@ class FBadgeStyles with Diagnosticable {
backgroundColor: colorScheme.secondary,
borderColor: colorScheme.secondary,
content: FBadgeContentStyle(
labelTextStyle: TextStyle(
labelTextStyle: typography.sm.copyWith(
color: colorScheme.secondaryForeground,
fontSize: typography.sm,
fontWeight: FontWeight.w600,
),
),
Expand All @@ -53,9 +51,8 @@ class FBadgeStyles with Diagnosticable {
backgroundColor: colorScheme.background,
borderColor: colorScheme.border,
content: FBadgeContentStyle(
labelTextStyle: TextStyle(
labelTextStyle: typography.sm.copyWith(
color: colorScheme.foreground,
fontSize: typography.sm,
fontWeight: FontWeight.w600,
),
),
Expand All @@ -65,9 +62,8 @@ class FBadgeStyles with Diagnosticable {
backgroundColor: colorScheme.destructive,
borderColor: colorScheme.destructive,
content: FBadgeContentStyle(
labelTextStyle: TextStyle(
labelTextStyle: typography.sm.copyWith(
color: colorScheme.destructiveForeground,
fontSize: typography.sm,
fontWeight: FontWeight.w600,
),
),
Expand Down
9 changes: 3 additions & 6 deletions forui/lib/src/widgets/button/button_content.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@ final class FButtonContent extends StatelessWidget {

@override
Widget build(BuildContext context) {
final typography = context.theme.typography;
final (:style, :enabled) = FButton._of(context);

return Padding(
padding: style.content.padding,
child: DefaultTextStyle.merge(
style: enabled ? style.content.enabledTextStyle.scale(typography) : style.content.disabledTextStyle.scale(typography),
style: enabled ? style.content.enabledTextStyle : style.content.disabledTextStyle,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: separate([
Expand Down Expand Up @@ -75,13 +74,11 @@ class FButtonContentStyle with Diagnosticable {
horizontal: 16,
vertical: 12.5,
),
enabledTextStyle = TextStyle(
fontSize: typography.base,
enabledTextStyle = typography.base.copyWith(
fontWeight: FontWeight.w500,
color: enabled,
),
disabledTextStyle = TextStyle(
fontSize: typography.base,
disabledTextStyle = typography.base.copyWith(
fontWeight: FontWeight.w500,
color: disabled,
);
Expand Down
1 change: 0 additions & 1 deletion forui/lib/src/widgets/card/card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ final class FCard extends StatelessWidget {
super.debugFillProperties(properties);
properties.add(DiagnosticsProperty('style', style));
}

}

/// [FCard]'s style.
Expand Down
64 changes: 31 additions & 33 deletions forui/lib/src/widgets/card/card_content.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
part of 'card.dart';

@internal final class FCardContent extends StatelessWidget {
@internal
final class FCardContent extends StatelessWidget {
final String? title;
final Widget? rawTitle;
final String? subtitle;
Expand All @@ -13,48 +14,46 @@ part of 'card.dart';
this.rawTitle,
this.subtitle,
this.rawSubtitle,
this.child,
this.style,
this.child,
this.style,
super.key,
});

@override
Widget build(BuildContext context) {
final typography = context.theme.typography;
final style = this.style ?? context.theme.cardStyle.content;

final title = switch ((this.title, rawTitle)) {
(final String title, _) => Text(title),
(_, final Widget title) => title,
_ => null,
};

final subtitle = switch ((this.subtitle, rawSubtitle)) {
(final String subtitle, _) => Text(subtitle),
(_, final Widget subtitle) => subtitle,
_ => null,
};

return Padding(
padding: style.padding,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
if (title != null)
DefaultTextStyle.merge(
style: style.titleTextStyle.scale(typography),
style: style.titleTextStyle,
child: title,
),

if (subtitle != null)
DefaultTextStyle.merge(
style: style.subtitleTextStyle.scale(typography),
style: style.subtitleTextStyle,
child: subtitle,
),

if (child != null)
Padding(
padding: (title == null && subtitle == null) ? const EdgeInsets.only(top: 4) : const EdgeInsets.only(top: 10),
padding:
(title == null && subtitle == null) ? const EdgeInsets.only(top: 4) : const EdgeInsets.only(top: 10),
child: child!,
),
],
Expand Down Expand Up @@ -91,17 +90,13 @@ final class FCardContentStyle with Diagnosticable {
});

/// Creates a [FCardContentStyle] that inherits its properties from [colorScheme] and [typography].
FCardContentStyle.inherit({required FColorScheme colorScheme, required FTypography typography}):
titleTextStyle = TextStyle(
fontSize: typography.base,
fontWeight: FontWeight.w600,
color: colorScheme.foreground,
),
subtitleTextStyle = TextStyle(
fontSize: typography.sm,
color: colorScheme.mutedForeground,
),
padding = const EdgeInsets.fromLTRB(16, 12, 16, 16);
FCardContentStyle.inherit({required FColorScheme colorScheme, required FTypography typography})
: titleTextStyle = typography.base.copyWith(
fontWeight: FontWeight.w600,
color: colorScheme.foreground,
),
subtitleTextStyle = typography.sm.copyWith(color: colorScheme.mutedForeground),
padding = const EdgeInsets.fromLTRB(16, 12, 16, 16);

/// Returns a copy of this [FCardContentStyle] with the given properties replaced.
///
Expand All @@ -120,11 +115,12 @@ final class FCardContentStyle with Diagnosticable {
TextStyle? titleTextStyle,
TextStyle? subtitleTextStyle,
EdgeInsets? padding,
}) => FCardContentStyle(
titleTextStyle: titleTextStyle ?? this.titleTextStyle,
subtitleTextStyle: subtitleTextStyle ?? this.subtitleTextStyle,
padding: padding ?? this.padding,
);
}) =>
FCardContentStyle(
titleTextStyle: titleTextStyle ?? this.titleTextStyle,
subtitleTextStyle: subtitleTextStyle ?? this.subtitleTextStyle,
padding: padding ?? this.padding,
);

@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
Expand All @@ -136,11 +132,13 @@ final class FCardContentStyle with Diagnosticable {
}

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

@override
int get hashCode => titleTextStyle.hashCode ^ subtitleTextStyle.hashCode ^ padding.hashCode;
Expand Down
Loading

0 comments on commit be16d9e

Please sign in to comment.