Skip to content

Commit

Permalink
feat: Component search bar (#29)
Browse files Browse the repository at this point in the history
* create ZetaSearchBar with examples

* create Widgetbook for ZetaSearchBar

* rename callback

* full instead of stadium shape

* default hint Search

* add parameters showLeadingIcon & showSpeechToText

* fix comments

* use ZetaWidgetBorder & ZetaWidgetSize from enums.dart
  • Loading branch information
atanasyordanov21 authored and thelukewalton committed Apr 25, 2024
1 parent 85cab8e commit 837f482
Show file tree
Hide file tree
Showing 6 changed files with 412 additions and 0 deletions.
2 changes: 2 additions & 0 deletions example/lib/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import 'package:zeta_example/pages/components/navigation_bar_example.dart';
import 'package:zeta_example/pages/components/navigation_rail_example.dart';
import 'package:zeta_example/pages/components/phone_input_example.dart';
import 'package:zeta_example/pages/components/radio_example.dart';
import 'package:zeta_example/pages/components/search_bar_example.dart';
import 'package:zeta_example/pages/components/segmented_control_example.dart';
import 'package:zeta_example/pages/components/stepper_example.dart';
import 'package:zeta_example/pages/components/switch_example.dart';
Expand Down Expand Up @@ -70,6 +71,7 @@ final List<Component> components = [
Component(DateInputExample.name, (context) => const DateInputExample()),
Component(PhoneInputExample.name, (context) => const PhoneInputExample()),
Component(DialogExample.name, (context) => const DialogExample()),
Component(SearchBarExample.name, (context) => const SearchBarExample()),
Component(TooltipExample.name, (context) => const TooltipExample()),
Component(NavigationRailExample.name, (context) => const NavigationRailExample()),
];
Expand Down
89 changes: 89 additions & 0 deletions example/lib/pages/components/search_bar_example.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import 'package:flutter/material.dart';
import 'package:zeta_example/widgets.dart';
import 'package:zeta_flutter/zeta_flutter.dart';

class SearchBarExample extends StatefulWidget {
static const String name = 'SearchBar';

const SearchBarExample({Key? key}) : super(key: key);

@override
State<SearchBarExample> createState() => _SearchBarExampleState();
}

class _SearchBarExampleState extends State<SearchBarExample> {
@override
Widget build(BuildContext context) {
return ExampleScaffold(
name: 'Search Bar',
child: SingleChildScrollView(
child: Column(
children: [
Padding(
padding: const EdgeInsets.only(top: 20),
child: Text('Rounded', style: ZetaTextStyles.titleMedium),
),
Padding(
padding: const EdgeInsets.all(20),
child: ZetaSearchBar(
onChanged: (value) {},
),
),
Padding(
padding: const EdgeInsets.only(top: 20),
child: Text('Full', style: ZetaTextStyles.titleMedium),
),
Padding(
padding: const EdgeInsets.all(20),
child: ZetaSearchBar(
shape: ZetaWidgetBorder.full,
onSpeechToText: () async => 'I wanted to say...',
),
),
Padding(
padding: const EdgeInsets.only(top: 20),
child: Text('Sharp', style: ZetaTextStyles.titleMedium),
),
Padding(
padding: const EdgeInsets.all(20),
child: ZetaSearchBar(
initialValue: 'Initial value',
shape: ZetaWidgetBorder.sharp,
),
),
Padding(
padding: const EdgeInsets.only(top: 20),
child: Text('Disabled', style: ZetaTextStyles.titleMedium),
),
Padding(
padding: const EdgeInsets.all(20),
child: ZetaSearchBar(
enabled: false,
),
),
Padding(
padding: const EdgeInsets.only(top: 20),
child: Text('Medium', style: ZetaTextStyles.titleMedium),
),
Padding(
padding: const EdgeInsets.all(20),
child: ZetaSearchBar(
size: ZetaWidgetSize.medium,
),
),
Padding(
padding: const EdgeInsets.only(top: 20),
child: Text('Small', style: ZetaTextStyles.titleMedium),
),
Padding(
padding: const EdgeInsets.all(20),
child: ZetaSearchBar(
size: ZetaWidgetSize.small,
),
),
],
),
),
);
}
}
2 changes: 2 additions & 0 deletions example/widgetbook/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import 'pages/components/password_input_widgetbook.dart';
import 'pages/components/phone_input_widgetbook.dart';
import 'pages/components/progress_widgetbook.dart';
import 'pages/components/radio_widgetbook.dart';
import 'pages/components/search_bar_widgetbook.dart';
import 'pages/components/segmented_control_widgetbook.dart';
import 'pages/components/stepper_widgetbook.dart';
import 'pages/components/switch_widgetbook.dart';
Expand Down Expand Up @@ -133,6 +134,7 @@ class HotReload extends StatelessWidget {
builder: (context) => stepperUseCase(context),
),
WidgetbookUseCase(name: 'Dialog', builder: (context) => dialogUseCase(context)),
WidgetbookUseCase(name: 'Search Bar', builder: (context) => searchBarUseCase(context)),
WidgetbookUseCase(name: 'Navigation Rail', builder: (context) => navigationRailUseCase(context)),
WidgetbookUseCase(name: 'Tooltip', builder: (context) => tooltipUseCase(context)),
]..sort((a, b) => a.name.compareTo(b.name)),
Expand Down
80 changes: 80 additions & 0 deletions example/widgetbook/pages/components/search_bar_widgetbook.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import 'package:flutter/material.dart';
import 'package:widgetbook/widgetbook.dart';
import 'package:zeta_flutter/zeta_flutter.dart';

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

const List<String> _items = [
'The quick...',
'The quick brown...',
'The quick brown fox...',
'The quick brown fox jumped...',
'The quick brown fox jumped into...',
'The quick brown fox jumped into the hole...',
];

Widget searchBarUseCase(BuildContext context) {
List<String> items = List.from(_items);
return WidgetbookTestWidget(
widget: StatefulBuilder(
builder: (context, setState) {
final hint = context.knobs.string(
label: 'Hint',
initialValue: 'Search',
);
final enabled = context.knobs.boolean(
label: 'Enabled',
initialValue: true,
);
final size = context.knobs.list<ZetaWidgetSize>(
label: 'Size',
options: ZetaWidgetSize.values,
labelBuilder: (size) => size.name,
);
final shape = context.knobs.list<ZetaWidgetBorder>(
label: 'Shape',
options: ZetaWidgetBorder.values,
labelBuilder: (shape) => shape.name,
);
final showLeadingIcon = context.knobs.boolean(
label: 'Show leading icon',
initialValue: true,
);
final showSpeechToText = context.knobs.boolean(
label: 'Show Speech-To-Text button',
initialValue: true,
);

return Padding(
padding: const EdgeInsets.all(ZetaSpacing.x5),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
ZetaSearchBar(
size: size,
shape: shape,
enabled: enabled,
hint: hint,
showLeadingIcon: showLeadingIcon,
showSpeechToText: showSpeechToText,
onChanged: (value) {
if (value == null) return;
setState(
() => items = _items
.where((item) => item.toLowerCase().contains(
value.toLowerCase(),
))
.toList(),
);
},
onSpeechToText: () async => 'I wanted to say...',
),
const SizedBox(height: ZetaSpacing.x5),
...items.map((item) => Text(item)).toList(),
],
),
);
},
),
);
}
Loading

0 comments on commit 837f482

Please sign in to comment.