8
8
9
9
//import { DateTime } from './current-time';
10
10
11
- // Define the custom element
12
- //customElements.define('current-time', DateTime);
11
+ class DateTimeElement extends HTMLElement {
12
+ // Attach a shadow root to the custom element
13
+ #shadowRoot = this . attachShadow ( { mode : 'open' } )
13
14
14
- // The class for the custom element
15
- export class DateTimeElement extends HTMLElement {
16
- public shadowRoot : ShadowRoot
17
15
private dateElement : HTMLElement
18
16
private timeElement : HTMLElement
19
17
private culture = 'en-US'
@@ -23,15 +21,12 @@ export class DateTimeElement extends HTMLElement {
23
21
static get observedAttributes ( ) : string [ ] {
24
22
return [ 'date-format' , 'time-format' , 'culture' ]
25
23
}
24
+ // eslint-disable-next-line custom-elements/no-constructor
26
25
constructor ( ) {
27
26
super ( )
28
-
29
- // Attach a shadow root to the custom element
30
- this . shadowRoot = this . attachShadow ( { mode : 'open' } )
31
-
32
27
// Add the template to the shadow root
33
28
const template = document . createElement ( 'template' )
34
-
29
+ // eslint-disable-next-line github/no-inner-html
35
30
template . innerHTML = `
36
31
<style>
37
32
#time-container {
@@ -50,11 +45,11 @@ export class DateTimeElement extends HTMLElement {
50
45
<p id="time"></p>
51
46
</div>
52
47
`
53
- this . shadowRoot . appendChild ( template . content . cloneNode ( true ) )
48
+ this . # shadowRoot. appendChild ( template . content . cloneNode ( true ) )
54
49
55
50
// Get the date and time elements
56
- this . dateElement = this . shadowRoot . querySelector ( '#date' ) !
57
- this . timeElement = this . shadowRoot . querySelector ( '#time' ) !
51
+ this . dateElement = this . # shadowRoot. querySelector ( '#date' ) !
52
+ this . timeElement = this . # shadowRoot. querySelector ( '#time' ) !
58
53
}
59
54
60
55
// Update the element when the format attribute changes
0 commit comments