fteschke

fteschke

Phoenix LiveView + HeadlessUI

I wrote a short description of how to use HeadlessUI components with LiveView:

Tailored to HeadlessUI, but in fact not HeadlesUI specific, but applicable to React components in general.

Approach:

  • React Component
  • Wrapped in Web Component that handles server->client (attribute changes) and client-server (events) communication
  • Rendered to light DOM (not shadow DOM, due to lacking HeadlessUI support)
  • micro LiveView Hook with glue code push LiveView events to server

Pros:

  • integrates well with minimal esbuild assets pipeline
  • web component is a good interface boundary for LiveView / “custom” Javascript
  • sprinkle minimal amounts of Javascript where necessary

Cons:

  • use with caution, prefer LiveView Phoenix.LiveView.JS bindings where sufficient

Do you use similar techniques? What are your experiences?
Are there better ways of implementing this approach?

First Post!

LostKobrakai

LostKobrakai

While I really like the idea and effort put into those components, I’ll never understand why I’d use them, when they cannot replace native inputs. It’s nice to have a fancy combobox (especially for multi select), but not if it means all my phx-change / phx-submit form bindings break, because the input doesn’t integrate with a form.

Most Liked

LostKobrakai

LostKobrakai

There had been an interesting talk at last years elixir conf: https://www.youtube.com/watch?v=xXWyOy9XdA8

I don’t think they’re just useful for input fields, but more anything interactive. They’re useful wherever you want to abstract some behaviour without enforcing how the UI around said behaviours looks like.

Last Post!

fteschke

fteschke

Nope.

Great talk, wasn’t aware of that. I would look at my post as a port of Chris’s ideas to react/JSX world, where he focuses more on lit.
I especially like his call for simplicity by avoiding JS rendering, shadow DOM etc. if not needed.

Where Next?

Popular in Discussions Top

AstonJ
If a newbie asked you about Phoenix Contexts, how would you explain the basics to them? Feel free to be as concise or in-depth as you li...
New
und0ck3d
Hello everyone! A few days ago I’ve created a topic here about how people were creating CMSs with Elixir and Phoenix. I’ve been studying...
New
Crowdhailer
I’ve been hearing much about the new formatter and it’s something I have been keen to try. I find examples buy far the most illuminating...
248 19760 150
New
joeerl
I’m playing with Elixir - It’s fun. I think @rvirding does give Elixir courses these days. Re: files and database - when I given Erlang ...
New
PragTob
Hey everyone, this has been brewing in my head some time and it came up again while reading Adopting Elixir. GenServers, supervisors et...
New
klo
Got a question about when to concat vs. prepending items to list then reversing to achieve appending. So i know lists boil down to [1 | ...
New
paulanthonywilson
I like Umbrella projects and pretty much always use them for personal Elixir stuff, especially Nerves things. But I don’t think this is ...
New

Other popular topics Top

vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 49134 226
New
saif
Hello everyone, Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New

We're in Beta

About us Mission Statement