-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AdvancedTable
: create component (#2615)
- Loading branch information
1 parent
f3eed40
commit 96b94b6
Showing
49 changed files
with
7,010 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
"@hashicorp/design-system-components": minor | ||
--- | ||
|
||
`AdvancedTable` - Added `AdvancedTable` component and related sub-components | ||
|
||
Add `tabbable` as a dependency. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
packages/components/src/components/hds/advanced-table/expandable-tr-group.hbs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
{{! | ||
Copyright (c) HashiCorp, Inc. | ||
SPDX-License-Identifier: MPL-2.0 | ||
}} | ||
{{yield | ||
(hash | ||
data=@record | ||
isExpandable=this.hasChildren | ||
id=this._id | ||
depth=this.depth | ||
onClickToggle=this.onClickToggle | ||
isExpanded=this._isExpanded | ||
parentId=@parentId | ||
rowIndex=this.rowIndex | ||
) | ||
}} | ||
{{#if (and this.hasChildren this._isExpanded)}} | ||
{{#each this.children as |childRecord|}} | ||
<Hds::AdvancedTable::ExpandableTrGroup | ||
@record={{childRecord}} | ||
@depth={{this.childrenDepth}} | ||
@align={{@align}} | ||
@parentId={{this._id}} | ||
@childrenKey={{this.childrenKey}} | ||
@rowIndex="{{this.rowIndex}}.{{this.childrenDepth}}" | ||
as |T| | ||
> | ||
{{yield | ||
(hash | ||
data=T.data | ||
isExpandable=T.isExpandable | ||
depth=T.depth | ||
onClickToggle=T.onClickToggle | ||
isExpanded=T.isExpanded | ||
parentId=T.parentId | ||
id=T.id | ||
) | ||
}} | ||
</Hds::AdvancedTable::ExpandableTrGroup> | ||
{{/each}} | ||
{{/if}} |
97 changes: 97 additions & 0 deletions
97
packages/components/src/components/hds/advanced-table/expandable-tr-group.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/** | ||
* Copyright (c) HashiCorp, Inc. | ||
* SPDX-License-Identifier: MPL-2.0 | ||
*/ | ||
import Component from '@glimmer/component'; | ||
import { guidFor } from '@ember/object/internals'; | ||
import { tracked } from '@glimmer/tracking'; | ||
import { action } from '@ember/object'; | ||
|
||
import type { HdsAdvancedTableHorizontalAlignment } from './types.ts'; | ||
export interface HdsAdvancedTableExpandableTrGroupSignature { | ||
Args: { | ||
align?: HdsAdvancedTableHorizontalAlignment; | ||
depth?: number; | ||
record: Record<string, unknown>; | ||
parentId?: string; | ||
childrenKey?: string; | ||
rowIndex: number | string; | ||
}; | ||
Blocks: { | ||
default?: [ | ||
{ | ||
data: Record<string, unknown>; | ||
isExpandable: boolean; | ||
id?: string; | ||
parentId?: string; | ||
depth: number; | ||
onClickToggle?: () => void; | ||
isExpanded?: boolean; | ||
rowIndex?: string; | ||
}, | ||
]; | ||
}; | ||
Element: HTMLDivElement; | ||
} | ||
|
||
export default class HdsAdvancedTableExpandableTrGroup extends Component<HdsAdvancedTableExpandableTrGroupSignature> { | ||
@tracked private _isExpanded = false; | ||
|
||
private _id = guidFor(this); | ||
|
||
constructor( | ||
owner: unknown, | ||
args: HdsAdvancedTableExpandableTrGroupSignature['Args'] | ||
) { | ||
super(owner, args); | ||
|
||
this._isExpanded = | ||
this.args.record['isOpen'] && | ||
typeof this.args.record['isOpen'] === 'boolean' | ||
? this.args.record['isOpen'] | ||
: false; | ||
} | ||
|
||
get childrenKey(): string { | ||
const { childrenKey = 'children' } = this.args; | ||
|
||
return childrenKey; | ||
} | ||
|
||
get children(): Array<Record<string, unknown>> | undefined { | ||
const { record } = this.args; | ||
|
||
if (record[this.childrenKey]) { | ||
const children = record[this.childrenKey]; | ||
|
||
if (Array.isArray(children)) { | ||
return children; | ||
} | ||
} | ||
return undefined; | ||
} | ||
|
||
get hasChildren(): boolean { | ||
if (!this.children) return false; | ||
return true; | ||
} | ||
|
||
get depth(): number { | ||
const { depth = 0 } = this.args; | ||
|
||
return depth; | ||
} | ||
|
||
get rowIndex(): string { | ||
const { rowIndex } = this.args; | ||
return `${rowIndex}`; | ||
} | ||
|
||
get childrenDepth(): number { | ||
return this.depth + 1; | ||
} | ||
|
||
@action onClickToggle() { | ||
this._isExpanded = !this._isExpanded; | ||
} | ||
} |
Oops, something went wrong.