Uses new NavigationTree
in widgetbook
Current System:
(all within the widgetbook
package)
Organizer
- Takes
name
- Implements
path
- Has non-final
Organizer? parent
param.
- Subclasses:
WidgetbookUseCase
- Takes
Widget Function(BuildContext) builder
that returns the use case widget
ExpandableOrganizer
, subclasses:
WidgetbookCategory
- Takes
List<WidgetbookFolder> folders
& List<WidgetbookComponent> widgets
WidgetbookFolder
- Takes
List<WidgetbookFolder> folders
& List<WidgetbookComponent> widgets
WidgetbookComponent
- Takes
List<WidgetbookUseCase> useCases
only
Limitations:
- Only a
WidgetbookCategory
is accepted as the root tree element
- Having two nested lists (
folders
& widgets
)
- Old UI
New System
The main objectives are:
- Implement the new
NavigationTree
UI with search functionality
- Eliminate the limitation of only taking
WidgetbookCategory
as the root tree element
- Eliminate the need to provide 2 child lists (
folders
& widgets
) and handle sorting folders
(or any expandable organizer) at the top internally
- Internally, there should be 2 types of classes, one that can expand (has children), and one that is selectable and doesn't take children (leaf) such that, the developer, when manually creating the tree, should be able to start with any of the Multi child/Expandable node subclasses
- The structure that the developer creates when they create the tree should be internally mapped to the structure that the
NavigationTree
widget takes which is a List<NavigationTreeNodeData>
(from the widgetbook_core
package), this was done through subclasses in this PR.
Classes:
NavigationTreeNodeData
(widgetbook_core
package)
- Takes
name
- Implements
path
- Has non-final
NavigationTreeNodeData? parent
param.
- Extends
Equatable
- Note: although all tests currently pass, value equality might not work perfectly due to the mutable nature of this class caused by the
parent
param. If any improvement were to be applied later it might be useful to find a way to create the tree structure with immutable classes to make it more testable.
- Subclasses
LeafNavigationNodeData
- A node that doesn't take children
- Subclasses - (
widgetbook
package)
WidgetbookUseCase
(original class)
MultiChildNavigationNodeData
- A node that takes children
- Subclasses - (
widgetbook
package) (what the navigation tree can take a list of)
- NEW
WidgetbookPackage
takes List<MultiChildNavigationNodeData> children
WidgetbookFolder
takes List<MultiChildNavigationNodeData> children
WidgetbookCategory
takes List<MultiChildNavigationNodeData> children
WidgetbookComponent
takes List<WidgetbookUseCase> useCases
Example tree of List<NavigationTreeNodeData>
final tree = [
NavigationTreeNodeData(
name: 'Package',
type: NavigationNodeType.package,
children: [
NavigationTreeNodeData(
name: 'Category',
type: NavigationNodeType.category,
children: [
NavigationTreeNodeData(
name: 'Component',
type: NavigationNodeType.component,
children: [
NavigationTreeNodeData(
id: 'use_case_1_id',
name: 'Use Case 1',
type: NavigationNodeType.useCase,
),
NavigationTreeNodeData(
id: 'use_case_2_id',
name: 'Use Case 2',
type: NavigationNodeType.useCase,
),
],
),
],
),
],
),
NavigationTreeNodeData(
name: 'Component',
type: NavigationNodeType.component,
children: [
NavigationTreeNodeData(
id: 'use_case_3_id',
name: 'Use Case 3',
type: NavigationNodeType.useCase,
),
],
),
];
Corresponding List<MultiChildNavigationNodeData>
This is the tree provided by the developer to the Widgetbook
app
final tree = [
WidgetbookPackage(
name: 'Package',
children: [
WidgetbookCategory(
name: 'Category',
children: [
WidgetbookComponent(
name: 'Component',
useCases: [
WidgetbookUseCase(
name: 'Use Case 1',
builder: (context) {},
),
WidgetbookUseCase(
name: 'Use Case 2',
builder: (context) {},
),
],
),
],
),
],
),
WidgetbookComponent(
name: 'Component',
useCases: [
WidgetbookUseCase(
name: 'Use Case 3',
builder: (context) {},
),
],
),
];
For later PRs:
- Expand All/Collapse All on the
NavigationTreeItem
level.
- This will require some major change on the way expanding items is currently implemented.
- Extract search into
FilterService
to reuse in cloud