Skip to content

Commit

Permalink
use ZetaWidgetSize from enums.dart (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
atanasyordanov21 authored and thelukewalton committed Apr 25, 2024
1 parent da13199 commit b04527c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 30 deletions.
4 changes: 2 additions & 2 deletions example/lib/pages/components/date_input_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class _DateInputExampleState extends State<DateInputExample> {
label: 'Label',
hint: 'Default hint text',
errorText: 'Oops! Error hint text',
size: ZetaDateInputSize.medium,
size: ZetaWidgetSize.medium,
),
),
Divider(color: Colors.grey[200]),
Expand All @@ -96,7 +96,7 @@ class _DateInputExampleState extends State<DateInputExample> {
label: 'Label',
hint: 'Default hint text',
errorText: 'Oops! Error hint text',
size: ZetaDateInputSize.small,
size: ZetaWidgetSize.small,
),
),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ Widget dateInputUseCase(BuildContext context) {
);
final rounded = context.knobs.boolean(label: 'Rounded', initialValue: true);
final enabled = context.knobs.boolean(label: 'Enabled', initialValue: true);
final size = context.knobs.list<ZetaDateInputSize>(
final size = context.knobs.list<ZetaWidgetSize>(
label: 'Size',
options: ZetaDateInputSize.values,
options: ZetaWidgetSize.values,
labelBuilder: (size) => size.name,
);
final datePattern = context.knobs.list<String>(
Expand Down
40 changes: 14 additions & 26 deletions lib/src/components/date_input/date_input.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,6 @@ import 'package:intl/intl.dart';
import 'package:mask_text_input_formatter/mask_text_input_formatter.dart';
import '../../../zeta_flutter.dart';

/// [ZetaDateInput] size
enum ZetaDateInputSize {
/// [large] 48 pixels height of the input field.
large,

/// [medium] 40 pixels height of the input field.
medium,

/// [small] 32 pixels height of the input field.
small,
}

/// ZetaDateInput allows entering date in a pre-defined format.
/// Validation is performed to make sure the date is valid
/// and is in the proper format.
Expand Down Expand Up @@ -57,7 +45,7 @@ class ZetaDateInput extends StatefulWidget {

/// Determines the size of the input field.
/// Default is `ZetaDateInputSize.large`
final ZetaDateInputSize? size;
final ZetaWidgetSize? size;

/// If provided, displays a label above the input field.
final String? label;
Expand Down Expand Up @@ -102,7 +90,7 @@ class ZetaDateInput extends StatefulWidget {
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties
..add(EnumProperty<ZetaDateInputSize>('size', size))
..add(EnumProperty<ZetaWidgetSize>('size', size))
..add(StringProperty('label', label))
..add(StringProperty('hint', hint))
..add(DiagnosticsProperty<bool>('enabled', enabled))
Expand All @@ -116,7 +104,7 @@ class ZetaDateInput extends StatefulWidget {

class _ZetaDateInputState extends State<ZetaDateInput> {
final _controller = TextEditingController();
late ZetaDateInputSize _size;
late ZetaWidgetSize _size;
late final String _hintText;
late final MaskTextInputFormatter _dateFormatter;
bool _invalidDate = false;
Expand All @@ -141,7 +129,7 @@ class _ZetaDateInputState extends State<ZetaDateInput> {
}

void _setParams() {
_size = widget.size ?? ZetaDateInputSize.large;
_size = widget.size ?? ZetaWidgetSize.large;
_hasError = widget.hasError;
}

Expand Down Expand Up @@ -197,7 +185,7 @@ class _ZetaDateInputState extends State<ZetaDateInput> {
inputFormatters: [_dateFormatter],
keyboardType: TextInputType.number,
onChanged: (_) => _onChanged(),
style: _size == ZetaDateInputSize.small ? ZetaTextStyles.bodyXSmall : ZetaTextStyles.bodyMedium,
style: _size == ZetaWidgetSize.small ? ZetaTextStyles.bodyXSmall : ZetaTextStyles.bodyMedium,
decoration: InputDecoration(
isDense: true,
contentPadding: EdgeInsets.symmetric(
Expand Down Expand Up @@ -235,7 +223,7 @@ class _ZetaDateInputState extends State<ZetaDateInput> {
minHeight: ZetaSpacing.m,
minWidth: ZetaSpacing.m,
),
hintStyle: _size == ZetaDateInputSize.small
hintStyle: _size == ZetaWidgetSize.small
? ZetaTextStyles.bodyXSmall.copyWith(
color: widget.enabled ? zeta.colors.textDefault : zeta.colors.cool.shade50,
)
Expand Down Expand Up @@ -289,16 +277,16 @@ class _ZetaDateInputState extends State<ZetaDateInput> {
);
}

double _inputVerticalPadding(ZetaDateInputSize size) => switch (size) {
ZetaDateInputSize.large => ZetaSpacing.x3,
ZetaDateInputSize.medium => ZetaSpacing.x2,
ZetaDateInputSize.small => ZetaSpacing.x2,
double _inputVerticalPadding(ZetaWidgetSize size) => switch (size) {
ZetaWidgetSize.large => ZetaSpacing.x3,
ZetaWidgetSize.medium => ZetaSpacing.x2,
ZetaWidgetSize.small => ZetaSpacing.x2,
};

double _iconSize(ZetaDateInputSize size) => switch (size) {
ZetaDateInputSize.large => ZetaSpacing.x6,
ZetaDateInputSize.medium => ZetaSpacing.x5,
ZetaDateInputSize.small => ZetaSpacing.x4,
double _iconSize(ZetaWidgetSize size) => switch (size) {
ZetaWidgetSize.large => ZetaSpacing.x6,
ZetaWidgetSize.medium => ZetaSpacing.x5,
ZetaWidgetSize.small => ZetaSpacing.x4,
};

OutlineInputBorder _defaultInputBorder(
Expand Down

0 comments on commit b04527c

Please sign in to comment.