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.
- Loading branch information
1 parent
fb399b3
commit 6065770
Showing
7 changed files
with
165 additions
and
63 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,18 @@ | ||
export default function decorate(block) { | ||
const id = `gen${crypto.randomUUID().split('-')[0]}`; | ||
block.id = id; | ||
import { | ||
addCssVariables, | ||
} from '../../scripts/lib-franklin.js'; | ||
|
||
export default function decorate(block) { | ||
const columns = block.querySelectorAll(':scope > div > div'); | ||
const columnCount = columns.length; | ||
// following line regex matches partition sizes separated by dashes like 1-2-3 | ||
const columnPartionRegex = /^\d{1,}(?:-\d{1,})*$/; | ||
const columnPartions = [...block.classList].find((c) => columnPartionRegex.test(c))?.split('-') || []; | ||
|
||
let variables = ''; | ||
const variables = {}; | ||
for (let i = 0; i < columnCount; i += 1) { | ||
const partition = columnPartions.length > i ? columnPartions[i] : 1; | ||
variables += `--column${i}-flex: ${partition};`; | ||
variables[`column${i}-flex`] = partition; | ||
} | ||
|
||
const style = document.createElement('style'); | ||
style.textContent = `#${id} { | ||
${variables} | ||
}`; | ||
block.parentNode.insertBefore(style, block); | ||
addCssVariables(block, variables); | ||
} |
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,31 @@ | ||
.section.grid { | ||
display: grid; | ||
grid-template-columns: var(--grid-template-columns); | ||
grid-template-rows: var(--grid-template-rows); | ||
} | ||
|
||
.section.grid .element { | ||
grid-column-start: var(--grid-column-start-position, auto); | ||
grid-row-start: var(--grid-row-start-position, auto); | ||
grid-column-end: var(--grid-column-end-position, auto); | ||
grid-row-end: var(--grid-row-end-position, auto); | ||
width: 100%; | ||
max-width: unset; | ||
background-color: var(--background-color, transparent); | ||
color: var(--text-color); | ||
margin: auto; | ||
} | ||
|
||
.section.grid .element .image-wrapper { | ||
margin: 0; | ||
padding: 0; | ||
} | ||
|
||
.section.grid .element img { | ||
width: 100%; | ||
} | ||
|
||
.section.grid .element p { | ||
margin: 0; | ||
padding: var(--padding-vertical) var(--padding-horizontal); | ||
} |
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,34 @@ | ||
import { | ||
addCssVariables, | ||
} from '../../scripts/lib-franklin.js'; | ||
|
||
export default function decorate(block) { | ||
const elements = [...block.querySelectorAll(':scope > div')]; | ||
|
||
const columnTemplate = elements.find((e) => e.dataset.gridColumns)?.dataset.gridColumns; | ||
const rowTemplate = elements.find((e) => e.dataset.gridRows)?.dataset.gridRows; | ||
if(columnTemplate || rowTemplate) { | ||
const variables = {}; | ||
if(columnTemplate) { | ||
variables['grid-template-columns'] = columnTemplate; | ||
} | ||
if(columnTemplate) { | ||
variables['grid-template-rows'] = rowTemplate; | ||
} | ||
addCssVariables(block, variables); | ||
} | ||
|
||
elements.forEach((e) => { | ||
e.classList.add('element'); | ||
|
||
const [[startColumnPosition, startRowPosition], [endColumnPosition, endRowPosition]] = | ||
Check failure on line 24 in blocks/grid/grid.js GitHub Actions / build
|
||
e.dataset.gridPosition.split(/\s*\/\s*/).map((p) => p.split(/\s*-\s*/)); | ||
|
||
addCssVariables(e, { | ||
'grid-column-start-position': startColumnPosition, | ||
'grid-row-start-position': startRowPosition, | ||
'grid-column-end-position': endColumnPosition, | ||
'grid-row-end-position': endRowPosition, | ||
}); | ||
}); | ||
} | ||
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