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
// | HTML tag name | use shadow-dom | use adoptedStyleSheets |
20
18
// Component definition Observed attributes Encapsulation mode for the shadow DOM tree Root is serializable
21
19
```
22
20
23
-
> _**\*Note:** as per the [Custom Elements specification](https://html.spec.whatwg.org/multipage/custom-elements.html#valid-custom-element-name), the tag name must contain a hyphen._
21
+
> _**Note:** as per the [Custom Elements specification](https://html.spec.whatwg.org/multipage/custom-elements.html#valid-custom-element-name), the tag name must contain a hyphen._
24
22
25
23
Use the new tag name in HTML, attribute keys and values will be passed in as props:
26
24
@@ -50,15 +48,15 @@ import register from 'preact-custom-element';
50
48
51
49
// <x-greeting name="Bo"></x-greeting>
52
50
classGreetingextendsComponent {
53
-
// Register as <x-greeting>:
54
-
static tagName ='x-greeting';
51
+
// Register as <x-greeting>:
52
+
static tagName ='x-greeting';
55
53
56
-
// Track these attributes:
57
-
static observedAttributes = ['name'];
54
+
// Track these attributes:
55
+
static observedAttributes = ['name'];
58
56
59
-
render({ name }) {
60
-
return<p>Hello, {name}!</p>;
61
-
}
57
+
render({ name }) {
58
+
return<p>Hello, {name}!</p>;
59
+
}
62
60
}
63
61
register(Greeting);
64
62
```
@@ -68,12 +66,16 @@ If no `observedAttributes` are specified, they will be inferred from the keys of
68
66
```js
69
67
// Other option: use PropTypes:
70
68
functionFullName({ first, last }) {
71
-
return<span>{first} {last}</span>
69
+
return (
70
+
<span>
71
+
{first} {last}
72
+
</span>
73
+
);
72
74
}
73
75
74
76
FullName.propTypes= {
75
-
first:Object,// you can use PropTypes, or this
76
-
last:Object// trick to define untyped props.
77
+
first:Object, // you can use PropTypes, or this
78
+
last:Object,// trick to define untyped props.
77
79
};
78
80
79
81
register(FullName, 'full-name');
@@ -87,21 +89,21 @@ When using shadow DOM, you can make use of named `<slot>` elements in your compo
0 commit comments