Skip to content

Commit

Permalink
Rewrite radio in the new architecture
Browse files Browse the repository at this point in the history
  • Loading branch information
tilucasoli committed Aug 21, 2024
1 parent 9fdd2bd commit 0c33b4e
Show file tree
Hide file tree
Showing 10 changed files with 237 additions and 456 deletions.
56 changes: 16 additions & 40 deletions packages/remix/demo/lib/components/radio_use_case.dart
Original file line number Diff line number Diff line change
@@ -1,33 +1,20 @@
import 'package:demo/helpers/string.dart';
import 'package:flutter/material.dart';
import 'package:remix/components/radio/radio.dart';
import 'package:widgetbook/widgetbook.dart';
import 'package:widgetbook_annotation/widgetbook_annotation.dart' as widgetbook;

final _key = GlobalKey();

enum RadioType {
solid,
outline,
soft,
surface;

RadioVariant get variant {
switch (this) {
case RadioType.solid:
return RadioVariant.solid;
case RadioType.outline:
return RadioVariant.outline;
case RadioType.soft:
return RadioVariant.soft;
case RadioType.surface:
return RadioVariant.surface;
}
}
enum Theme {
dark,
light,
system,
}

@widgetbook.UseCase(
name: 'Radio Component',
type: RxRadio,
type: XRadio,
)
Widget buildRadioUseCase(BuildContext context) {
return const RadioExample();
Expand All @@ -41,7 +28,7 @@ class RadioExample extends StatefulWidget {
}

class _RadioExampleState extends State<RadioExample> {
RadioType? _type = RadioType.outline;
Theme _theme = Theme.dark;

@override
Widget build(BuildContext context) {
Expand All @@ -51,38 +38,27 @@ class _RadioExampleState extends State<RadioExample> {
mainAxisSize: MainAxisSize.min,
key: _key,
children: <Widget>[
for (var type in RadioType.values)
for (var theme in Theme.values) ...[
Row(
children: [
RxRadio<RadioType>(
value: type,
groupValue: _type,
variant: type.variant,
onChanged: (RadioType? value) {
XRadio<Theme>(
value: theme,
groupValue: _theme,
onChanged: (Theme? value) {
setState(() {
_type = value;
_theme = value!;
});
},
size: context.knobs.list(
label: 'Size',
options: RadioSize.values,
initialOption: RadioSize.medium,
labelBuilder: (value) => value.label,
),
disabled: context.knobs.boolean(
label: 'Disabled',
initialValue: false,
),
),
const SizedBox(width: 16, height: 30),
Text(
type.name,
style: const TextStyle(
fontSize: 16,
),
text: theme.name.capitalize(),
),
],
),
const SizedBox(height: 8),
]
],
),
);
Expand Down
5 changes: 5 additions & 0 deletions packages/remix/demo/lib/helpers/string.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
extension StringExtension on String {
String capitalize() {
return "${this[0].toUpperCase()}${substring(1).toLowerCase()}";
}
}
149 changes: 1 addition & 148 deletions packages/remix/demo/macos/Flutter/ephemeral/FlutterInputs.xcfilelist

Large diffs are not rendered by default.

13 changes: 7 additions & 6 deletions packages/remix/lib/components/radio/radio.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,16 @@ import 'package:mix/mix.dart';
import 'package:mix_annotations/mix_annotations.dart';
import '../../helpers/utility_extension.dart';

import '../../helpers/variant.dart';
import '../../tokens/remix_tokens.dart';

part 'radio.g.dart';
part 'radio_style.dart';
part 'radio_variants.dart';
part 'radio_widget.dart';
part 'radio_blank.dart';

@MixableSpec()
base class RadioSpec extends Spec<RadioSpec> with _$RadioSpec, Diagnosticable {
final BoxSpec container;
final BoxSpec indicator;
final FlexSpec flex;
final TextSpec text;

/// {@macro radio_spec_of}
static const of = _$RadioSpec.of;
Expand All @@ -27,10 +24,14 @@ base class RadioSpec extends Spec<RadioSpec> with _$RadioSpec, Diagnosticable {
const RadioSpec({
BoxSpec? container,
BoxSpec? indicator,
FlexSpec? flex,
TextSpec? text,
super.modifiers,
super.animated,
}) : container = container ?? const BoxSpec(),
indicator = indicator ?? const BoxSpec();
indicator = indicator ?? const BoxSpec(),
text = text ?? const TextSpec(),
flex = flex ?? const FlexSpec();

@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
Expand Down
36 changes: 36 additions & 0 deletions packages/remix/lib/components/radio/radio.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

75 changes: 0 additions & 75 deletions packages/remix/lib/components/radio/radio_blank.dart

This file was deleted.

Loading

0 comments on commit 0c33b4e

Please sign in to comment.