msaraiva

msaraiva

Broadway Core Team

Hi folks!

I wonder if any of you have already tried to implement scoped CSS styles for live components. I’m specifically interested in how would be the best way to handle dynamic styles (styles that need to be updated when a related assign changes).

This feature seems to be quite popular among frontend devs using React and friends. It’s also one of the most requested features for Surface.

I was reluctant to implement something like that on top of LV but after talking to a few people I was convinced that this might be a good fit for live components.

An initial proposal has been submitted along with a PoC project, so if you’re interested in the subject, feel free to give it a try and share your thoughts.

Some questions I still have:

  1. How beneficial is using this approach comparing with other solutions?
  2. What are the downsides and limitations?
  3. Should/could this be implemented as a separate lib so any project using LiveView could benefit from?

In case you’re curious, here’s how it looks like:

Full source code can be found here.

Cheers.

Showing Posts 1 to 9

mhanberg

mhanberg

Expert LSP Core Team

Not related to the actual topic, but I wishing Elixir had named heredocs, so syntax highlighting that like that would be easier :grinning_face_with_smiling_eyes:

hauleth

hauleth

That is why we have sigil for. (Un)fortunately for now these are limited to single characters, but I remember proposal to allow multi-character sigils.

mhanberg

mhanberg

Expert LSP Core Team

Yeah, but for what I’m referring to, the name has no effect on the string. It’s just a name for the string, that your editor can use to do some highlighting.

Sigils are macros that need to be implemented, and imported, which is unnecessary.

gdub01

gdub01

My only feedback is that this looks awesome =)

Separating the static and dynamic parts is phenomenal in terms of optimization.

Having styles locally scoped is also amazing.

Having the option to apply a function to it is also great. I’m thinking of a theme option where you can pass ‘primary’ as a dynamic color and lookup a user’s setting to get what their primary color actually is potentially.

The only question I have is regarding the var(--my-color). If I define a global root var like ‘primary-color’ outside of surface/scoped styles, and don’t pass a style var, I’m still able to use it like border: solid 3px var(--primary-color) and it’ll pick up the globally set css variable of:

:root {
  --primary-color: coral; 
}

?

msaraiva

msaraiva OP

Broadway Core Team

Yup. If the variable is not listed in vars, it will take the global value.

coen.bakker

coen.bakker

Any updates regarding your thoughts about bringing or not bringing scoped styles to the core of Surface? It has been some time since the Github proposal was closed. And full disclosure: I was pretty thrilled initially to see this proposal. :nerd_face:

Edit: Just realized there is a ‘css-parser’ branch in Surface’s GitHub repository. See plenty of recent commits. Thank you for all the great initiatives/work and looking forward to the new features.

dmitriid

dmitriid

Yes, please. Automatically scoped CSS is one of the best features of Svelte, for example, and saves you from many headaches.

msaraiva

msaraiva OP

Broadway Core Team
trisolaran

trisolaran

Resurrecting this topic :slight_smile:

Is there a plan to bring scoped CSS styles to LiveView components (without Surface)?

Are there any good workarounds?

Cheers!

10
Post #9
— All posts loaded —

Where Next? Top

Trending in Questions Top

Blokh
Hey guys, I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly Do you guys have any suggestions what is the best prac...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
Onor.io
I have what I’ve heard referred to as a “lookup table” in my database. This is a way of assigning codes to common values. One common lo...
New
Trolleger
What approach to take when sending live updates to “random” users Hi! I have a question, I have a little chat app, and when I create a DM...
New
matt-savvy
Anyone here using Honeybadger? My Honeybadger account is being overwhelmed with noise from some bots. Seeing a lot of Bandit.HTTPError...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
wintermeyer
There are three potential reasons for members of this forum to have a look at https://vutuv.de You are tired or annoyed of LinkedIn. Yo...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews