Skip to content

Commit

Permalink
feat: adding widgetbook (#112)
Browse files Browse the repository at this point in the history
* feat: adding widgetbook

* moving widgetbook to be a standalone app

* fix workflow

* format

* fixing tests
  • Loading branch information
erickzanardo authored Jan 2, 2024
1 parent a207567 commit 9324d9a
Show file tree
Hide file tree
Showing 21 changed files with 459 additions and 0 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/widgetbook.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: widgetbook

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

on:
push:
paths:
- "widgetbook/**"
- ".github/workflows/widgetbook.yaml"

pull_request:
paths:
- "widgetbook/**"
- ".github/workflows/widgetbook.yaml"

jobs:
build:
uses: VeryGoodOpenSource/very_good_workflows/.github/workflows/[email protected]
with:
min_coverage: 0
working_directory: widgetbook
43 changes: 43 additions & 0 deletions widgetbook/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Miscellaneous
*.class
*.log
*.pyc
*.swp
.DS_Store
.atom/
.buildlog/
.history
.svn/
migrate_working_dir/

# IntelliJ related
*.iml
*.ipr
*.iws
.idea/

# The .vscode folder contains launch configuration and tasks you configure in
# VS Code which you may wish to be included in version control, so this line
# is commented out by default.
#.vscode/

# Flutter/Dart/Pub related
**/doc/api/
**/ios/Flutter/.last_build_id
.dart_tool/
.flutter-plugins
.flutter-plugins-dependencies
.pub-cache/
.pub/
/build/

# Symbolication related
app.*.symbols

# Obfuscation related
app.*.map.json

# Android Studio will place build artifacts here
/android/app/debug
/android/app/profile
/android/app/release
30 changes: 30 additions & 0 deletions widgetbook/.metadata
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# This file tracks properties of this Flutter project.
# Used by Flutter tool to assess capabilities and perform upgrades etc.
#
# This file should be version controlled and should not be manually edited.

version:
revision: "b0366e0a3f089e15fd89c97604ab402fe26b724c"
channel: "stable"

project_type: app

# Tracks metadata for the flutter migrate command
migration:
platforms:
- platform: root
create_revision: b0366e0a3f089e15fd89c97604ab402fe26b724c
base_revision: b0366e0a3f089e15fd89c97604ab402fe26b724c
- platform: web
create_revision: b0366e0a3f089e15fd89c97604ab402fe26b724c
base_revision: b0366e0a3f089e15fd89c97604ab402fe26b724c

# User provided section

# List of Local paths (relative to this file) that should be
# ignored by the migrate tool.
#
# Files that are not part of the templates will be ignored by default.
unmanaged_files:
- 'lib/main.dart'
- 'ios/Runner.xcodeproj/project.pbxproj'
3 changes: 3 additions & 0 deletions widgetbook/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# widgetbook

Widgetbook for NES UI
1 change: 1 addition & 0 deletions widgetbook/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include: package:very_good_analysis/analysis_options.5.1.0.yaml
6 changes: 6 additions & 0 deletions widgetbook/lib/main.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import 'package:flutter/material.dart';
import 'package:widgetbook_app/widgetbook/widgetbook.dart';

void main() {
runApp(const WidgetbookApp());
}
62 changes: 62 additions & 0 deletions widgetbook/lib/widgetbook/use_cases/buttons.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// ignore_for_file: public_member_api_docs

import 'package:flutter/material.dart';
import 'package:nes_ui/nes_ui.dart';
import 'package:widgetbook_annotation/widgetbook_annotation.dart' as widgetbook;

Widget build({
required NesButtonType type,
required String text,
}) =>
Center(
child: NesButton(
onPressed: () {},
type: type,
child: Text(text),
),
);

@widgetbook.UseCase(
name: 'normal',
type: NesButton,
)
Widget normal(BuildContext context) => build(
type: NesButtonType.normal,
text: 'Normal',
);

@widgetbook.UseCase(
name: 'primary',
type: NesButton,
)
Widget primary(BuildContext context) => build(
type: NesButtonType.primary,
text: 'Primary',
);

@widgetbook.UseCase(
name: 'success',
type: NesButton,
)
Widget success(BuildContext context) => build(
type: NesButtonType.success,
text: 'Success',
);

@widgetbook.UseCase(
name: 'warning',
type: NesButton,
)
Widget warning(BuildContext context) => build(
type: NesButtonType.warning,
text: 'Warning',
);

@widgetbook.UseCase(
name: 'error',
type: NesButton,
)
Widget error(BuildContext context) => build(
type: NesButtonType.error,
text: 'Error',
);
29 changes: 29 additions & 0 deletions widgetbook/lib/widgetbook/use_cases/checkboxes.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// ignore_for_file: public_member_api_docs

import 'package:flutter/material.dart';
import 'package:nes_ui/nes_ui.dart';
import 'package:widgetbook_annotation/widgetbook_annotation.dart' as widgetbook;

Widget build() {
var selected = false;
return Center(
child: StatefulBuilder(
builder: (context, setState) {
return NesCheckBox(
onChange: (value) {
setState(() {
selected = value;
});
},
value: selected,
);
},
),
);
}

@widgetbook.UseCase(
name: 'default',
type: NesCheckBox,
)
Widget checkbox(BuildContext context) => build();
49 changes: 49 additions & 0 deletions widgetbook/lib/widgetbook/widgetbook.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// ignore_for_file: public_member_api_docs

import 'package:flutter/material.dart';
import 'package:nes_ui/nes_ui.dart';
import 'package:widgetbook/widgetbook.dart';
import 'package:widgetbook_annotation/widgetbook_annotation.dart' as widgetbook;
import 'package:widgetbook_app/widgetbook/widgetbook.directories.g.dart';
import 'package:widgetbook_app/widgetbook/widgets/widgets.dart';

@widgetbook.App()
class WidgetbookApp extends StatelessWidget {
const WidgetbookApp({super.key});

@override
Widget build(BuildContext context) {
return Widgetbook.material(
directories: directories,
integrations: [
WidgetbookCloudIntegration(),
],
addons: [
BuilderAddon(
name: 'Decorator',
builder: (context, child) {
return UseCaseDecorator(child: child);
},
),
ThemeAddon(
themes: [
WidgetbookTheme(
name: 'Light',
data: flutterNesTheme(),
),
WidgetbookTheme(
name: 'Dark',
data: flutterNesTheme(brightness: Brightness.dark),
),
],
themeBuilder: (context, theme, child) {
return Theme(
data: theme,
child: child,
);
},
),
],
);
}
}
54 changes: 54 additions & 0 deletions widgetbook/lib/widgetbook/widgetbook.directories.g.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// coverage:ignore-file
// ignore_for_file: type=lint
// ignore_for_file: unused_import, prefer_relative_imports, directives_ordering

// GENERATED CODE - DO NOT MODIFY BY HAND

// **************************************************************************
// AppGenerator
// **************************************************************************

// ignore_for_file: no_leading_underscores_for_library_prefixes
import 'package:widgetbook/widgetbook.dart' as _i1;
import 'package:widgetbook_app/widgetbook/use_cases/buttons.dart' as _i2;
import 'package:widgetbook_app/widgetbook/use_cases/checkboxes.dart' as _i3;

final directories = <_i1.WidgetbookNode>[
_i1.WidgetbookFolder(
name: 'widgets',
children: [
_i1.WidgetbookComponent(
name: 'NesButton',
useCases: [
_i1.WidgetbookUseCase(
name: 'error',
builder: _i2.error,
),
_i1.WidgetbookUseCase(
name: 'normal',
builder: _i2.normal,
),
_i1.WidgetbookUseCase(
name: 'primary',
builder: _i2.primary,
),
_i1.WidgetbookUseCase(
name: 'success',
builder: _i2.success,
),
_i1.WidgetbookUseCase(
name: 'warning',
builder: _i2.warning,
),
],
),
_i1.WidgetbookLeafComponent(
name: 'NesCheckBox',
useCase: _i1.WidgetbookUseCase(
name: 'default',
builder: _i3.checkbox,
),
),
],
)
];
24 changes: 24 additions & 0 deletions widgetbook/lib/widgetbook/widgets/use_case_decorator.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// ignore_for_file: public_member_api_docs

import 'package:flutter/material.dart';

class UseCaseDecorator extends StatelessWidget {
const UseCaseDecorator({
required this.child,
super.key,
});

final Widget child;

@override
Widget build(BuildContext context) {
return DecoratedBox(
decoration: BoxDecoration(
color: Colors.grey[600],
),
child: SizedBox.expand(
child: child,
),
);
}
}
1 change: 1 addition & 0 deletions widgetbook/lib/widgetbook/widgets/widgets.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export 'use_case_decorator.dart';
28 changes: 28 additions & 0 deletions widgetbook/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: widgetbook_app
description: "Widgetbook for NES UI"

publish_to: 'none' # Remove this line if you wish to publish to pub.dev

version: 1.0.0+1

environment:
sdk: '>=3.2.3 <4.0.0'

dependencies:
cupertino_icons: ^1.0.2
flutter:
sdk: flutter
nes_ui:
path: ..
widgetbook: ^3.7.0
widgetbook_annotation: ^3.1.0

dev_dependencies:
build_runner: ^2.4.7
flutter_test:
sdk: flutter
very_good_analysis: ">=3.1.0 <6.0.0"
widgetbook_generator: ^3.7.0

flutter:
uses-material-design: true
12 changes: 12 additions & 0 deletions widgetbook/test/widgetbook_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// ignore_for_file: prefer_const_constructors

import 'package:flutter_test/flutter_test.dart';
import 'package:widgetbook_app/widgetbook/widgetbook.dart';

void main() {
testWidgets('renders', (WidgetTester tester) async {
await tester.pumpWidget(WidgetbookApp());

expect(find.byType(WidgetbookApp), findsOneWidget);
});
}
Binary file added widgetbook/web/favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added widgetbook/web/icons/Icon-192.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added widgetbook/web/icons/Icon-512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added widgetbook/web/icons/Icon-maskable-192.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added widgetbook/web/icons/Icon-maskable-512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 9324d9a

Please sign in to comment.