Skip to content

Commit

Permalink
feat: [MDS-429] Create Popover component (#74)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kypsis committed Mar 11, 2023
1 parent 6655cda commit 33ec0c9
Show file tree
Hide file tree
Showing 12 changed files with 1,011 additions and 65 deletions.
132 changes: 132 additions & 0 deletions example/lib/src/storybook/stories/popover.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
import 'package:example/src/storybook/common/options.dart';
import 'package:flutter/material.dart';
import 'package:moon_design/moon_design.dart';
import 'package:storybook_flutter/storybook_flutter.dart';

class PopoverStory extends Story {
PopoverStory()
: super(
name: "Popover",
builder: (context) {
final customLabelTextKnob = context.knobs.text(
label: "Custom label text",
initial: "Custom popover text",
);

final popoverPositionsKnob = context.knobs.options(
label: "popoverPosition",
description: "Popover position variants.",
initial: MoonPopoverPosition.top,
options: const [
Option(label: "top", value: MoonPopoverPosition.top),
Option(label: "bottom", value: MoonPopoverPosition.bottom),
Option(label: "left", value: MoonPopoverPosition.left),
Option(label: "right", value: MoonPopoverPosition.right),
Option(label: "topLeft", value: MoonPopoverPosition.topLeft),
Option(label: "topRight", value: MoonPopoverPosition.topRight),
Option(label: "bottomLeft", value: MoonPopoverPosition.bottomLeft),
Option(label: "bottomRight", value: MoonPopoverPosition.bottomRight),
Option(label: "vertical", value: MoonPopoverPosition.vertical),
Option(label: "horizontal", value: MoonPopoverPosition.horizontal),
],
);

final colorsKnob = context.knobs.options(
label: "backgroundColor",
description: "MoonColors variants for Popover background.",
initial: 4, // gohan
options: colorOptions,
);

final color = colorTable(context)[colorsKnob];

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

final distanceToTargetKnob = context.knobs.slider(
label: "distanceToTarget",
description: "Set the distance to target child widget.",
initial: 8,
max: 100,
);

final showShadowKnob = context.knobs.boolean(
label: "Show shadow",
description: "Show shadows under the Popover.",
initial: true,
);

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

bool show = true;

return Directionality(
textDirection: setRtlModeKnob ? TextDirection.rtl : TextDirection.ltr,
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const SizedBox(height: 64),
StatefulBuilder(
builder: (context, setState) {
return MoonPopover(
show: show,
backgroundColor: color,
borderRadius: BorderRadius.circular(borderRadiusKnob.toDouble()),
distanceToTarget: distanceToTargetKnob,
popoverPosition: popoverPositionsKnob,
popoverShadows: showShadowKnob == true ? null : [],
content: ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 190),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Row(
textDirection: Directionality.of(context),
mainAxisSize: MainAxisSize.min,
children: [
MoonAvatar(
backgroundColor: context.moonColors?.heles,
child: const Icon(MoonIconsOther.rocket24),
),
const SizedBox(width: 12),
Expanded(child: Text(customLabelTextKnob)),
],
),
const SizedBox(height: 16),
MoonPrimaryButton(
buttonSize: MoonButtonSize.sm,
isFullWidth: true,
onTap: () {
setState(() => show = false);
},
label: const Text("Close"),
),
],
),
),
child: MoonButton(
backgroundColor: context.moonColors!.bulma,
onTap: () {
setState(() => show = true);
},
label: const Text("MDS"),
),
);
},
),
const SizedBox(height: 64),
],
),
),
);
},
);
}
76 changes: 47 additions & 29 deletions example/lib/src/storybook/stories/tooltip.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,50 +34,58 @@ class TooltipStory extends Story {

final colorsKnob = context.knobs.options(
label: "backgroundColor",
description: "MoonColors variants for base MoonButton.",
description: "MoonColors variants for Tooltip background.",
initial: 4, // gohan
options: colorOptions,
);

final color = colorTable(context)[colorsKnob];

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

final arrowOffsetKnob = context.knobs.slider(
label: "arrowOffsetValue",
description: "Set the offset of the tooltip arrow.",
description: "Set the offset of the Tooltip arrow.",
initial: 0,
min: -100,
max: 100,
);

final arrowTipDistanceKnob = context.knobs.slider(
label: "arrowTipDistance",
description: "Set the distance to target child widget.",
initial: 8,
max: 100,
);

final arrowBaseWidthKnob = context.knobs.slider(
label: "arrowBaseWidth",
description: "Set the base width of the tooltip arrow.",
description: "Set the base width of the Tooltip arrow.",
initial: 16,
max: 100,
);

final arrowLengthKnob = context.knobs.slider(
label: "arrowLength",
description: "Set the length of the tooltip arrow.",
description: "Set the length of the Tooltip arrow.",
initial: 8,
max: 100,
);

final showTooltipKnob = context.knobs.boolean(
label: "show",
description: "Show the tooltip.",
final showShadowKnob = context.knobs.boolean(
label: "Show shadow",
description: "Show shadows under the Tooltip.",
initial: true,
);

final showArrowKnob = context.knobs.boolean(
label: "hasArrow",
description: "Does tooltip have an arrow (tail).",
initial: true,
);

final showShadowKnob = context.knobs.boolean(
label: "Show shadow",
description: "Show shadows under the tooltip.",
description: "Does Tooltip have an arrow (tail).",
initial: true,
);

Expand All @@ -86,6 +94,8 @@ class TooltipStory extends Story {
description: "Switch between LTR and RTL modes.",
);

bool show = true;

return Directionality(
textDirection: setRtlModeKnob ? TextDirection.rtl : TextDirection.ltr,
child: Center(
Expand All @@ -95,21 +105,29 @@ class TooltipStory extends Story {
const SizedBox(height: 64),
const TextDivider(text: "Customisable tooltip"),
const SizedBox(height: 32),
MoonTooltip(
arrowBaseWidth: arrowBaseWidthKnob,
arrowLength: arrowLengthKnob,
arrowOffsetValue: arrowOffsetKnob,
show: showTooltipKnob,
tooltipPosition: tooltipPositionsKnob,
hasArrow: showArrowKnob,
backgroundColor: color,
tooltipShadows: showShadowKnob == true ? null : [],
content: Text(customLabelTextKnob),
child: MoonButton(
backgroundColor: context.moonColors!.bulma,
onTap: () {},
label: const Text("MDS"),
),
StatefulBuilder(
builder: (context, setState) {
return MoonTooltip(
show: show,
backgroundColor: color,
borderRadiusValue: borderRadiusKnob.toDouble(),
tooltipPosition: tooltipPositionsKnob,
hasArrow: showArrowKnob,
arrowBaseWidth: arrowBaseWidthKnob,
arrowLength: arrowLengthKnob,
arrowOffsetValue: arrowOffsetKnob,
arrowTipDistance: arrowTipDistanceKnob,
tooltipShadows: showShadowKnob == true ? null : [],
content: Text(customLabelTextKnob),
child: MoonButton(
backgroundColor: context.moonColors!.bulma,
onTap: () {
setState(() => show = true);
},
label: const Text("MDS"),
),
);
},
),
const SizedBox(height: 40),
const TextDivider(text: "Default tooltip"),
Expand Down
2 changes: 2 additions & 0 deletions example/lib/src/storybook/storybook.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:example/src/storybook/stories/circular_progress.dart';
import 'package:example/src/storybook/stories/icons.dart';
import 'package:example/src/storybook/stories/linear_loader.dart';
import 'package:example/src/storybook/stories/linear_progress.dart';
import 'package:example/src/storybook/stories/popover.dart';
import 'package:example/src/storybook/stories/tag.dart';
import 'package:example/src/storybook/stories/tooltip.dart';
import 'package:flutter/material.dart';
Expand Down Expand Up @@ -71,6 +72,7 @@ class StorybookPage extends StatelessWidget {
IconsStory(),
LinearLoaderStory(),
LinearProgressStory(),
PopoverStory(),
TagStory(),
TooltipStory(),
],
Expand Down
4 changes: 3 additions & 1 deletion lib/moon_design.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ export 'package:moon_design/src/theme/effects/effects.dart';
export 'package:moon_design/src/theme/loaders/circular_loader/circular_loader_theme.dart';
export 'package:moon_design/src/theme/loaders/linear_loader/linear_loader_theme.dart';
export 'package:moon_design/src/theme/opacity.dart';
export 'package:moon_design/src/theme/popover/popover_theme.dart';
export 'package:moon_design/src/theme/progress/circular_progress/circular_progress_theme.dart';
export 'package:moon_design/src/theme/progress/linear_progress/linear_progress_theme.dart';
export 'package:moon_design/src/theme/shadows.dart';
export 'package:moon_design/src/theme/sizes.dart';
export 'package:moon_design/src/theme/theme.dart';
export 'package:moon_design/src/theme/tooltip/tooltip_properties.dart';
export 'package:moon_design/src/theme/tooltip/tooltip_theme.dart';
export 'package:moon_design/src/theme/typography/text_colors.dart';
export 'package:moon_design/src/theme/typography/text_styles.dart';
export 'package:moon_design/src/theme/typography/typography.dart';
Expand All @@ -40,6 +41,7 @@ export 'package:moon_design/src/widgets/common/progress_indicators/circular_prog
export 'package:moon_design/src/widgets/common/progress_indicators/linear_progress_indicator.dart';
export 'package:moon_design/src/widgets/loaders/circular_loader.dart';
export 'package:moon_design/src/widgets/loaders/linear_loader.dart';
export 'package:moon_design/src/widgets/popover/popover.dart';
export 'package:moon_design/src/widgets/progress/circular_progress.dart';
export 'package:moon_design/src/widgets/progress/linear_progress.dart';
export 'package:moon_design/src/widgets/tag/tag.dart';
Expand Down
46 changes: 46 additions & 0 deletions lib/src/theme/popover/popover_colors.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';

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

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

static final dark = MoonPopoverColors(
backgroundColor: MoonColors.dark.gohan,
);

/// Popover background color.
final Color backgroundColor;

const MoonPopoverColors({
required this.backgroundColor,
});

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

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

return MoonPopoverColors(
backgroundColor: Color.lerp(backgroundColor, other.backgroundColor, t)!,
);
}

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

0 comments on commit 33ec0c9

Please sign in to comment.