Skip to main content

Documentation

Widgetbook serves as both an interactive development sandbox and published documentation at design.zebra.com. Just adding a use-case is not enough - ensure that the documentation is thorough and complete, and that all properties and events are documented.

What is auto-generated

@widgetbook.UseCase generates a Docs page from the component's dart doc and use case definition. Keep dart doc accurate and complete — it is the documentation:

SourceGenerated as
Class dart doc descriptionComponent description on the Docs page
Constructor parameter dart docsParameter descriptions in knobs panel
context.knobs.* callsInteractive controls
designLink in @UseCaseFigma design panel
Rebuild after changing parameters

Run dart run build_runner build -d from the widgetbook/ directory before opening a PR — otherwise the controls panel will be out of date.

Standard template

widgetbook/lib/src/components/foo.widgetbook.dart
import 'package:flutter/material.dart';
import 'package:widgetbook/widgetbook.dart';
import 'package:widgetbook_annotation/widgetbook_annotation.dart' as widgetbook;
import 'package:zeta_flutter/zeta_flutter.dart';

.UseCase(
name: 'ZetaFoo',
type: ZetaFoo,
path: 'components/Foo',
designLink: 'https://www.figma.com/design/JesXQFLaPJLc1BdBM4sisI/...',
)
Widget zetaFoo(BuildContext context) {
return ZetaFoo(
label: context.knobs.string(label: 'Label', initialValue: 'Foo'),
flavor: context.knobs.list(
label: 'Flavor',
options: ZetaWidgetStatus.values,
labelBuilder: (v) => v.name,
),
size: context.knobs.list(
label: 'Size',
options: ZetaWidgetSize.values,
labelBuilder: (v) => v.name,
),
rounded: context.knobs.boolean(label: 'Rounded', initialValue: true),
onTap: context.knobs.boolean(label: 'onTap enabled', initialValue: true)
? () {}
: null,
);
}

Count and naming

One use case by default

All variants are explored through the knobs panel. Add a named use case only when a variant cannot be expressed through knobs — for example, a use case requiring specific child widgets or a complex composed state.

Never create one use case per flavor or per size — that is what knobs are for.

Keep names short: WithLeadingIcon, Disabled, WithActions.