-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement RFC 13 #5628
Comments
Honestly, looks bad. It will wrap my component markup with extra |
@zamanruhy The RFC addresses this, essentially it comes down to using
Edit: I see now that this is not at all what you were commenting on. The times you would run into this is when you would do |
@kevmodrome Yes, that's exactly what I meant. Regardless of any workaround, I don't like the idea of adding an extra node without my knowledge. The good thing is this is an optional feature and doesn't add any code to runtime ... |
Notice that this will make targeting a component that doesn't want to be targeted even easier: <style>
[style*=--starRating] > * {}
</style>
<StarRating --starRating /> Edit: The RFC mentions under drawbacks the idea of allowing a component to explicitly expose its "style properties" for validation and completions. that would help reduce marking an instance like this, and potentially you could then namespace the properties (although with namespace you would lose global theming - that can probably be handled differently anyhow in order to achieve validation and completions as well). |
This feature would definitely be useful but something feels odd/bad about this approach. |
I know the RFC already been merged, and I don't mean to drag this on. I do really like the idea of embracing CSS variables for this, but at the same time I share the concern about the use of Wouldn't treating Implementing the above would also make it possible to achieve behavior described in the RFC as part of a theming or design system library like this: <script>
let vars = {}
$: spread = Object.fromEntries(
Object.entries(vars).map([key, val] => ['--' + key, val])
)
</script>
<style>
theme-context { display: contents; }
</style>
<theme-context {...spread}>
<slot />
</theme-context> This has the advantage of making the use of an extra element a bit more explicit. Support for targeting components directly could be also achieved by exposing passed css vars as a special prop (eg Edit: Something like the |
I believe that keeping the status quo is better than implementing this RFC. But if it's inevitable, I prefer the first variant of the implementation described here. The previous variant looks good in comparison with the current one. At least it doesn't imply implicit creation of additional elements and a huge number of side effects. |
I too have some serious doubts about syntax of this RFC, write Moreover this extra wrapper div seems very bad, as others appointed, it breaks css selectors.
This would allow someone else to write something like this (without :global):
Of course the compiler should do some work to understand that Getting back to what stated in the RFC, another nice feature is to have props working in style tag, this would be great but i understand the difficulties on implement such a thing. |
I feel something like this would be better <script>
export let color = 'red';
</script>
<style>
div {color: var(color);}
span {color: var(--color)}
</style>
<div>
<span />
</div> OUTPUT <div class="svelte-nerdboi" style="--color: red;">
<span class="svelte-nerdboi" />
</div>
<style>
div {color: var(--color);}
span {color: var(--color);}
</style> |
I'm going to lock this conversation as it's unproductive. The RFC repo (where the reaction was strongly positive) is the place for discussion about what features to add; the decision has been made. I will quickly address some of the feedback here though:
This is untrue. Since this syntax applies to components, not elements, we're talking about selectors that cross a component boundary. The only way CSS selectors are affected is if you have one like this The whole point of this RFC is it gives us an idiomatic way to avoid the need for those sorts of selectors in the first place.
Elements can already be styled. There's much less value to adding syntactic sugar for element styling than for components, where
That's invalid CSS. We don't want to write our own bootleg CSS parser to handle non-standard syntax unless it's absolutely necessary, and it's not at all clear that there's an advantage here (on the contrary, making
Don't be silly. |
This is implemented in 3.38.0 whether you like it or not. I've created #6267 for documenting this feature. |
sveltejs/rfcs#13
The text was updated successfully, but these errors were encountered: