Skip to content

Commit

Permalink
feat: [MDS-503] Create Input widget (#144)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kypsis committed May 5, 2023
1 parent 23e9268 commit fc5cd2a
Show file tree
Hide file tree
Showing 22 changed files with 1,468 additions and 134 deletions.
5 changes: 1 addition & 4 deletions example/lib/src/storybook/stories/tag.dart
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,7 @@ class TagStory extends Story {
backgroundColor: backgroundColor,
leading: showLeadingKnob ? const MoonIcon(MoonIcons.close_small_16) : null,
label: showLabelKnob
? Padding(
padding: EdgeInsets.only(top: setUpperCase ? 1.5 : 0),
child: Text(setUpperCase ? customLabelTextKnob.toUpperCase() : customLabelTextKnob),
)
? Text(setUpperCase ? customLabelTextKnob.toUpperCase() : customLabelTextKnob)
: null,
trailing: showTrailingKnob ? const MoonIcon(MoonIcons.close_small_16) : null,
),
Expand Down
177 changes: 177 additions & 0 deletions example/lib/src/storybook/stories/text_input.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
import 'package:example/src/storybook/common/color_options.dart';
import 'package:flutter/material.dart';
import 'package:moon_design/moon_design.dart';
import 'package:storybook_flutter/storybook_flutter.dart';

TextEditingController _textEditingController = TextEditingController();

class TextInputStory extends Story {
TextInputStory()
: super(
name: "TextInput",
builder: (context) {
final textInputSizesKnob = context.knobs.nullable.options(
label: "textInputSize",
description: "Size variants for MoonTextInput.",
enabled: false,
initial: MoonTextInputSize.md,
options: const [
Option(label: "sm", value: MoonTextInputSize.sm),
Option(label: "md", value: MoonTextInputSize.md),
Option(label: "lg", value: MoonTextInputSize.lg),
Option(label: "xl", value: MoonTextInputSize.xl)
],
);

final textColorsKnob = context.knobs.nullable.options(
label: "textColor",
description: "MoonColors variants for MoonTextInput text.",
enabled: false,
initial: 0, // piccolo
options: colorOptions,
);

final textColor = colorTable(context)[textColorsKnob ?? 40];

final hintTextColorsKnob = context.knobs.nullable.options(
label: "hintTextColor",
description: "MoonColors variants for MoonTextInput hint text.",
enabled: false,
initial: 0, // piccolo
options: colorOptions,
);

final hintTextColor = colorTable(context)[hintTextColorsKnob ?? 40];

final backgroundColorsKnob = context.knobs.nullable.options(
label: "backgroundColor",
description: "MoonColors variants for MoonTextInput background.",
enabled: false,
initial: 0, // piccolo
options: colorOptions,
);

final backgroundColor = colorTable(context)[backgroundColorsKnob ?? 40];

final activeBorderColorsKnob = context.knobs.nullable.options(
label: "activeBorderColor",
description: "MoonColors variants for MoonTextInput active border.",
enabled: false,
initial: 0, // piccolo
options: colorOptions,
);

final activeBorderColor = colorTable(context)[activeBorderColorsKnob ?? 40];

final inactiveBorderColorsKnob = context.knobs.nullable.options(
label: "inactiveBorderColor",
description: "MoonColors variants for MoonTextInput inactive border.",
enabled: false,
initial: 0, // piccolo
options: colorOptions,
);

final inactiveBorderColor = colorTable(context)[inactiveBorderColorsKnob ?? 40];

final errorBorderColorsKnob = context.knobs.nullable.options(
label: "errorBorderColor",
description: "MoonColors variants for MoonTextInput error border.",
enabled: false,
initial: 0, // piccolo
options: colorOptions,
);

final errorBorderColor = colorTable(context)[errorBorderColorsKnob ?? 40];

final borderRadiusKnob = context.knobs.nullable.sliderInt(
label: "borderRadius",
description: "Border radius for MoonTextInput.",
enabled: false,
initial: 8,
max: 32,
);

final enabledKnob = context.knobs.boolean(
label: "enabled",
description: "Switch between enabled and disabled states.",
initial: true,
);

final showLeadingKnob = context.knobs.boolean(
label: "leading",
description: "Show widget in MoonTextInput leading slot.",
initial: true,
);

final showTrailingKnob = context.knobs.boolean(
label: "trailing",
description: "Show widget in MoonTextInput trailing slot.",
initial: true,
);

final showSupportingKnob = context.knobs.boolean(
label: "supporting",
description: "Show widget in MoonTextInput supporting slot.",
);

return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const SizedBox(height: 64),
Form(
child: Builder(
builder: (context) {
return Column(
children: [
SizedBox(
height: 86,
child: MoonTextInput(
controller: _textEditingController,
textInputSize: textInputSizesKnob,
enabled: enabledKnob,
textColor: textColor,
hintTextColor: hintTextColor,
backgroundColor: backgroundColor,
activeBorderColor: activeBorderColor,
inactiveBorderColor: inactiveBorderColor,
errorBorderColor: errorBorderColor,
borderRadius: borderRadiusKnob != null
? BorderRadius.circular(borderRadiusKnob.toDouble())
: null,
hintText: "Enter your text here...",
validator: (value) => value?.length != null && value!.length < 10
? "The text should be longer than 10 characters."
: null,
leading: showLeadingKnob ? const MoonIcon(MoonIcons.search_24) : null,
trailing: showTrailingKnob
? MoonButton.icon(
icon: MoonIcon(
MoonIcons.close_24,
color: DefaultTextStyle.of(context).style.color,
),
buttonSize: MoonButtonSize.xs,
onTap: () => _textEditingController.clear(),
)
: null,
supporting: showSupportingKnob ? const Text("Supporting text") : null,
errorBuilder: (context, errorText) => Text(errorText!),
),
),
const SizedBox(height: 8),
MoonFilledButton(
label: const Text("Submit"),
onTap: () => Form.of(context).validate(),
)
],
);
},
),
),
const SizedBox(height: 64),
],
),
);
},
);
}
6 changes: 4 additions & 2 deletions example/lib/src/storybook/storybook.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import 'package:example/src/storybook/stories/popover.dart';
import 'package:example/src/storybook/stories/radio.dart';
import 'package:example/src/storybook/stories/switch.dart';
import 'package:example/src/storybook/stories/tag.dart';
import 'package:example/src/storybook/stories/textarea.dart';
import 'package:example/src/storybook/stories/text_area.dart';
import 'package:example/src/storybook/stories/text_input.dart';
import 'package:example/src/storybook/stories/toast.dart';
import 'package:example/src/storybook/stories/tooltip.dart';
import 'package:flutter/material.dart';
Expand All @@ -43,7 +44,7 @@ class StorybookPage extends StatelessWidget {
return Stack(
children: [
Storybook(
initialStory: "Accordion",
initialStory: "TextInput",
plugins: _plugins,
brandingWidget: const MoonVersionWidget(),
wrapperBuilder: (context, child) => MaterialApp(
Expand Down Expand Up @@ -93,6 +94,7 @@ class StorybookPage extends StatelessWidget {
SwitchStory(),
TagStory(),
TextAreaStory(),
TextInputStory(),
ToastStory(),
TooltipStory(),
],
Expand Down
6 changes: 4 additions & 2 deletions lib/moon_design.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ export 'package:moon_design/src/theme/radio/radio_theme.dart';
export 'package:moon_design/src/theme/shadows.dart';
export 'package:moon_design/src/theme/sizes.dart';
export 'package:moon_design/src/theme/switch/switch_theme.dart';
export 'package:moon_design/src/theme/textarea/textarea_theme.dart';
export 'package:moon_design/src/theme/text_area/text_area_theme.dart';
export 'package:moon_design/src/theme/text_input/text_input_theme.dart';
export 'package:moon_design/src/theme/theme.dart';
export 'package:moon_design/src/theme/toast/toast_theme.dart';
export 'package:moon_design/src/theme/tooltip/tooltip_theme.dart';
Expand Down Expand Up @@ -63,6 +64,7 @@ export 'package:moon_design/src/widgets/progress/linear_progress.dart';
export 'package:moon_design/src/widgets/radio/radio.dart';
export 'package:moon_design/src/widgets/switch/switch.dart';
export 'package:moon_design/src/widgets/tag/tag.dart';
export 'package:moon_design/src/widgets/textarea/textarea.dart';
export 'package:moon_design/src/widgets/text_area/text_area.dart';
export 'package:moon_design/src/widgets/text_input/text_input.dart';
export 'package:moon_design/src/widgets/toast/toast.dart';
export 'package:moon_design/src/widgets/tooltip/tooltip.dart';
23 changes: 16 additions & 7 deletions lib/src/theme/borders.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ class MoonBorders extends ThemeExtension<MoonBorders> with DiagnosticableTreeMix
surfaceSm: BorderRadius.all(Radius.circular(8)),
surfaceMd: BorderRadius.all(Radius.circular(12)),
surfaceLg: BorderRadius.all(Radius.circular(16)),
borderWidth: 1,
defaultBorderWidth: 1,
activeBorderWidth: 1.5,
);

/// Interactive radius XS.
Expand All @@ -38,7 +39,10 @@ class MoonBorders extends ThemeExtension<MoonBorders> with DiagnosticableTreeMix
final BorderRadiusGeometry surfaceLg;

/// Default border width.
final double borderWidth;
final double defaultBorderWidth;

/// Active border width.
final double activeBorderWidth;

const MoonBorders({
required this.interactiveXs,
Expand All @@ -48,7 +52,8 @@ class MoonBorders extends ThemeExtension<MoonBorders> with DiagnosticableTreeMix
required this.surfaceSm,
required this.surfaceMd,
required this.surfaceLg,
required this.borderWidth,
required this.defaultBorderWidth,
required this.activeBorderWidth,
});

@override
Expand All @@ -60,7 +65,8 @@ class MoonBorders extends ThemeExtension<MoonBorders> with DiagnosticableTreeMix
BorderRadiusGeometry? surfaceSm,
BorderRadiusGeometry? surfaceMd,
BorderRadiusGeometry? surfaceLg,
double? borderWidth,
double? defaultBorderWidth,
double? activeBorderWidth,
}) {
return MoonBorders(
interactiveXs: interactiveXs ?? this.interactiveXs,
Expand All @@ -70,7 +76,8 @@ class MoonBorders extends ThemeExtension<MoonBorders> with DiagnosticableTreeMix
surfaceSm: surfaceSm ?? this.surfaceSm,
surfaceMd: surfaceMd ?? this.surfaceMd,
surfaceLg: surfaceLg ?? this.surfaceLg,
borderWidth: borderWidth ?? this.borderWidth,
defaultBorderWidth: defaultBorderWidth ?? this.defaultBorderWidth,
activeBorderWidth: activeBorderWidth ?? this.activeBorderWidth,
);
}

Expand All @@ -86,7 +93,8 @@ class MoonBorders extends ThemeExtension<MoonBorders> with DiagnosticableTreeMix
surfaceSm: BorderRadiusGeometry.lerp(surfaceSm, other.surfaceSm, t)!,
surfaceMd: BorderRadiusGeometry.lerp(surfaceMd, other.surfaceMd, t)!,
surfaceLg: BorderRadiusGeometry.lerp(surfaceLg, other.surfaceLg, t)!,
borderWidth: lerpDouble(borderWidth, other.borderWidth, t)!,
defaultBorderWidth: lerpDouble(defaultBorderWidth, other.defaultBorderWidth, t)!,
activeBorderWidth: lerpDouble(activeBorderWidth, other.activeBorderWidth, t)!,
);
}

Expand All @@ -102,6 +110,7 @@ class MoonBorders extends ThemeExtension<MoonBorders> with DiagnosticableTreeMix
..add(DiagnosticsProperty<BorderRadiusGeometry>("surfaceSm", surfaceSm))
..add(DiagnosticsProperty<BorderRadiusGeometry>("surfaceMd", surfaceMd))
..add(DiagnosticsProperty<BorderRadiusGeometry>("surfaceLg", surfaceLg))
..add(DoubleProperty("borderWidth", borderWidth));
..add(DoubleProperty("defaultBorderWidth", defaultBorderWidth))
..add(DoubleProperty("activeBorderWidth", activeBorderWidth));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class MoonTextAreaColors extends ThemeExtension<MoonTextAreaColors> with Diagnos
activeBorderColor: MoonColors.light.piccolo,
inactiveBorderColor: MoonColors.light.beerus,
errorBorderColor: MoonColors.light.chiChi100,
hoverBorderColor: MoonColors.light.beerus,
hintTextColor: MoonColors.light.trunks,
);

Expand All @@ -18,6 +19,7 @@ class MoonTextAreaColors extends ThemeExtension<MoonTextAreaColors> with Diagnos
activeBorderColor: MoonColors.dark.piccolo,
inactiveBorderColor: MoonColors.dark.beerus,
errorBorderColor: MoonColors.dark.chiChi100,
hoverBorderColor: MoonColors.dark.beerus,
hintTextColor: MoonColors.dark.trunks,
);

Expand All @@ -33,6 +35,9 @@ class MoonTextAreaColors extends ThemeExtension<MoonTextAreaColors> with Diagnos
/// TextArea error border color.
final Color errorBorderColor;

/// TextArea error border color.
final Color hoverBorderColor;

/// TextArea hint text color.
final Color hintTextColor;

Expand All @@ -41,6 +46,7 @@ class MoonTextAreaColors extends ThemeExtension<MoonTextAreaColors> with Diagnos
required this.activeBorderColor,
required this.inactiveBorderColor,
required this.errorBorderColor,
required this.hoverBorderColor,
required this.hintTextColor,
});

Expand All @@ -50,13 +56,15 @@ class MoonTextAreaColors extends ThemeExtension<MoonTextAreaColors> with Diagnos
Color? activeBorderColor,
Color? inactiveBorderColor,
Color? errorBorderColor,
Color? hoverBorderColor,
Color? hintTextColor,
}) {
return MoonTextAreaColors(
backgroundColor: backgroundColor ?? this.backgroundColor,
activeBorderColor: activeBorderColor ?? this.activeBorderColor,
inactiveBorderColor: inactiveBorderColor ?? this.inactiveBorderColor,
errorBorderColor: errorBorderColor ?? this.errorBorderColor,
hoverBorderColor: hoverBorderColor ?? this.hoverBorderColor,
hintTextColor: hintTextColor ?? this.hintTextColor,
);
}
Expand All @@ -70,6 +78,7 @@ class MoonTextAreaColors extends ThemeExtension<MoonTextAreaColors> with Diagnos
activeBorderColor: Color.lerp(activeBorderColor, other.activeBorderColor, t)!,
inactiveBorderColor: Color.lerp(inactiveBorderColor, other.inactiveBorderColor, t)!,
errorBorderColor: Color.lerp(errorBorderColor, other.errorBorderColor, t)!,
hoverBorderColor: Color.lerp(hoverBorderColor, other.hoverBorderColor, t)!,
hintTextColor: Color.lerp(hintTextColor, other.hintTextColor, t)!,
);
}
Expand All @@ -83,6 +92,7 @@ class MoonTextAreaColors extends ThemeExtension<MoonTextAreaColors> with Diagnos
..add(ColorProperty("activeBorderColor", activeBorderColor))
..add(ColorProperty("inactiveBorderColor", inactiveBorderColor))
..add(ColorProperty("errorBorderColor", errorBorderColor))
..add(ColorProperty("hoverBorderColor", hoverBorderColor))
..add(ColorProperty("hintTextColor", hintTextColor));
}
}
Loading

0 comments on commit fc5cd2a

Please sign in to comment.