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
Copy file name to clipboardExpand all lines: .devcontainer/Dockerfile
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.222.0/containers/javascript-node/.devcontainer/base.Dockerfile
2
2
3
3
# [Choice] Node.js version (use -bullseye variants on local arm64/Apple Silicon): 16, 14, 12, 16-bullseye, 14-bullseye, 12-bullseye, 16-buster, 14-buster, 12-buster
4
-
ARG VARIANT="16"
4
+
ARG VARIANT="24"
5
5
FROM mcr.microsoft.com/vscode/devcontainers/javascript-node:0-${VARIANT}
6
6
7
7
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
Copy file name to clipboardExpand all lines: docs/_guide/your-first-component.md
+35-2Lines changed: 35 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -31,6 +31,27 @@ Catalyst will automatically convert the classes name; removing the trailing `Ele
31
31
32
32
By convention Catalyst controllers end in `Element`; Catalyst will omit this when generating a tag name. The `Element` suffix is _not_ required - just convention. All examples in this guide use `Element` suffixed names.
33
33
34
+
### Custom Element Names
35
+
36
+
If you need to use a specific element name that doesn't match your class name (for example, to support minification), you can pass the element name directly to the `@controller` decorator:
37
+
38
+
```js
39
+
import {controller} from'@github/catalyst'
40
+
41
+
@controller('hello-widget')
42
+
classSomeClassextendsHTMLElement {
43
+
connectedCallback() {
44
+
this.innerHTML='Hello from hello-widget!'
45
+
}
46
+
}
47
+
```
48
+
<br>
49
+
50
+
This will register the element as `<hello-widget>` regardless of the class name. This is particularly useful when:
51
+
- Your production build minifies class names
52
+
- You want explicit control over the element name
53
+
- The class name doesn't follow the naming pattern required for automatic naming
54
+
34
55
{% capture callout %}
35
56
Remember! A class name _must_ include at least two CamelCased words (not including the `Element` suffix). One-word elements will raise exceptions. Example of good names: `UserListElement`, `SubTaskElement`, `PagerContainerElement`
36
57
{% endcapture %}{% include callout.md %}
@@ -40,8 +61,8 @@ Remember! A class name _must_ include at least two CamelCased words (not includi
40
61
41
62
The `@controller` decorator ties together the various other decorators within Catalyst, plus a few extra conveniences such as automatically registering the element, which saves you writing some boilerplate that you'd otherwise have to write by hand. Specifically the `@controller` decorator:
42
63
43
-
- Derives a tag name based on your class name, removing the trailing `Element` suffix and lowercasing all capital letters, separating them with a dash.
44
-
- Calls `window.customElements.define` with the newly derived tag name and your class.
64
+
- Derives a tag name based on your class name, removing the trailing `Element` suffix and lowercasing all capital letters, separating them with a dash. You can optionally provide a custom element name as a parameter (e.g., `@controller('my-element')`).
65
+
- Calls `window.customElements.define` with the newly derived (or provided) tag name and your class.
45
66
- Calls `defineObservedAttributes` with the class to add map any `@attr` decorators. See [attrs]({{ site.baseurl }}/guide/attrs) for more on this.
46
67
- Injects the following code inside of the `connectedCallback()` function of your class:
47
68
-`bind(this)`; ensures that as your element connects it picks up any `data-action` handlers. See [actions]({{ site.baseurl }}/guide/actions) for more on this.
0 commit comments