UNPKG

@hashicorp/design-system-components

Version:
103 lines (97 loc) 2.36 kB
import { tracked } from '@glimmer/tracking'; import { action } from '@ember/object'; import { guidFor } from '@ember/object/internals'; import { g, i, n } from 'decorator-transforms/runtime'; /** * Copyright (c) HashiCorp, Inc. * SPDX-License-Identifier: MPL-2.0 */ class HdsAdvancedTableRow { id = guidFor(this); // row data static { g(this.prototype, "isOpen", [tracked], function () { return false; }); } #isOpen = (i(this, "isOpen"), void 0); static { g(this.prototype, "cells", [tracked], function () { return []; }); } #cells = (i(this, "cells"), void 0); children = []; childrenKey; table; get hasChildren() { return this.children.length > 0; } get showChildren() { return this.isOpen && this.hasChildren; } get orderedCells() { const { columnOrder, hasReorderableColumns } = this.table; if (hasReorderableColumns) { return columnOrder.reduce((acc, key) => { const cell = this.cells.find(cell => cell.columnKey === key); if (cell !== undefined) { acc.push(cell); } return acc; }, []); } else { return this.cells; } } constructor(args) { const { columns, table } = args; this.table = table; this.cells = columns.map(column => { const cell = args[column.key ?? '']; return { columnKey: column.key ?? '', content: cell }; }); // set row data Object.assign(this, args); this.childrenKey = args.childrenKey ?? 'children'; const childModels = args[this.childrenKey]; if (Array.isArray(childModels)) { this.children = childModels.map(child => new HdsAdvancedTableRow({ ...child, columns: args.columns, childrenKey: this.childrenKey })); } } openAll() { this.isOpen = true; this.children.forEach(child => child.openAll()); } static { n(this.prototype, "openAll", [action]); } collapseAll() { this.isOpen = false; this.children.forEach(child => child.collapseAll()); } static { n(this.prototype, "collapseAll", [action]); } onClickToggle() { this.isOpen = !this.isOpen; } static { n(this.prototype, "onClickToggle", [action]); } } export { HdsAdvancedTableRow as default }; //# sourceMappingURL=row.js.map