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: Add ListItem component #40

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .firebaserc
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
{
"projects": {
"default": "zeta-ds"
},
"targets": {
"zeta-ds": {
"hosting": {
"flutter": [
"zeta-flutter-main"
]
}
}
}
}
18 changes: 18 additions & 0 deletions .github/workflows/on-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,21 @@ jobs:
git add -A
git commit -m '[automated commit] lint format and import sort'
git push -f
deploy-qa-demo:
name: Deploy preview version of the storybook on firebase
needs: code-quality
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: subosito/flutter-action@v2
- name: Setup flutter
run: flutter pub get
- name: Build example app
run: |
cd example
flutter build web -t widgetbook/main.dart -o ../build --no-tree-shake-icons
- uses: FirebaseExtended/action-hosting-deploy@v0
with:
repoToken: "${{ secrets.GITHUB_TOKEN }}"
firebaseServiceAccount: "${{ secrets.FIREBASE_SERVICE_ACCOUNT_ZETA_DS }}"
channelId: "live"
5 changes: 0 additions & 5 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,6 @@ jobs:
with:
ref: ${{ github.head_ref }}
- uses: subosito/flutter-action@v2
with:
flutter-version: "3.19.x"
channel: "stable"
- name: Setup flutter
run: flutter pub get
- name: Build example app
Expand All @@ -100,6 +97,4 @@ jobs:
with:
repoToken: "${{ secrets.GITHUB_TOKEN }}"
firebaseServiceAccount: "${{ secrets.FIREBASE_SERVICE_ACCOUNT_ZETA_DS }}"
expires: 7d
projectId: zeta-ds
channelId: "pr-${{ github.event.number }}-${{ github.event.pull_request.head.ref }}"
27 changes: 0 additions & 27 deletions CONTRIBUTING

This file was deleted.

53 changes: 53 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Getting Involved

Thank you for your interest in this project. We'd love to see your contributions. There are just few small guidelines you need to follow.
Please note we have a code of conduct, please follow it in all your interactions with the project.

## Opening an issue

If you've noticed a bug or you have a suggestion for a new feature, please go ahead and open an issue in this project. Please do include as much information as possible.

Please file issues before doing substantial work; this will ensure that others don't duplicate the work and that there's a chance to discuss any design issues.

## Making a code change

We're always open to pull requests, but these should be small and clearly described so that we can understand what you're trying to do.

When you're ready to start coding, fork the needed repository to your own GitHub account and make your changes in a new branch. Once you're happy, open a pull request and explain what the change is and why you think we should include it in our project.

If the change is a bug fix, try to create a test that aligns with the bug.

### Creating a new component

We want the designs to be the source of truth for this repository, so new components will only be accepted if they are with the design files.

New components should use all tokens matching the design, and should not use hardcoded values for color, spacing, or radius. This ensures that changes made to these fundamental tokens are reflected throughout the library.

All components should have inline [dartdoc](https://dart.dev/tools/dart-doc) documentation on public functions and variables. This is enforced by the lint rules.

To demonstrate a component, we need to create 2 examples: firstly in the zeta_flutter example app and secondly in widgetbook.

Example app should show basic examples to compare against the designs and is typically used by developers whilst building out components.

The widgetbook is used by the wider team to review components. We should attempt to show the full functionality of a component in a single Widgetbook instance. We have some helper functions for building knobs for icons and rounded bool in [utils.dart](./example/widgetbook/utils/utils.dart).
For more information on widgetbook, [read the docs](https://docs.widgetbook.io/).

We should also create a test for each widget created.

## Code reviews

All submissions, including submissions by project members, require review. We use GitHub pull requests (PRs) for this purpose. Consult [GitHub Help](https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/about-pull-requests) for more information on using pull requests.

Before a PR can be reviewed, ensure you have done the following, and fixed any issues that may arise:

- Ensure branch is up to date `git rebase main`
- Check formatting: `flutter format .`
- Run static analyses: `flutter analyze`
- Run unit-tests: `flutter test`

All PRs should be titled according to [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/), as the branch will be squashed, so the PR title will become the commit message.
Examples:

- `feat(X):` for new features
- `fix(x):` for bug fixes
- `chore(x):` for admin / chores.
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: () {},
),
),
],
),
),
),
);
}
}
2 changes: 2 additions & 0 deletions 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 @@ -76,6 +77,7 @@ 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: 'List Item', builder: (context) => listItemUseCase(context)),
WidgetbookUseCase(name: 'Navigation Bar', builder: (context) => navigationBarUseCase(context)),
WidgetbookComponent(
name: 'Progress',
Expand Down
45 changes: 45 additions & 0 deletions example/widgetbook/pages/components/list_item_widgetbook.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
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: () {},
);
},
),
);
}
1 change: 1 addition & 0 deletions firebase.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"hosting": {
"public": "build",
"target": "flutter",
"rewrites": [
{
"source": "**",
Expand Down
Loading