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

fix(table): add container query support #1881

Merged
merged 5 commits into from
Sep 18, 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 .changeset/gentle-rings-scream.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rhds/elements": patch
---

`<rh-table>`: adds container query support
246 changes: 124 additions & 122 deletions elements/rh-table/rh-table-lightdom.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
rh-table {
container: host / inline-size;

--_row-border:
var(--rh-table-row-border,
var(--rh-border-width-sm, 1px)
Expand All @@ -12,151 +14,151 @@ rh-table {
var(--rh-table-column-background-hover-color,
rgb(var(--rh-color-blue-50-rgb, 0 102 204)
/ var(--rh-opacity-10, 10%)));
}

rh-table table {
min-width: 100%;
margin: 0 auto;
table-layout: fixed;
border: 0;
border-collapse: collapse;
}

rh-table thead th {
position: relative;
padding-top: var(--rh-space-lg, 16px);
padding-bottom: var(--rh-space-lg, 16px);
text-align: left;
font-weight: var(--rh-font-weight-heading-bold, 700);
}

rh-table tr {
border-bottom: var(--_row-border);
}

rh-table tr:hover {
background: var(--_row-background-hover-color);
}

rh-table tr > * {
border: none;
}

rh-table :is(tr, col) {
transition: background 0.3s ease-out;
}

rh-table a {
color: var(--rh-color-interactive-primary-default-on-light, #0066cc);
text-decoration: none;
}

rh-table a:hover {
color: var(--rh-color-interactive-primary-hover-on-light, #003366);
text-decoration: underline;
}

rh-table caption {
font-family: var(--rh-font-family-body-text, RedHatText, 'Red Hat Text', 'Noto Sans Arabic', 'Noto Sans Hebrew', 'Noto Sans JP', 'Noto Sans KR', 'Noto Sans Malayalam', 'Noto Sans SC', 'Noto Sans TC', 'Noto Sans Thai', Helvetica, Arial, sans-serif);
font-size: var(--rh-font-size-body-text-lg, 1.125rem);
font-weight: var(--rh-font-weight-heading-bold, 700);
line-height: var(--rh-line-height-body-text, 1.5);
margin-bottom: var(--rh-space-xl, 24px);
text-align: center;
font-style: normal;
}

rh-table :is(th, td) {
padding-right: var(--rh-space-lg, 16px);
padding-left: var(--rh-space-lg, 16px);
}

rh-table td {
padding-top: var(--rh-space-xl, 24px);
padding-bottom: var(--rh-space-xl, 24px);
}

rh-table :is(col.active) {
background: var(--_column-background-hover-color);
}

@media (max-width: 768px) {
rh-table table {
display: grid;
& thead {
& th {
position: relative;
padding-block: var(--rh-space-lg, 16px);
text-align: start;
font-weight: var(--rh-font-weight-heading-bold, 700);
}
}

rh-table thead {
display: none;
visibility: hidden;
& table {
min-width: 100%;
margin: 0 auto;
table-layout: fixed;
border: 0;
border-collapse: collapse;
}

rh-table tbody {
display: block;
}

rh-table :not(thead) ~ tbody tr {
display: grid;
grid-auto-columns: auto;
grid-auto-flow: column;
& :is(tr, col) {
transition: background 0.3s ease-out;
}

rh-table thead ~ tbody tr {
border: none;
display: grid;
grid-template-columns: 1fr;
height: auto;
grid-auto-columns: max-content;
grid-auto-flow: unset;
& :is(th, td) {
padding-inline: var(--rh-space-lg, 16px);
}

rh-table thead ~ tbody tr:first-child {
border-top: var(--_row-border);
& :is(col.active) {
background: var(--_column-background-hover-color);
}

rh-table thead ~ tbody tr:last-child {
border-bottom: var(--_row-border);
}
& tr {
border-block-end: var(--_row-border);

rh-table thead ~ tbody tr:nth-child(even) {
background: var(--_row-background-hover-color);
}
&:hover {
background: var(--_row-background-hover-color);
}

rh-table thead ~ tbody tr:hover {
background: var(---_column-background-hover-color);
& > * {
border: none;
}
}

rh-table thead ~ tbody tr > * {
padding: var(--rh-space-lg, 16px);
& td {
padding-block: var(--rh-space-xl, 24px);
}

rh-table thead ~ tbody tr th {
text-align: center;
}
& a {
color: var(--rh-color-interactive-primary-default-on-light, #0066cc);
text-decoration: none;

rh-table thead ~ tbody tr :is(th, td) {
padding-top: calc(var(--rh-space-md, 8px) + var(--rh-space-xs, 4px));
padding-bottom: calc(var(--rh-space-md, 8px) + var(--rh-space-xs, 4px));
display: grid;
grid-column-gap: var(--rh-space-lg, 16px);
grid-template-columns: 1fr minmax(0, 1.5fr);
align-items: start;
white-space: normal;
word-wrap: break-word;
text-align: left;
&:hover {
color: var(--rh-color-interactive-primary-hover-on-light, #003366);
text-decoration: underline;
}
}

rh-table thead ~ tbody tr :is(td,th):before {
& caption {
font-family: var(--rh-font-family-body-text, RedHatText, 'Red Hat Text', 'Noto Sans Arabic', 'Noto Sans Hebrew', 'Noto Sans JP', 'Noto Sans KR', 'Noto Sans Malayalam', 'Noto Sans SC', 'Noto Sans TC', 'Noto Sans Thai', Helvetica, Arial, sans-serif);
font-size: var(--rh-font-size-body-text-lg, 1.125rem);
font-weight: var(--rh-font-weight-heading-bold, 700);
text-align: left;
content: attr(data-label);
display: inline-block;
line-height: var(--rh-line-height-body-text, 1.5);
margin-block-end: var(--rh-space-xl, 24px);
text-align: center;
font-style: normal;
}
}

rh-table thead ~ tbody tr:first-child td:first-child {
padding-top: var(--rh-space-lg, 16px);
}
@container host (max-width: 768px) {
table {
display: grid;

rh-table thead ~ tbody tr:last-child td:last-child {
padding-bottom: var(--rh-space-lg, 16px);
& *:not(thead) + tbody {
& tr {
display: grid;
grid-auto-columns: auto;
grid-auto-flow: column;
}
}

& thead {
display: none;
visibility: hidden;

& ~ tbody {
display: block;

& tr {
border: none;
display: grid;
grid-template-columns: 1fr;
height: auto;
grid-auto-columns: max-content;
grid-auto-flow: unset;

&:first-child {
border-block-start: var(--_row-border);

& td:first-child {
padding-block-start: var(--rh-space-lg, 16px);
}

& td:last-child {
padding-block-end: var(--rh-space-lg, 16px);
}
}

&:nth-child(even) {
background: var(--_row-background-hover-color);
}

&:last-child {
border-block-end: var(--_row-border);
}

&:hover {
background: var(---_column-background-hover-color);
}

& > * {
padding: var(--rh-space-lg, 16px);
}

& :is(th, td) {
padding-block: calc(var(--rh-space-md, 8px) + var(--rh-space-xs, 4px));
display: grid;
grid-column-gap: var(--rh-space-lg, 16px);
grid-template-columns: 1fr minmax(0, 1.5fr);
align-items: start;
white-space: normal;
word-wrap: break-word;
text-align: start;
}

& :is(td,th):before {
font-weight: var(--rh-font-weight-heading-bold, 700);
text-align: start;
content: attr(data-label);
display: inline-block;
}

& th {
text-align: center;
}
}
}
}
}
}
Loading