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

Typography revamp #49

Merged
merged 11 commits into from
Jun 23, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
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
6 changes: 0 additions & 6 deletions .idea/runConfigurations/Forui_Example___run.xml

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/runConfigurations/forui___tests.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/runConfigurations/samples___run.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions forui/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,16 @@ class _ExampleWidgetState extends State<ExampleWidget> {
crossAxisAlignment: CrossAxisAlignment.start,
children: [
FButton(
design: FButtonVariant.destructive,
style: FButtonStyle.destructive,
label: 'Delete?',
onPress: () => showAdaptiveDialog(
context: context,
builder: (context) => FDialog(
alignment: FDialogAlignment.horizontal,
direction: Axis.horizontal,
title: 'Are you absolutely sure?',
body: 'This action cannot be undone. This will permanently delete your account and remove your data from our servers.',
actions: [
FButton(design: FButtonVariant.outline, label: 'Cancel', onPress: () {
FButton(style: FButtonStyle.outline, label: 'Cancel', onPress: () {
Navigator.of(context).pop();
}),
FButton(label: 'Continue', onPress: () {}),
Expand Down
4 changes: 2 additions & 2 deletions forui/lib/forui.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ export 'src/theme/typography.dart';
export 'src/theme/themes.dart';

// Widgets
export 'src/widgets/badge/badge.dart' hide FBadgeContent;
export 'src/widgets/badge/badge.dart' hide FBadgeContent, Variant;
export 'src/foundation/tappable.dart' hide FTappable;
export 'src/widgets/button/button.dart' hide FButtonContent;
export 'src/widgets/button/button.dart' hide FButtonContent, Variant;
export 'src/widgets/card/card.dart' hide FCardContent;
export 'src/widgets/dialog/dialog.dart' hide FDialogContent, FHorizontalDialogContent, FVerticalDialogContent;
export 'src/widgets/header/header.dart';
Expand Down
2 changes: 1 addition & 1 deletion forui/lib/src/theme/color_scheme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ final class FColorScheme with Diagnosticable {
required this.border,
});

/// Creates a copy of this [FColorScheme] with the given properties replaced.
/// Returns a copy of this [FColorScheme] with the given properties replaced.
///
/// ```dart
/// final scheme = FColorScheme(
Expand Down
2 changes: 1 addition & 1 deletion forui/lib/src/theme/style.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ final class FStyle with Diagnosticable {
this.borderWidth = 1,
});

/// Creates a copy of this [FStyle] with the given properties replaced.
/// Returns a copy of this [FStyle] with the given properties replaced.
///
/// ```dart
/// final style = FStyle(
Expand Down
33 changes: 16 additions & 17 deletions forui/lib/src/theme/theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ class FTheme extends StatelessWidget {
/// );
/// }
/// ```
@useResult static FThemeData of(BuildContext context) {
@useResult
static FThemeData of(BuildContext context) {
final theme = context.dependOnInheritedWidgetOfExactType<_InheritedTheme>();
return theme?.data ?? FThemes.zinc.light;
}
Expand All @@ -99,25 +100,25 @@ class FTheme extends StatelessWidget {

@override
Widget build(BuildContext context) => _InheritedTheme(
data: data,
child: Directionality(
textDirection: textDirection ?? Directionality.of(context),
child: DefaultTextStyle(
style: data.typography.toTextStyle(
fontSize: data.typography.base,
color: data.colorScheme.foreground,
data: data,
child: Directionality(
textDirection: textDirection ?? Directionality.of(context),
child: DefaultTextStyle(
style: data.typography.base.copyWith(
fontFamily: data.typography.defaultFontFamily,
color: data.colorScheme.foreground,
),
kawaijoe marked this conversation as resolved.
Show resolved Hide resolved
child: child,
),
),
child: child,
),
),
);
);

@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties
..add(DiagnosticsProperty<FThemeData>('data', data, showName: false))
..add(EnumProperty<TextDirection?>('textDirection', textDirection));
..add(DiagnosticsProperty('data', data, showName: false))
..add(EnumProperty('textDirection', textDirection));
}
}

Expand All @@ -132,13 +133,12 @@ class _InheritedTheme extends InheritedWidget {
@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties.add(DiagnosticsProperty<FThemeData>('data', data));
properties.add(DiagnosticsProperty('data', data));
}
}

/// Provides functions for accessing the current [FThemeData].
extension ThemeBuildContext on BuildContext {

/// Returns the current [FThemeData], or [FThemes.zinc.light] if there is no ancestor [FTheme].
///
/// ## Troubleshooting:
Expand Down Expand Up @@ -180,5 +180,4 @@ extension ThemeBuildContext on BuildContext {
/// }
/// ```
FThemeData get theme => FTheme.of(this);

}
48 changes: 29 additions & 19 deletions forui/lib/src/theme/theme_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -70,24 +70,33 @@ final class FThemeData with Diagnosticable {
});

/// Creates a [FThemeData] that configures the widget styles using the given properties.
FThemeData.inherit({
required this.colorScheme,
this.typography = const FTypography(),
this.style = const FStyle(),
}) : 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);

/// Creates a copy of this [FThemeData] with the given properties replaced.
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.
///
/// ```dart
/// final foo = FTypography();
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
Loading
Loading