npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

elm-ui-book

v2.1.0

Published

UI documentation tool for Elm applications

Downloads

6

Readme

UI Book

A book that tells the story of the UI elements of your Elm application.

  • Plain Elm (no custom setup)
  • Customizable theme colors and header
  • Organize your UI elements into chapters and sections
  • Showcase stateful widgets, not only static elements
  • Log your actions
  • Built-in integration with elm-ui, elm-css and others
  • Built-in development server (Optional)

A live example can be found here: https://elm-ui-book.netlify.app/

Start with a chapter.

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 x
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, if it's useful to have a catalog of possible colors or typographic styles in your documentation, why not dedicate a chapter to it?

Then, create your book.

Your UIBook is a collection of chapters.

book : UIBook ()
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.

Customize the book's style.

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 [ ... ]

Built-in integration with elm-css, elm-ui and others.

If you're using one of these two common ways of styling your Elm app, just import the proper definitions and you're good to go.

import UIBook.ElmCSS exposing (UIBook, book)
import UIBook exposing (withChapters)

main : UIBook ()
main =
    book "MyElmCSSApp" ()
        |> withChapters []

If you're using other packages that also work with a custom html, don't worry , defining a custom setup is pretty simple as well. Check the docs!

Log your actions

Log your action intents to showcase how your components would react to interactions.

-- Will log "Clicked!" after pressing the button
button [ onClick <| logAction "Clicked!" ] []

-- Will log "Input: x" after pressing the "x" key
input [ onInput <| logActionWithString "Input: " ] []

Showcase stateful widgets

Sometimes it's useful to display a complex component so people can understand how it works on an isolated environment, not only see their possible static states. But how to accomplish this with Elm's static typing? Simply provide your own custom "state" that can be used and updated by your own elements.

type alias MyState =
    { input : String, counter : Int }


initialState : MyState
initialState =
    { input = "", counter = 0 }


main : UIBook MyState
main =
    book "MyStatefulApp" initialState
        |> withChapters
            [ inputChapter
            , counterChapter
            ]


counterChapter : UIChapter { x | counter : Int }
counterChapter =
    let
        updateCounter state =
            { state | counter = state.counter + 1 }
    in
    chapter "Counter"
        |> withStatefulSection
            (\state ->
                button
                    [ onClick (updateState updateCounter) ]
                    [ text <| String.fromInt state.counter ]
            )


inputChapter : UIChapter { x | input : String }
inputChapter =
    let
        updateInput value state =
            { state | input = value }
    in
    chapter "Input"
        |> withStatefulSection
            (\state ->
                input
                    [ value state.input
                    , onInput (updateState1 updateInput)
                    ]
                    []
            )

Built-in Development Server

If you want to use our zero-config dev server, just install elm-ui-book as an npm devDependency then run npx elm-ui-book {MyBookModule}.elm and you should see your brand new Book running on your browser.

🤫 I'll let you in on a secret… this is just an instance of elm-live with a few predefined arguments passed in! So any additional arguments you pass to this command will work exactly like it would with elm-live, so npx elm-ui-book {MyBookModule}.elm --port=3000 --dir=./static would start your development server on port 3000 with static files from the ./static folder.

What's next?

So far this project has been following a lot of the same standards as storybook – however, why should we limit ourselves by it? I'm thinking about exploring more book-like features that would make this project more useful for design systems and documentations and not only a library of UI components. Let's see! :)

If you have any ideas or problems, please reach me on Elm's slack as georgesboris.