Skip to content

Commit

Permalink
docs: improve naming docs
Browse files Browse the repository at this point in the history
  • Loading branch information
digitalsadhu committed Sep 29, 2024
1 parent a47c8bc commit 7eeaeb7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ const podlet = new Podlet(options);

#### name

The name the podlet identifies itself by. This value must be in camelCase.
The name the podlet identifies itself by. This value can contain upper and lower case letters, numbers, the - character and the \_ character. No spaces.
When shadow DOM is used, either via the `useShadowDOM` constructor option or via the `wrapWithShadowDOM` method, the name must comply with custom element naming rules.
See [MDN](https://developer.mozilla.org/en-US/docs/Web/API/CustomElementRegistry/define#valid_custom_element_names) for more information.

_Example:_

Expand Down Expand Up @@ -268,6 +270,7 @@ const podlet = new Podlet({ ..., useShadowDOM: true });
```

Please note the following caveats when using this feature:

1. You must name your podlet following custom element naming conventions as explained here: https://developer.mozilla.org/en-US/docs/Web/API/CustomElementRegistry/define#valid_custom_element_names
2. In order to style your content, you will need to include your CSS inside the shadow DOM wrapper. You can do this using one of the following 2 options:

Expand Down
10 changes: 4 additions & 6 deletions lib/podlet.js
Original file line number Diff line number Diff line change
Expand Up @@ -841,12 +841,10 @@ export default class PodiumPodlet {
* ```
*/
wrapWithShadowDOM(data) {
if (!this.#useShadowDOM) {
assert.ok(
customElementRegex.test(this.name),
`When using the constructor argument "useShadowDOM" or the method podlet.wrapWithShadowDOM, podlet.name must conform to custom element naming conventions. The name "${this.name}" does not comply. See https://developer.mozilla.org/en-US/docs/Web/API/CustomElementRegistry/define#valid_custom_element_names for more information.`,
);
}
assert.ok(
customElementRegex.test(this.name),
`When using the constructor argument "useShadowDOM" or the method podlet.wrapWithShadowDOM, podlet.name must conform to custom element naming conventions. The name "${this.name}" does not comply. See https://developer.mozilla.org/en-US/docs/Web/API/CustomElementRegistry/define#valid_custom_element_names for more information.`,
);

const styles = this.cssRoute
.filter((css) => css.scope === 'shadow-dom')
Expand Down

0 comments on commit 7eeaeb7

Please sign in to comment.