sveltejs / svelte

web development for the rest of us
https://svelte.dev
MIT License
79.75k stars 4.23k forks source link

Add native support for classMap and styleMap #10045

Closed MohamedElmdary closed 10 months ago

MohamedElmdary commented 10 months ago

Describe the problem

Idea

Currently, svelte is evolving and getting way better, simpler, powerful, and solid. but sadly most svelte-ui frameworks implement its own version of styleMap & classMap.

Also we should provide a default style and class attribute in custom element (can be used optionally) which gonna make developing framework much easier

What is classMap & styleMap?

<!-- Current -->
<div  class={`c1 ${someVariable ? 'c2' : '' }`} ></div>

<!-- Map -->
<div class={['c1', { 'c2': someVariable } ]} ></div>

Describe the proposed solution

I would love to see this feature stable in svelte5 as svelte5 is really very promising with runes and snippets. I will try to implement it on my own wish I can do it and will open PR

Alternatives considered

alternative, Svelte might introduce a public method/ compiler macro / runes or whatever it's name which user can use and transform it in compile time into regular template syntax if it's any better

Importance

would make my life easier

brunnerh commented 10 months ago

Duplicate of:

MohamedElmdary commented 10 months ago

@brunnerh Thanks for mentioning that issue ... sadly I was having some real fun implementing it but it's ok hope to see multi class directive support in svelte 5