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

SPIKE: DataGrid #2432

Draft
wants to merge 2 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
10 changes: 7 additions & 3 deletions packages/components/src/components/hds/table/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
SPDX-License-Identifier: MPL-2.0
}}

<table class={{this.classNames}} ...attributes>
<table class={{this.classNames}} ...attributes role={{if @isGrid "grid"}}>
{{#if @columns}}
<caption class="sr-only" aria-live="polite">{{@caption}} {{this.sortedMessageText}}</caption>
{{else if @caption}}
Expand All @@ -30,6 +30,8 @@
@align={{column.align}}
@width={{column.width}}
@tooltip={{column.tooltip}}
@isGrid={{@isGrid}}
@isActiveGridCell={{if (eq column.key this.currentActiveGridCell) true false}}
>
{{column.label}}
</Hds::Table::ThSort>
Expand All @@ -39,6 +41,8 @@
@width={{column.width}}
@tooltip={{column.tooltip}}
@isVisuallyHidden={{column.isVisuallyHidden}}
@isGrid={{@isGrid}}
@isActiveGridCell={{if (eq column.key this.currentActiveGridCell) true false}}
>{{column.label}}</Hds::Table::Th>
{{/if}}
{{/each}}
Expand Down Expand Up @@ -88,7 +92,7 @@
selectionAriaLabelSuffix=@selectionAriaLabelSuffix
)
Th=(component "hds/table/th" scope="row")
Td=(component "hds/table/td" align=@align)
Td=(component "hds/table/td" align=@align isGrid=@isGrid)
data=record
)
to="body"
Expand All @@ -107,7 +111,7 @@
selectionAriaLabelSuffix=@selectionAriaLabelSuffix
)
Th=(component "hds/table/th" scope="row")
Td=(component "hds/table/td" align=@align)
Td=(component "hds/table/td" align=@align isGrid=@isGrid)
sortBy=this.sortBy
sortOrder=this.sortOrder
)
Expand Down
4 changes: 4 additions & 0 deletions packages/components/src/components/hds/table/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export interface HdsTableArgs {
density?: HdsTableDensities;
identityKey?: string;
isFixedLayout?: boolean;
isGrid?: boolean;
isSelectable?: boolean;
isStriped?: boolean;
model?: HdsTableModel;
Expand Down Expand Up @@ -93,6 +94,9 @@ export default class HdsTable extends Component<HdsTableArgs> {
undefined;
selectableRows: HdsTableSelectableRow[] = [];
@tracked isSelectAllCheckboxSelected?: boolean = undefined;
@tracked currentActiveGridCell?: string = this.args.isGrid
? this.args?.columns?.[0]?.key ?? undefined
: undefined;

get getSortCriteria(): string | HdsTableSortingFunction<unknown> {
// get the current column
Expand Down
7 changes: 6 additions & 1 deletion packages/components/src/components/hds/table/td.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
Copyright (c) HashiCorp, Inc.
SPDX-License-Identifier: MPL-2.0
}}
<td class={{this.classNames}} ...attributes>
<td
class={{this.classNames}}
...attributes
role={{if @isGrid "gridcell"}}
tabindex={{if @isGrid (if @isActiveGridCell 0 -1)}}
>
{{yield}}
</td>
10 changes: 10 additions & 0 deletions packages/components/src/components/hds/table/td.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export const DEFAULT_ALIGN = HdsTableHorizontalAlignmentValues.Left;
export interface HdsTableTdArgs {
Args: {
align?: HdsTableHorizontalAlignment;
isGrid?: boolean;
isActiveGridCell?: boolean;
};
Blocks: {
default: [];
Expand Down Expand Up @@ -59,6 +61,14 @@ export default class HdsTableTd extends Component<HdsTableTdArgs> {
classes.push(`hds-table__td--align-${this.align}`);
}

if (this.args.isGrid) {
classes.push(`hds-table__td--gridcell`);
}

if (this.args.isActiveGridCell) {
classes.push(`hds-table__td--gridcell-active`);
}

return classes.join(' ');
}
}
1 change: 1 addition & 0 deletions packages/components/src/components/hds/table/th-sort.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
{{style width=@width minWidth=@width}}
...attributes
scope="col"
tabindex={{if @isGrid (if @isActiveGridCell 0 -1)}}
>
<div class="hds-table__th-content">
<span id={{this.labelId}} class="hds-typography-body-200 hds-font-weight-semibold">{{yield}}</span>
Expand Down
10 changes: 10 additions & 0 deletions packages/components/src/components/hds/table/th-sort.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ export interface HdsTableThSortArgs {
sortOrder?: HdsTableThSortOrder;
tooltip?: string;
width?: string;
isGrid?: boolean;
isActiveGridCell?: boolean;
};
Blocks: {
default: [];
Expand Down Expand Up @@ -96,6 +98,14 @@ export default class HdsTableThSort extends Component<HdsTableThSortArgs> {
classes.push(`hds-table__th--align-${this.align}`);
}

if (this.args.isGrid) {
classes.push(`hds-table__td--gridcell`);
}

if (this.args.isActiveGridCell) {
classes.push(`hds-table__td--gridcell-active`);
}

return classes.join(' ');
}
}
8 changes: 7 additions & 1 deletion packages/components/src/components/hds/table/th.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@
Copyright (c) HashiCorp, Inc.
SPDX-License-Identifier: MPL-2.0
}}
<th class={{this.classNames}} {{style width=@width minWidth=@width}} ...attributes scope={{(or @scope "col")}}>
<th
class={{this.classNames}}
{{style width=@width minWidth=@width}}
...attributes
scope={{(or @scope "col")}}
tabindex={{if @isGrid (if @isActiveGridCell 0 -1)}}
>
{{#if @isVisuallyHidden}}
<span class="sr-only">{{yield}}</span>
{{else}}
Expand Down
10 changes: 10 additions & 0 deletions packages/components/src/components/hds/table/th.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ export interface HdsTableThArgs {
scope?: HdsTableScope;
tooltip?: string;
width?: string;
isGrid?: boolean;
isActiveGridCell?: boolean;
};
Blocks: {
default: [];
Expand Down Expand Up @@ -68,6 +70,14 @@ export default class HdsTableTh extends Component<HdsTableThArgs> {
classes.push(`hds-table__th--align-${this.align}`);
}

if (this.args.isGrid) {
classes.push(`hds-table__td--gridcell`);
}

if (this.args.isActiveGridCell) {
classes.push(`hds-table__td--gridcell-active`);
}

return classes.join(' ');
}
}
5 changes: 5 additions & 0 deletions packages/components/src/styles/components/table.scss
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ $hds-table-cell-padding-medium: 14px 16px 13px 16px; // the 1px difference is to
$hds-table-cell-padding-short: 6px 16px 5px 16px; // the 1px difference is to account for the bottom border
$hds-table-cell-padding-tall: 22px 16px 21px 16px; // the 1px difference is to account for the bottom border

.hds-table {
.hds-table__td--gridcell-active {
background-color: red
}
}

// TABLE

Expand Down
33 changes: 33 additions & 0 deletions showcase/app/templates/components/table.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,39 @@

<Shw::Text::H1>Table</Shw::Text::H1>

<Hds::Table
@isGrid={{true}}
@model={{this.model.music}}
@columns={{array
(hash key="artist" label="Artist" isSortable=true)
(hash key="album" label="Album" isSortable=true)
(hash key="year" label="Release Year" isSortable=true)
(hash key="other" label="Additional Actions")
}}
>
<:body as |B|>
<B.Tr>
<B.Td><Hds::Link::Inline @href="#showcase">{{B.data.artist}}</Hds::Link::Inline></B.Td>
<B.Td>
<div class="shw-component-table-cell-content-div">
<Hds::Icon @name={{B.data.icon}} @isInline={{true}} />
{{B.data.album}}
</div>
</B.Td>
<B.Td>
<Hds::Badge @text={{B.data.year}} @type={{B.data.badge-type}} @color={{B.data.badge-color.name}} />
</B.Td>
<B.Td>
<Hds::ButtonSet>
<Hds::Button @text="Add" @isIconOnly={{true}} @icon="plus" @size="small" />
<Hds::Button @text="Edit" @isIconOnly={{true}} @icon="edit" @size="small" @color="secondary" />
<Hds::Button @text="Delete" @isIconOnly={{true}} @icon="trash" @size="small" @color="critical" />
</Hds::ButtonSet>
</B.Td>
</B.Tr>
</:body>
</Hds::Table>

<section data-test-percy>
<Shw::Text::H2>Data model</Shw::Text::H2>

Expand Down
Loading