| ... |
... |
@@ -9,17 +9,21 @@ |
| 9 |
9 |
this.attachShadow({ mode: 'open'}); |
| 10 |
10 |
} |
| 11 |
11 |
|
| 12 |
|
- createTemplate(htmlString) { |
|
12 |
+ get template() { |
| 13 |
13 |
const template = document.createElement('template'); |
| 14 |
14 |
template.innerHTML = ` |
| 15 |
15 |
<style> |
| 16 |
16 |
${this.styles} |
| 17 |
17 |
</style> |
| 18 |
|
- ${htmlString} |
|
18 |
+ ${this.html} |
| 19 |
19 |
`; |
| 20 |
20 |
return template; |
| 21 |
21 |
} |
| 22 |
22 |
|
|
23 |
+ |
|
24 |
+ get styles() { |
|
25 |
+ return ``; |
|
26 |
+ } |
| 23 |
23 |
$(selector) { |
| 24 |
24 |
return this.shadowRoot.querySelector(selector); |
| 25 |
25 |
} |
| ... |
... |
@@ -55,6 +55,13 @@ |
| 55 |
55 |
}); |
| 56 |
56 |
} |
| 57 |
57 |
|
|
62 |
+ get styles() { |
|
63 |
+ return ` |
|
64 |
+ input[type="text"] { |
|
65 |
+ border: 1px solid red; |
|
66 |
+ } |
|
67 |
+ ` |
|
68 |
+ } |
| 58 |
58 |
|
| 59 |
59 |
handleSearch = () => { |
| 60 |
60 |
const value = this.$('input[type="text"]').value; |
| ... |
... |
@@ -64,8 +64,8 @@ |
| 64 |
64 |
} |
| 65 |
65 |
|
| 66 |
66 |
|
| 67 |
|
- get searchInputTemplate() { |
| 68 |
|
- return this.createTemplate(` |
|
78 |
+ get html() { |
|
79 |
+ return ` |
| 69 |
69 |
<div> |
| 70 |
70 |
<input type="text"><button id="search">Search</button> |
| 71 |
71 |
<div id="results"></div> |
| ... |
... |
@@ -72,7 +72,7 @@ |
| 72 |
72 |
<button id="prev">prev</button> |
| 73 |
73 |
<button id="next">next</button> |
| 74 |
74 |
</div> |
| 75 |
|
- `); |
|
86 |
+ `; |
| 76 |
76 |
} |
| 77 |
77 |
|
| 78 |
78 |
renderResults = (results) => { |
| ... |
... |
@@ -89,7 +89,7 @@ |
| 89 |
89 |
} |
| 90 |
90 |
|
| 91 |
91 |
render() { |
| 92 |
|
- this.shadowRoot.appendChild(this.searchInputTemplate.content.cloneNode(true)); |
|
103 |
+ this.shadowRoot.appendChild(this.template.content.cloneNode(true)); |
| 93 |
93 |
} |
| 94 |
94 |
} |
| 95 |
95 |
); |
| ... |
... |
@@ -108,19 +108,26 @@ |
| 108 |
108 |
return this.getAttribute('data-href'); |
| 109 |
109 |
} |
| 110 |
110 |
|
| 111 |
|
- get resultTemplate() { |
| 112 |
|
- return this.createTemplate(` |
|
122 |
+ get styles() { |
|
123 |
+ return ` |
|
124 |
+ a { |
|
125 |
+ color: var(--color-brand-primary); |
|
126 |
+ } |
|
127 |
+ `; |
|
128 |
+ } |
|
129 |
+ get html() { |
|
130 |
+ return ` |
| 113 |
113 |
<div> |
| 114 |
114 |
<a href=${this.hrefAttr}>${this.titleAttr}</a> |
| 115 |
115 |
<div> |
| 116 |
116 |
<slot></slot> |
| 117 |
117 |
</div> |
| 118 |
|
- </div> |
| 119 |
|
- `); |
|
136 |
+ </div> ` |
| 120 |
120 |
} |
|
138 |
+ |
| 121 |
121 |
connectedCallback() { |
| 122 |
122 |
this.attachShadow({ mode: 'open' }); |
| 123 |
|
- this.shadowRoot.appendChild(this.resultTemplate.content.cloneNode(true)); |
|
141 |
+ this.shadowRoot.appendChild(this.template.content.cloneNode(true)); |
| 124 |
124 |
} |
| 125 |
125 |
} |
| 126 |
126 |
); |