-
Notifications
You must be signed in to change notification settings - Fork 25
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
Allow for stylesheet composition using constructible stylesheets #24
Comments
Sounds like an interesting use case, but could it be solved in CSSOM? |
Potentially, but there's not really solid documentation on Regardless, I think the usability and functionality afforded to developers using the const sheet1 = new CSSStyleSheet(`
:root {
--primary: #004977;
--secondary: #011728;
--alert: #d03027;
}`);
const sheet2 = new CSSStyleSheet(`
h1 {
background: var(--secondary);
color: var(--primary);
}`);
const sheet3 = new CSSStylesheet(`
.error {
color: var(--alert);
}`);
const importSheet1 = new CSSImportRule(sheet1);
sheet2.insertRule(importSheet1);
sheet3.insertRule(importSheet1); or something similar which is far less developer friendly, especially for library authors who are using this feature in conjunction with the web components feature I listed above. Adding a composition syntax of some sort to the Also, any given constructed stylesheet might have multiple imports (say variables like Adding this feature would be a concise way for library authors to create short, succinct CSS partials that have one specific job and import them where they are needed without a lot of overhead and allow browser vendors to optimize applying those stylesheets well (because |
I'm not sure referring a JS object from CSS stylesheet ever worked like the OP ( Anyway this is an addition on top of constructed stylesheets, so this is not blocking the stylesheet constructor itself. |
@TakayoshiKochi I suppose that makes sense, but we are proposing new interfaces and features to the CSSOM with this proposal, so I don't necessarily think it's a non-starter. What I do know is that this feature (along with web components issue 468) would go a long way in solving a lot of the long-term strategy my organization has with web components. |
Another option, depending on how #10 and #25 pan out is to have the const customProps = new CSSStyleSheet(`
:root {
--primary: #004977;
--secondary: #011728;
--alert: #d03027;
}`);
const sheet = new CSSStyleSheet(`
@import ${customProps};
h1 {
background: var(--secondary);
color: var(--primary);
}`); |
We should add some way to compose stylesheets to support reuse over repetition. This is in relation to @annevk's comment on Web components issue 468. Consider adding an optional configuration argument to the
CSSStyleSheet
constructor that would essentially@import
existing stylesheets into a the current object:This would solve for my concern in the aforementioned issue about only allowing one stylesheet to be attached to a single custom element in the registry, would not interfere with current CSS behavior and would require only minimal modifications to the current proposal.
I think the only question I would have is how does the config import play with any
@import
in the sheet body (I would assume it is inserted before). Even if this syntax doesn't work, there needs to have a way to custom import constructed stylesheets into other constructed stylesheets to make the solution for 468 viable.The text was updated successfully, but these errors were encountered: