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.
Trending in Announcing
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #blog-post
- #phoenix_html
- #iex
- #graphql
- #ai
- #genstage
- #elixirconf-us
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex










Showing Posts 1 to 10- Show Best Posts
- Show All Posts (oldest first)
- Show All Posts (newest first)
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
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.exsextension). 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
Presented LiveCapture at Copenhagen Elixir meetup
netoum
Thanks for the detailed reply.
So I tried couple of way, but I am bit lost
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
I’ve created a PR with integration example. Feel free to ping me in the linked PR.
netoum
Thanks a lot, you are a saver. It works like a charm.
I will keep you updated with some stories
achempion
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
Output Format
captures.json
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:
we would do:
on the component thant dont require :let it works good and render the full item as the user would create it
achempion
Thank you for the feedback, I’ll get back to you in a couple of days.
achempion
I’ve released a new version that supports binding local variables for slot templates.
It’s now possible to pass
:letbindings inside slot templates.Example
Table component
Capture definition
See how the local variable is referenced with
inner_block: "row {row_number}"