achempion

achempion

Hey, Elixir Forum. I’m excited to introduce LiveCapture, a storybook-like library for Phoenix LiveView components.

I like having stories for my components, but I’ve always felt some friction when creating and maintaining them. With LiveCapture, I tried to reduce the boilerplate as much as possible, up to the point where you don’t need to write stories at all to get a storybook.

Here’s an example of two simple LiveView components:

defmodule SimpleComponents do
  use MyAppWeb, :component
  
  capture_all()
  
  attr :name, required: true, default: "World"
  def greeting(assigns), do: ~H"Hello, {@name}!"

  attr :title, required: true, examples: ["H1 header"]
  def title(assigns), do: ~H"<h1>{@title}</h1>"
end

Just add capture_all() to capture all components in the module. You don’t need to do anything else, LiveCapture can infer component attributes automatically.

I’ve created an example module that shows typical capture patterns. LiveCapture also supports state variants, slots with HEEx templates, dynamic attribute resolution, and more.

Here’s a live example of a hosted storybook for all Phoenix LiveDashboard components.

The main use case for LiveCapture is local development, where you can quickly build and review complex UI states. For example, I was working on a component that renders a live transcription of an ongoing phone call. It helped a lot to be able to render different states without having to actually start a call.

Main features:

  • Render HEEx components with predefined state snapshots
  • Quickly test visual quality by switching between different width breakpoints
  • Explore component documentation with dynamic state inspection
  • Nice DSL with a strong focus on ergonomics and simplicity

If you like the project, please give it a star on GitHub.

P.S. I also built the Captures website, which hosts storybooks from other projects.

I’ll appreciate any feedback and your thoughts on the library.

https://github.com/achempion/live_capture

Showing Posts 1 to 10

netoum

netoum

Very interesting and an amazing alternative.
Is it possible to capture components from a dependency ?
Or the components must live in the same app where live capture is running
I am working a UI library and I would like to keep a separation between the main library and testing/playground?

achempion

achempion OP

Thank you! I built LiveCapture with the UI-library use case in mind.

You can mount the Storybook from any project that uses LiveCapture inside a playground app. For example, here’s how I mounted the Phoenix LiveDashboard Storybook inside the Captures app, which hosts storybooks from other open-source projects and libraries.

If you’d like, you can add your library there as well, and it’ll be available on the Captures website.

P.S. There’s a common pattern libraries use to set up a development playground for local testing. It’s usually a bare-bones Phoenix app defined in dev.exs (note the .exs extension). See LiveCapture’s dev.exs and Phoenix LiveDashboard’s dev.exs for reference.

Let me know if you have any questions or run into any rough edges. I’m happy to fix them.

achempion

achempion OP

Presented LiveCapture at Copenhagen Elixir meetup

netoum

netoum

Thanks for the detailed reply.
So I tried couple of way, but I am bit lost :sweat_smile:
My goal is to keep the component files as it is without modifying them
Is it possible to capture the components, without adding capture_all() inside the component file.
Here is the library if it helps, I would like to add live capture as a dependency but only in e2e app without modifying the original components

https://github.com/corex-ui/corex

achempion

achempion OP

I’ve created a PR with integration example. Feel free to ping me in the linked PR.

netoum

netoum

Thanks a lot, you are a saver. It works like a charm.
I will keep you updated with some stories

achempion

achempion OP

I’ve released a new version which adds component schema generation with component urls. It’s now become possible to use this schema with Playwright for visual regression testing.

Usage

mix live_capture.gen.schema --module MyAppWeb.LiveCapture --url-prefix /storybook path/to/captures.json

Output Format

captures.json

[
  {
    "schema": "MyAppWeb.LiveCapture",
    "breakpoints": [
      {"name": "s", "width": "480px"},
      {"name": "m", "width": "768px"}
    ],
    "captures": [
      {"module": "MyAppWeb.Example", "function": "simple", "variant": null, "url": "/storybook/raw/components/Example/button"},
      {"module": "MyAppWeb.Example", "function": "with_capture_variants", "variant": "main", "url": "/storybook/raw/components/Example/button/main"},
      {"module": "MyAppWeb.Example", "function": "with_capture_variants", "variant": "secondary", "url": "/storybook/raw/components/Example/button/secondary"}
    ]
  }
]
netoum

netoum

@achempion I hope you are doing great

I have added some Captures on the Live Demo.
I could edit the root layout and it works good.
I have 2 questions you can maybe help with

1.Can we catch the Live View handle events to display them ?

2.Slots with :let
Currently when using slot with :let , I use an internal function but ideally it would render the way the user would write the slot

Instead of this:

trigger: [%{inner_block: &__MODULE__.custom_trigger/2}],

we would do:

trigger: [%{
inner_block: """<.icon name={item.data.meta.icon} />{item.data.trigger}""",
let: item
}],

on the component thant dont require :let it works good and render the full item as the user would create it

<Listbox.listbox
class="listbox"
collection={[...]}>
<:label>
Choose a country
</:label>
<:item_indicator>
<.icon name="hero-check" />
</:item_indicator>
</Listbox.listbox>
achempion

achempion OP

Thank you for the feedback, I’ll get back to you in a couple of days.

achempion

achempion OP

I’ve released a new version that supports binding local variables for slot templates.

It’s now possible to pass :let bindings inside slot templates.

Example

Table component

slot :column do
  attr :label, :string, required: true
end

attr :rows, :list, default: []

def table(assigns) do
  ~H"""
  <table>
    <tr>
      <th :for={col <- @column}>{col.label}</th>
    </tr>

    <tr :for={row <- @rows}>
      <td :for={col <- @column}>{render_slot(col, row)}</td>
    </tr>
  </table>
  """
end

Capture definition

capture attributes: %{
          rows: [1, 2, 3],
          column: [
            %{inner_block: "row {row_number}", label: "Row number", let: :row_number},
            %{inner_block: "column", label: "Column"},
          ]
        }

See how the local variable is referenced with inner_block: "row {row_number}"

Where Next? Top

Trending in Announcing Top

woylie
Flop is an Elixir library that applies filtering, ordering and pagination parameters to your Ecto queries. offset-based pagination with...
New
MRdotB
I needed to reuse React components from my Chrome extension in my Phoenix/LiveView backend. I noticed that for Svelte/Vue, there are live...
New
woylie
I released Doggo, a collection of unstyled Phoenix components. https://github.com/woylie/doggo Features Unstyled Phoenix components....
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
anuaralfetahe
Hello Published a new library - ProcessHub! ProcessHub is a library designed to manage process distribution within the Elixir cluster. ...
New
rodloboz
I’ve started working on a new library to run SQL queries and do basic business intelligence. Think “Blazer for Elixir.” Currently it fe...
New

Other Trending Topics Top

mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New
AstonJ
This showed up on my feed.. anyone heard of it? Just hype? Ox Alpha is a reasoning model designed for coding, sustained ag...
New
bartblast
Hey folks, I just published a post about Hologram’s funding and where the project goes next - the short version: Curiosum as Main Spons...
New
CodeSync
:microphone: ElixirConf 2026 - Call for Talks is open! We’re heading to Chicago :united_states: :round_pushpin: In person + virtual :d...
New
Null-logic-0
What IDE or editor are you using for Elixir development? Personally, I use Zed, and I really like it, but sometimes I wish there were a ...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews