Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(UX-1231): created avatar rail #196

Merged
merged 10 commits into from
Oct 28, 2024
2 changes: 2 additions & 0 deletions example/lib/home.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:zeta_example/pages/components/accordion_example.dart';
import 'package:zeta_example/pages/components/avatar_rail_example.dart';
import 'package:zeta_example/pages/components/avatar_example.dart';
import 'package:zeta_example/pages/components/badges_example.dart';
import 'package:zeta_example/pages/components/banner_example.dart';
Expand Down Expand Up @@ -61,6 +62,7 @@ class Component {
final List<Component> components = [
Component(AccordionExample.name, (context) => const AccordionExample()),
Component(TopAppBarExample.name, (context) => const TopAppBarExample()),
Component(AvatarRailExample.name, (context) => const AvatarRailExample()),
Component(AvatarExample.name, (context) => const AvatarExample()),
Component(BannerExample.name, (context) => const BannerExample()),
Component(BadgesExample.name, (context) => const BadgesExample()),
Expand Down
96 changes: 96 additions & 0 deletions example/lib/pages/components/avatar_rail_example.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
// import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:zeta_example/widgets.dart';
import 'package:zeta_flutter/zeta_flutter.dart';

class AvatarRailExample extends StatefulWidget {
static const String name = 'AvatarRail';

const AvatarRailExample({super.key});

@override
State<AvatarRailExample> createState() => _AvatarRailExampleState();
}

class _AvatarRailExampleState extends State<AvatarRailExample> {
int? selected;
@override
Widget build(BuildContext context) {
final avatarList = [
ZetaAvatar.initials(
initials: 'AZ',
label: 'Archie',
),
ZetaAvatar.initials(
initials: 'BY',
label: 'Beth',
),
ZetaAvatar.initials(
initials: 'CX',
label: 'Clara',
),
ZetaAvatar.initials(
initials: 'DW',
label: 'Dan',
),
ZetaAvatar.initials(
initials: 'EV',
label: 'Emily',
),
ZetaAvatar.initials(
initials: 'FU',
label: 'Frank',
),
ZetaAvatar.initials(
initials: 'GT',
label: 'George',
),
ZetaAvatar.initials(
initials: 'HS',
label: 'Harith',
),
ZetaAvatar.initials(
initials: 'IR',
label: 'Irene',
),
ZetaAvatar.initials(
initials: 'KQ',
label: 'Katie',
),
];
return ExampleScaffold(
name: AvatarRailExample.name,
child: SingleChildScrollView(
child: Column(
children: [
for (final size in ZetaAvatarSize.values)
Row(
children: [
Text(size.toString()),
SizedBox(
width: 500,
child: ZetaAvatarRail(
gap: 10,
size: size,
labelMaxLines: 3,
onTap: (key) => {
setState(() {
selected = int.parse(key.toString().replaceAll(RegExp(r'[^0-9]'), ''));
})
},
avatars: avatarList,
),
),
if (selected != null)
Padding(
padding: const EdgeInsets.all(8.0),
child: avatarList[selected!].copyWith(size: size),
),
].gap(50),
)
],
),
),
);
}
}
10 changes: 9 additions & 1 deletion example/widgetbook/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import 'pages/components/notification_list_item_widgetbook.dart';
import 'pages/components/slider_widgetbook.dart';
import 'pages/components/text_input_widgetbook.dart';
import 'pages/components/top_app_bar_widgetbook.dart';
import 'pages/components/avatar_rail_widgetbook.dart';
import 'pages/components/avatar_widgetbook.dart';
import 'pages/components/badges_widgetbook.dart';
import 'pages/components/banner_widgetbook.dart';
Expand Down Expand Up @@ -121,6 +122,13 @@ class _HotReloadState extends State<HotReload> {
name: 'Components',
isInitiallyExpanded: false,
children: [
WidgetbookComponent(
name: 'Avatar',
useCases: [
WidgetbookUseCase(name: 'Avatar', builder: (context) => avatarUseCase(context)),
WidgetbookUseCase(name: 'Avatar Rail', builder: (context) => avatarRailUseCase(context)),
],
),
WidgetbookComponent(
name: 'Top App Bar',
useCases: [
Expand Down Expand Up @@ -181,7 +189,6 @@ class _HotReloadState extends State<HotReload> {
],
),
WidgetbookUseCase(name: 'Accordion', builder: (context) => accordionUseCase(context)),
WidgetbookUseCase(name: 'Avatar', builder: (context) => avatarUseCase(context)),
WidgetbookUseCase(name: 'Banners', builder: (context) => bannerUseCase(context)),
WidgetbookUseCase(name: 'Bottom Sheet', builder: (context) => bottomSheetContentUseCase(context)),
WidgetbookUseCase(name: 'BreadCrumbs', builder: (context) => breadCrumbsUseCase(context)),
Expand Down Expand Up @@ -247,6 +254,7 @@ class _HotReloadState extends State<HotReload> {
InspectorAddon(enabled: false),
ZoomAddon(initialZoom: 1.0),
TextScaleAddon(min: 1, max: 2, divisions: 4, initialScale: 1),
// TextScaleAddon(scales: [1, 1.25, 1.75, 2], initialScale: 1),
],
);
}
Expand Down
174 changes: 174 additions & 0 deletions example/widgetbook/pages/components/avatar_rail_widgetbook.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
import 'package:flutter/material.dart';
import 'package:widgetbook/widgetbook.dart';
import 'package:zeta_flutter/zeta_flutter.dart';

import '../../utils/scaffold.dart';

Widget avatarRailUseCase(BuildContext context) {
final Widget image = Image.asset('assets/Omer.jpg', fit: BoxFit.cover);
final colors = Zeta.of(context).colors;

return WidgetbookScaffold(
builder: (context, _) => ZetaAvatarRail(
labelMaxLines: context.knobs.int.slider(label: 'Label Max Lines', min: 1, max: 3, initialValue: 1),
avatars: [
ZetaAvatar(
image: context.knobs.boolean(label: 'Image') ? image : null,
size: context.knobs.list(
label: 'Size',
options: ZetaAvatarSize.values,
labelBuilder: (value) => value.name.split('.').last.toUpperCase(),
initialOption: ZetaAvatarSize.m,
),
upperBadge: context.knobs.boolean(label: 'Status Badge', initialValue: false)
? ZetaAvatarBadge.icon(
icon: ZetaIcons.close,
color: context.knobs.colorOrNull(label: "Upper Badge Color", initialValue: colors.green) ??
colors.iconDefault,
)
: null,
borderColor: context.knobs.colorOrNull(label: 'Outline', initialValue: colors.green),
lowerBadge: context.knobs.boolean(label: 'Notification Badge', initialValue: false)
? ZetaAvatarBadge.notification(
value: context.knobs.intOrNull.input(label: "Value", initialValue: 1),
)
: null,
initials: context.knobs.stringOrNull(label: 'Initials', initialValue: 'AZ'),
backgroundColor: context.knobs.colorOrNull(label: 'Background color', initialValue: colors.purple.shade80),
onTap: () => print('Avatar tapped'),
label: context.knobs.stringOrNull(label: 'Label', initialValue: 'ABC'),
),
ZetaAvatar(
image: context.knobs.boolean(label: 'Image') ? image : null,
size: context.knobs.list(
label: 'Size',
options: ZetaAvatarSize.values,
labelBuilder: (value) => value.name.split('.').last.toUpperCase(),
initialOption: ZetaAvatarSize.m,
),
upperBadge: context.knobs.boolean(label: 'Status Badge', initialValue: false)
? ZetaAvatarBadge.icon(
icon: ZetaIcons.close,
color: context.knobs.colorOrNull(label: "Upper Badge Color", initialValue: colors.green) ??
colors.iconDefault,
)
: null,
borderColor: context.knobs.colorOrNull(label: 'Outline', initialValue: colors.green),
lowerBadge: context.knobs.boolean(label: 'Notification Badge', initialValue: false)
? ZetaAvatarBadge.notification(
value: context.knobs.intOrNull.input(label: "Value", initialValue: 1),
)
: null,
initials: context.knobs.stringOrNull(label: 'Initials', initialValue: 'AZ'),
backgroundColor: context.knobs.colorOrNull(label: 'Background color', initialValue: colors.purple.shade80),
onTap: () => print('Avatar tapped'),
label: context.knobs.stringOrNull(label: 'Label', initialValue: 'ABC'),
),
ZetaAvatar(
image: context.knobs.boolean(label: 'Image') ? image : null,
size: context.knobs.list(
label: 'Size',
options: ZetaAvatarSize.values,
labelBuilder: (value) => value.name.split('.').last.toUpperCase(),
initialOption: ZetaAvatarSize.m,
),
upperBadge: context.knobs.boolean(label: 'Status Badge', initialValue: false)
? ZetaAvatarBadge.icon(
icon: ZetaIcons.close,
color: context.knobs.colorOrNull(label: "Upper Badge Color", initialValue: colors.green) ??
colors.iconDefault,
)
: null,
borderColor: context.knobs.colorOrNull(label: 'Outline', initialValue: colors.green),
lowerBadge: context.knobs.boolean(label: 'Notification Badge', initialValue: false)
? ZetaAvatarBadge.notification(
value: context.knobs.intOrNull.input(label: "Value", initialValue: 1),
)
: null,
initials: context.knobs.stringOrNull(label: 'Initials', initialValue: 'AZ'),
backgroundColor: context.knobs.colorOrNull(label: 'Background color', initialValue: colors.purple.shade80),
onTap: () => print('Avatar tapped'),
label: context.knobs.stringOrNull(label: 'Label', initialValue: 'ABC'),
),
ZetaAvatar(
image: context.knobs.boolean(label: 'Image') ? image : null,
size: context.knobs.list(
label: 'Size',
options: ZetaAvatarSize.values,
labelBuilder: (value) => value.name.split('.').last.toUpperCase(),
initialOption: ZetaAvatarSize.m,
),
upperBadge: context.knobs.boolean(label: 'Status Badge', initialValue: false)
? ZetaAvatarBadge.icon(
icon: ZetaIcons.close,
color: context.knobs.colorOrNull(label: "Upper Badge Color", initialValue: colors.green) ??
colors.iconDefault,
)
: null,
borderColor: context.knobs.colorOrNull(label: 'Outline', initialValue: colors.green),
lowerBadge: context.knobs.boolean(label: 'Notification Badge', initialValue: false)
? ZetaAvatarBadge.notification(
value: context.knobs.intOrNull.input(label: "Value", initialValue: 1),
)
: null,
initials: context.knobs.stringOrNull(label: 'Initials', initialValue: 'AZ'),
backgroundColor: context.knobs.colorOrNull(label: 'Background color', initialValue: colors.purple.shade80),
onTap: () => print('Avatar tapped'),
label: context.knobs.stringOrNull(label: 'Label', initialValue: 'ABC'),
),
ZetaAvatar(
image: context.knobs.boolean(label: 'Image') ? image : null,
size: context.knobs.list(
label: 'Size',
options: ZetaAvatarSize.values,
labelBuilder: (value) => value.name.split('.').last.toUpperCase(),
initialOption: ZetaAvatarSize.m,
),
upperBadge: context.knobs.boolean(label: 'Status Badge', initialValue: false)
? ZetaAvatarBadge.icon(
icon: ZetaIcons.close,
color: context.knobs.colorOrNull(label: "Upper Badge Color", initialValue: colors.green) ??
colors.iconDefault,
)
: null,
borderColor: context.knobs.colorOrNull(label: 'Outline', initialValue: colors.green),
lowerBadge: context.knobs.boolean(label: 'Notification Badge', initialValue: false)
? ZetaAvatarBadge.notification(
value: context.knobs.intOrNull.input(label: "Value", initialValue: 1),
)
: null,
initials: context.knobs.stringOrNull(label: 'Initials', initialValue: 'AZ'),
backgroundColor: context.knobs.colorOrNull(label: 'Background color', initialValue: colors.purple.shade80),
onTap: () => print('Avatar tapped'),
label: context.knobs.stringOrNull(label: 'Label', initialValue: 'ABC'),
),
ZetaAvatar(
image: context.knobs.boolean(label: 'Image') ? image : null,
size: context.knobs.list(
label: 'Size',
options: ZetaAvatarSize.values,
labelBuilder: (value) => value.name.split('.').last.toUpperCase(),
initialOption: ZetaAvatarSize.m,
),
upperBadge: context.knobs.boolean(label: 'Status Badge', initialValue: false)
? ZetaAvatarBadge.icon(
icon: ZetaIcons.close,
color: context.knobs.colorOrNull(label: "Upper Badge Color", initialValue: colors.green) ??
colors.iconDefault,
)
: null,
borderColor: context.knobs.colorOrNull(label: 'Outline', initialValue: colors.green),
lowerBadge: context.knobs.boolean(label: 'Notification Badge', initialValue: false)
? ZetaAvatarBadge.notification(
value: context.knobs.intOrNull.input(label: "Value", initialValue: 1),
)
: null,
initials: context.knobs.stringOrNull(label: 'Initials', initialValue: 'AZ'),
backgroundColor: context.knobs.colorOrNull(label: 'Background color', initialValue: colors.purple.shade80),
onTap: () => print('Avatar tapped'),
label: context.knobs.stringOrNull(label: 'Label', initialValue: 'ABC'),
),
],
),
);
}
3 changes: 3 additions & 0 deletions example/widgetbook/pages/components/avatar_widgetbook.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ Widget avatarUseCase(BuildContext context) {
: null,
initials: context.knobs.stringOrNull(label: 'Initials', initialValue: 'AZ'),
backgroundColor: context.knobs.colorOrNull(label: 'Background color', initialValue: colors.purple.shade80),
onTap: () => print('Avatar tapped'),
label: context.knobs.stringOrNull(label: 'Label', initialValue: 'ABC'),
labelMaxLines: context.knobs.int.slider(label: 'Label Max Lines', min: 1, max: 3, initialValue: 1),
),
);
}
Loading