brainlid

brainlid

Elixir Blog Post: Plucking the "A" from PETAL

This post asks if we can remove Alpine from the PETAL stack. Can we do everything we need with just LiveView? Also, let’s explore an area where LiveView can still improve.

Most Liked

Sebb

Sebb

Arrr good stuff. Only a deleted line of JS-code is a good line of JS-code.

11
Post #2
mgibowski

mgibowski

Furthermore, once Phoenix v1.8 arrives and starts using TailwindCSS by default, I don’t think calling this stack anything more than just LiveView is very useful…

The acronym PETAL played it’s role before, when we had to compose our own stack on top of LiveView.

Now, as LiveView comes with all the necessary elements built-in (JS commands, TailwindCSS set up by default), I think the PETAL acronym can be retired and we don’t need any replacement for it.

trisolaran

trisolaran

Same here. I never understood the appeal of AlpineJS for a LiveView project. When I started using LiveView (long before LiveView.JS) I decided to use JS hooks to keep things simple, cause I didn’t want to add a JS framework. Later on, because everyone was talking about Alpine, I gave it a try out of curiosity. I tried to replace my hooks with AlpineJS. I really had a hard time trying to make it all work, and I came to the conclusion that LV hooks are more flexible and better suited than Alpine for a LiveView project, also because they can hook into LV life-cycle events directly. So I stripped the “A” from PETAL a long time ago. Even more so now that we have LiveView.JS. I suspect Alpine is something so many people were using mainly because so many people were using it.

f0rest8

f0rest8

This is great and I’ve been thinking about this a lot and recently refactored a lot of the Alpine in Metamorphic (including creating the glide photo effect with JS commands).

Though there’s still a few things that I’m not sure would be as easy to do with JS commands, like counting the number of characters in a form as you type. AFAIK that’s still easier/better experience with Alpine but it’s definitely getting closer!

tj0

tj0

I tried Alpine I think last year for a few weeks and ripped it out. Tabs can be done via CS and everything is pretty much instantaneous. No JS of any kind is required.

In production, I’m using nested css elements handled by radio buttons.
css

#radio-page-1 { display: none }
#radio-page-2 { display: none }
#radio-page-3 { display: none }
#radio-page-4 { display: none }
#radio-page-5 { display: none }
#radio-page-1:checked ~ &--wrapper >  #display_control > #page-button-1 {border: red 0.2px solid; color: red;}
#radio-page-1:checked ~ &--wrapper > #display_control > #page-button-1:hover {color: white;}
#radio-page-1:checked ~ &--wrapper > &--subgrid1 {display: grid;}
#radio-page-1:checked ~ &--wrapper > &--subgrid2 {display: none;}

html

<input type="radio" phx-update="ignore" name="radio-page-group" id="radio-page-1" checked value="1">
<input type="radio" phx-update="ignore" name="radio-page-group" id="radio-page-2" value="2">
<input type="radio" phx-update="ignore" name="radio-page-group" id="radio-page-3" value="3">
<input type="radio" phx-update="ignore" name="radio-page-group" id="radio-page-4" value="4">
<input type="radio" phx-update="ignore" name="radio-page-group" id="radio-page-5" value="5">
<div id="main--wrapper" class="main-wrapper">
  <div class="main-subgrid1"></div>
  <div class="main-subgrid2"></div>
</div>

Here is another example done using z-index instead:

Modals can also be done via css, but I think Phoenix.JS is a bit cleaner.
https://sheer.tj/phoenix_live_view_modals.html

Where Next?

Popular in Blog Posts Top

danschultzer
How to set up the Content Security Policy header with Phoenix LiveView and support inline styles and scripts with CSP nonces.
New
jordiee
https://medium.com/@jpiepkow/team-based-login-with-accesspass-be236d4bd7dd
New
pillaiindu
Our very handsome and humble José Valim (@josevalim) just published Kubernetes and the Erlang VM: orchestration on the large and the sma...
New
aymanosman
This is a very short article about using AWS Systems Manager Parameter Store to load secret configuration in a simple way.
New
brainlid
Livebook was created for machine learning in Elixir but Livebook isn’t limited to machine learning. I found it works really well for docu...
New
brainlid
There is a new community resource available on writing “Safe Ecto Migrations”. When we get a migration wrong, it can lock up your product...
New
brainlid
This post asks if we can remove Alpine from the PETAL stack. Can we do everything we need with just LiveView? Also, let’s explore an area...
New
bram209
Hello everyone, I just published my first blog post ever. I am learning Elixir, OTP &amp; Phoenix and wanted to start a blog for a while ...
New
lawik
Building on other people’s work I bashed things together and suddenly I can know when someone is speaking using Elixir and Membrane.
New
aymanosman
The desire to produce structured logs is common. In this article, I will survey the major approaches one could take to achieve this goal ...
New

Other popular topics Top

JDanielMartinez
Hi! May someone helps me, please! I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
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 45766 226
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
lk-geimfari
What is most correct way to open, read and parse JSON file with poison? For example if we have example.json file in root of some projec...
New
mgjohns61585
Could someone help me? I'm making my first elixir program, number guessing game. I can't figure out how to convert the user's guess from ...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
AstonJ
by Lance Halvorsen Elixir and Phoenix are generating tremendous excitement as an unbeatable platform for building modern web application...
460 27162 124
New

We're in Beta

About us Mission Statement