-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: [MDS-442] Create Radio widget (#85)
- Loading branch information
Showing
12 changed files
with
550 additions
and
50 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
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,108 @@ | ||
import 'package:example/src/storybook/common/options.dart'; | ||
import 'package:example/src/storybook/common/widgets/text_divider.dart'; | ||
import 'package:flutter/cupertino.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:moon_design/moon_design.dart'; | ||
import 'package:storybook_flutter/storybook_flutter.dart'; | ||
|
||
enum ChoiceCustom { first, second } | ||
|
||
enum ChoiceLabel { first, second } | ||
|
||
ChoiceCustom? valueCustom = ChoiceCustom.first; | ||
ChoiceLabel? valueLabel = ChoiceLabel.first; | ||
|
||
class RadioStory extends Story { | ||
RadioStory() | ||
: super( | ||
name: "Radio", | ||
builder: (context) { | ||
final activeColorsKnob = context.knobs.options( | ||
label: "activeColor", | ||
description: "MoonColors variants for when Radio is checked.", | ||
initial: 0, // piccolo | ||
options: colorOptions, | ||
); | ||
|
||
final activeColor = colorTable(context)[activeColorsKnob]; | ||
|
||
final inactiveColorsKnob = context.knobs.options( | ||
label: "inactiveColor", | ||
description: "MoonColors variants for when Radio is unchecked.", | ||
initial: 6, // trunks | ||
options: colorOptions, | ||
); | ||
|
||
final inactiveColor = colorTable(context)[inactiveColorsKnob]; | ||
|
||
final isToggleable = context.knobs.boolean( | ||
label: "toggleable", | ||
description: "Whether the selected Radio can be unselected.", | ||
); | ||
|
||
final isDisabled = context.knobs.boolean( | ||
label: "Disabled", | ||
description: "onChanged() 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: StatefulBuilder( | ||
builder: (context, setState) { | ||
return Column( | ||
mainAxisAlignment: MainAxisAlignment.center, | ||
children: [ | ||
const SizedBox(height: 64), | ||
const TextDivider(text: "Customisable Radio buttons"), | ||
const SizedBox(height: 32), | ||
MoonRadio( | ||
value: ChoiceCustom.first, | ||
groupValue: valueCustom, | ||
onChanged: isDisabled ? null : (ChoiceCustom? choice) => setState(() => valueCustom = choice), | ||
activeColor: activeColor, | ||
inactiveColor: inactiveColor, | ||
toggleable: isToggleable, | ||
), | ||
const SizedBox(height: 8), | ||
MoonRadio( | ||
value: ChoiceCustom.second, | ||
groupValue: valueCustom, | ||
onChanged: isDisabled ? null : (ChoiceCustom? choice) => setState(() => valueCustom = choice), | ||
activeColor: activeColor, | ||
inactiveColor: inactiveColor, | ||
toggleable: isToggleable, | ||
), | ||
const SizedBox(height: 40), | ||
const TextDivider(text: "Radios with clickable text"), | ||
const SizedBox(height: 32), | ||
MoonRadio.withLabel( | ||
context, | ||
value: ChoiceLabel.first, | ||
groupValue: valueLabel, | ||
label: "With label #1", | ||
onChanged: isDisabled ? null : (ChoiceLabel? choice) => setState(() => valueLabel = choice), | ||
), | ||
const SizedBox(height: 8), | ||
MoonRadio.withLabel( | ||
context, | ||
value: ChoiceLabel.second, | ||
groupValue: valueLabel, | ||
label: "With label #2", | ||
onChanged: isDisabled ? null : (ChoiceLabel? choice) => setState(() => valueLabel = choice), | ||
), | ||
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,58 @@ | ||
import 'package:flutter/foundation.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
import 'package:moon_design/src/theme/colors.dart'; | ||
|
||
@immutable | ||
class MoonRadioColors extends ThemeExtension<MoonRadioColors> with DiagnosticableTreeMixin { | ||
static final light = MoonRadioColors( | ||
activeColor: MoonColors.light.piccolo, | ||
inactiveColor: MoonColors.light.trunks, | ||
); | ||
|
||
static final dark = MoonRadioColors( | ||
activeColor: MoonColors.dark.piccolo, | ||
inactiveColor: MoonColors.dark.trunks, | ||
); | ||
|
||
/// Radio active color. | ||
final Color activeColor; | ||
|
||
/// Radio inactive color. | ||
final Color inactiveColor; | ||
|
||
const MoonRadioColors({ | ||
required this.activeColor, | ||
required this.inactiveColor, | ||
}); | ||
|
||
@override | ||
MoonRadioColors copyWith({ | ||
Color? activeColor, | ||
Color? inactiveColor, | ||
}) { | ||
return MoonRadioColors( | ||
activeColor: activeColor ?? this.activeColor, | ||
inactiveColor: inactiveColor ?? this.inactiveColor, | ||
); | ||
} | ||
|
||
@override | ||
MoonRadioColors lerp(ThemeExtension<MoonRadioColors>? other, double t) { | ||
if (other is! MoonRadioColors) return this; | ||
|
||
return MoonRadioColors( | ||
activeColor: Color.lerp(activeColor, other.activeColor, t)!, | ||
inactiveColor: Color.lerp(inactiveColor, other.inactiveColor, t)!, | ||
); | ||
} | ||
|
||
@override | ||
void debugFillProperties(DiagnosticPropertiesBuilder properties) { | ||
super.debugFillProperties(properties); | ||
properties | ||
..add(DiagnosticsProperty("type", "MoonRadioColors")) | ||
..add(ColorProperty("activeColor", activeColor)) | ||
..add(ColorProperty("inactiveColor", inactiveColor)); | ||
} | ||
} |
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,48 @@ | ||
import 'package:flutter/foundation.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
import 'package:moon_design/src/theme/radio/radio_colors.dart'; | ||
|
||
@immutable | ||
class MoonRadioTheme extends ThemeExtension<MoonRadioTheme> with DiagnosticableTreeMixin { | ||
static final light = MoonRadioTheme( | ||
colors: MoonRadioColors.light, | ||
); | ||
|
||
static final dark = MoonRadioTheme( | ||
colors: MoonRadioColors.dark, | ||
); | ||
|
||
/// Radio colors. | ||
final MoonRadioColors colors; | ||
|
||
const MoonRadioTheme({ | ||
required this.colors, | ||
}); | ||
|
||
@override | ||
MoonRadioTheme copyWith({ | ||
MoonRadioColors? colors, | ||
}) { | ||
return MoonRadioTheme( | ||
colors: colors ?? this.colors, | ||
); | ||
} | ||
|
||
@override | ||
MoonRadioTheme lerp(ThemeExtension<MoonRadioTheme>? other, double t) { | ||
if (other is! MoonRadioTheme) return this; | ||
|
||
return MoonRadioTheme( | ||
colors: colors.lerp(other.colors, t), | ||
); | ||
} | ||
|
||
@override | ||
void debugFillProperties(DiagnosticPropertiesBuilder diagnosticProperties) { | ||
super.debugFillProperties(diagnosticProperties); | ||
diagnosticProperties | ||
..add(DiagnosticsProperty("type", "MoonRadioTheme")) | ||
..add(DiagnosticsProperty<MoonRadioColors>("colors", colors)); | ||
} | ||
} |
Oops, something went wrong.