generated from adobe/aem-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#461424 #461425 - Improve boilerplate and add component nesting featu…
…re. Add global linked images and CTA definitions.
- Loading branch information
Showing
25 changed files
with
933 additions
and
248 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,20 @@ | ||
import ComponentBase from '../../scripts/component-base.js'; | ||
|
||
export default class Button extends ComponentBase { | ||
ready() { | ||
this.setAttribute('role', 'button'); | ||
this.setAttribute('tabindex', '0'); | ||
static loaderConfig = { | ||
...ComponentBase.loaderConfig, | ||
targetsSelectors: ':is(p,div):has(> a:only-child)', | ||
selectorTest: (el) => el.childNodes.length === 1, | ||
}; | ||
|
||
extendConfig() { | ||
return [ | ||
...super.extendConfig(), | ||
{ | ||
targetsAsContainers: { | ||
addToTargetMethod: 'append', | ||
}, | ||
}, | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
raqn-column { | ||
margin: var(--scope-margin, 0); | ||
width: 100%; | ||
display: grid; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import ComponentBase from '../../scripts/component-base.js'; | ||
|
||
// ! Solution 1 to remove mixins | ||
export default class ColumnN extends ComponentBase { | ||
static observedAttributes = ['position', 'size', 'justify']; | ||
|
||
connected() { | ||
this.position = parseInt(this.getAttribute('position'), 10); | ||
this.size = this.getAttribute('size'); | ||
this.justify = this.getAttribute('justify') || 'stretch'; | ||
this.calculateGridTemplateColumns(); | ||
} | ||
|
||
calculateGridTemplateColumns() { | ||
this.style.setProperty('justify-content', this.justify); | ||
if (this.position) { | ||
const parent = this.parentElement; | ||
const children = Array.from(parent.children); | ||
parent.classList.add('raqn-grid'); | ||
let parentGridTemplateColumns = parent.style.getPropertyValue( | ||
'--grid-template-columns', | ||
); | ||
if (!parentGridTemplateColumns) { | ||
// we have no grid template columns yet | ||
parentGridTemplateColumns = children | ||
.map((child, index) => { | ||
if (this.position === index + 1) { | ||
return this.size || 'auto'; | ||
} | ||
return 'auto'; | ||
}) | ||
.join(' '); | ||
// set the new grid template columns | ||
parent.style.setProperty( | ||
'--grid-template-columns', | ||
parentGridTemplateColumns, | ||
); | ||
} else { | ||
const { position } = this; | ||
const prio = children.indexOf(this) + 1; | ||
parentGridTemplateColumns = parentGridTemplateColumns | ||
.split(' ') | ||
.map((size, i) => { | ||
// we have a non standard value for this position | ||
const hasValue = size !== 'auto'; | ||
// we are at the position | ||
const isPosition = i + 1 === position; | ||
// we are at a position before the prio | ||
const isBeforePrio = i + 1 <= prio; | ||
// we have a non standard value for this position and we are at the position | ||
if (!hasValue && isPosition) { | ||
return this.size || 'auto'; | ||
} | ||
// we have a non standard value for this position and we are at a position before the prio | ||
if (hasValue && isPosition && isBeforePrio) { | ||
return this.size || size; | ||
} | ||
return size; | ||
}) | ||
.join(' '); | ||
// set the new grid template columns | ||
parent.style.setProperty( | ||
'--grid-template-columns', | ||
parentGridTemplateColumns, | ||
); | ||
} | ||
this.style.gridColumn = this.position; | ||
this.style.gridRow = 1; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
raqn-column { | ||
margin: var(--scope-margin, 0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import { collectAttributes } from '../../scripts/libs.js'; | ||
|
||
// ! Solution 2 to remove mixins | ||
export default class Columns { | ||
static observedAttributes = ['position', 'size', 'justify']; | ||
|
||
constructor(data) { | ||
this.element = data.target; | ||
|
||
const { currentAttributes } = collectAttributes( | ||
data.componentName, | ||
data.rawClasses, | ||
[], | ||
Columns.observedAttributes, | ||
this.element, | ||
); | ||
|
||
Object.keys(currentAttributes).forEach((key) => { | ||
this.element.setAttribute(key, currentAttributes[key]); | ||
}); | ||
|
||
this.position = parseInt(this.getAttribute('position'), 10); | ||
this.size = this.getAttribute('size'); | ||
this.justify = this.getAttribute('justify') || 'stretch'; | ||
this.calculateGridTemplateColumns(); | ||
} | ||
|
||
calculateGridTemplateColumns() { | ||
if (this.justify) { | ||
this.element.style.justifyContent = this.justify; | ||
} | ||
if (this.position) { | ||
const parent = this.element.parentElement; | ||
const children = Array.from(parent.children); | ||
parent.classList.add('raqn-grid'); | ||
let parentGridTemplateColumns = parent.style.getPropertyValue( | ||
'--grid-template-columns', | ||
); | ||
if (!parentGridTemplateColumns) { | ||
// we have no grid template columns yet | ||
parentGridTemplateColumns = children | ||
.map((child, index) => { | ||
if (this.position === index + 1) { | ||
return this.size || 'auto'; | ||
} | ||
return 'auto'; | ||
}) | ||
.join(' '); | ||
// set the new grid template columns | ||
parent.style.setProperty( | ||
'--grid-template-columns', | ||
parentGridTemplateColumns, | ||
); | ||
} else { | ||
const { position } = this; | ||
const prio = children.indexOf(this.element) + 1; | ||
parentGridTemplateColumns = parentGridTemplateColumns | ||
.split(' ') | ||
.map((size, i) => { | ||
// we have a non standard value for this position | ||
const hasValue = size !== 'auto'; | ||
// we are at the position | ||
const isPosition = i + 1 === position; | ||
// we are at a position before the prio | ||
const isBeforePrio = i + 1 <= prio; | ||
// we have a non standard value for this position and we are at the position | ||
if (!hasValue && isPosition) { | ||
return this.size || 'auto'; | ||
} | ||
// we have a non standard value for this position and we are at a position before the prio | ||
if (hasValue && isPosition && isBeforePrio) { | ||
return this.size || size; | ||
} | ||
return size; | ||
}) | ||
.join(' '); | ||
// set the new grid template columns | ||
parent.style.setProperty( | ||
'--grid-template-columns', | ||
parentGridTemplateColumns, | ||
); | ||
} | ||
this.element.style.gridColumn = this.position; | ||
this.element.style.gridRow = 1; | ||
} | ||
} | ||
|
||
getAttribute(name) { | ||
return ( | ||
this.element.getAttribute(name) || | ||
this.element.getAttribute(`data-${name}`) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.