A book that tells the story of the UI elements of your Elm application.
You can create one chapter for each one of your UI elements and split it in sections to showcase all of their possible variants.
buttonsChapter : UIChapter (Html UIBookMsg)
buttonsChapter =
chapter "Buttons"
|> withSections
[ ( "Default", button [] [] )
, ( "Disabled", button [ disabled True ] [] )
]Don't be limited by this pattern though. A chapter and its sections may be used however you want. For instance, it's useful to have a catalog of possible colors or branding guidelines in your documentation. Why not dedicate a chapter to it?
Your UIBook is a collection of chapters.
book : Book
book =
book "MyApp"
|> withChapters
[ colorsChapter
, buttonsChapter
, inputsChapter
, chartsChapter
]This returns a standard Browser.application. You can choose to use it just as you would any Elm application – however, this package can also be added as a NPM dependency to be used as zero-config dev server to get things started.
If you want to use our zero-config dev server, just install elm-ui-book as a devDependency then run npx elm-ui-book {MyBookModule}.elm and you should see your brand new Book running on your browser.
You can configure your book with a few extra settings to make it more personalized. Want to change the theme color so it's more fitting to your brand? Sure. Want to use your app's logo as the header? Go crazy.
book "MyApp"
|> withColor "#007"
|> withSubtitle "Design System"
|> withChapters [ ... ]If you're building your UI elements with something other than elm/html, no worries. Just specify a renderer function that will transform your custom elements to what Elm's runtime is expecting and everything is going to be just fine. For instance, if you're using elm-ui, you would do something like this:
import Element exposing (layout)
book "MyApp"
|> withRenderer (layout [])
|> withChapters [ ... ]For now, you can't really create interactive elements inside your UIBook. However, you can showcase their different states and log actions that represent the intent to move between states. Something like this:
-- Will log "Clicked!" after pressing the button
button [ onClick <| logAction "Clicked!" ] []
-- Will log "Input: x" after pressing the "x" key
input [ onInput <| logActionWithString "Input: " ] []This package is still being actively developed. This is what is in the roadmap for now: