-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
102 lines (87 loc) · 3.32 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<template id="menu-component">
<popover-component popover>
<slot></slot>
</popover-component>
</div>
</template>
<template id="popover-component">
<slot></slot>
<div>Popover's content</div>
</div>
</template>
<template id="menu-item-component">
<div>
<slot></slot>
</div>
</div>
</template>
</head>
<body>
<button id="btn">Toggle the menu</button>
<menu-component>
<menu-item-component>Item 1</menu-item-component>
<menu-item-component>Item 2</menu-item-component>
<menu-item-component>Item 3</menu-item-component>
<menu-item-component>Item 4</menu-item-component>
<menu-item-component>Item 5</menu-item-component>
</menu-component>
<button popovertarget="mypopover" id="btn2">Toggle the popover</button>
<div class="menu-component">
<div id="mypopover" popover class="popover-component">
<div class="menu-item-component">Item 1</div>
<div class="menu-item-component">Item 2</div>
<div class="menu-item-component">Item 3</div>
<div class="menu-item-component">Item 4</div>
<div class="menu-item-component">Item 5</div>
Popover's content
</div>
<script>
customElements.define(
"menu-component",
class extends HTMLElement {
constructor() {
super();
let template = document.getElementById("menu-component");
let templateContent = template.content;
const shadowRoot = this.attachShadow({ mode: "open" });
shadowRoot.appendChild(templateContent.cloneNode(true));
}
},
);
customElements.define(
"popover-component",
class extends HTMLElement {
constructor() {
super();
let template = document.getElementById("popover-component");
let templateContent = template.content;
const shadowRoot = this.attachShadow({ mode: "open" });
shadowRoot.appendChild(templateContent.cloneNode(true));
}
},
);
customElements.define(
"menu-item-component",
class extends HTMLElement {
constructor() {
super();
let template = document.getElementById("menu-item-component");
let templateContent = template.content;
const shadowRoot = this.attachShadow({ mode: "open" });
shadowRoot.appendChild(templateContent.cloneNode(true));
}
},
);
btn.addEventListener("click", () => {
const menuComponent = document.querySelector("menu-component")
menuComponent.shadowRoot.querySelector("popover-component").showPopover()
})
</script>
</body>
</html>