Storybooks for Gleam
  • Gleam 78.2%
  • Erlang 17.9%
  • Nix 3.5%
  • JavaScript 0.4%
Find a file
Dominik Süß f9d318106d
All checks were successful
test / test (push) Successful in 1m17s
docs: mention blogpost in docs
2025-12-23 13:27:20 +01:00
.forgejo/workflows fix release workflow 2025-12-22 17:39:06 +01:00
birdie_snapshots move package.json to top level 2025-12-21 11:11:18 +01:00
examples support loading of global styles 2025-12-22 17:30:26 +01:00
src support loading of global styles 2025-12-22 17:30:26 +01:00
test simplified & documented api 2025-12-22 16:20:48 +01:00
.envrc.example init 2025-12-17 06:55:55 +01:00
.gitignore init 2025-12-17 06:55:55 +01:00
flake.lock init 2025-12-17 06:55:55 +01:00
flake.nix use nix for test env 2025-12-17 07:42:40 +01:00
gleam.toml support loading of global styles 2025-12-22 17:30:26 +01:00
LICENSE licensing and release prep 2025-12-22 17:09:07 +01:00
manifest.toml nicer command line output 2025-12-22 16:20:48 +01:00
README.md docs: mention blogpost in docs 2025-12-23 13:27:20 +01:00

storygleam

Package Version Hex Docs

storygleam is an interface for using storybook in your gleam projects.

Instead of integrating through @external functions, it uses code generation and @storybook/vite-html to leave the bundling up to storybook.

If you want a full tutorial, you can read my blog post announcing storygleam.

Prerequisites

To use storygleam, your project must support the javascript target. If you are developing a full stack application, this can still be done by splitting your frontend into a separate package. For now, JS package management is depending on pnpm but this should become configurable in the future.

Installation

First, add storygleam as a dev dependency to your project

gleam add --dev storygleam@1

Then, modify the test entrypoint in the test directory to bootstrap the story files and build stories:

import storygleam

pub fn main() {
  storygleam.run(
    [
      storygleam.StoryCollection(
        meta: storygleam.Meta(
          "Example/Header",
          args: [storygleam.StringArg("name", "Dominik")],
          render_fn: "example_component",
          id: "example_header",
        ),
        stories: [storygleam.Story("NoArgs", [])],
        module_path: "example/example",
      ),
    ],
    storygleam.default_preview(),
  )
}

Usage

To start storybook, you need to run the following commands:

gleam test init # only needed once
pnpm install # whenever you update dependencies in package.json
pnpm dev # to watch for code & story changes

Further documentation can be found at https://hexdocs.pm/storygleam.

Development

gleam test  # Run the tests

When developing, you can use the example project to test your changes