forked from adobe-rnd/aem-boilerplate-xwalk
-
Notifications
You must be signed in to change notification settings - Fork 0
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
a81e7d6
commit 0c9a40f
Showing
5 changed files
with
220 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
.table { | ||
width: 100%; | ||
overflow-x: auto; | ||
} | ||
|
||
.table table { | ||
width: 100%; | ||
max-width: 100%; | ||
border-collapse: collapse; | ||
font-size: var(--body-font-size-xs); | ||
} | ||
|
||
@media (width >= 600px) { | ||
.table table { | ||
font-size: var(--body-font-size-s); | ||
} | ||
} | ||
|
||
@media (width >= 900px) { | ||
.table table { | ||
font-size: var(--body-font-size-m); | ||
} | ||
} | ||
|
||
.table table thead tr { | ||
border-top: 2px solid #dadada; | ||
border-bottom: 2px solid #dadada; | ||
} | ||
|
||
.table table tbody tr { | ||
border-bottom: 1px solid #dadada; | ||
} | ||
|
||
.table table th { | ||
font-weight: 700; | ||
} | ||
|
||
.table table th, | ||
.table table td { | ||
padding: 0.5em; | ||
text-align: left; | ||
} | ||
|
||
.table table th p, | ||
.table table td p { | ||
margin: 0; | ||
} | ||
|
||
.table table td p + p { | ||
margin-top: 0.25em; | ||
} | ||
|
||
/* no header variant */ | ||
.table.no-header table tbody tr { | ||
border-top: 1px solid #dadada; | ||
} | ||
|
||
/* striped variant */ | ||
.table.striped tbody tr:nth-child(odd) { | ||
background-color: var(--light-color); | ||
} | ||
|
||
/* bordered variant */ | ||
.table.bordered table th, | ||
.table.bordered table td { | ||
border: 1px solid #dadada; | ||
} |
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 @@ | ||
/* | ||
* Table Block | ||
* Recreate a table | ||
* https://www.hlx.live/developer/block-collection/table | ||
*/ | ||
|
||
function buildCell(rowIndex) { | ||
const cell = rowIndex ? document.createElement('td') : document.createElement('th'); | ||
if (!rowIndex) cell.setAttribute('scope', 'col'); | ||
return cell; | ||
} | ||
|
||
export default async function decorate(block) { | ||
const table = document.createElement('table'); | ||
const thead = document.createElement('thead'); | ||
const tbody = document.createElement('tbody'); | ||
|
||
const header = !block.classList.contains('no-header'); | ||
if (header) table.append(thead); | ||
table.append(tbody); | ||
|
||
[...block.children].forEach((child, i) => { | ||
const row = document.createElement('tr'); | ||
if (header && i === 0) thead.append(row); | ||
else tbody.append(row); | ||
[...child.children].forEach((col) => { | ||
const cell = buildCell(header ? i : i + 1); | ||
cell.innerHTML = col.innerHTML; | ||
row.append(cell); | ||
}); | ||
}); | ||
block.innerHTML = ''; | ||
block.append(table); | ||
} |
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