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

Fixed the table issues #57

Merged
merged 1 commit into from
Oct 27, 2023
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
4 changes: 2 additions & 2 deletions blocks/table/table.css
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ table td {
}

.heading-top tr:first-child td {
background-color: var(--primary-color); /* Specify your desired background color here */
background-color: var(--primary-color);
}

.heading-left tr td:first-child {
.left-heading {
background-color: var(--primary-color);
text-align: left;
}
Expand Down
17 changes: 17 additions & 0 deletions blocks/table/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,23 @@ function removeClassesFromChildTables(table) {
}

export default function decorate(block) {
const getHeadingLeftClass = block.classList.contains('heading-left');
if (getHeadingLeftClass !== null && getHeadingLeftClass !== undefined) {
const tds = block.querySelectorAll('tr td:first-child');
let index = 0;
while (index < tds.length) {
const td = tds[index];
td.classList.add('left-heading');
const rowspan = td.getAttribute('rowspan');
if (rowspan !== null && rowspan > 1) {
const rowspanCount = parseInt(rowspan, 10);
index += rowspanCount;
} else {
index += 1;
}
}
}

const tableRows = block.querySelectorAll('.table[data-block-name="table"] tr');
tableRows.forEach((row) => {
const cells = row.querySelectorAll('td');
Expand Down