Skip to content

Style CPart: IsolateClass feature #16

@michaelpb

Description

@michaelpb

Currently, the Style CPart will NOT scope either vanish or vanish-into-document. However, there is a possible use case for vanish-into-document being scoped: Basically, if you have multiple layouts in a single project, and you want completely different CSS for each layout, with no room for conflict.

Proposal: IsolateClass feature, in addition to, or even instead of prefixing by default (?)

<Style -isolate-class="my_super_unique_class">
   h3 { color: blue; }
</Style>

Would result in CSS like: .my_super_unique_class:has(h3) { color: blue; }

By default, IsolateClass will get set to the Component name, if the Component name is in anything but "regular" render mode.

  • allowing more granular, unsurprising styling and for vanish-* and even shadow to still prefix

Def / configuration:

{
   class: '?', // defaults to "false" if mode=normal, otherwise "i__x-ComponentName" 
   renderClass: '?', // defaults to "false" if component mode=normal, otherwise "h1, a, p > whatever, .etc" (e.g. string of targeted elems)
   prefix: '?', // defaults to "false" if component mode!=normal, otherwise "x-ComponetnName" (e.g. string of targeted elems)
   setShadowRoot: null, // false, unless "shadow" is selected, then true
}

First shot at implementation: Loop through patches, getting checking if patch[0].matches && patch[0].matches(selector), then appending patch[0] to the end with a "attr-append" patch

    renderCallback(renderObj) {
        const className = this.attrs.isolateClass || '';// eg.. 'I__x__MyComponent';
        const patches = className ? renderObj.component.patches : [];
        const any = this.getAllClasses(); // e.g. 'h1, p > strong';
        for (const [ parent, method, node ]  of Array.from(patches)) {
            if ((method === 'insertBefore' || method === 'appendChild') && node.matches(any)) {
                patches.append('attr-append', node, 'class', ' .' + className);
            }
        }
    }
  • Approach 2: Just loop through selectors, using querySelectorAll on each CSS selector to get all matching elems

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestquestionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions