Skip to content

Commit b724dbd

Browse files
authored
AdvancedTable - add @maxHeight argument and fix the container styles (#2865)
1 parent 5d72ec7 commit b724dbd

File tree

9 files changed

+247
-154
lines changed

9 files changed

+247
-154
lines changed

.changeset/rotten-geese-swim.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@hashicorp/design-system-components": patch
3+
---
4+
5+
`AdvancedTable` - Added `@maxHeight` argument which automatically adds a sticky header when set and sets the max height of the AdvancedTable. Also updated the container styles to constrain the Advanced Table width to the parent's width.

packages/components/src/components/hds/advanced-table/index.hbs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
{{style
2222
grid-template-columns=this.gridTemplateColumns
2323
--hds-advanced-table-sticky-column-offset=this.stickyColumnOffset
24+
max-height=@maxHeight
2425
}}
2526
{{this._setUpScrollWrapper}}
2627
>

packages/components/src/components/hds/advanced-table/index.ts

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ export interface HdsAdvancedTableSignature {
132132
hasStickyHeader?: boolean;
133133
hasStickyFirstColumn?: boolean;
134134
childrenKey?: string;
135+
maxHeight?: string;
135136
};
136137
Blocks: {
137138
body?: [
@@ -311,6 +312,16 @@ export default class HdsAdvancedTable extends Component<HdsAdvancedTableSignatur
311312
return density;
312313
}
313314

315+
get hasStickyHeader(): boolean {
316+
if (this.args.maxHeight && this.args.hasStickyHeader !== false) {
317+
return true;
318+
} else if (this.args.hasStickyHeader && !this.args.maxHeight) {
319+
assert('Must set @maxHeight to use @hasStickyHeader.', false);
320+
}
321+
322+
return false;
323+
}
324+
314325
get valign(): HdsAdvancedTableVerticalAlignment {
315326
const { valign = DEFAULT_VALIGN } = this.args;
316327

@@ -371,7 +382,7 @@ export default class HdsAdvancedTable extends Component<HdsAdvancedTableSignatur
371382
get theadClassNames(): string {
372383
const classes = ['hds-advanced-table__thead'];
373384

374-
if (this.args.hasStickyHeader) {
385+
if (this.hasStickyHeader) {
375386
classes.push('hds-advanced-table__thead--sticky');
376387
}
377388

@@ -411,12 +422,12 @@ export default class HdsAdvancedTable extends Component<HdsAdvancedTableSignatur
411422

412423
// sticky header
413424
if (element.scrollTop > 0) {
414-
if (this.args.hasStickyHeader) {
425+
if (this.hasStickyHeader) {
415426
this.isStickyHeaderPinned = true;
416427
}
417428
this.showScrollIndicatorTop = true;
418429
} else {
419-
if (this.args.hasStickyHeader) {
430+
if (this.hasStickyHeader) {
420431
this.isStickyHeaderPinned = false;
421432
}
422433
this.showScrollIndicatorTop = false;
@@ -440,7 +451,7 @@ export default class HdsAdvancedTable extends Component<HdsAdvancedTableSignatur
440451
this.scrollIndicatorDimensions = getScrollIndicatorDimensions(
441452
element,
442453
this._theadElement,
443-
hasStickyHeader,
454+
this.hasStickyHeader,
444455
hasStickyFirstColumn
445456
);
446457

@@ -452,11 +463,7 @@ export default class HdsAdvancedTable extends Component<HdsAdvancedTableSignatur
452463
}
453464
};
454465

455-
const {
456-
hasStickyHeader = false,
457-
hasStickyFirstColumn = false,
458-
isSelectable = false,
459-
} = this.args;
466+
const { hasStickyFirstColumn = false, isSelectable = false } = this.args;
460467

461468
this._resizeObserver = new ResizeObserver((entries) => {
462469
entries.forEach(() => {

packages/components/src/styles/components/advanced-table.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ $hds-advanced-table-cell-padding-tall: 22px 16px 21px 16px; // the 1px differenc
2525

2626
.hds-advanced-table__container {
2727
position: relative;
28+
display: grid;
29+
align-items: start;
2830
width: 100%;
2931
height: 100%;
3032
// add overflow hidden and border radius so scroll shadows appear rounded in the corners

showcase/app/components/mock/app/main/generic-advanced-table.gts

Lines changed: 81 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -519,95 +519,93 @@ export default class MockAppMainGenericAdvancedTable extends Component<MockAppMa
519519
}
520520

521521
<template>
522-
<div class="mock-app-main-generic-advanced-table-wrapper">
523-
<HdsAdvancedTable
524-
@columns={{this.demoColumns}}
525-
@model={{this.demoModel}}
526-
@hasStickyHeader={{true}}
527-
@isSelectable={{true}}
528-
@isStriped={{true}}
529-
@onSelectionChange={{this.onSelectionChange}}
530-
@hasStickyFirstColumn={{true}}
531-
>
532-
<:body as |B|>
533-
{{! @glint-expect-error }}
534-
<B.Tr @selectionKey={{get B.data "name"}}>
535-
<B.Th>
536-
<HdsLinkInline @href="www.google.com">
537-
{{! @glint-expect-error }}
538-
{{get B.data "name"}}
539-
</HdsLinkInline>
540-
</B.Th>
541-
<B.Td>
542-
<HdsLinkInline @href="www.google.com">
543-
{{! @glint-expect-error }}
544-
{{get B.data "project-name"}}
545-
</HdsLinkInline>
546-
</B.Td>
547-
<B.Td>
548-
<HdsLinkInline @href="www.google.com">
549-
{{! @glint-expect-error }}
550-
{{get B.data "current-run-id"}}
551-
</HdsLinkInline>
552-
</B.Td>
553-
<B.Td>
554-
<HdsBadge
555-
@type="outlined"
556-
{{! @glint-expect-error }}
557-
@text={{get B.data "run-status"}}
558-
{{! @glint-expect-error }}
559-
@color={{get B.data "run-status-color"}}
560-
/>
561-
</B.Td>
562-
<B.Td>
522+
<HdsAdvancedTable
523+
@columns={{this.demoColumns}}
524+
@model={{this.demoModel}}
525+
@maxHeight="600px"
526+
@isSelectable={{true}}
527+
@isStriped={{true}}
528+
@onSelectionChange={{this.onSelectionChange}}
529+
@hasStickyFirstColumn={{true}}
530+
>
531+
<:body as |B|>
532+
{{! @glint-expect-error }}
533+
<B.Tr @selectionKey={{get B.data "name"}}>
534+
<B.Th>
535+
<HdsLinkInline @href="www.google.com">
563536
{{! @glint-expect-error }}
564-
{{get B.data "current-run-applied"}}
565-
</B.Td>
566-
<B.Td>
537+
{{get B.data "name"}}
538+
</HdsLinkInline>
539+
</B.Th>
540+
<B.Td>
541+
<HdsLinkInline @href="www.google.com">
567542
{{! @glint-expect-error }}
568-
{{get B.data "vcs-repo"}}
569-
</B.Td>
570-
<B.Td>
571-
<HdsLinkInline @href="www.google.com">
572-
{{! @glint-expect-error }}
573-
{{get B.data "module-count"}}
574-
</HdsLinkInline>
575-
</B.Td>
576-
<B.Td>
543+
{{get B.data "project-name"}}
544+
</HdsLinkInline>
545+
</B.Td>
546+
<B.Td>
547+
<HdsLinkInline @href="www.google.com">
577548
{{! @glint-expect-error }}
578-
{{get B.data "modules"}}
579-
</B.Td>
580-
<B.Td>
581-
<HdsLinkInline @href="www.google.com">
582-
{{! @glint-expect-error }}
583-
{{get B.data "provider-count"}}
584-
</HdsLinkInline>
585-
</B.Td>
586-
<B.Td>
549+
{{get B.data "current-run-id"}}
550+
</HdsLinkInline>
551+
</B.Td>
552+
<B.Td>
553+
<HdsBadge
554+
@type="outlined"
587555
{{! @glint-expect-error }}
588-
{{get B.data "providers"}}
589-
</B.Td>
590-
<B.Td>
556+
@text={{get B.data "run-status"}}
591557
{{! @glint-expect-error }}
592-
{{get B.data "terraform-version"}}
593-
</B.Td>
594-
<B.Td>
595-
<HdsLinkInline @href="www.google.com">
596-
{{! @glint-expect-error }}
597-
{{get B.data "state-terraform-version"}}
598-
</HdsLinkInline>
599-
</B.Td>
600-
<B.Td>
558+
@color={{get B.data "run-status-color"}}
559+
/>
560+
</B.Td>
561+
<B.Td>
562+
{{! @glint-expect-error }}
563+
{{get B.data "current-run-applied"}}
564+
</B.Td>
565+
<B.Td>
566+
{{! @glint-expect-error }}
567+
{{get B.data "vcs-repo"}}
568+
</B.Td>
569+
<B.Td>
570+
<HdsLinkInline @href="www.google.com">
601571
{{! @glint-expect-error }}
602-
{{get B.data "created"}}
603-
</B.Td>
604-
<B.Td>
572+
{{get B.data "module-count"}}
573+
</HdsLinkInline>
574+
</B.Td>
575+
<B.Td>
576+
{{! @glint-expect-error }}
577+
{{get B.data "modules"}}
578+
</B.Td>
579+
<B.Td>
580+
<HdsLinkInline @href="www.google.com">
605581
{{! @glint-expect-error }}
606-
{{get B.data "updated"}}
607-
</B.Td>
608-
</B.Tr>
609-
</:body>
610-
</HdsAdvancedTable>
611-
</div>
582+
{{get B.data "provider-count"}}
583+
</HdsLinkInline>
584+
</B.Td>
585+
<B.Td>
586+
{{! @glint-expect-error }}
587+
{{get B.data "providers"}}
588+
</B.Td>
589+
<B.Td>
590+
{{! @glint-expect-error }}
591+
{{get B.data "terraform-version"}}
592+
</B.Td>
593+
<B.Td>
594+
<HdsLinkInline @href="www.google.com">
595+
{{! @glint-expect-error }}
596+
{{get B.data "state-terraform-version"}}
597+
</HdsLinkInline>
598+
</B.Td>
599+
<B.Td>
600+
{{! @glint-expect-error }}
601+
{{get B.data "created"}}
602+
</B.Td>
603+
<B.Td>
604+
{{! @glint-expect-error }}
605+
{{get B.data "updated"}}
606+
</B.Td>
607+
</B.Tr>
608+
</:body>
609+
</HdsAdvancedTable>
612610
</template>
613611
}

showcase/app/styles/mock-components/app.scss

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,3 @@
4242
gap: 12px;
4343
margin-bottom: 12px;
4444
}
45-
46-
.mock-app-main-generic-advanced-table-wrapper {
47-
// TODO remove after https://hashicorp.atlassian.net/browse/HDS-4751 is done
48-
display: grid;
49-
height: 600px;
50-
overflow: auto;
51-
}

showcase/app/styles/showcase-pages/advanced-table.scss

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,17 @@ body.components-advanced-table {
2222
.shw-component-advanced-table-cell-content-div {
2323
display: flex;
2424
align-items: center;
25-
25+
2626
.hds-icon {
2727
flex: none;
2828
margin-right: 5px;
2929
}
3030
}
3131

32-
.shw-component-advanced-table-fixed-height-wrapper {
33-
height: 400px;
34-
}
35-
3632
.shw-component-advanced-table-fixed-width-wrapper {
3733
width: 400px;
3834
}
3935

40-
.shw-component-advanced-table-fixed-dimensions-wrapper {
41-
width: 400px;
42-
height: 400px;
43-
}
44-
4536
.shw-component-advanced-table-with-pagination-demo-wrapper {
4637
.hds-table + .hds-pagination {
4738
margin-top: 16px;
@@ -77,4 +68,4 @@ body.components-advanced-table {
7768
animation: shw-component-table-user-bounce 1s infinite ease-in-out;
7869
}
7970

80-
}
71+
}

0 commit comments

Comments
 (0)