AHBruns

AHBruns

Rethinking phx-no-feedback

Rethinking phx-no-feedback

So, I won’t go into how phx-no-feedback works in detail, but the tl;dr is that it lets you conditionally add a class to an element when it is not showing feedback. In most cases, feedback means validation feedback, aka errors. What this means, is that you effective have to style the feedback version of your component, then you use phx-no-feedback to hide the feedback portions of your component. This works, but I think it can be improved.

I think we should be able to come at the problem from both sides. I propose a new phx-with-feedback class. This would conditionally add a class when feedback is being shown. The idea being that, where it makes sense, we could style the no-feedback state first, then conditionally add classes to that to get to the feedback state’s style. I should mention this is possible today! This tailwind css variant plugin adds support for what I’m describing:

plugin(({ addVariant, e }) =>
  addVariant("phx-with-feedback", [
    "[phx-feedback-for]:not(.phx-no-feedback)&",
    "[phx-feedback-for]:not(.phx-no-feedback) &",
  ])
)

allows

phx-with-feedback:border-rose-400

I’m simply asking for a slightly better DX around this by creating this variant out of the box. A corollary of this might be that we should deprecate phx-no-feedback in favor of a renamed version phx-without-feedback to keep things intuitive, or alternatively, the new variant could be called phx-feedback to stay inline with the existing phx-no-feedback.

Most Liked

LostKobrakai

LostKobrakai

While I would generally agree with the results you describe I’m not sure I can agree with the expectation.

Yes core_components are not perfect, but they’re also way more customizable than what we had before 1.7. Nowadays you can at least think about trying to use generators while customizing how the pieces look that the generators generate. That either required very heavy handed css or customizing whole generator templates before. Yes there’s an interface to maintain there, but I’m not sure how else you’d expect generators to call into some customizable functionality. I’d love for that interface to be better documented (statically and across releases) though.

What I find over the top though is the expectation for the generators to be able to build you a complete application. The generators are there to get initial scaffolding done, but not to lift you till v1 of your application. I’d be happy if we eventually get there and someone puts in the work to make that happen, but I find it unreasonable to expect that as the default experience.

I acknowledge that liveview poses a lot of new challenges, but LV is still pre 1.0 and completely optional. If you don’t want to be involved with solving those challenges you’re free to not use LV. If you find the generators to be lacking details there’s also real life example applications with livebeats and todo_trek, which you can look at.

LostKobrakai

LostKobrakai

I don’t think that’s that’s something the phoenix team should provide – or even could for the matter.

AHBruns

AHBruns

I should add I’m currently working on a component library called Brainz (not yet public), that seeks to fill the role of a core headless UI component library for Phoenix LiveView applications. My plan is to do as I’ve described here, and allow generating a CoreComponents module that uses Brainz components, but only for the use-case of supporting generators, not for generic UI development.

To this end, I might suggest that instead of implicitly importing CoreComponents everywhere, generators should explicitly import CoreComponents as needed (which will hopefully be called something like GeneratorComponents). This would help make it clear those components are not generic.

Where Next?

Popular in Proposals: Ideas Top

mythicalprogrammer
Hello, since the 1.8rc0 was out, DaisyUI was noted to have the benefit of light and dark mode. From the elixir subreddit, it seem a few ...
New
DaAnalyst
@chrismccord @josevalim @steffend Been using colocated JS for a while and I keep on stumbling on the same limitation: there is no way (a...
New
jakeprem
Goal: To make JS.patch and JS.navigate more interoperable with JS.push. Scenario: Imagine making a reusable Phoenix component and you wa...
New
manhvu
In a large repo, working with module need to add alias too much is quite annoyed and not good for organizing code. I think better add su...
New
cevado
IEx is a very powerfull shell and it would be awesome to have all this power integrated inside a code editor. Clojure enables something l...
New
pejrich
I propose adding compact_map/2 to the Enum module. What is it? Sometimes you want to map over a collection, but sometimes you want to ma...
New
spicychickensauce
I’ve previously explored what is possible today with hacks to implement view transitions in our apps: I have since created a fork to im...
New
i-n-g-m-a-r
When debug_errors: true javascript can be executed. <html> <body> <form id="xss" action="https://domain.com/NateMai...
New
c4710n
This is an idea for improving the workflow of iex -S mix phx.server The Problem and The Solution in use When running multiple Phoenix en...
New
sevensidedmarble
I have a very simple suggestion: the generated config/dev.exs file should read from PORT at compile time to set the endpoints port. If ...
New

Other popular topics Top

Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
AstonJ
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
boundedvariable
I am going through the kafka architecture. All the features what the kafka is providing are already in Erlang. I would like hear your opi...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
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
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New

We're in Beta

About us Mission Statement