Skip to content

Commit

Permalink
refactor: Rewrite Fortaleza theme using the new code gen for tokens (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
tilucasoli authored Dec 5, 2024
1 parent 70111fc commit e9de199
Show file tree
Hide file tree
Showing 85 changed files with 1,884 additions and 1,480 deletions.
2 changes: 1 addition & 1 deletion packages/mix/lib/src/theme/mix/mix_theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import '../tokens/space_token.dart';
import '../tokens/text_style_token.dart';

class MixTheme extends InheritedWidget {
const MixTheme({required super.child, required this.data, super.key});
const MixTheme({required this.data, super.key, required super.child});

static MixThemeData of(BuildContext context) {
final themeData =
Expand Down
13 changes: 0 additions & 13 deletions packages/mix_generator/lib/src/helpers/builder_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -131,19 +131,6 @@ extension EnumElementX on EnumElement {
}
}

class TokenAnnotationContext extends AnnotationContext {
final Object? type;

TokenAnnotationContext({
required super.element,
required this.type,
});

String get name => element.name;

String get generatedName => element.generatedName;
}

extension ClassElementX on ClassElement {
bool get isConst => unnamedConstructor?.isConst ?? false;

Expand Down
44 changes: 30 additions & 14 deletions packages/remix/demo/lib/addons/brightness_addon.dart
Original file line number Diff line number Diff line change
@@ -1,43 +1,59 @@
import 'package:flutter/material.dart';
import 'package:widgetbook/widgetbook.dart';
import 'package:widgetbook_annotation/widgetbook_annotation.dart';

class BrightnessAddon extends WidgetbookAddon<Brightness> {
final Brightness initialBrightness;
class WidgetBookBrightness {
static const light = 'light';
static const dark = 'dark';
}

class BrightnessAddon extends WidgetbookAddon<String> {
final String initialBrightness;

BrightnessAddon({
this.initialBrightness = Brightness.light,
}) : super(name: 'Brightness');
this.initialBrightness = WidgetBookBrightness.light,
}) : super(name: 'brightness');

@override
Widget buildUseCase(
BuildContext context,
Widget child,
Brightness setting,
String setting,
) {
return Theme(
data: ThemeData(
brightness: setting,
return MediaQuery(
data: MediaQueryData(
platformBrightness: setting == WidgetBookBrightness.light
? Brightness.light
: Brightness.dark,
),
child: child,
);
}

@override
List<Field<Brightness>> get fields {
List<Field<String>> get fields {
return [
ListField<Brightness>(
ListField<String>(
name: 'brightness',
initialValue: initialBrightness,
values: [
Brightness.light,
Brightness.dark,
WidgetBookBrightness.light,
WidgetBookBrightness.dark,
],
)
];
}

@override
Brightness valueFromQueryGroup(Map<String, String> group) {
return valueOf<Brightness>('brightness', group)!;
String valueFromQueryGroup(Map<String, String> group) {
return valueOf<String>('brightness', group)!;
}
}

class BrightnessAddonConfig extends AddonConfig {
const BrightnessAddonConfig(String value)
: super(
'brightness',
'brightness:$value',
);
}
70 changes: 70 additions & 0 deletions packages/remix/demo/lib/addons/theme_addon.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import 'package:flutter/widgets.dart';
import 'package:remix/remix.dart';
import 'package:remix/themes/fortaleza.dart';
import 'package:widgetbook/widgetbook.dart';
import 'package:widgetbook_annotation/widgetbook_annotation.dart';

typedef ThemeMultiBrightness = ({RemixThemeData light, RemixThemeData dark});

final Map<String, ThemeMultiBrightness> themes = {
'fortaleza': (
light: FortalezaThemeData.light(),
dark: FortalezaThemeData.dark(),
),
'base': (
light: RemixThemeData.baseLight(),
dark: RemixThemeData.baseDark(),
),
};

class ComponentTheme {
static const fortaleza = 'fortaleza';
static const base = 'base';
}

class ComponentThemeAddon extends WidgetbookAddon<String> {
final String initialBrightness;

ComponentThemeAddon({
this.initialBrightness = ComponentTheme.fortaleza,
}) : super(name: 'component theme');

@override
Widget buildUseCase(
BuildContext context,
Widget child,
String setting,
) {
final theme = themes[setting];
return RemixApp(
debugShowCheckedModeBanner: false,
darkTheme: theme!.dark,
theme: theme.light,
home: child,
);
}

@override
List<Field<String>> get fields {
return [
ListField<String>(
name: 'brightness',
initialValue: initialBrightness,
values: [
ComponentTheme.fortaleza,
ComponentTheme.base,
],
)
];
}

@override
String valueFromQueryGroup(Map<String, String> group) {
return valueOf<String>('brightness', group)!;
}
}

class ComponentThemeAddonConfig extends AddonConfig {
const ComponentThemeAddonConfig(String value)
: super('component theme', 'component theme:$value');
}
1 change: 1 addition & 0 deletions packages/remix/demo/lib/components/avatar_use_case.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:demo/helpers/knob_builder.dart';
import 'package:flutter/widgets.dart';
import 'package:remix/remix.dart';
import 'package:remix/themes/fortaleza.dart';
import 'package:widgetbook/widgetbook.dart';
import 'package:widgetbook_annotation/widgetbook_annotation.dart' as widgetbook;

Expand Down
6 changes: 4 additions & 2 deletions packages/remix/demo/lib/components/badge_use_case.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import 'package:demo/helpers/knob_builder.dart';
import 'package:flutter/widgets.dart';
import 'package:remix/remix.dart';
import 'package:remix/themes/fortaleza.dart';
import 'package:widgetbook/widgetbook.dart';
import 'package:widgetbook_annotation/widgetbook_annotation.dart' as widgetbook;

Expand All @@ -15,8 +17,8 @@ Widget buildAvatarUseCase(BuildContext context) {
label: 'Label',
initialValue: 'New',
),
variants: const [
// context.knobs.variant(FortalezaBadgeStyle.variants),
variants: [
context.knobs.variant(FortalezaBadgeStyle.variants),
],
),
),
Expand Down
1 change: 1 addition & 0 deletions packages/remix/demo/lib/components/button_use_case.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:demo/addons/icon_data_knob.dart';
import 'package:demo/helpers/knob_builder.dart';
import 'package:flutter/widgets.dart';
import 'package:remix/remix.dart';
import 'package:remix/themes/fortaleza.dart';
import 'package:widgetbook/widgetbook.dart';
import 'package:widgetbook_annotation/widgetbook_annotation.dart' as widgetbook;

Expand Down
2 changes: 1 addition & 1 deletion packages/remix/demo/lib/components/callout_use_case.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import 'package:demo/helpers/knob_builder.dart';
import 'package:flutter/material.dart' as m;
import 'package:flutter/widgets.dart';

import 'package:remix/remix.dart';
import 'package:remix/themes/fortaleza.dart';
import 'package:widgetbook/widgetbook.dart';
import 'package:widgetbook_annotation/widgetbook_annotation.dart' as widgetbook;

Expand Down
19 changes: 16 additions & 3 deletions packages/remix/demo/lib/components/card_use_case.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:demo/helpers/knob_builder.dart';
import 'package:flutter/widgets.dart';
import 'package:mix/mix.dart';
import 'package:remix/remix.dart';
import 'package:remix/themes/fortaleza.dart';
import 'package:widgetbook/widgetbook.dart';
import 'package:widgetbook_annotation/widgetbook_annotation.dart' as widgetbook;

Expand Down Expand Up @@ -32,13 +33,25 @@ Widget buildCard(BuildContext context) {
children: [
StyledText(
'Leo Farias',
style: Style($text.style.ref($rx.text.text3)),
style: Style(
$text.chain
..style.fontSize(14)
..style.fontWeight.bold()
..style.color.black87(),
$on.dark(
$text.style.color.white(),
),
),
),
StyledText(
'Flutter Engineer',
style: Style(
$text.style.ref($rx.text.text2),
$text.style.color.$neutral(10),
$text.chain
..style.fontSize(12)
..style.color.black54(),
$on.dark(
$text.style.color.white70(),
),
),
),
],
Expand Down
1 change: 1 addition & 0 deletions packages/remix/demo/lib/components/checkbox_use_case.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:demo/helpers/knob_builder.dart';
import 'package:demo/helpers/use_case_state.dart';
import 'package:flutter/widgets.dart';
import 'package:remix/remix.dart';
import 'package:remix/themes/fortaleza.dart';
import 'package:widgetbook/widgetbook.dart';
import 'package:widgetbook_annotation/widgetbook_annotation.dart' as widgetbook;

Expand Down
1 change: 1 addition & 0 deletions packages/remix/demo/lib/components/chip_use_case.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:demo/helpers/knob_builder.dart';
import 'package:demo/helpers/use_case_state.dart';
import 'package:flutter/widgets.dart';
import 'package:remix/remix.dart';
import 'package:remix/themes/fortaleza.dart';
import 'package:widgetbook/widgetbook.dart';
import 'package:widgetbook_annotation/widgetbook_annotation.dart' as widgetbook;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart' as m;
import 'package:flutter/widgets.dart';
import 'package:remix/remix.dart';
import 'package:remix/themes/fortaleza.dart';
import 'package:widgetbook/widgetbook.dart';
import 'package:widgetbook_annotation/widgetbook_annotation.dart' as widgetbook;

Expand Down
1 change: 1 addition & 0 deletions packages/remix/demo/lib/components/progress_use_case.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:demo/helpers/knob_builder.dart';
import 'package:flutter/widgets.dart';
import 'package:remix/remix.dart';
import 'package:remix/themes/fortaleza.dart';
import 'package:widgetbook/widgetbook.dart';
import 'package:widgetbook_annotation/widgetbook_annotation.dart' as widgetbook;

Expand Down
1 change: 1 addition & 0 deletions packages/remix/demo/lib/components/radio_use_case.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:demo/helpers/knob_builder.dart';
import 'package:demo/helpers/string.dart';
import 'package:flutter/widgets.dart';
import 'package:remix/remix.dart';
import 'package:remix/themes/fortaleza.dart';
import 'package:widgetbook/widgetbook.dart';
import 'package:widgetbook_annotation/widgetbook_annotation.dart' as widgetbook;

Expand Down
1 change: 1 addition & 0 deletions packages/remix/demo/lib/components/select_use_case.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:demo/helpers/knob_builder.dart';
import 'package:flutter/material.dart' as m;
import 'package:flutter/widgets.dart';
import 'package:remix/remix.dart';
import 'package:remix/themes/fortaleza.dart';
import 'package:widgetbook/widgetbook.dart';
import 'package:widgetbook_annotation/widgetbook_annotation.dart' as widgetbook;

Expand Down
1 change: 1 addition & 0 deletions packages/remix/demo/lib/components/spinner_use_case.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:demo/helpers/knob_builder.dart';
import 'package:flutter/widgets.dart';
import 'package:remix/remix.dart';
import 'package:remix/themes/fortaleza.dart';
import 'package:widgetbook/widgetbook.dart';
import 'package:widgetbook_annotation/widgetbook_annotation.dart' as widgetbook;

Expand Down
1 change: 1 addition & 0 deletions packages/remix/demo/lib/components/switch_use_case.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:demo/helpers/knob_builder.dart';
import 'package:demo/helpers/use_case_state.dart';
import 'package:flutter/widgets.dart';
import 'package:remix/remix.dart';
import 'package:remix/themes/fortaleza.dart';
import 'package:widgetbook/widgetbook.dart';
import 'package:widgetbook_annotation/widgetbook_annotation.dart' as widgetbook;

Expand Down
1 change: 1 addition & 0 deletions packages/remix/demo/lib/components/textfield_use_case.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:demo/addons/icon_data_knob.dart';
import 'package:flutter/material.dart' as m;
import 'package:flutter/widgets.dart';
import 'package:remix/remix.dart';
import 'package:remix/themes/fortaleza.dart';
import 'package:widgetbook/widgetbook.dart';
import 'package:widgetbook_annotation/widgetbook_annotation.dart' as widgetbook;

Expand Down
32 changes: 0 additions & 32 deletions packages/remix/demo/lib/helpers/theme_addon.dart

This file was deleted.

Loading

0 comments on commit e9de199

Please sign in to comment.