-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: [MDS-429] Create Popover component (#74)
- Loading branch information
Showing
12 changed files
with
1,011 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
], | ||
), | ||
), | ||
); | ||
}, | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |
Oops, something went wrong.