Skip to content

Commit

Permalink
refactor: Made the documentation and behaviour for disabling componen…
Browse files Browse the repository at this point in the history
…ts more consistent. (#86)

* adding macros, consistent disabled behaviour

* deprecation warnings

* shared knobs

* deprecation warnings
  • Loading branch information
mikecoomber authored Jun 5, 2024
1 parent 05a32ac commit de8ac28
Show file tree
Hide file tree
Showing 34 changed files with 131 additions and 107 deletions.
9 changes: 3 additions & 6 deletions example/lib/pages/components/dropdown_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,8 @@ class _DropdownExampleState extends State<DropdownExample> {
crossAxisAlignment: CrossAxisAlignment.center,
children: [
ZetaDropdown(
disabled: true,
type: ZetaDropdownMenuType.standard,
onChange: (value) {
setState(() {
selectedItem = value;
});
},
onChange: (_) {},
value: selectedItem,
items: items,
),
Expand All @@ -58,11 +53,13 @@ class _DropdownExampleState extends State<DropdownExample> {
ZetaDropdown(
items: items,
value: selectedItem,
onChange: (_) {},
type: ZetaDropdownMenuType.checkbox,
),
ZetaDropdown(
items: items,
value: selectedItem,
onChange: (_) {},
size: ZetaDropdownSize.mini,
type: ZetaDropdownMenuType.radio,
),
Expand Down
2 changes: 1 addition & 1 deletion example/lib/pages/components/search_bar_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class _SearchBarExampleState extends State<SearchBarExample> {
Padding(
padding: const EdgeInsets.all(20),
child: ZetaSearchBar(
enabled: false,
disabled: true,
),
),
Padding(
Expand Down
3 changes: 2 additions & 1 deletion example/lib/pages/components/tabs_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class _TabsExampleState extends State<TabsExample> {
length: 2,
child: ZetaTabBar(
context: context,
onTap: (int) => print(int),
tabs: [
ZetaTab(icon: Icon(ZetaIcons.star_round), text: "Tab Item"),
ZetaTab(icon: Icon(ZetaIcons.star_round), text: "Tab Item"),
Expand All @@ -35,6 +36,7 @@ class _TabsExampleState extends State<TabsExample> {
child: ZetaTabBar(
context: context,
isScrollable: true,
onTap: (int) => print(int),
tabs: [
ZetaTab(text: "Tab Item"),
ZetaTab(text: "Tab Item"),
Expand All @@ -52,7 +54,6 @@ class _TabsExampleState extends State<TabsExample> {
child: ZetaTabBar(
context: context,
isScrollable: true,
enabled: false,
tabs: [
ZetaTab(icon: Icon(ZetaIcons.star_sharp), text: "Tab Item"),
ZetaTab(icon: Icon(ZetaIcons.star_sharp), text: "Tab Item"),
Expand Down
4 changes: 2 additions & 2 deletions example/widgetbook/pages/components/button_widgetbook.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Widget iconButtonUseCase(BuildContext context) {
return WidgetbookTestWidget(
widget: ZetaIconButton(
icon: iconKnob(context, rounded: borderType != ZetaWidgetBorder.sharp)!,
onPressed: context.knobs.boolean(label: 'Disabled') ? null : () {},
onPressed: disabledKnob(context) ? null : () {},
borderType: borderType,
size: context.knobs.list(
label: 'Size',
Expand All @@ -62,7 +62,7 @@ Widget iconButtonUseCase(BuildContext context) {
Widget buttonGroupUseCase(BuildContext context) {
final bool rounded = roundedKnob(context);

final onPressed = context.knobs.boolean(label: 'Disabled', initialValue: false) ? null : () {};
final onPressed = disabledKnob(context) ? null : () {};

return WidgetbookTestWidget(
widget: ZetaButtonGroup(
Expand Down
7 changes: 1 addition & 6 deletions example/widgetbook/pages/components/checkbox_widgetbook.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,7 @@ Widget checkboxUseCase(BuildContext context) {
return WidgetbookTestWidget(
widget: StatefulBuilder(
builder: (context, setState) {
ValueChanged<bool>? onChanged = context.knobs.boolean(
label: 'Enabled',
initialValue: true,
)
? (b2) => setState(() => b = b2)
: null;
ValueChanged<bool>? onChanged = !disabledKnob(context) ? (b2) => setState(() => b = b2) : null;
return ZetaCheckbox(
value: b,
onChanged: onChanged,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:widgetbook/widgetbook.dart';
import 'package:zeta_flutter/zeta_flutter.dart';

import '../../test/test_components.dart';
import '../../utils/utils.dart';

Widget dateInputUseCase(BuildContext context) {
String? _errorText;
Expand All @@ -15,7 +16,7 @@ Widget dateInputUseCase(BuildContext context) {
initialValue: 'Invalid date',
);
final rounded = context.knobs.boolean(label: 'Rounded', initialValue: true);
final disabled = context.knobs.boolean(label: 'Disabled', initialValue: false);
final disabled = disabledKnob(context);
final size = context.knobs.list<ZetaWidgetSize>(
label: 'Size',
options: ZetaWidgetSize.values,
Expand Down
16 changes: 6 additions & 10 deletions example/widgetbook/pages/components/dropdown_widgetbook.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,11 @@ import '../../utils/utils.dart';

Widget dropdownUseCase(BuildContext context) => WidgetbookTestWidget(
widget: Center(
child: DropdownExample(context),
child: DropdownExample(),
),
);

class DropdownExample extends StatefulWidget {
const DropdownExample(this.c);
final BuildContext c;

@override
State<DropdownExample> createState() => _DropdownExampleState();
}
Expand All @@ -35,18 +32,17 @@ class _DropdownExampleState extends State<DropdownExample> {
];

@override
Widget build(BuildContext _) {
Widget build(BuildContext context) {
return ZetaDropdown(
type: widget.c.knobs.list(
type: context.knobs.list(
label: "Dropdown type",
options: ZetaDropdownMenuType.values,
labelBuilder: enumLabelBuilder,
),
onChange: (value) {},
onChange: disabledKnob(context) ? null : (value) {},
items: items,
rounded: widget.c.knobs.boolean(label: "Rounded"),
disabled: widget.c.knobs.boolean(label: "Disabled"),
size: widget.c.knobs.list(
rounded: context.knobs.boolean(label: "Rounded"),
size: context.knobs.list(
label: 'Size',
options: ZetaDropdownSize.values,
labelBuilder: enumLabelBuilder,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Widget navigationRailUseCase(BuildContext context) {
initial: rounded ? ZetaIcons.star_round : ZetaIcons.star_sharp,
);
final wordWrap = context.knobs.boolean(label: 'Word wrap', initialValue: true);
final disabled = context.knobs.boolean(label: 'Disabled', initialValue: false);
final disabled = disabledKnob(context);
final itemsList = items.split(',').where((element) => element.trim().isNotEmpty).toList();
return SafeArea(
child: WidgetbookTestWidget(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:widgetbook/widgetbook.dart';
import 'package:zeta_flutter/zeta_flutter.dart';

import '../../test/test_components.dart';
import '../../utils/utils.dart';

Widget paginationUseCase(BuildContext context) => WidgetbookTestWidget(
widget: ZetaPagination(
Expand All @@ -12,7 +13,7 @@ Widget paginationUseCase(BuildContext context) => WidgetbookTestWidget(
options: ZetaPaginationType.values,
labelBuilder: (value) => value.name.split('.').last.toUpperCase(),
),
rounded: context.knobs.boolean(label: 'Rounded'),
disabled: context.knobs.boolean(label: 'Disabled'),
rounded: roundedKnob(context),
onChange: disabledKnob(context) ? null : (_) {},
),
);
7 changes: 3 additions & 4 deletions example/widgetbook/pages/components/radio_widgetbook.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import 'package:flutter/material.dart';
import 'package:widgetbook/widgetbook.dart';
import 'package:zeta_flutter/zeta_flutter.dart';

import '../../test/test_components.dart';
import '../../utils/utils.dart';

Widget radioButtonUseCase(BuildContext context) {
String option1 = 'Label 1';
Expand All @@ -12,9 +12,8 @@ Widget radioButtonUseCase(BuildContext context) {
return WidgetbookTestWidget(
widget: StatefulBuilder(
builder: (context, setState) {
ValueChanged<String?>? onChanged = context.knobs.boolean(label: 'Enabled', initialValue: true)
? (value) => setState(() => groupValue = value)
: null;
ValueChanged<String?>? onChanged =
!disabledKnob(context) ? (value) => setState(() => groupValue = value) : null;
return Padding(
padding: const EdgeInsets.all(ZetaSpacing.x5),
child: Column(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:widgetbook/widgetbook.dart';
import 'package:zeta_flutter/zeta_flutter.dart';

import '../../test/test_components.dart';
import '../../utils/utils.dart';

const List<String> _items = [
'The quick...',
Expand All @@ -22,10 +23,8 @@ Widget searchBarUseCase(BuildContext context) {
label: 'Hint',
initialValue: 'Search',
);
final enabled = context.knobs.boolean(
label: 'Enabled',
initialValue: true,
);
final disabled = disabledKnob(context);

final size = context.knobs.list<ZetaWidgetSize>(
label: 'Size',
options: ZetaWidgetSize.values,
Expand Down Expand Up @@ -53,7 +52,7 @@ Widget searchBarUseCase(BuildContext context) {
ZetaSearchBar(
size: size,
shape: shape,
enabled: enabled,
disabled: disabled,
hint: hint,
showLeadingIcon: showLeadingIcon,
showSpeechToText: showSpeechToText,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ Widget stepperInputUseCase(BuildContext context) {
options: ZetaStepperInputSize.values,
labelBuilder: enumLabelBuilder,
),
rounded: context.knobs.boolean(label: 'Rounded', initialValue: true),
onChange: context.knobs.boolean(label: 'Disabled', initialValue: false) ? null : (_) {},
rounded: roundedKnob(context),
onChange: disabledKnob(context) ? null : (_) {},
),
);
}
3 changes: 2 additions & 1 deletion example/widgetbook/pages/components/stepper_widgetbook.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:widgetbook/widgetbook.dart';
import 'package:zeta_flutter/zeta_flutter.dart';

import '../../test/test_components.dart';
import '../../utils/utils.dart';

Widget stepperUseCase(BuildContext context) {
int currentStep = 0;
Expand All @@ -24,7 +25,7 @@ Widget stepperUseCase(BuildContext context) {
labelBuilder: (type) => type.name,
);

final rounded = context.knobs.boolean(label: 'Rounded', initialValue: true);
final rounded = roundedKnob(context);

final enabledContent = context.knobs.boolean(label: 'Enabled Content', initialValue: true);

Expand Down
4 changes: 1 addition & 3 deletions example/widgetbook/pages/components/switch_widgetbook.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ Widget switchUseCase(BuildContext context) {
return WidgetbookTestWidget(
widget: StatefulBuilder(
builder: (context, setState) {
ValueChanged<bool?>? onChanged = context.knobs.boolean(label: 'Enabled', initialValue: true)
? (value) => setState(() => isOn = value)
: null;
ValueChanged<bool?>? onChanged = !disabledKnob(context) ? (value) => setState(() => isOn = value) : null;
return Padding(
padding: const EdgeInsets.all(ZetaSpacing.x5),
child: Column(
Expand Down
13 changes: 8 additions & 5 deletions example/widgetbook/pages/components/tabs_widgetbook.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:widgetbook/widgetbook.dart';
import 'package:zeta_flutter/zeta_flutter.dart';

import '../../test/test_components.dart';
import '../../utils/utils.dart';

Widget tabsUseCase(BuildContext context) {
return WidgetbookTestWidget(
Expand All @@ -15,10 +16,12 @@ Widget tabsUseCase(BuildContext context) {
length: 2,
child: ZetaTabBar(
context: context,
enabled: context.knobs.boolean(
label: "Enabled",
initialValue: true,
),
onTap: context.knobs.boolean(
label: "Disabled",
initialValue: false,
)
? null
: (_) {},
tabs: [
ZetaTab(icon: Icon(ZetaIcons.star_round), text: "Tab Item"),
ZetaTab(icon: Icon(ZetaIcons.star_round), text: "Tab Item"),
Expand All @@ -32,7 +35,7 @@ Widget tabsUseCase(BuildContext context) {
length: 5,
child: ZetaTabBar(
context: context,
enabled: context.knobs.boolean(label: "Enabled"),
onTap: disabledKnob(context) ? null : (_) {},
isScrollable: true,
tabs: [
ZetaTab(text: "Tab Item"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:widgetbook/widgetbook.dart';
import 'package:zeta_flutter/zeta_flutter.dart';

import '../../test/test_components.dart';
import '../../utils/utils.dart';

Widget textInputUseCase(BuildContext context) {
return WidgetbookTestWidget(
Expand All @@ -20,8 +21,8 @@ Widget textInputUseCase(BuildContext context) {
label: 'Hint',
initialValue: 'Default hint text',
);
final rounded = context.knobs.boolean(label: 'Rounded', initialValue: true);
final disabled = context.knobs.boolean(label: 'Disabled', initialValue: false);
final rounded = roundedKnob(context);
final disabled = disabledKnob(context);
final size = context.knobs.list<ZetaWidgetSize>(
label: 'Size',
options: ZetaWidgetSize.values,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:widgetbook/widgetbook.dart';
import 'package:zeta_flutter/zeta_flutter.dart';

import '../../test/test_components.dart';
import '../../utils/utils.dart';

Widget timeInputUseCase(BuildContext context) {
String? _errorText;
Expand All @@ -22,8 +23,8 @@ Widget timeInputUseCase(BuildContext context) {
label: 'Hint',
initialValue: 'Default hint text',
);
final rounded = context.knobs.boolean(label: 'Rounded', initialValue: true);
final disabled = context.knobs.boolean(label: 'Disabled', initialValue: false);
final rounded = roundedKnob(context);
final disabled = disabledKnob(context);
final size = context.knobs.list<ZetaWidgetSize>(
label: 'Size',
options: ZetaWidgetSize.values,
Expand Down
5 changes: 5 additions & 0 deletions example/widgetbook/utils/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,8 @@ IconData? iconKnob(
}

bool roundedKnob(BuildContext context) => context.knobs.boolean(label: 'Rounded');

bool disabledKnob(BuildContext context) => context.knobs.boolean(
label: 'Disabled',
initialValue: false,
);
6 changes: 1 addition & 5 deletions lib/src/components/accordion/accordion.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,7 @@ class ZetaAccordion extends StatefulWidget {
/// If null, component will render as disabled.
final Widget? child;

/// {@template zeta-component-rounded}
/// Sets rounded or sharp border of the containing box and the icon style.
///
/// Defaults to `true`.
/// {@endtemplate}
/// {@macro zeta-component-rounded}
final bool rounded;

/// Determines if the [ZetaAccordion]s should be in a box.
Expand Down
6 changes: 1 addition & 5 deletions lib/src/components/badges/badge.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@ class ZetaBadge extends StatelessWidget {
/// {@macro zeta-component-rounded}
final bool rounded;

/// {@template zeta-component-badge-status}
/// Indicates the status of the badge.
///
/// Defaults to "info"
/// {@endtemplate}
/// {@macro zeta-component-badge-status}
final ZetaWidgetStatus status;

/// Label of the badge.
Expand Down
Loading

0 comments on commit de8ac28

Please sign in to comment.