-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Description
Is your feature request related to a problem? Please describe.
Basically, the needed to repeat the code when you want to inject multiple classes using the same condition, or extract the condition logic.
<div
class='default-style'
class:px-10={size === 'large'}
class:py-5={size === 'large'}
>
// or
<script>
// ...
$: isLarge = size === 'large'
</script>
<div
class='default-style'
class:px-10={isLarge}
class:py-5={isLarge}
>
Describe the solution you'd like
I'm not sure if it's the best solution, but I was just thinking something like:
<div
class='default-style'
class:px-10,py-5={size === 'large'}
>
Describe alternatives you've considered
For now, I'm using this approach to bypass:
<div class={`
default-style
${size === 'large' ? 'px-10 py-5' : ''}
`}>
But it get big really quick, and if you mix different conditions, every time a single value changes, all the conditions need to be evaluated again.
How important is this feature to you?
Well, I was just thinking to improve the flexibility and the possibilities of the class: syntax.
Additional context
Maybe if we use something like a .split(',')
and .map()
on the toggle_class function, this feature can be added easily. Because, if I use class:x,y,z={true}
today, svelte will inject the string x,y,z
on the element, literally!
svelte/src/runtime/internal/dom.ts
Line 233 in 8e62bd0
export function toggle_class(element, name, toggle) { |
Tks guys! 😄