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

Add optimisation to the custom table #446

Merged
merged 1 commit into from
Feb 12, 2025
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
20 changes: 19 additions & 1 deletion tailoff/css/site/components/table.css
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
.custom-table .table {
@apply w-full;
}
.custom-table table {
@apply block w-full border border-black;

th {
@apply px-4 py-2 text-left bg-primary-300;
@apply px-4 py-2 text-left align-top bg-primary-300;
}

tr {
Expand Down Expand Up @@ -34,6 +37,10 @@
}
tbody {
display: block;

th {
@apply block w-full text-center;
}
}
}

Expand All @@ -43,6 +50,11 @@
display: block;
}

.custom-table table tbody th {
display: table-caption;
text-align: center;
}

.custom-table table tr {
display: table;
width: 100%;
Expand Down Expand Up @@ -83,6 +95,12 @@
display: table-row-group;
}

.custom-table table tbody th {
display: table-cell;
text-align: left;
width: auto;
}

.custom-table table th::before,
.custom-table table td::before {
display: none;
Expand Down
12 changes: 9 additions & 3 deletions tailoff/js/components/table.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,15 @@ export class TableComponent {

const tableHead = table.querySelector('thead');
if (tableHead) {
const headings = Array.from(tableHead.querySelectorAll('th')).map((th) => th.innerText);
Array.from(table.querySelectorAll('td')).forEach((td, index) => {
td.setAttribute('data-label', headings[index % headings.length]);
const headings = Array.from(tableHead.querySelectorAll('th'))
.reverse()
.map((th) => th.innerText);
Array.from(table.querySelectorAll('tbody tr')).forEach((tr) => {
Array.from(tr.querySelectorAll('td'))
.reverse()
.forEach((td, index) => {
td.setAttribute('data-label', headings[index]);
});
});
}
}
Expand Down