Skip to content

Commit

Permalink
Add Layouts: Cluster, Cover, Frame, Grid Reel, SideBar
Browse files Browse the repository at this point in the history
Modify: Box, Center, Stack and all *.html files
Add: notes.txt
  • Loading branch information
backspaces committed Jul 24, 2023
1 parent a548dc6 commit 995a19f
Show file tree
Hide file tree
Showing 25 changed files with 2,331 additions and 78 deletions.
7 changes: 4 additions & 3 deletions BoxLayout.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ customElements.define(
}

render() {
// prettier-ignore
this.shadowRoot.innerHTML = `
<style>
:host {
Expand All @@ -18,11 +19,12 @@ customElements.define(
}
::slotted(*) {
color: inherit;
background-color: inherit;
}
</style>
<slot></slot>
`
console.log('box:', this.shadowRoot.innerHTML)
}

connectedCallback() {
Expand All @@ -36,15 +38,14 @@ customElements.define(
return ['padding', 'borderWidth']
}
get padding() {
return this.getAttribute('padding') || '1rem'
return this.getAttribute('padding') || 'var(--s1)'
}
set padding(val) {
return this.setAttribute('padding', val)
}
get borderWidth() {
return this.getAttribute('borderWidth') || 'var(--border-thin)'
}

set borderWidth(val) {
return this.setAttribute('borderWidth', val)
}
Expand Down
54 changes: 37 additions & 17 deletions CenterLayout.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,35 @@ customElements.define(
}

render() {
// prettier-ignore
this.shadowRoot.innerHTML = `
<style>
:host {
display: block;
${ this.intrinsic ? `
display: flex;
flex-direction: column;
align-items: center;` : `display: block;`
}
box-sizing: content-box;
margin-inline: auto;
max-inline-size: var(--measure);
}
::slotted(*) {
max-width: ${this.max};
${
this.gutters
? `
${ this.gutters ? `
padding-inline-start: ${this.gutters};
padding-inline-end: ${this.gutters};`
: ''
padding-inline-end: ${this.gutters};` : ''
}
${this.andText ? `text-align: center;` : ''}
${
this.intrinsic
? `
display: flex;
flex-direction: column;
align-items: center;`
: ''
}
}
</style>
<slot></slot>
`
console.log(this.shadowRoot.innerHTML)
console.log('center', this.shadowRoot.innerHTML)
}

connectedCallback() {
Expand Down Expand Up @@ -85,3 +82,26 @@ customElements.define(
}
}
)

/*
::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;`
: ''
}
*/
56 changes: 56 additions & 0 deletions ClusterLayout.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
customElements.define(
'cluster-layout',
class extends HTMLElement {
constructor() {
super()
this.attachShadow({ mode: 'open' })
}

render() {
// prettier-ignore
this.shadowRoot.innerHTML = `
<style>
:host {
display: flex;
flex-wrap: wrap;
justify-content: ${this.justify};
align-items: ${this.align};
gap: ${this.space};
}
</style>
<slot></slot>
`
console.log('box:', this.shadowRoot.innerHTML)
}

connectedCallback() {
this.render()
}
attributeChangedCallback() {
this.render()
}

static get observedAttributes() {
return ['justify', 'align', 'space']
}
get justify() {
return this.getAttribute('justify') || 'flex-start'
}
set justify(val) {
return this.setAttribute('justify', val)
}
get align() {
return this.getAttribute('align') || 'flex-start'
}
set align(val) {
return this.setAttribute('align', val)
}
get space() {
return this.getAttribute('space') || 'var(--s1)'
}
set space(val) {
return this.setAttribute('space', val)
}
}
)
153 changes: 153 additions & 0 deletions CoverLayout.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
customElements.define(
'cover-layout',
class extends HTMLElement {
constructor() {
super()
this.attachShadow({ mode: 'open' })
}

render() {
// prettier-ignore
this.shadowRoot.innerHTML = `
<style>
:host {
display: flex;
flex-direction: column;
min-block-size: ${this.minHeight};
min-height: ${this.minHeight};
padding: ${this.noPad ? '0' : this.space };
}
::slotted(:firstChild) {
margin-block-start: 0;
}
::slotted(:lastChild) {
margin-block-end: 0;
}
::slotted(:nth-Child(2)) {
margin-block: auto;
}
</style>
<slot></slot>
`
console.log('cover:', this.shadowRoot.innerHTML)
console.log('children:', this.childElementCount)
}

connectedCallback() {
this.render()
}
attributeChangedCallback() {
this.render()
}

static get observedAttributes() {
return ['centered', 'space', 'minHeight', 'noPad']
}
get centered() {
return this.getAttribute('centered') || 'h1'
}
set centered(val) {
return this.setAttribute('centered', val)
}
get space() {
return this.getAttribute('space') || 'var(--s1)'
}
set space(val) {
return this.setAttribute('space', val)
}
get minHeight() {
return this.getAttribute('minHeight') || '100vh'
}
set minHeight(val) {
return this.setAttribute('minHeight', val)
}
get noPad() {
return this.hasAttribute('noPad')
}
set noPad(val) {
if (val) {
return this.setAttribute('noPad', '')
} else {
return this.removeAttribute('noPad')
}
}
}
)

/*
::slotted(*) {
margin-block: ${this.space};
}
cover-l {
display: flex;
flex-direction: column;
min-block-size: 100vh;
padding: var(--s1);
}
styleEl.innerHTML = `
[data-i="${this.i}"] {
min-height: ${this.minHeight};
padding: ${!this.noPad ? this.space : '0'};
}
[data-i="${this.i}"] > * {
margin-block: ${this.space};
}
[data-i="${this.i}"] > :first-child:not(${this.centered}) {
margin-block-start: 0;
}
[data-i="${this.i}"] > :last-child:not(${this.centered}) {
margin-block-end: 0;
}
[data-i="${this.i}"] > ${this.centered} {
margin-block: auto;
}
`
<style>
:host {
display: flex;
flex-direction: column;
min-block-size: 100vh;
min-height: ${this.minHeight};
padding: ${!this.noPad ? this.space : '0'};
}
::slotted(*) {
margin-block: ${this.space};
}
::slotted(:firstChild:not(${this.centered}) ) {
margin-block-start: 0;
}
::slotted(:lastChild:not(${this.centered}) ) {
margin-block-end: 0;
}
::slotted((${this.centered}) ) {
margin-block-end: auto;
}
</style>
<slot></slot>
`
*/
56 changes: 56 additions & 0 deletions FrameLayout.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
customElements.define(
'frame-layout',
class extends HTMLElement {
constructor() {
super()
this.attachShadow({ mode: 'open' })
}

render() {
if (this.children.length !== 1) {
console.warn('<frame-layout> can have just one child element')
}

let ratio = this.ratio.split(':')
// prettier-ignore
this.shadowRoot.innerHTML = `
<style>
:host {
aspect-ratio: ${ratio[0]} / ${ratio[1]};
overflow: hidden;
display: flex;
justify-content: center;
align-items: center;
}
::slotted(img),
::slotted(video){
inline-size: 100%;
block-size: 100%;
object-fit: cover;
}
</style>
<slot></slot>
`
console.log('frame:', this.shadowRoot.innerHTML)
}

connectedCallback() {
this.render()
}
attributeChangedCallback() {
this.render()
}

static get observedAttributes() {
return ['ratio']
}
get ratio() {
return this.getAttribute('ratio') || '16:9'
}
set ratio(val) {
return this.setAttribute('ratio', val)
}
}
)
Loading

0 comments on commit 995a19f

Please sign in to comment.