-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathmondrian.js
More file actions
37 lines (35 loc) · 1007 Bytes
/
mondrian.js
File metadata and controls
37 lines (35 loc) · 1007 Bytes
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
import {define} from 'https://unpkg.com/wicked-elements?module';
const {render, html} = uhtml;
define('#app .mondrian', {
connected() { this.render(); },
render(blocks = this.generateBlocks()) {
render(this.element, html`${blocks.map(
({colSpan, rowSpan, colorIndex}) => html`
<div class="mondrian__block"
data-col-span=${colSpan}
data-row-span=${rowSpan}
data-color-index=${colorIndex} />`
)}`);
},
generateBlocks() {
const blocks = [];
for (let i = 0; i < 10; i++) {
blocks.push({
colSpan: Math.floor(Math.random() * 3 + 1),
rowSpan: Math.floor(Math.random() * 3 + 1),
colorIndex: Math.floor(Math.random() * 6 + 1),
});
}
return blocks;
},
onGenerate() {
this.render([]);
setTimeout(() => this.render());
}
});
define('#app .generate-button', {
onclick() {
const mondrian = document.querySelector('.mondrian');
mondrian.dispatchEvent(new Event('generate'));
}
});