@hashicorp/design-system-components
Version:
Helios Design System Components
60 lines (57 loc) • 1.84 kB
JavaScript
import Component from '@glimmer/component';
import { cached } from '@glimmer/tracking';
import { guidFor } from '@ember/object/internals';
import { hash } from '@ember/helper';
import { precompileTemplate } from '@ember/template-compilation';
import { setComponentTemplate } from '@ember/component';
import { n } from 'decorator-transforms/runtime';
class HdsAdvancedTableBody extends Component {
get rows() {
const {
sortedModel,
childrenKey,
expandedRowIds
} = this.args;
const rows = [];
const traverse = (items, depth, ancestorsExpanded) => {
for (const item of items) {
const id = guidFor(item);
const isExpanded = expandedRowIds.has(id);
const children = item[childrenKey];
const hasChildren = Array.isArray(children) && children.length > 0;
const isVisible = depth === 0 || ancestorsExpanded;
rows.push({
id,
source: item,
depth,
isExpanded,
isVisible,
hasChildren
});
if (hasChildren) {
traverse(children, depth + 1, isVisible && isExpanded);
}
}
};
traverse(sortedModel, 0, false);
return rows;
}
static {
n(this.prototype, "rows", [cached]);
}
get lastVisibleRowId() {
const visibleRows = this.rows.filter(row => row.isVisible);
const lastVisibleRow = visibleRows[visibleRows.length - 1];
return lastVisibleRow?.id;
}
static {
setComponentTemplate(precompileTemplate("<div class=\"hds-advanced-table__tbody\" role=\"rowgroup\" ...attributes>\n {{yield (hash lastVisibleRowId=this.lastVisibleRowId rows=this.rows)}}\n</div>", {
strictMode: true,
scope: () => ({
hash
})
}), this);
}
}
export { HdsAdvancedTableBody as default };
//# sourceMappingURL=body.js.map