-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
[feat] Style directives #5923
[feat] Style directives #5923
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
keep up the work!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your PR, great job 👍🏻
I've left some comments on the PR and also i wonder what happens if the style:
directive clashes with the style
attribute?
eg:
<h1 style:font-size="30px" style="color: red; font-size: 40px;" style:color="blue" />
test/runtime/samples/inline-style-directive-multiple/_config.js
Outdated
Show resolved
Hide resolved
test/runtime/samples/inline-style-directive-and-style-attr/main.svelte
Outdated
Show resolved
Hide resolved
@tanhauhau @Rich-Harris Anything else this needs? |
Are there any blockers to this being merged? Would love to use this feature! :) |
29f7db2
to
c3b6140
Compare
i've rebased the branch to the latest master and
|
c3b6140
to
a0cb068
Compare
Also closes #5204 (we don't want to adjust the behavior, it's not worth documenting that small gotcha, and the OP in that issue presented exactly this style directive as a workaround) |
Thank you so much @tanhauhau! Some of those changes were definitely over my head 😅 |
Gentle nudge to @benmccann @tanhauhau — any thoughts on merging this? |
@tanhauhau / @Conduitry would have to sign off on this one. I'm not qualified 😄 |
Another gentle nudge on this 👀 Would love to start using this! |
The RFC mentions variables (I assume also vendor prefixes, because <div style:--border-color="saddleBrown" /> I couldn't find a test for that in this PR (I did ctrl+f for |
Good point, I'll add a test |
I'm a little late to the game on this, but I'd like to see camelCase variable names supported as well as pipe-case, i.e., I would think this shouldn't be too much trouble; since we're a compiler, we can optimize for either case. Why it matters: if we allow for shorthand, |
This gap exists for shorthand attributes like |
🥳🥳🥳 |
Style Directives
Related RFC
To-Do
Code
compile/nodes/Element.ts
, matchStyle
types and push styles in tostyles
array:Style
node, gettext
frominfo
:compile/nodes/Style.ts
tag.ts
:Style
node with string valueexpression
todirective
Style
toget_directive_type
Style
interface tocompile/nodes/interfaces.ts
Style
interface tocompiler/interfaces.ts
compile/render_dom/wrappers/Element/index.ts
, push updaters into hydrate chunksruntime/internal/ssr.ts
, create newadd_styles
functionadd_styles
with concatenated style expressionsspread
internal to handle stylesTests
style
attributeCleanup
.solo
tests