Skip to content

Commit

Permalink
feat: [MDS-463] Create Alert widget (#97)
Browse files Browse the repository at this point in the history
Co-authored-by: BirgittMajas <79840500+BirgittMajas@users.noreply.github.com>
  • Loading branch information
Kypsis and GittHub-d authored Apr 3, 2023
1 parent bf058f6 commit a491dc7
Show file tree
Hide file tree
Showing 11 changed files with 1,013 additions and 1 deletion.
253 changes: 253 additions & 0 deletions example/lib/src/storybook/stories/alert.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,253 @@
import 'package:example/src/storybook/common/color_options.dart';
import 'package:example/src/storybook/common/widgets/text_divider.dart';
import 'package:flutter/material.dart';
import 'package:moon_design/moon_design.dart';
import 'package:storybook_flutter/storybook_flutter.dart';

bool showAlert = true;

class AlertStory extends Story {
AlertStory()
: super(
name: "Alert",
builder: (context) {
final backgroundColorsKnob = context.knobs.options(
label: "backgroundColor",
description: "MoonColors variants for background.",
initial: 4, // Gohan
options: colorOptions,
);

final backgroundColor = colorTable(context)[backgroundColorsKnob];

final textColorsKnob = context.knobs.options(
label: "textColor",
description: "MoonColors variants for text.",
initial: 5, // Bulma
options: colorOptions,
);

final textColor = colorTable(context)[textColorsKnob];

final leadingColorsKnob = context.knobs.options(
label: "leadingColor",
description: "MoonColors variants for leading.",
initial: 5, // Bulma
options: colorOptions,
);

final leadingColor = colorTable(context)[leadingColorsKnob];

final trailingColorsKnob = context.knobs.options(
label: "trailingColor",
description: "MoonColors variants for trailing.",
initial: 5, // Bulma
options: colorOptions,
);

final trailingColor = colorTable(context)[trailingColorsKnob];

final borderColorsKnob = context.knobs.options(
label: "borderColor",
description: "MoonColors variants for border.",
initial: 5, // Bulma
options: colorOptions,
);

final borderColor = colorTable(context)[borderColorsKnob];

final borderRadiusKnob = context.knobs.sliderInt(
max: 12,
initial: 8,
label: "borderRadius",
description: "Border radius for Alert.",
);

final showBorderKnob = context.knobs.boolean(
label: "showBorder",
description: "Show border for Alert.",
);

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

final showBodyKnob = context.knobs.boolean(
label: "body",
description: "Show widget in the body slot.",
);

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

final showDisabledKnob = context.knobs.boolean(
label: "Disabled",
description: "onTrailingTap() is null.",
);

final setRtlModeKnob = context.knobs.boolean(
label: "RTL mode",
description: "Switch between LTR and RTL modes.",
);

return Directionality(
textDirection: setRtlModeKnob ? TextDirection.rtl : TextDirection.ltr,
child: Center(
child: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const SizedBox(height: 64),
const TextDivider(text: "Base Alert"),
const SizedBox(height: 32),
StatefulBuilder(
builder: (context, setState) {
return Column(
children: [
MoonAlert(
show: showAlert,
title: const SizedBox(
height: 24,
child: Align(
alignment: AlignmentDirectional.centerStart,
child: Text("Base Alert"),
),
),
borderRadius: BorderRadius.circular(borderRadiusKnob.toDouble()),
leading: showLeadingKnob ? const Icon(MoonIconsOther.frame24) : null,
trailing: showTrailingKnob
? MoonButton.icon(
buttonSize: MoonButtonSize.xs,
borderRadius: BorderRadius.circular(borderRadiusKnob.toDouble()),
disabledOpacityValue: 1,
icon: Icon(
MoonIconsControls.close_small24,
color: trailingColor,
size: 24,
),
gap: 0,
onTap: showDisabledKnob
? null
: () {
setState(() => showAlert = !showAlert);
},
)
: null,
backgroundColor: backgroundColor,
showBorder: showBorderKnob,
leadingColor: leadingColor,
trailingColor: trailingColor,
textColor: textColor,
borderColor: borderColor,
body: showBodyKnob
? const SizedBox(
height: 24,
child: Align(
alignment: AlignmentDirectional.centerStart,
child: Text("Here goes Alert body"),
),
)
: null,
),
const SizedBox(height: 16),
MoonFilledButton(
label: const Text("Show/Hide Alert"),
backgroundColor: context.moonColors!.piccolo,
onTap: () {
setState(() => showAlert = !showAlert);
},
),
],
);
},
),
const SizedBox(height: 40),
const TextDivider(text: "Filled Alert variant"),
const SizedBox(height: 32),
MoonFilledAlert(
show: true,
title: const Text("Filled error Alert"),
borderRadius: BorderRadius.circular(borderRadiusKnob.toDouble()),
leading: showLeadingKnob ? const Icon(MoonIconsNotifications.alert24) : null,
color: context.moonColors!.chiChi100,
body: showBodyKnob
? const SizedBox(
height: 24,
child: Align(
alignment: AlignmentDirectional.centerStart,
child: Text("Here goes Alert body"),
),
)
: null,
onTrailingTap: () {},
),
const SizedBox(height: 16),
MoonFilledAlert(
show: true,
title: const Text("Filled warning Alert"),
borderRadius: BorderRadius.circular(borderRadiusKnob.toDouble()),
leading: showLeadingKnob ? const Icon(MoonIconsGeneric.alarm24) : null,
color: context.moonColors!.krillin100,
body: showBodyKnob
? const SizedBox(
height: 24,
child: Align(
alignment: AlignmentDirectional.centerStart,
child: Text("Here goes Alert body"),
),
)
: null,
onTrailingTap: () {},
),
const SizedBox(height: 40),
const TextDivider(text: "Outlined Alert variant"),
const SizedBox(height: 32),
MoonOutlinedAlert(
show: true,
title: const Text("Outlined success Alert"),
borderRadius: BorderRadius.circular(borderRadiusKnob.toDouble()),
leading: showLeadingKnob ? const Icon(MoonIconsGeneric.check_rounded24) : null,
color: context.moonColors!.roshi100,
body: showBodyKnob
? const SizedBox(
height: 24,
child: Align(
alignment: AlignmentDirectional.centerStart,
child: Text("Here goes Alert body"),
),
)
: null,
onTrailingTap: () {},
),
const SizedBox(height: 16),
MoonOutlinedAlert(
show: true,
title: const Text('Outlined info Alert'),
borderRadius: BorderRadius.circular(borderRadiusKnob.toDouble()),
leading: showLeadingKnob ? const Icon(MoonIconsNotifications.alert24) : null,
color: context.moonColors!.whis100,
body: showBodyKnob
? const SizedBox(
height: 24,
child: Align(
alignment: AlignmentDirectional.centerStart,
child: Text("Here goes Alert body"),
),
)
: null,
onTrailingTap: () {},
),
const SizedBox(height: 64),
],
),
),
),
);
},
);
}
2 changes: 2 additions & 0 deletions example/lib/src/storybook/storybook.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:example/src/storybook/common/widgets/version.dart';
import 'package:example/src/storybook/stories/accordion.dart';
import 'package:example/src/storybook/stories/alert.dart';
import 'package:example/src/storybook/stories/avatar.dart';
import 'package:example/src/storybook/stories/button.dart';
import 'package:example/src/storybook/stories/checkbox.dart';
Expand Down Expand Up @@ -70,6 +71,7 @@ class StorybookPage extends StatelessWidget {
),
stories: [
AccordionStory(),
AlertStory(),
AvatarStory(),
ButtonStory(),
CheckboxStory(),
Expand Down
4 changes: 4 additions & 0 deletions lib/moon_design.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
library moon_design;

export 'package:moon_design/src/theme/accordion/accordion_theme.dart';
export 'package:moon_design/src/theme/alert/alert_theme.dart';
export 'package:moon_design/src/theme/avatar/avatar_theme.dart';
export 'package:moon_design/src/theme/borders.dart';
export 'package:moon_design/src/theme/button/button_theme.dart';
Expand Down Expand Up @@ -30,6 +31,9 @@ export 'package:moon_design/src/utils/measure_size.dart';
export 'package:moon_design/src/utils/widget_surveyor.dart';

export 'package:moon_design/src/widgets/accordion/accordion_item.dart';
export 'package:moon_design/src/widgets/alert/alert.dart';
export 'package:moon_design/src/widgets/alert/filled_alert.dart';
export 'package:moon_design/src/widgets/alert/outlined_alert.dart';
export 'package:moon_design/src/widgets/avatar/avatar.dart';
export 'package:moon_design/src/widgets/buttons/button.dart';
export 'package:moon_design/src/widgets/buttons/filled_button.dart';
Expand Down
68 changes: 68 additions & 0 deletions lib/src/theme/alert/alert_colors.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';

import 'package:moon_design/src/theme/colors.dart';

@immutable
class MoonAlertColors extends ThemeExtension<MoonAlertColors> with DiagnosticableTreeMixin {
static final light = MoonAlertColors(
backgroundColor: MoonColors.light.gohan,
borderColor: MoonColors.light.bulma,
outlinedVariantColor: MoonColors.light.bulma,
);

static final dark = MoonAlertColors(
backgroundColor: MoonColors.dark.gohan,
borderColor: MoonColors.dark.trunks,
outlinedVariantColor: MoonColors.dark.bulma,
);

/// Alert background color.
final Color backgroundColor;

/// Alert border color.
final Color borderColor;

/// Alert text color.
final Color outlinedVariantColor;

const MoonAlertColors({
required this.backgroundColor,
required this.borderColor,
required this.outlinedVariantColor,
});

@override
MoonAlertColors copyWith({
Color? backgroundColor,
Color? borderColor,
Color? outlinedVariantColor,
}) {
return MoonAlertColors(
backgroundColor: backgroundColor ?? this.backgroundColor,
borderColor: borderColor ?? this.borderColor,
outlinedVariantColor: outlinedVariantColor ?? this.outlinedVariantColor,
);
}

@override
MoonAlertColors lerp(ThemeExtension<MoonAlertColors>? other, double t) {
if (other is! MoonAlertColors) return this;

return MoonAlertColors(
backgroundColor: Color.lerp(backgroundColor, other.backgroundColor, t)!,
borderColor: Color.lerp(borderColor, other.borderColor, t)!,
outlinedVariantColor: Color.lerp(outlinedVariantColor, other.outlinedVariantColor, t)!,
);
}

@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties
..add(DiagnosticsProperty("type", "MoonAlertColors"))
..add(ColorProperty("backgroundColor", backgroundColor))
..add(ColorProperty("borderColor", borderColor))
..add(ColorProperty("outlinedVariantColor", outlinedVariantColor));
}
}
Loading

0 comments on commit a491dc7

Please sign in to comment.