Skip to content

Commit

Permalink
feat: Add List Item
Browse files Browse the repository at this point in the history
  • Loading branch information
Simeon Dimitrov authored and sd-athlon committed Mar 21, 2024
1 parent e63476a commit 3103139
Show file tree
Hide file tree
Showing 6 changed files with 387 additions and 1 deletion.
2 changes: 2 additions & 0 deletions example/lib/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import 'package:zeta_example/pages/components/button_example.dart';
import 'package:zeta_example/pages/components/checkbox_example.dart';
import 'package:zeta_example/pages/components/chip_example.dart';
import 'package:zeta_example/pages/components/dialpad_example.dart';
import 'package:zeta_example/pages/components/list_item_example.dart';
import 'package:zeta_example/pages/components/navigation_bar_example.dart';
import 'package:zeta_example/pages/theme/color_example.dart';
import 'package:zeta_example/pages/components/password_input_example.dart';
Expand Down Expand Up @@ -38,6 +39,7 @@ final List<Component> components = [
Component(ButtonExample.name, (context) => const ButtonExample()),
Component(CheckBoxExample.name, (context) => const CheckBoxExample()),
Component(ChipExample.name, (context) => const ChipExample()),
Component(ListItemExample.name, (context) => const ListItemExample()),
Component(NavigationBarExample.name, (context) => const NavigationBarExample()),
Component(PasswordInputExample.name, (context) => const PasswordInputExample()),
Component(ProgressExample.name, (context) => const ProgressExample()),
Expand Down
115 changes: 115 additions & 0 deletions example/lib/pages/components/list_item_example.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import 'package:flutter/material.dart';
import 'package:zeta_example/widgets.dart';
import 'package:zeta_flutter/zeta_flutter.dart';

class ListItemExample extends StatefulWidget {
static const String name = 'ListItem';

const ListItemExample({super.key});

@override
State<ListItemExample> createState() => _ListItemExampleState();
}

class _ListItemExampleState extends State<ListItemExample> {
bool _isCheckBoxEnabled = false;
bool _isSelected = true;

_onDefaultListItemTap() {
setState(() => _isCheckBoxEnabled = !_isCheckBoxEnabled);
}

@override
Widget build(BuildContext context) {
final zetaColors = Zeta.of(context).colors;

return ExampleScaffold(
name: ListItemExample.name,
child: Container(
color: zetaColors.surfaceSecondary,
child: SingleChildScrollView(
child: Column(
children: [
// List Item with descriptor
Padding(
padding: const EdgeInsets.only(top: ZetaSpacing.x4),
child: ZetaListItem(
dense: true,
leading: Container(
width: 48,
height: 48,
decoration: BoxDecoration(borderRadius: ZetaRadius.rounded),
child: Placeholder(),
),
subtitle: Text("Descriptor"),
title: Text("List Item"),
trailing: ZetaCheckbox(
value: _isCheckBoxEnabled,
onChanged: (_) => _onDefaultListItemTap(),
),
onTap: _onDefaultListItemTap,
),
),

// Enabled
Padding(
padding: const EdgeInsets.only(top: ZetaSpacing.l),
child: Text(
"Enabled",
style: ZetaTextStyles.titleLarge,
),
),
Padding(
padding: const EdgeInsets.only(top: ZetaSpacing.m),
child: ZetaListItem(title: Text("List Item")),
),

// Selected
Padding(
padding: const EdgeInsets.only(top: ZetaSpacing.l),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
"Selected",
style: ZetaTextStyles.titleLarge,
),
),
),
Padding(
padding: const EdgeInsets.only(top: ZetaSpacing.m),
child: ZetaListItem(
title: Text("List Item"),
selected: _isSelected,
trailing: _isSelected
? Icon(
ZetaIcons.check_mark_sharp,
color: zetaColors.primary,
)
: null,
onTap: () => setState(() => _isSelected = !_isSelected),
),
),

// Disabled
Padding(
padding: const EdgeInsets.only(top: ZetaSpacing.l),
child: Text(
"Disabled",
style: ZetaTextStyles.titleLarge,
),
),
Padding(
padding: const EdgeInsets.only(top: ZetaSpacing.m),
child: ZetaListItem(
title: Text("List Item"),
enabled: false,
onTap: () {},
),
),
],
),
),
),
);
}
}
8 changes: 7 additions & 1 deletion example/widgetbook/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import 'pages/components/checkbox_widgetbook.dart';
import 'pages/components/chip_widgetbook.dart';
import 'pages/components/dial_pad_widgetbook.dart';
import 'pages/components/in_page_banner_widgetbook.dart';
import 'pages/components/list_item_widgetbook.dart';
import 'pages/components/navigation_bar_widgetbook.dart';
import 'pages/components/password_input_widgetbook.dart';
import 'pages/components/progress_widgetbook.dart';
Expand Down Expand Up @@ -75,7 +76,12 @@ class HotReload extends StatelessWidget {
),
WidgetbookUseCase(name: 'Password Input', builder: (context) => passwordInputUseCase(context)),
WidgetbookUseCase(name: 'Content', builder: (context) => bottomSheetContentUseCase(context)),
WidgetbookUseCase(name: 'Dial Pad', builder: (context) => dialPadUseCase(context)),
WidgetbookUseCase(
name: 'Dial Pad',
builder: (context) => dialPadUseCase(context)),
WidgetbookUseCase(
name: 'List Item',
builder: (context) => listItemUseCase(context)),
WidgetbookUseCase(name: 'Navigation Bar', builder: (context) => navigationBarUseCase(context)),
WidgetbookComponent(
name: 'Progress',
Expand Down
49 changes: 49 additions & 0 deletions example/widgetbook/pages/components/list_item_widgetbook.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import 'package:flutter/material.dart';
import 'package:widgetbook/widgetbook.dart';
import 'package:zeta_flutter/zeta_flutter.dart';

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

Widget listItemUseCase(BuildContext context) {
return WidgetbookTestWidget(
widget: StatefulBuilder(
builder: (context, setState) {
final subtitle =
context.knobs.stringOrNull(label: 'Descriptor', initialValue: null);

final trailing =
context.knobs.boolean(label: 'Trailing', initialValue: false)
? Checkbox(value: false, onChanged: (_) {})
: null;

final leading =
context.knobs.boolean(label: 'Leading', initialValue: false)
? Container(
width: 48,
height: 48,
decoration: BoxDecoration(borderRadius: ZetaRadius.rounded),
child: Placeholder(),
)
: null;

return ZetaListItem(
dense: context.knobs.boolean(label: 'Dense', initialValue: false),
enabled: context.knobs.boolean(label: 'Enabled', initialValue: true),
enabledDivider: context.knobs.boolean(
label: 'Enabled Divider',
initialValue: true,
),
selected:
context.knobs.boolean(label: 'Selected', initialValue: true),
leading: leading,
title: Text(
context.knobs.string(label: 'Title', initialValue: 'List Item'),
),
subtitle: subtitle != null ? Text(subtitle) : null,
trailing: trailing,
onTap: () {},
);
},
),
);
}
Loading

0 comments on commit 3103139

Please sign in to comment.