|
1 |
| -import { define, props } from '@bolt/core/utils'; |
2 |
| -import { h, withPreact, Fragment, Markup } from '@bolt/core/renderers'; |
3 |
| -import styles from './block-list.scss'; |
| 1 | +import { BoltElement, customElement, unsafeCSS, html } from '@bolt/element'; |
| 2 | +import { unsafeHTML } from 'lit-html/directives/unsafe-html'; |
| 3 | +import blockListStyles from './block-list.scss'; |
4 | 4 |
|
5 |
| -@define |
6 |
| -class BoltBlockList extends withPreact() { |
7 |
| - static is = 'bolt-block-list'; |
| 5 | +@customElement('bolt-block-list') |
| 6 | +class BoltBlockList extends BoltElement { |
| 7 | + static get properties() { |
| 8 | + return { |
| 9 | + items: Array, |
| 10 | + }; |
| 11 | + } |
8 | 12 |
|
9 |
| - static props = { |
10 |
| - items: props.any, |
11 |
| - }; |
| 13 | + static get styles() { |
| 14 | + return [unsafeCSS(blockListStyles)]; |
| 15 | + } |
12 | 16 |
|
13 |
| - constructor(self) { |
14 |
| - self = super(self); |
15 |
| - this.useShadow = false; // @todo: Get this working with shadowDOM + slots |
16 |
| - return self; |
| 17 | + connectedCallback() { |
| 18 | + super.connectedCallback && super.connectedCallback(); |
| 19 | + this.items = this.items || []; |
17 | 20 | }
|
18 | 21 |
|
19 | 22 | render() {
|
20 |
| - const theItems = this.props.items ? this.props.items.split(',') : []; |
21 |
| - let finalItems = ''; |
22 |
| - theItems.forEach(value => { |
23 |
| - finalItems += `<li class="c-bolt-block-list__item">${value}</li>`; |
24 |
| - }); |
25 |
| - return ( |
26 |
| - <> |
27 |
| - {this.useShadow && <style>{styles[0][1]}</style>} |
28 |
| - <ul className="c-bolt-block-list"> |
29 |
| - <Markup markup={finalItems} /> |
30 |
| - </ul> |
31 |
| - </> |
32 |
| - ); |
| 23 | + return html` |
| 24 | + <ul class="c-bolt-block-list"> |
| 25 | + ${this.items && this.items.length >= 1 |
| 26 | + ? this.items.map( |
| 27 | + item => |
| 28 | + html` |
| 29 | + <li class="c-bolt-block-list__item">${unsafeHTML(item)}</li> |
| 30 | + `, |
| 31 | + ) |
| 32 | + : ''} |
| 33 | + </ul> |
| 34 | + `; |
33 | 35 | }
|
34 | 36 | }
|
35 | 37 |
|
|
0 commit comments