-
Notifications
You must be signed in to change notification settings - Fork 262
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
Update Compiler Fork #8
Comments
@thysultan what do you think about |
@rauchg So these will be the same |
yep so
Alternatively, we could make the |
cc @giuseppeg |
sure i can add that, |
@rauchg correct One thing to keep in mind is that styles applied from the outside should win over Nice to have then it would be to get <body>
<div>
<style jsx>{`
:host-context(body) {
color: red
}
`}</style>
</div>
</body> yields body div[data-jsx="abc"] { color: red } But probably it is better to tackle this later and maybe also consider the |
@rauchg @giuseppeg pushed a patch for all the host variations
|
@thysultan cool in order for |
@giuseppeg |
@thysultan oh I see, sorry I was thinking in terms of styled-jsx :) |
@rauchg instead of this <style jsx>{`
:host {
color: red
}
`}</style> can this work <style jsx>`
:host {
color: red
}
`</style> or better yet a plugin that treats everything in the <style jsx>
:host {
color: red
}
</style> |
The latter is invalid JSX unfortunately. It'll think of |
We picked the most optimal syntax considering how JSX works today I think :D |
@thysultan what happens here https://github.com/zeit/styled-jsx/blob/master/lib/style-transform.js#L197 if the selector is something like:
|
@thysultan do you think that it would be trivial to switch to your version of the compiler and write a middleware to add scoping the styled-jsx way (with data-jsx to each selector)? If so would you be interested in helping out? |
Sure, the middleware will look something like this function middleware (ctx, str, line, col, prefix) {
if (ctx === 1.5) {
// avoids name-spacing :global() functions
if (str.indexOf(prefix) === 0) {
return str.replace(prefix, '') + prefix;
}
}
} This will change The |
@giuseppeg On the repl site https://stylis.js.org/ You can try the following in the console. stylis.use(middleware (ctx, str, line, col, prefix) {
if (ctx === 1.5) {
if (str.indexOf(prefix+' ') === 0) {
var pos = (str = str.substring(prefix.length).replace('&', '').trim()).indexOf(' ');
return pos !== -1 ? str.substring(0, pos) + prefix + str.substring(pos) : str + prefix;
}
}
}); and input something into the editor and it should namespace the styled-jsx way. |
@thysultan the selector below should be i.e. the prefix should be added to every part of the selector (except for globals). Do you think that it is doable with the current version of stylis + middleware? |
@giuseppeg Yes doable, what should |
cool |
Then this should work as expected. function middleware (ctx, str, line, col, prefix) {
if (ctx === 1.5) {
// avoid :global()
if (str.indexOf(prefix+' ') === 0) {
// strips stylis added namespace
str = str.substring(prefix.length).trim();
// flag if single selector
var pos = str.indexOf(' ');
// multiple selectors, i.e h1 h2
if (pos !== -1) {
var parts = str.split(' ');
// add namespace to all parts
for (var i = 0; i < parts.length; i++) {
var part = parts[i];
pos = part.indexOf(':');
// if has pseudo selector
parts[i] = pos !== -1 ? part.substring(0, pos) + prefix + part.substring(pos) : part + prefix;
}
return parts.join(' ');
}
// single selector
else {
return str + prefix;
}
}
}
} |
@thysultan @rauchg I started to work on this tonight #125 keep in mind that it is very wip |
fixed by #134 |
There's a few things missing pre-v0.6.4 of the stylis compiler that your fork will not handle that could be nice to have.
full prefix support in
@root and @keyframes blocks
.support opting out of name-spacing keyframes and animations.
I've done away with the regex solution i was using, and added supports for
stylis("[data-id=namespace]")
namespaces.The text was updated successfully, but these errors were encountered: