-
Notifications
You must be signed in to change notification settings - Fork 0
/
CenterLayout.js
107 lines (95 loc) · 3.08 KB
/
CenterLayout.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
customElements.define(
'center-layout',
class extends HTMLElement {
constructor() {
super()
this.attachShadow({ mode: 'open' })
}
render() {
// prettier-ignore
this.shadowRoot.innerHTML = `
<style>
:host {
${this.intrinsic ? `
display: flex;
flex-direction: column;
align-items: center;` : `display: block;`
}
box-sizing: content-box;
margin-inline: auto;
/* max-inline-size: var(--measure); */
max-width: ${this.max};
${ this.gutters ? `
padding-inline-start: ${this.gutters};
padding-inline-end: ${this.gutters};` : ''
}
${this.andText ? `text-align: center;` : ''}
}
</style>
<slot></slot>
`
// console.log('center', this.shadowRoot.innerHTML)
}
connectedCallback() {
this.render()
}
attributeChangedCallback() {
this.render()
}
static get observedAttributes() {
return ['max', 'andText', 'gutters', 'intrinsic']
}
get max() {
return this.getAttribute('max') || 'var(--measure)'
}
set max(val) {
return this.setAttribute('max', val)
}
get andText() {
return this.hasAttribute('andText')
}
set andText(val) {
if (val) {
return this.setAttribute('andText', '')
} else {
return this.removeAttribute('andText')
}
}
get gutters() {
return this.getAttribute('gutters') || null
}
set gutters(val) {
return this.setAttribute('gutters', val)
}
get intrinsic() {
return this.hasAttribute('intrinsic')
}
set intrinsic(val) {
if (val) {
return this.setAttribute('intrinsic', '')
} else {
return this.removeAttribute('intrinsic')
}
}
}
)
/*
::slotted(*) {
max-width: ${this.max};
${
this.gutters
? `
padding-inline-start: ${this.gutters};
padding-inline-end: ${this.gutters};`
: ''
}
${this.andText ? `text-align: center;` : ''}
${
this.intrinsic
? `
display: flex;
flex-direction: column;
align-items: center;`
: ''
}
*/