-
Notifications
You must be signed in to change notification settings - Fork 319
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
Does this code go against how lit-element should be used? #845
Comments
This could be improved further by adding the slot programmatically rather than having to define it in the template. I frankly haven't attempted that route yet, as I needed a way to theme my own components rather than providing a generic mixin to allow styling. Also, I would much rather use a function to add an entry to the |
Maybe look into what https://jelements.netlify.com/stylable-mixin is thinking about cc @jouni |
@lkraav I like this one better.
So ANY mixing element will be styleable like this:
You can even import external CSS:
Although you end up with FOUC (but there is no way around it for now, not till CSS modules exist) |
To your original point: no, I don’t think this is an anti-pattern. The current ways of styling web components are lacking. The new So, we need more powerful ways for designers to style web components. And for the time being that means injecting styles inside the shadow DOM. That said, perhaps we shouldn’t open the door to modifying all the internals of a component. The way we do it with Vaadin components is that we clearly define which elements the user is free to style, the styling API of the component. Basically only the The problem I see in your approach is that it requires the designer to write additional HTML for each instance of a component in order to have them styled. Using Regarding my own Basically, it allows you to write stylesheets in all the ways you can: Modifying @mercmobily’s examples: <style>
@media fancy-input-text {
#label {
color: blue;
}
}
</style>
<link rel="stylesheet" href="cust/custom-input.css" media="fancy-input-text"> Or alternatively: <style>
@import "cust/custom-input.css" fancy-input-text;
@media fancy-input-text {
#label {
color: blue;
}
}
</style> You can structure and import your stylesheets pretty much however you want. Traditional style sheets ( One might argue that this is abusing media queries, and they’d be right 😅 But it’s only meant as a temporary workaround. And for the time being it works quite nicely IMHO. |
@jouni I have to be honest, and I say this in the humblest way possible... I think I prefer my solution. The problem I have with it is exactly what you mentioned: you can't have the same style for everybody without causing FOUC. (using @import will cause FOUC). I also have to say that ::part and ::theme have basically zero support, and I think there is a chance they might not stick, even in 5 years. I just don't see designers really getting into them -- but I might be wrong. |
Sure, all good – I probably sounded a bit defensive in my response, apologies for that (I’ve been thinking about this problem on and off during the 2–3 years or so, so it’s sometimes hard for me to keep a clear vision). It’s good that we explore different alternative workarounds, as it seems we agree about the current state having problems regarding theming/styling 🤗 And true, I looked a bit closer, and there are nasty timing issues with external style sheets (either
|
I think |
Just to sum up and close out this discussion:
|
Thanks for the input Kevin. Just one thing:
But shadyCss shouldn't have anything to do with this -- right? I mean, what do you mean by "It's not currently supported by the ShadyCSS polyfill"? What will happen if an older browser using the ShadyCSS polyfill has a <style> added? My impression was that it should simply work, since the browser will pick it up -- am I missing something? |
@kevinpschaaf Just tagging you in case you missed my previous message. I am trying to look at existing issues about it. One question I have is: is there an API call I can use to "wake up" ShadyCSS to the new styles? Since my code is specifically for lit-element and web components, I can adjust my code to make the right call (if there is one) |
In short, not currently. ShadyCSS style scoping is designed to work at a class level on the styles in an element class’s template (via the The CSS Custom Property Shim does have to do a form of per-instance style targeting, but it is very slow as a result despite a lot of complexity to cache styles between instances, and we’ve held back from adding even more complexity to support instance-time |
Hi,
Ouch OK. So... wait, adding the style tag has _no_ effect? Doesn't the
browser even register it at all? I thought so, since it's clear CSS into
HTML! I mean, it might not support CSS properties etc., but doesn't it
support straight CSS?
Merc.
…On Thu, 23 Jan 2020 at 11:18, Kevin Schaaf ***@***.***> wrote:
In short, not currently. ShadyCSS style scoping is designed to work at a
*class* level on the styles in an element class’s template (via the
prepareTemplate API), which scopes the styles based on the element name.
It does not support instance-level style scoping, which would require
scoped styles that target individual instances.
The CSS Custom Property Shim does have to do a form of per-instance style
targeting, but it is very slow as a result despite a lot of complexity to
cache styles between instances, and we’ve held back from adding even more
complexity to support instance-time <style> support given the performance
footguns.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#845>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAQHWXRKACYUR4YOAAHKBW3Q7EEA5ANCNFSM4JII7KZA>
.
|
@kevinpschaaf O forgot to tag you again. Please accept my apologies for pestering; I would like to release a project and am trying to make a decision about this one... |
It all comes down to the dreaded IE11 support... |
In short, yes, but not the effect you want. Remember that ShadyCSS is polyfilling the new CSS syntax and semantics for shadow DOM that does not exist in IE11. Consider shadow styles like this for <style>
:host([disabled]) { opacity: 0.5; }
div { color: red; }
</style> If you just appended this into the DOM, IE11 has no idea what As such, when we call <style>
my-element[disabled] { opacity: 0.5; }
div.my-element { color: red; }
</style> However, those styles apply to all <style>
my-element[disabled].instance-42 { opacity: 0.5; }
div.my-element.instance-42 { color: red; }
</style> Now rather than generating new
|
@kevinpschaaf First of all, I wanted to say THANK YOU for responding and supporting us. It all makes sense now. It's all obvious -- now that I read it. Really, heart-felt thank you. I can see :host has 86% coverage (https://caniuse.com/#search=%3Ahost). Shadow DOM v1, on the other hand, has 89.89% coverage (https://caniuse.com/#feat=shadowdomv1). I could provide this ... Or wait, I am wrong, scoped <style> tags are not a thing anymore, so regardless of where they are, <style> will affect the WHOLE document, right? EDIT: Ah, I now totally get your sentence "(remember, in a browser without shadow DOM, to the styling engine every <style> tag in the document applies to the whole page)." I guess I could work harder and work out a way to assign a unique class to each element, and allow developers to store the specific ones. |
Hi,
I am creating an issue because I feel that if this is a good idea, it should catch the maintainers' attention; and if it's a bad idea, it should be "officially bad".
I want to create some elements (who doesn't?) but at the same time I want to give designers a chance to really theme them (again, who doesn't?). I realise there are custom properties etc., but I don't think they go quite far enough.
This is what I want the end result to be:
I achieved this by writing
StyleableMixin.js
:So,
FancyInputText.js
that uses the mixin is simply:Basically, StyleableMixin will copy over to the shadow DOM any style tags defined in in the slots named
style
. Designers have a way to really change whatever they like about an element, without getting FOUC.Is this an anti-pattern? Am I doing something absolutely terrible? Or is this what it looks like it is: the holy grain of allowing designers to really change the CSS when custom properties don't go far enough?
Please feel free to throw tomatoes at me if I deserve it!
The text was updated successfully, but these errors were encountered: