Skip to content

Commit 8835513

Browse files
committed
feat: refactor existing Block List component to render via LitElement vs Preact; workaround to double-rendering quirk flagged
1 parent 9b154e3 commit 8835513

File tree

1 file changed

+28
-26
lines changed

1 file changed

+28
-26
lines changed

packages/components/bolt-block-list/src/block-list.standalone.js

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,37 @@
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';
44

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+
}
812

9-
static props = {
10-
items: props.any,
11-
};
13+
static get styles() {
14+
return [unsafeCSS(blockListStyles)];
15+
}
1216

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 || [];
1720
}
1821

1922
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+
`;
3335
}
3436
}
3537

0 commit comments

Comments
 (0)