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

AdvancedTable: add support for a sticky column #2770

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from
Draft
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
240 changes: 133 additions & 107 deletions packages/components/src/components/hds/advanced-table/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,119 +2,145 @@
Copyright (c) HashiCorp, Inc.
SPDX-License-Identifier: MPL-2.0
}}

<div
class={{this.classNames}}
...attributes
role="grid"
aria-describedby={{this._captionId}}
{{style grid-template-columns=this.gridTemplateColumns}}
{{this._setUpObservers}}
>
<div id={{this._captionId}} class="sr-only hds-advanced-table__caption" aria-live="polite">
{{@caption}}
{{this.sortedMessageText}}
</div>
<div class="hds-advanced-table__thead {{if @hasStickyHeader 'hds-advanced-table__thead--sticky'}}" role="rowgroup">
<Hds::AdvancedTable::Tr
@selectionScope="col"
@onClickSortBySelected={{if @selectableColumnKey (fn this.setSortBy @selectableColumnKey)}}
@sortBySelectedOrder={{if (eq this._sortBy @selectableColumnKey) this._sortOrder}}
@isSelectable={{this.isSelectable}}
@onSelectionChange={{this.onSelectionAllChange}}
@didInsert={{this.didInsertSelectAllCheckbox}}
@willDestroy={{this.willDestroySelectAllCheckbox}}
@selectionAriaLabelSuffix="all rows"
<div {{style position="relative" height="100%" width="100%"}} {{this._setUpOuter}}>
<div class={{this.scrollWrapperClassNames}} {{this._setUpScrollWrapper}}>
<div
class={{this.classNames}}
...attributes
role="grid"
aria-describedby={{this._captionId}}
{{style
grid-template-columns=this.gridTemplateColumns
--hds-advanced-table-sticky-column-offset=(concat this.stickyColumnOffset "px")
}}
{{this._setUpObservers}}
>
{{#each @columns as |column|}}
{{#if column.isSortable}}
<Hds::AdvancedTable::ThSort
@sortOrder={{if (eq column.key this._sortBy) this._sortOrder}}
@onClickSort={{fn this.setSortBy column.key}}
@align={{column.align}}
@tooltip={{column.tooltip}}
>
{{column.label}}
</Hds::AdvancedTable::ThSort>
{{else}}
<Hds::AdvancedTable::Th
@align={{column.align}}
@tooltip={{column.tooltip}}
@isVisuallyHidden={{column.isVisuallyHidden}}
@isExpandable={{column.isExpandable}}
@onClickToggle={{this.onExpandAllClick}}
@isExpanded={{this._expandAllButtonState}}
@hasExpandAllButton={{this.hasNestedRows}}
@didInsertExpandButton={{this.didInsertExpandAllButton}}
@willDestroyExpandButton={{this.willDestroyExpandAllButton}}
>{{column.label}}</Hds::AdvancedTable::Th>
{{/if}}
{{/each}}
</Hds::AdvancedTable::Tr>
</div>
<div id={{this._captionId}} class="sr-only hds-advanced-table__caption" aria-live="polite">
{{@caption}}
{{this.sortedMessageText}}
</div>
<div
class="hds-advanced-table__thead {{if @hasStickyHeader 'hds-advanced-table__thead--sticky'}}"
role="rowgroup"
>
<Hds::AdvancedTable::Tr
@selectionScope="col"
@onClickSortBySelected={{if @selectableColumnKey (fn this.setSortBy @selectableColumnKey)}}
@sortBySelectedOrder={{if (eq this._sortBy @selectableColumnKey) this._sortOrder}}
@isSelectable={{this.isSelectable}}
@onSelectionChange={{this.onSelectionAllChange}}
@didInsert={{this.didInsertSelectAllCheckbox}}
@willDestroy={{this.willDestroySelectAllCheckbox}}
@selectionAriaLabelSuffix="all rows"
@hasStickyColumn={{@hasStickyFirstColumn}}
>
{{#each @columns as |column index|}}
{{#if column.isSortable}}
<Hds::AdvancedTable::ThSort
@sortOrder={{if (eq column.key this._sortBy) this._sortOrder}}
@onClickSort={{fn this.setSortBy column.key}}
@align={{column.align}}
@tooltip={{column.tooltip}}
@isStickyColumn={{if (and (eq index 0) @hasStickyFirstColumn) true}}
>
{{column.label}}
</Hds::AdvancedTable::ThSort>
{{else}}
<Hds::AdvancedTable::Th
@align={{column.align}}
@tooltip={{column.tooltip}}
@isVisuallyHidden={{column.isVisuallyHidden}}
@isExpandable={{column.isExpandable}}
@onClickToggle={{this.onExpandAllClick}}
@isExpanded={{this._expandAllButtonState}}
@hasExpandAllButton={{this.hasNestedRows}}
@didInsertExpandButton={{this.didInsertExpandAllButton}}
@willDestroyExpandButton={{this.willDestroyExpandAllButton}}
@isStickyColumn={{if (and (eq index 0) @hasStickyFirstColumn) true}}
>{{column.label}}</Hds::AdvancedTable::Th>
{{/if}}
{{/each}}
</Hds::AdvancedTable::Tr>
</div>

<div class="hds-advanced-table__tbody" role="rowgroup">
{{! ----------------------------------------------------------------------------------------
<div class="hds-advanced-table__tbody" role="rowgroup">
{{! ----------------------------------------------------------------------------------------
IMPORTANT: we loop on the `model` array and for each record
we yield the Tr/Td/Th elements _and_ the record itself as `data`
this means the consumer will *have to* use the `data` key to access it in their template
-------------------------------------------------------------------------------------------- }}
{{#each (sort-by this.getSortCriteria @model) key=this.identityKey as |record index|}}
{{#if this.hasNestedRows}}
<Hds::AdvancedTable::ExpandableTrGroup
@record={{record}}
@childrenKey={{this.childrenKey}}
@rowIndex={{index}}
@didInsertExpandButton={{this.didInsertExpandButton}}
@willDestroyExpandButton={{this.willDestroyExpandButton}}
@onClickToggle={{this.setExpandAllState}}
as |T|
>
{{yield
(hash
Tr=(component
"hds/advanced-table/tr" isParentRow=T.isExpandable depth=T.depth displayRow=T.shouldDisplayChildRows
)
Th=(component
"hds/advanced-table/th"
scope="row"
isExpandable=T.isExpandable
newLabel=T.id
parentId=T.parentId
onClickToggle=T.onClickToggle
isExpanded=T.isExpanded
depth=T.depth
didInsertExpandButton=T.didInsertExpandButton
willDestroyExpandButton=T.willDestroyExpandButton
{{#each (sort-by this.getSortCriteria @model) key=this.identityKey as |record index|}}
{{#if this.hasNestedRows}}
<Hds::AdvancedTable::ExpandableTrGroup
@record={{record}}
@childrenKey={{this.childrenKey}}
@rowIndex={{index}}
@didInsertExpandButton={{this.didInsertExpandButton}}
@willDestroyExpandButton={{this.willDestroyExpandButton}}
@onClickToggle={{this.setExpandAllState}}
as |T|
>
{{yield
(hash
Tr=(component
"hds/advanced-table/tr" isParentRow=T.isExpandable depth=T.depth displayRow=T.shouldDisplayChildRows
)
Th=(component
"hds/advanced-table/th"
scope="row"
isExpandable=T.isExpandable
newLabel=T.id
parentId=T.parentId
onClickToggle=T.onClickToggle
isExpanded=T.isExpanded
depth=T.depth
didInsertExpandButton=T.didInsertExpandButton
willDestroyExpandButton=T.willDestroyExpandButton
)
Td=(component "hds/advanced-table/td" align=@align)
data=T.data
isOpen=T.isExpanded
rowIndex=T.rowIndex
)
to="body"
}}
</Hds::AdvancedTable::ExpandableTrGroup>
{{else}}
{{yield
(hash
Tr=(component
"hds/advanced-table/tr"
selectionScope="row"
isSelectable=this.isSelectable
onSelectionChange=this.onSelectionRowChange
didInsert=this.didInsertRowCheckbox
willDestroy=this.willDestroyRowCheckbox
selectionAriaLabelSuffix=@selectionAriaLabelSuffix
hasStickyColumn=@hasStickyFirstColumn
)
Th=(component "hds/advanced-table/th" scope="row" isStickyColumn=@hasStickyFirstColumn)
Td=(component "hds/advanced-table/td" align=@align)
data=record
rowIndex=index
)
Td=(component "hds/advanced-table/td" align=@align)
data=T.data
isOpen=T.isExpanded
rowIndex=T.rowIndex
)
to="body"
}}
</Hds::AdvancedTable::ExpandableTrGroup>
{{else}}
{{yield
(hash
Tr=(component
"hds/advanced-table/tr"
selectionScope="row"
isSelectable=this.isSelectable
onSelectionChange=this.onSelectionRowChange
didInsert=this.didInsertRowCheckbox
willDestroy=this.willDestroyRowCheckbox
selectionAriaLabelSuffix=@selectionAriaLabelSuffix
)
Th=(component "hds/advanced-table/th" scope="row")
Td=(component "hds/advanced-table/td" align=@align)
data=record
rowIndex=index
)
to="body"
}}
{{/if}}
{{/each}}
to="body"
}}
{{/if}}
{{/each}}
</div>
</div>
</div>
{{#if (and @hasStickyFirstColumn this.showScrollIndicatorLeft)}}
<div
class="hds-advanced-table__scroll-indicator hds-advanced-table__scroll-indicator-left"
{{style height=(concat this.scrollIndicatorHeight "px") left=(concat this.scrollIndicatorLeftOffset "px")}}
/>
{{/if}}

{{!-- {{#if (and @hasStickyColumn this.showScrollIndicatorRight)}}
<div
class="hds-advanced-table__scroll-indicator hds-advanced-table__scroll-indicator-right"
{{style height=(concat this.scrollIndicatorHeight "px") right=(concat this.scrollIndicatorRightOffset "px")}}
/>
{{/if}} --}}
</div>
Loading