Lesson 8 — Module review and Lookbook documentation
The living style guide
By the end of this module /lookbook shows the complete Phlex::UI
library with previews for every component. This is now the living
reference for the design system — when a new developer joins the project,
Lookbook is where they go to understand what components exist and how
they behave.
Adding documentation to previews
Lookbook supports Markdown documentation alongside previews.
There are two styles of documentaion:
- notes attached to a particular preview
- doc pages which appear in a separate section.
For completeness we’ll cover examples of them both here:
Attached notes
This is the simplest approach. Take the button_preview and add a note
above the preview as shown below:
|
|
Check in lookbook now, you should see a note attached to the default component (in the section at the bottom)
Documentation pages
A way to add comprehensive documentation to assist in using complex components. There’s a bit of setup involved:
Firstly, update the config/initializer/lookbook.rb page to add a path to our docs
|
|
Add a docs
directory alongside previews:
test/components/
previews/
button_preview.rb
docs/
button.md.erbThen create your document - here’s an example.
|
|
The lookbook-embed helper embeds live component previews inline in the
documentation. Documentation stays accurate because it renders the real
component, not a screenshot.
In most cases the additional documentation is not necessary since most components are pretty much self-explanatory.
Module summary
- Lookbook provides a proper component browser at
/lookbook— previews for everyPhlex::UIcomponent, resizable viewport, live updates - Preview files live in
test/components/previews/and extendLookbook::Preview EmptyStatehandles the empty collection case throughout the appBreadcrumbuses thevanish+itempattern to collect navigation items before renderingTablenow supports row actions via anactionsblock and empty state handling- Component unit tests use the simple
component_test_helper - View tests use the
view_test_helper - The
view_template/ privaterender_method pattern keeps views readable as complexity grows
Components built this module
Components::EmptyState— title, message, optional CTAComponents::Breadcrumb— navigation hierarchy viaitemslotsComponents::Table— expanded withactionsblock and empty state
Views built this module
Views::Boards::Index— board grid withEmptyStateViews::Boards::Show— column placeholder withBreadcrumb