You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After discussion in the Dev Roundtable today, the effort overweights the benefits. We'll keep this ticket open if something evolves in the addons or on ideas.
First solution would be the simplest actually, as Stencil uses adoptedStyleSheets. That means, we only need to adapt one component stylesheet to make the changes available through all the same components. Hooking into adoptedStylesheets makes it reliable as it's a standard and not something
Here is an example function, how you can add copied rules where you replace the pseudo-class with a class:
exportfunctionaddPseudoClassClassesToWebComponents(componentName: string,pseudoClass: string){constadoptedStyleSheets=document.querySelector(componentName)?.shadowRoot?.adoptedStyleSheets;if(!adoptedStyleSheets){console.warn('Web component not found, to apply simulated Pseudo Class');return;}construlesToTransform=Array.from(adoptedStyleSheets[0].cssRules).filter(rule=>rule.cssText.includes(`:${pseudoClass}`),);constpattern=`:${pseudoClass}(?<!-)$`;// Basic replacement, maybe we need something a bit smarter or share similar function with postcss plugin.constregex=newRegExp(pattern);constclassName=serializeSimulatedPseudoClass(pseudoClass);constnewRules=rulesToTransform.map(rule=>rule.cssText.replace(regex,className));constlength=adoptedStyleSheets[0].cssRules.length;newRules.forEach((newRule,index)=>{adoptedStyleSheets[0].insertRule(newRule,length+index);});}
Another function using componentOnReady (Stencil only – allow to hook into ShadowRoot when it's ready) on the web component would add the class name on the element, similarly to what we are doing with standard element in their stories.
Follow-up of #1051 and #2092, where web-components are not supported by the solution.
In web-component, the CSS is embedded in the JS file and is not transformed by vite and PostCSS.
Example with post-tabs.cjs.entry.js
Some ideas:
The text was updated successfully, but these errors were encountered: