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

feat: Bring TextStyle properties to the root of TextSpecUtility #516

Merged
merged 2 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ base class TextStyleData extends Dto<TextStyle>
final TextDecoration? decoration;
final ColorDto? decorationColor;
final TextDecorationStyle? decorationStyle;
final Locale? locale;
final String? debugLabel;
final double? height;
final Paint? foreground;
Expand All @@ -93,7 +92,6 @@ base class TextStyleData extends Dto<TextStyle>
this.foreground,
this.height,
this.letterSpacing,
this.locale,
this.shadows,
this.textBaseline,
this.wordSpacing,
Expand All @@ -120,7 +118,6 @@ base class TextStyleData extends Dto<TextStyle>
properties.addUsingDefault('foreground', foreground);
properties.addUsingDefault('height', height);
properties.addUsingDefault('letterSpacing', letterSpacing);
properties.addUsingDefault('locale', locale);
properties.addUsingDefault('shadows', shadows);
properties.addUsingDefault('textBaseline', textBaseline);
properties.addUsingDefault('wordSpacing', wordSpacing);
Expand Down Expand Up @@ -156,7 +153,6 @@ final class TextStyleDto extends Dto<TextStyle>
ColorDto? decorationColor,
TextDecorationStyle? decorationStyle,
List<FontVariation>? fontVariations,
Locale? locale,
double? height,
Paint? foreground,
Paint? background,
Expand Down Expand Up @@ -184,7 +180,6 @@ final class TextStyleDto extends Dto<TextStyle>
foreground: foreground,
height: height,
letterSpacing: letterSpacing,
locale: locale,
shadows: shadows,
textBaseline: textBaseline,
wordSpacing: wordSpacing,
Expand Down Expand Up @@ -260,7 +255,6 @@ extension TextStyleExt on TextStyle {
foreground: foreground,
height: height,
letterSpacing: letterSpacing,
locale: locale,
shadows: shadows?.map((e) => e.toDto()).toList(),
textBaseline: textBaseline,
wordSpacing: wordSpacing,
Expand Down

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

Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ final class TextStyleUtility<T extends Attribute>

T fontFeatures(List<FontFeature> v) => call(fontFeatures: v);

T locale(Locale v) => call(locale: v);

T debugLabel(String v) => call(debugLabel: v);

T decorationThickness(double v) => call(decorationThickness: v);
Expand All @@ -84,7 +82,6 @@ final class TextStyleUtility<T extends Attribute>
List<FontFeature>? fontFeatures,
TextDecoration? decoration,
TextDecorationStyle? decorationStyle,
Locale? locale,
String? debugLabel,
List<String>? fontFamilyFallback,
Paint? foreground,
Expand Down Expand Up @@ -112,7 +109,6 @@ final class TextStyleUtility<T extends Attribute>
background: background,
decorationThickness: decorationThickness,
fontFamilyFallback: fontFamilyFallback,
locale: locale,
debugLabel: debugLabel,
height: height,
fontFamily: fontFamily,
Expand All @@ -139,7 +135,6 @@ final class TextStyleUtility<T extends Attribute>
Paint? background,
double? decorationThickness,
List<String>? fontFamilyFallback,
Locale? locale,
String? debugLabel,
double? height,
String? fontFamily,
Expand All @@ -160,7 +155,6 @@ final class TextStyleUtility<T extends Attribute>
decorationColor: decorationColor,
decorationStyle: decorationStyle,
fontVariations: fontVariations,
locale: locale,
height: height,
foreground: foreground,
background: background,
Expand Down
29 changes: 29 additions & 0 deletions packages/mix/lib/src/specs/text/text_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,33 @@ import 'text_widget.dart';

part 'text_spec.g.dart';

const _style = MixableUtility(
type: TextStyle,
properties: [
(path: 'color', alias: 'color'),
(path: 'fontFamily', alias: 'fontFamily'),
(path: 'fontWeight', alias: 'fontWeight'),
(path: 'fontStyle', alias: 'fontStyle'),
(path: 'fontSize', alias: 'fontSize'),
(path: 'letterSpacing', alias: 'letterSpacing'),
(path: 'wordSpacing', alias: 'wordSpacing'),
(path: 'textBaseline', alias: 'textBaseline'),
(path: 'backgroundColor', alias: 'backgroundColor'),
(path: 'shadows', alias: 'shadows'),
(path: 'fontFeatures', alias: 'fontFeatures'),
(path: 'fontVariations', alias: 'fontVariations'),
(path: 'decoration', alias: 'decoration'),
(path: 'decorationColor', alias: 'decorationColor'),
(path: 'decorationStyle', alias: 'decorationStyle'),
(path: 'debugLabel', alias: 'debugLabel'),
(path: 'height', alias: 'height'),
(path: 'foreground', alias: 'foreground'),
(path: 'background', alias: 'background'),
(path: 'decorationThickness', alias: 'decorationThickness'),
(path: 'fontFamilyFallback', alias: 'fontFamilyFallback'),
],
);

@MixableSpec()
final class TextSpec extends Spec<TextSpec> with _$TextSpec, Diagnosticable {
final TextOverflow? overflow;
Expand All @@ -34,6 +61,8 @@ final class TextSpec extends Spec<TextSpec> with _$TextSpec, Diagnosticable {
final int? maxLines;
final TextWidthBasis? textWidthBasis;
final TextScaler? textScaler;

@MixableProperty(utilities: [_style])
final TextStyle? style;
final TextDirection? textDirection;
final bool? softWrap;
Expand Down
63 changes: 63 additions & 0 deletions packages/mix/lib/src/specs/text/text_spec.g.dart

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

Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ void main() {
decoration: TextDecoration.underline,
decorationColor: Colors.blue.toDto(),
decorationStyle: TextDecorationStyle.dashed,
locale: const Locale('en', 'US'),
height: 2.0,
);

Expand All @@ -45,7 +44,6 @@ void main() {
decoration: TextDecoration.lineThrough,
decorationColor: Colors.red.toDto(),
decorationStyle: TextDecorationStyle.dotted,
locale: const Locale('en', 'US'),
height: 3.0,
);

Expand All @@ -62,7 +60,6 @@ void main() {
expect(merged.letterSpacing, 2.0);
expect(merged.wordSpacing, 3.0);
expect(merged.height, 3.0);
expect(merged.locale, const Locale('en', 'US'));
expect(merged.textBaseline, TextBaseline.alphabetic);
});
test('resolve returns correct TextStyle with specific values', () {
Expand All @@ -80,7 +77,6 @@ void main() {
decoration: TextDecoration.underline,
decorationColor: Colors.blue.toDto(),
decorationStyle: TextDecorationStyle.dashed,
locale: const Locale('en', 'US'),
height: 2.0,
);
final textStyle = attr.resolve(EmptyMixData);
Expand All @@ -95,7 +91,6 @@ void main() {
expect(textStyle.letterSpacing, 1.0);
expect(textStyle.wordSpacing, 2.0);
expect(textStyle.height, 2.0);
expect(textStyle.locale, const Locale('en', 'US'));
expect(textStyle.textBaseline, TextBaseline.ideographic);

return const Placeholder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ void main() {
fontWeight: FontWeight.bold,
height: 2.0,
letterSpacing: 1.0,
locale: const Locale('en', 'US'),
shadows: [
const Shadow(
color: Colors.black,
Expand Down Expand Up @@ -70,7 +69,6 @@ void main() {
expect(resolvedValue.fontVariations, [const FontVariation('wght', 900)]);

expect(resolvedValue.debugLabel, 'debugLabel');
expect(resolvedValue.locale, const Locale('en', 'US'));
expect(resolvedValue.height, 2.0);
expect(resolvedWithPaint.foreground, yellowPaint);
expect(resolvedWithPaint.background, purplePaint);
Expand Down
Loading