Skip to content

Commit 8e3aea1

Browse files
authored
fix: Ensure defineElement is used instead of customElement (#685)
This prevents elements from being registered multiple times. Also adds ESLint rule configured as a warning.
1 parent c662cc3 commit 8e3aea1

File tree

8 files changed

+30
-14
lines changed

8 files changed

+30
-14
lines changed

.eslintrc.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@ module.exports = {
2727
'lit/prefer-nothing': 'error',
2828
'local-rules/uui-class-prefix': 'warn',
2929
'local-rules/prefer-static-styles-last': 'warn',
30+
'no-restricted-syntax': [
31+
'warn',
32+
{
33+
message:
34+
'Elements should not be defined with customElement, use defineElement instead.',
35+
selector:
36+
'ClassDeclaration > Decorator[expression.callee.name="customElement"]',
37+
},
38+
],
3039
},
3140
parserOptions: {
3241
project: './tsconfig.json',

packages/uui-combobox/lib/uui-combobox-async-example.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
import { defineElement } from '@umbraco-ui/uui-base/lib/registration';
12
import { css, html, LitElement, nothing } from 'lit';
2-
import { customElement, state } from 'lit/decorators.js';
3+
import { state } from 'lit/decorators.js';
34

45
interface Fruit {
56
name: string;
@@ -26,7 +27,7 @@ const data: Array<Fruit> = [
2627
{ name: 'Lime', value: 'lime' },
2728
];
2829

29-
@customElement('uui-combobox-async-example')
30+
@defineElement('uui-combobox-async-example')
3031
export class UUIComboboxAsyncExampleElement extends LitElement {
3132
@state()
3233
_options: any[] = [];

packages/uui-combobox/lib/uui-combobox-async-options-example.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
import { defineElement } from '@umbraco-ui/uui-base/lib/registration';
12
import { html, LitElement } from 'lit';
2-
import { customElement, property, state } from 'lit/decorators.js';
3+
import { property, state } from 'lit/decorators.js';
34

45
interface Fruit {
56
name: string;
@@ -30,7 +31,7 @@ async function getFruits() {
3031
return Promise.resolve(data);
3132
}
3233

33-
@customElement('uui-combobox-async-options-example')
34+
@defineElement('uui-combobox-async-options-example')
3435
export class UUIComboboxAsyncOptionsExampleElement extends LitElement {
3536
@state()
3637
_options: any[] = [];

packages/uui-modal/lib/modal-example.element.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { LitElement, css, html, TemplateResult } from 'lit';
2-
import { customElement, state } from 'lit/decorators.js';
2+
import { state } from 'lit/decorators.js';
33
import './uui-modal-container';
44
import { ref, createRef } from 'lit/directives/ref.js';
55
import { UUIModalElement } from './uui-modal.element';
6+
import { defineElement } from '@umbraco-ui/uui-base/lib/registration';
67

7-
@customElement('modal-example')
8+
@defineElement('modal-example')
89
export class ModalExampleElement extends LitElement {
910
@state()
1011
private _modals: TemplateResult<1>[] = [];

packages/uui-modal/lib/uui-modal-container.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import { LitElement, PropertyValueMap, css, html } from 'lit';
2-
import { customElement, property, query, state } from 'lit/decorators.js';
2+
import { property, query, state } from 'lit/decorators.js';
33
import { UUIModalSidebarElement } from './uui-modal-sidebar.element';
44
import { UUIModalElement } from './uui-modal.element';
5-
@customElement('uui-modal-container')
5+
import { defineElement } from '@umbraco-ui/uui-base/lib/registration';
6+
7+
@defineElement('uui-modal-container')
68
export class UUIModalContainerElement extends LitElement {
79
@query('slot')
810
modalSlot?: HTMLSlotElement;

packages/uui-modal/lib/uui-modal-dialog.element.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { css, html } from 'lit';
2-
import { customElement } from 'lit/decorators.js';
32
import { UUIModalElement } from './uui-modal.element';
3+
import { defineElement } from '@umbraco-ui/uui-base/lib/registration';
44

5-
@customElement('uui-modal-dialog')
5+
@defineElement('uui-modal-dialog')
66
export class UUIModalDialogElement extends UUIModalElement {
77
render() {
88
return html`

packages/uui-modal/lib/uui-modal-sidebar.element.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { css, html, PropertyValueMap } from 'lit';
2-
import { customElement, property } from 'lit/decorators.js';
2+
import { property } from 'lit/decorators.js';
33
import { UUIModalElement } from './uui-modal.element';
4+
import { defineElement } from '@umbraco-ui/uui-base/lib/registration';
45

56
export type UUIModalSidebarSize = 'small' | 'medium' | 'large' | 'full';
67

7-
@customElement('uui-modal-sidebar')
8+
@defineElement('uui-modal-sidebar')
89
export class UUIModalSidebarElement extends UUIModalElement {
910
/**
1011
* @attr

packages/uui-table/lib/uui-table-advanced-example.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ import '@umbraco-ui/uui-tag/lib';
88

99
import { UUITextStyles } from '@umbraco-ui/uui-css/lib';
1010
import { css, html, LitElement } from 'lit';
11-
import { customElement, state } from 'lit/decorators.js';
11+
import { state } from 'lit/decorators.js';
1212
import { repeat } from 'lit/directives/repeat.js';
13+
import { defineElement } from '@umbraco-ui/uui-base/lib/registration';
1314

1415
interface TableColumn {
1516
name: string;
@@ -25,7 +26,7 @@ interface TableItem {
2526
newsletter: boolean;
2627
}
2728

28-
@customElement('uui-table-with-selection-example')
29+
@defineElement('uui-table-with-selection-example')
2930
export class UUITableWithSelectionExampleElement extends LitElement {
3031
@state()
3132
private _columns: Array<TableColumn> = [];

0 commit comments

Comments
 (0)