open-wc / open-wc

Open Web Components: guides, tools and libraries for developing web components.
https://open-wc.org/
MIT License
2.25k stars 422 forks source link

[Feature Request] @open-wc/scoped-elements, make the tagName optional #2433

Open RoXuS opened 2 years ago

RoXuS commented 2 years ago

90% of the time we don’t change the tagName of the component.

Maybe it should be a good idea to add a “mode” on scopedElements to avoid tagName?

Something like:

static get scopedElements() {
  return {
    DtTooltip,
    DtNotification,
    'dt-tooltip': DtTooltip...
  }
}
RoCat commented 2 years ago

Is it intended to have a tagName in pascal/camel case like in react ? In my vision, all tag names should be kebab cased. If so, maybe we just could convert pascalized tag name to kebab case.

Other solution is to use Class.name property, or static get is, but it seems unset when one uses @customElement

RoXuS commented 2 years ago

Yes but technically we don't have to use @customElements with scopedElementMixin so we will not have customElements too.

daKmoR commented 2 years ago

Maybe add a static defaultTagName?

It will be used if a scopedElement is not defined with a tag name.

could look something like this:

class DtTooltip extends HTMLElement {
  static defaultTagName = 'dt-tooltip';
}

class MyEl extends ScopedElementsMixin(LitElement) {
  static get scopedElements() {
    return {
      DtTooltip,
    }
  }

  render() {
    return html`
      <dt-tooltip>Hello World</dt-tooltip>
    `;
  }
}      
RoXuS commented 2 years ago

yeah it's a good solution for us but that it's not a generic thing...

justinfagnani commented 2 years ago

@daKmoR if the polyfill supported something like that it should probably be hashed out as a WCCG community protocol. Some other utilities I've seen look for a static tagName or is property.