Skip to content

Commit

Permalink
Adding spacing widgetbook
Browse files Browse the repository at this point in the history
  • Loading branch information
thelukewalton committed Feb 14, 2024
1 parent 2643fbe commit 91addfb
Show file tree
Hide file tree
Showing 5 changed files with 149 additions and 8 deletions.
1 change: 1 addition & 0 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ dependencies:
sdk: flutter
go_router: ^11.1.2
google_fonts: ^6.1.0
path_drawing: ^1.0.1
shared_preferences: ^2.2.2
zeta_flutter:
path: ../
Expand Down
2 changes: 1 addition & 1 deletion example/widgetbook/pages/theme/color_widgetbook.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ WidgetbookComponent colorWidgetBook() {
name: 'Colors',
useCases: [
WidgetbookUseCase(
name: 'Light Mode',
name: 'Colors',
builder: (BuildContext context) {
return ZetaProvider(
initialThemeMode: ThemeMode.light,
Expand Down
138 changes: 138 additions & 0 deletions example/widgetbook/pages/theme/spacing_widgetbook.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
import 'package:flutter/material.dart';
import 'package:path_drawing/path_drawing.dart';
import 'package:widgetbook/widgetbook.dart';

import 'package:zeta_flutter/zeta_flutter.dart';

WidgetbookComponent spacingWidgetBook() {
return WidgetbookComponent(
name: 'Spacing',
useCases: [
WidgetbookUseCase(
name: 'Named spaces',
builder: (context) => SingleChildScrollView(
child: Row(
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: namedSpacings.entries.map((obj) => _SizeObject(obj)).toList(),
)
],
),
),
),
WidgetbookUseCase(
name: 'Value spaces',
builder: (context) => SingleChildScrollView(
child: Row(
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: valueSpacings.entries.map((obj) => _SizeObject(obj)).toList(),
)
],
),
),
),
],
);
}

Map<String, double> namedSpacings = {
'xxs': ZetaSpacing.xxs,
'xs': ZetaSpacing.xs,
's': ZetaSpacing.s,
'b': ZetaSpacing.b,
'm': ZetaSpacing.m,
'l': ZetaSpacing.l,
'xl': ZetaSpacing.xl,
'xxl': ZetaSpacing.xxl,
'xxxl': ZetaSpacing.xxxl,
};
Map<String, double> valueSpacings = {
'x1': ZetaSpacing.x1,
'x2': ZetaSpacing.x2,
'x3': ZetaSpacing.x3,
'x3.5': ZetaSpacing.x3_5,
'x4': ZetaSpacing.x4,
'x5': ZetaSpacing.x5,
'x6': ZetaSpacing.x6,
'x7': ZetaSpacing.x7,
'x8': ZetaSpacing.x8,
'x9': ZetaSpacing.x9,
'x10': ZetaSpacing.x10,
'x11': ZetaSpacing.x11,
'x12': ZetaSpacing.x12,
'x13': ZetaSpacing.x13,
'x14': ZetaSpacing.x14,
'x16': ZetaSpacing.x16,
'x20': ZetaSpacing.x20,
'x24': ZetaSpacing.x24,
};

class _SizeObject extends StatelessWidget {
final MapEntry<String, double> size;

const _SizeObject(this.size);

@override
Widget build(BuildContext context) {
final colors = Zeta.of(context).colors;
return Container(
color: colors.blue.shade30,
margin: EdgeInsets.all(ZetaSpacing.m),
child: CustomPaint(
painter: _TagPainter(color: colors.pink),
child: LayoutBuilder(builder: (context, c2) {
return Container(
margin: EdgeInsets.all(size.value),
padding: EdgeInsets.all(ZetaSpacing.s),
color: colors.surfacePrimary,
child: Text(
'ZetaSpacing.' + size.key,
style: ZetaTextStyles.titleMedium.apply(
color: Zeta.of(context).colors.textDefault,
fontStyle: FontStyle.normal,
decoration: TextDecoration.none,
),
),
);
}),
),
);
}
}

class _TagPainter extends CustomPainter {
const _TagPainter({
required this.color,
});

final Color color;

@override
void paint(Canvas canvas, Size size) {
final Paint paint = Paint()
..color = color
..style = PaintingStyle.stroke;

final horizontal = Path()
..moveTo(0, (size.height / 2))
..lineTo(size.width, (size.height / 2))
..close();

final vertical = Path()
..moveTo(size.width / 2, 0)
..lineTo(size.width / 2, size.height)
..close();

canvas.drawPath(dashPath(horizontal, dashArray: CircularIntervalList([2, 3])), paint);
canvas.drawPath(
dashPath(vertical, dashArray: CircularIntervalList([2, 3]), dashOffset: DashOffset.absolute(size.height)),
paint,
);
}

@override
bool shouldRepaint(covariant CustomPainter oldDelegate) => false;
}
10 changes: 5 additions & 5 deletions example/widgetbook/pages/theme/typography_widgetbook.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'package:widgetbook/widgetbook.dart';
import 'package:zeta_flutter/zeta_flutter.dart';

WidgetbookComponent textWidgetBook() {
final dedicatedSizes = {
final Map<String, TextStyle> allTypes = {
'Display large': ZetaTextStyles.displayLarge,
'Display medium': ZetaTextStyles.displayMedium,
'Display small': ZetaTextStyles.displaySmall,
Expand Down Expand Up @@ -33,8 +33,8 @@ WidgetbookComponent textWidgetBook() {
style: context.knobs
.list(
label: 'Sizes',
labelBuilder: (p0) => dedicatedSizes.entries.firstWhere((element) => element.value == p0).key,
options: dedicatedSizes.values.toList(),
labelBuilder: (p0) => allTypes.entries.firstWhere((element) => element.value == p0).key,
options: allTypes.values.toList(),
)
.apply(
color: Zeta.of(context).colors.textDefault,
Expand All @@ -51,11 +51,11 @@ WidgetbookComponent textWidgetBook() {
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: dedicatedSizes.keys.map(
children: allTypes.keys.map(
(e) {
return Text(
e,
style: dedicatedSizes[e]?.apply(
style: allTypes[e]?.apply(
color: Zeta.of(context).colors.textDefault,
fontStyle: FontStyle.normal,
decoration: TextDecoration.none,
Expand Down
6 changes: 4 additions & 2 deletions example/widgetbook/widgetbook.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import 'pages/theme/color_widgetbook.dart';
import 'pages/components/banner_widgetbook.dart';
import 'pages/components/chip_widgetbook.dart';
import 'pages/components/password_input_widgetbook.dart';
import 'pages/theme/spacing_widgetbook.dart';
import 'pages/theme/typography_widgetbook.dart';
import 'utils/zebra.dart';

Expand Down Expand Up @@ -42,11 +43,12 @@ class HotReload extends StatelessWidget {
WidgetbookCategory(
name: 'Theme',
isInitiallyExpanded: false,
children: [textWidgetBook(), colorWidgetBook()]..sort((a, b) => a.name.compareTo(b.name)),
children: [textWidgetBook(), colorWidgetBook(), spacingWidgetBook()]
..sort((a, b) => a.name.compareTo(b.name)),
),
WidgetbookCategory(
name: 'Assets',
isInitiallyExpanded: true,
isInitiallyExpanded: false,
children: [iconWidgetbook()]..sort((a, b) => a.name.compareTo(b.name)),
),
],
Expand Down

0 comments on commit 91addfb

Please sign in to comment.