Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add no-header table variant #36

Merged
merged 3 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions blocks/table/table.css
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@
text-align: left;
}

/* no header variant */
.table.no-header table tbody tr {
border-top: 1px solid;
}

/* striped variant */
.table.striped tbody tr:nth-child(odd) {
background-color: var(--overlay-background-color);
Expand Down
14 changes: 10 additions & 4 deletions blocks/table/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,19 @@ export default async function decorate(block) {
const table = document.createElement('table');
const thead = document.createElement('thead');
const tbody = document.createElement('tbody');
table.append(thead, 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 (i) tbody.append(row);
else thead.append(row);
if (header && i === 0) thead.append(row);
else tbody.append(row);
[...child.children].forEach((col) => {
const cell = buildCell(i);
const cell = buildCell(header ? i : i + 1);
cell.innerHTML = col.innerHTML;
row.append(cell);
});
Expand Down