-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(main): Tabs * [automated commit] lint format and import sort --------- Co-authored-by: github-actions <[email protected]>
- Loading branch information
1 parent
cbf46d9
commit 31bc20a
Showing
7 changed files
with
191 additions
and
0 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,70 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:zeta_example/widgets.dart'; | ||
import 'package:zeta_flutter/zeta_flutter.dart'; | ||
|
||
class TabsExample extends StatefulWidget { | ||
const TabsExample({super.key}); | ||
|
||
static const String name = 'Tabs'; | ||
|
||
@override | ||
State<TabsExample> createState() => _TabsExampleState(); | ||
} | ||
|
||
class _TabsExampleState extends State<TabsExample> { | ||
@override | ||
Widget build(BuildContext context) { | ||
return ExampleScaffold( | ||
name: TabsExample.name, | ||
child: Column( | ||
children: [ | ||
DefaultTabController( | ||
length: 2, | ||
child: ZetaTabBar( | ||
context: context, | ||
tabs: [ | ||
ZetaTab(icon: Icon(ZetaIcons.star_round), text: "Tab Item"), | ||
ZetaTab(icon: Icon(ZetaIcons.star_round), text: "Tab Item"), | ||
], | ||
), | ||
), | ||
Padding( | ||
padding: const EdgeInsets.only(top: ZetaSpacing.l), | ||
child: DefaultTabController( | ||
length: 5, | ||
child: ZetaTabBar( | ||
context: context, | ||
isScrollable: true, | ||
tabs: [ | ||
ZetaTab(text: "Tab Item"), | ||
ZetaTab(text: "Tab Item"), | ||
ZetaTab(text: "Tab Item"), | ||
ZetaTab(text: "Tab Item"), | ||
ZetaTab(text: "Tab Item"), | ||
], | ||
), | ||
), | ||
), | ||
Padding( | ||
padding: const EdgeInsets.only(top: ZetaSpacing.l), | ||
child: DefaultTabController( | ||
length: 5, | ||
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"), | ||
ZetaTab(icon: Icon(ZetaIcons.star_sharp), text: "Tab Item"), | ||
ZetaTab(icon: Icon(ZetaIcons.star_sharp), text: "Tab Item"), | ||
ZetaTab(icon: Icon(ZetaIcons.star_sharp), text: "Tab Item"), | ||
], | ||
), | ||
), | ||
), | ||
], | ||
), | ||
); | ||
} | ||
} |
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,51 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:widgetbook/widgetbook.dart'; | ||
import 'package:zeta_flutter/zeta_flutter.dart'; | ||
|
||
import '../../test/test_components.dart'; | ||
|
||
Widget tabsUseCase(BuildContext context) { | ||
return WidgetbookTestWidget( | ||
widget: SingleChildScrollView( | ||
child: Column( | ||
children: [ | ||
Padding( | ||
padding: const EdgeInsets.only(top: ZetaSpacing.l), | ||
child: DefaultTabController( | ||
length: 2, | ||
child: ZetaTabBar( | ||
context: context, | ||
enabled: context.knobs.boolean( | ||
label: "Enabled", | ||
initialValue: true, | ||
), | ||
tabs: [ | ||
ZetaTab(icon: Icon(ZetaIcons.star_round), text: "Tab Item"), | ||
ZetaTab(icon: Icon(ZetaIcons.star_round), text: "Tab Item"), | ||
], | ||
), | ||
), | ||
), | ||
Padding( | ||
padding: const EdgeInsets.only(top: ZetaSpacing.l), | ||
child: DefaultTabController( | ||
length: 5, | ||
child: ZetaTabBar( | ||
context: context, | ||
enabled: context.knobs.boolean(label: "Enabled"), | ||
isScrollable: true, | ||
tabs: [ | ||
ZetaTab(text: "Tab Item"), | ||
ZetaTab(text: "Tab Item"), | ||
ZetaTab(text: "Tab Item"), | ||
ZetaTab(text: "Tab Item"), | ||
ZetaTab(text: "Tab Item"), | ||
], | ||
), | ||
), | ||
), | ||
], | ||
), | ||
), | ||
); | ||
} |
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,29 @@ | ||
import 'package:flutter/material.dart'; | ||
import '../../../zeta_flutter.dart'; | ||
|
||
/// Defines how the bounds of the selected tab indicator are computed. Intended to be used with [ZetaTabBar]. | ||
class ZetaTab extends Tab { | ||
/// Creates a Zeta Design tab bar. | ||
ZetaTab({ | ||
Widget? icon, | ||
String? text, | ||
super.key, | ||
}) : super( | ||
child: Row( | ||
mainAxisSize: MainAxisSize.min, | ||
mainAxisAlignment: MainAxisAlignment.center, | ||
children: [ | ||
if (icon != null) ...[ | ||
const SizedBox(width: ZetaSpacing.s), | ||
icon, | ||
], | ||
if (text != null) | ||
Padding( | ||
padding: icon != null ? const EdgeInsets.only(left: ZetaSpacing.x2) : EdgeInsets.zero, | ||
child: Text(text), | ||
), | ||
if (icon != null) const SizedBox(width: ZetaSpacing.s), | ||
], | ||
), | ||
); | ||
} |
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,35 @@ | ||
import 'package:flutter/material.dart'; | ||
import '../../../zeta_flutter.dart'; | ||
|
||
/// A Zeta Design primary tab bar. | ||
class ZetaTabBar extends TabBar { | ||
/// Creates a Zeta Design primary tab bar. | ||
ZetaTabBar({ | ||
required BuildContext context, | ||
required List<ZetaTab> super.tabs, | ||
TabAlignment super.tabAlignment = TabAlignment.center, | ||
bool enabled = true, | ||
super.isScrollable, | ||
super.enableFeedback, | ||
super.dragStartBehavior, | ||
super.padding, | ||
super.onTap, | ||
super.key, | ||
}) : super( | ||
indicatorSize: isScrollable ? TabBarIndicatorSize.label : TabBarIndicatorSize.tab, | ||
labelPadding: isScrollable ? null : EdgeInsets.zero, | ||
indicator: UnderlineTabIndicator( | ||
borderSide: BorderSide( | ||
color: Zeta.of(context).colors.primary, | ||
width: enabled ? 4 : 0, | ||
), | ||
borderRadius: ZetaRadius.none, | ||
), | ||
labelStyle: ZetaTextStyles.labelLarge.copyWith( | ||
color: enabled ? Zeta.of(context).colors.textDefault : Zeta.of(context).colors.textDisabled, | ||
), | ||
unselectedLabelStyle: ZetaTextStyles.labelLarge.copyWith( | ||
color: enabled ? Zeta.of(context).colors.textSubtle : Zeta.of(context).colors.textDisabled, | ||
), | ||
); | ||
} |
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