-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSidebarLayout.js
76 lines (71 loc) · 2.21 KB
/
SidebarLayout.js
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
customElements.define(
'sidebar-layout',
class extends HTMLElement {
constructor() {
super()
this.attachShadow({ mode: 'open' })
}
render() {
// prettier-ignore
this.shadowRoot.innerHTML = `
<style>
:host {
display: flex;
flex-wrap: wrap;
gap: ${this.space};
${this.noStretch ? 'align-items: flex-start;' : ''}
}
::slotted(*) {
flex-grow: 1;
${this.sideWidth ? `flex-basis: ${this.sideWidth};` : ''}
}
::slotted(
${this.side !== 'left' ? `*:first-child` : `*:last-child`}
) {
flex-basis: 0;
flex-grow: 999;
min-inline-size: ${this.contentMin};
}
</style>
<slot></slot>
`
// console.log('stack:', this.shadowRoot.innerHTML)
}
connectedCallback() {
this.render()
}
attributeChangedCallback() {
this.render()
}
static get observedAttributes() {
return ['side', 'sideWidth', 'contentMin', 'space', 'noStretch']
}
get side() {
return this.getAttribute('side') || 'left'
}
set side(val) {
return this.setAttribute('side', val)
}
get sideWidth() {
return this.getAttribute('sideWidth') || null
}
set sideWidth(val) {
return this.setAttribute('sideWidth', val)
}
get contentMin() {
return this.getAttribute('contentMin') || '50%'
}
set contentMin(val) {
return this.setAttribute('contentMin', val)
}
get space() {
return this.getAttribute('space') || 'var(--s1)'
}
set space(val) {
return this.setAttribute('space', val)
}
get noStretch() {
return this.hasAttribute('noStretch')
}
}
)