Skip to content

Commit c1ecdf2

Browse files
authored
feat: minor theme updates (#239)
1 parent e232f93 commit c1ecdf2

File tree

3 files changed

+58
-24
lines changed

3 files changed

+58
-24
lines changed

packages/cosmos_ui_components/lib/components/cosmos_elevated_button.dart

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ class CosmosElevatedButton extends StatelessWidget {
1313
this.prefixIcon,
1414
this.height = GlobalConstants.defaultButtonHeight,
1515
this.contentPadding,
16+
this.elevation,
17+
this.backgroundColor,
18+
this.textColor,
19+
this.shadowColor,
1620
}) : super(key: key);
1721

1822
final VoidCallback? onTap;
@@ -21,29 +25,37 @@ class CosmosElevatedButton extends StatelessWidget {
2125
final Widget? prefixIcon;
2226
final double height;
2327
final double? contentPadding;
28+
final double? elevation;
29+
final Color? backgroundColor;
30+
final Color? textColor;
31+
final Color? shadowColor;
2432

2533
@override
2634
Widget build(BuildContext context) {
35+
final theme = CosmosTheme.of(context);
2736
return ElevatedButton(
2837
onPressed: onTap,
2938
style: ElevatedButton.styleFrom(
39+
primary: backgroundColor,
40+
onPrimary: textColor,
3041
fixedSize: Size.fromHeight(height),
31-
shape: RoundedRectangleBorder(borderRadius: CosmosTheme.of(context).borderRadiusM),
32-
elevation: 0,
42+
shape: RoundedRectangleBorder(borderRadius: theme.borderRadiusM),
43+
elevation: elevation ?? 0,
44+
shadowColor: shadowColor ?? theme.colors.shadowColor,
3345
),
3446
child: Row(
3547
mainAxisSize: MainAxisSize.min,
3648
children: [
3749
if (prefixIcon != null) ...[
3850
prefixIcon!,
39-
SizedBox(width: contentPadding ?? CosmosTheme.of(context).spacingS),
51+
SizedBox(width: contentPadding ?? theme.spacingS),
4052
],
4153
Text(
4254
text,
4355
style: CosmosTextTheme.elevatedButton,
4456
),
4557
if (suffixIcon != null) ...[
46-
SizedBox(width: contentPadding ?? CosmosTheme.of(context).spacingS),
58+
SizedBox(width: contentPadding ?? theme.spacingS),
4759
suffixIcon!,
4860
],
4961
],
@@ -58,6 +70,10 @@ class CosmosElevatedButton extends StatelessWidget {
5870
..add(DoubleProperty('contentPadding', contentPadding))
5971
..add(DoubleProperty('height', height))
6072
..add(StringProperty('text', text))
61-
..add(ObjectFlagProperty<VoidCallback?>.has('onTap', onTap));
73+
..add(ObjectFlagProperty<VoidCallback?>.has('onTap', onTap))
74+
..add(DoubleProperty('elevation', elevation))
75+
..add(ColorProperty('textColor', textColor))
76+
..add(ColorProperty('backgroundColor', backgroundColor))
77+
..add(ColorProperty('shadowColor', shadowColor));
6278
}
6379
}

packages/cosmos_ui_components/lib/components/cosmos_text_field.dart

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ class CosmosTextField extends StatefulWidget {
1414
this.hint,
1515
this.keyboardType,
1616
this.controller,
17+
this.textAlign = TextAlign.start,
18+
this.style,
1719
Key? key,
1820
}) : super(key: key);
1921

@@ -26,6 +28,8 @@ class CosmosTextField extends StatefulWidget {
2628
final Widget? suffix;
2729
final TextInputType? keyboardType;
2830
final TextEditingController? controller;
31+
final TextAlign textAlign;
32+
final TextStyle? style;
2933

3034
@override
3135
State<CosmosTextField> createState() => _CosmosTextFieldState();
@@ -41,26 +45,28 @@ class CosmosTextField extends StatefulWidget {
4145
..add(IntProperty('minLines', minLines))
4246
..add(ObjectFlagProperty<Function(String p1)>.has('onChanged', onChanged))
4347
..add(DiagnosticsProperty<TextEditingController?>('controller', controller))
44-
..add(StringProperty('hint', hint));
48+
..add(StringProperty('hint', hint))
49+
..add(EnumProperty<TextAlign>('textAlign', textAlign))
50+
..add(DiagnosticsProperty<TextStyle?>('style', style));
4551
}
4652
}
4753

4854
class _CosmosTextFieldState extends State<CosmosTextField> {
49-
late TextEditingController controller;
50-
bool isTextEmpty = false;
55+
late TextEditingController _controller;
56+
bool _isTextEmpty = false;
5157

5258
@override
5359
void initState() {
5460
super.initState();
55-
controller = widget.controller ?? TextEditingController();
56-
controller.text = widget.initialText;
61+
_controller = widget.controller ?? TextEditingController();
62+
_controller.text = widget.initialText;
5763
}
5864

5965
@override
6066
void dispose() {
6167
if (widget.controller == null) {
6268
// it's a controller created internally by the CosmosTextField, thus we'll take care of disposing it properly here
63-
controller.dispose();
69+
_controller.dispose();
6470
}
6571
super.dispose();
6672
}
@@ -69,18 +75,20 @@ class _CosmosTextFieldState extends State<CosmosTextField> {
6975
Widget build(BuildContext context) {
7076
final theme = CosmosTheme.of(context);
7177
return TextField(
72-
controller: controller,
78+
controller: _controller,
7379
maxLines: widget.maxLines,
7480
maxLength: widget.maxLength,
7581
minLines: widget.minLines,
7682
keyboardType: widget.keyboardType,
7783
onChanged: (value) {
7884
widget.onChanged(value);
79-
if (value.isEmpty == isTextEmpty) {
85+
if (value.isEmpty == _isTextEmpty) {
8086
setState(() {});
81-
isTextEmpty = !isTextEmpty;
87+
_isTextEmpty = !_isTextEmpty;
8288
}
8389
},
90+
textAlign: widget.textAlign,
91+
style: widget.style,
8492
decoration: InputDecoration(
8593
counterText: widget.maxLength == null ? null : '',
8694
border: UnderlineInputBorder(borderSide: BorderSide(color: theme.colors.inputBorder)),
@@ -90,15 +98,15 @@ class _CosmosTextFieldState extends State<CosmosTextField> {
9098
),
9199
suffix: widget.suffix == null
92100
? _buildClearButton()
93-
: (controller.text.isEmpty ? widget.suffix : _buildClearButton()),
101+
: (_controller.text.isEmpty ? widget.suffix : _buildClearButton()),
94102
),
95103
);
96104
}
97105

98106
InkWell _buildClearButton() {
99107
return InkWell(
100108
onTap: () {
101-
controller.clear();
109+
_controller.clear();
102110
setState(() {});
103111
},
104112
child: SizedBox(
@@ -108,12 +116,4 @@ class _CosmosTextFieldState extends State<CosmosTextField> {
108116
),
109117
);
110118
}
111-
112-
@override
113-
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
114-
super.debugFillProperties(properties);
115-
properties
116-
..add(DiagnosticsProperty<TextEditingController>('controller', controller))
117-
..add(DiagnosticsProperty<bool>('isTextEmpty', isTextEmpty));
118-
}
119119
}

packages/cosmos_ui_components/lib/cosmos_theme.dart

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class CosmosTheme extends InheritedWidget {
2828

2929
@override
3030
bool updateShouldNotify(CosmosTheme oldWidget) => oldWidget.themeData != themeData;
31+
3132
@override
3233
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
3334
super.debugFillProperties(properties);
@@ -60,6 +61,8 @@ class CosmosThemeData extends Equatable {
6061
this.borderRadiusM = defaultBorderRadiusM,
6162
this.borderRadiusS = defaultBorderRadiusS,
6263
this.elevationS = defaultElevationS,
64+
this.elevationM = defaultElevationM,
65+
this.elevationL = defaultElevationL,
6366
this.colors = const CosmosColorsData(),
6467
});
6568

@@ -88,6 +91,8 @@ class CosmosThemeData extends Equatable {
8891
static const defaultFontSizeXL = 28.0;
8992
static const defaultFontSizeXXL = 40.0;
9093
static const defaultElevationS = 4.0;
94+
static const defaultElevationM = 8.0;
95+
static const defaultElevationL = 12.0;
9196

9297
static const defaultBorderRadiusL = BorderRadius.all(Radius.circular(defaultRadiusL));
9398
static const defaultBorderRadiusM = BorderRadius.all(Radius.circular(defaultRadiusM));
@@ -113,6 +118,8 @@ class CosmosThemeData extends Equatable {
113118
final double fontSizeXL;
114119
final double fontSizeXXL;
115120
final double elevationS;
121+
final double elevationM;
122+
final double elevationL;
116123
final BorderRadius borderRadiusM;
117124
final BorderRadius borderRadiusL;
118125
final BorderRadius borderRadiusS;
@@ -122,6 +129,7 @@ class CosmosThemeData extends Equatable {
122129
List<Object?> get props => [
123130
spacingXXXL,
124131
spacingXXL,
132+
spacingXL,
125133
spacingL,
126134
spacingM,
127135
spacingS,
@@ -130,15 +138,21 @@ class CosmosThemeData extends Equatable {
130138
mediumDuration,
131139
shortDuration,
132140
radiusXL,
141+
radiusL,
133142
radiusM,
134143
radiusS,
135144
fontSizeS,
136145
fontSizeM,
137146
fontSizeL,
138147
fontSizeXL,
139148
fontSizeXXL,
149+
borderRadiusL,
140150
borderRadiusM,
141151
borderRadiusS,
152+
elevationS,
153+
elevationM,
154+
elevationL,
155+
colors,
142156
];
143157
}
144158

@@ -157,6 +171,7 @@ class CosmosColorsData extends Equatable {
157171
this.inputBorder = lightBorder,
158172
this.avatarBg = silver,
159173
this.error = defaultError,
174+
this.shadowColor = defaultShadowColor,
160175
});
161176

162177
static const lightBg = Color(0xFFFFFFFF);
@@ -179,6 +194,7 @@ class CosmosColorsData extends Equatable {
179194
static const darkDivider = Color(0x17FFFFFF);
180195
static const iosError = Color(0xFFE74444);
181196
static const defaultError = Color(0xFFFF3D56);
197+
static const defaultShadowColor = Colors.black38;
182198

183199
final Color inactive;
184200
final Color divider;
@@ -193,6 +209,7 @@ class CosmosColorsData extends Equatable {
193209
final Color inputBorder;
194210
final Color avatarBg;
195211
final Color error;
212+
final Color shadowColor;
196213

197214
@override
198215
List<Object?> get props => [
@@ -209,5 +226,6 @@ class CosmosColorsData extends Equatable {
209226
inputBorder,
210227
avatarBg,
211228
error,
229+
shadowColor,
212230
];
213231
}

0 commit comments

Comments
 (0)