Skip to content
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

[css-shadow-parts] Web Component default *exportparts=* #3508

Open
frivoal opened this issue Jan 14, 2019 · 2 comments
Open

[css-shadow-parts] Web Component default *exportparts=* #3508

frivoal opened this issue Jan 14, 2019 · 2 comments

Comments

@frivoal
Copy link
Collaborator

frivoal commented Jan 14, 2019

(Split from issue #3467, reported by @stefsullrew)

When building a custom web component via composition not having to explicitly specify exportparts= would improve the experience.

The example below presents a possible solution where, at component creation, exportparts= is defined.

class BarElement extends HTMLElement {
  constructor() {
    super();
    
    const shadowRoot = this.attachShadow({mode: 'closed'});
    
    shadowRoot.innerHTML = `
        <h1 part="header">Headline</h1>
        <p part="metadata">Posted on: 2019-01-10</p>
        <div part="content">...</div>
    `;

    if (!this.hasAttribute('exportparts'))
        this.setAttribute('exportparts', 'header, metadata, content');
  }
}

customElements.define('bar-element', BarElement);
<x-foo>
    <!-- iteration of bar-elements -->
    <!-- since no manual "exportparts=" was specified on each instance
         the defaults are exported -->
    <bar-element></bar-element>
    <bar-element></bar-element>
    ...
</x-foot>
x-foo::part(header) {
    color: green;
}
@fergald
Copy link
Contributor

fergald commented Jan 15, 2019

So you'd prefer a default where if it's not specified, all parts are exported under their original name and to prevent exporting you'd have to explicitly do e.g.

<custom-foo exportparts=""></custom-foo>

The counter proposal to that would be to implement wildcard forwarding so that it is at least trivial to export everything with e.g.

<custom-foo exportparts="*"></custom-foo>

I'm not sure how decide which of all or nothing should be the default. I don't recall any previous debate on it. @tabatkins do you remember anything?

@fredboyle
Copy link

@fergald Not so much to export everything but define a list of parts that would always be exported unless overridden.

So in the example above (initial post) if we wanted to always export the header part if no exportparts= was provided, we could do that. This would avoid consuming developers from having to always specify it and simply use the component with no exportparts= attribute. Does that make sense?

This facilitates the composition scenario and avoids deeply nested exportparts= chains. We want to provide ease of use and remain flexible in the ability to customize but with some guardrails in place.

Hope that helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants