;
- @state() private _selectValue: number[] = [];
+ @state() private _selectValue: string[] = [];
@state() private _sortKey: string = "";
@@ -124,14 +131,14 @@ export default class BlTable extends LitElement {
return isHeaderCell ? this.multiple && this.selectable : this.selectable;
}
- isRowSelected(index: number) {
- return this.selectValue.includes(index);
+ isRowSelected(selectionKey: string) {
+ return this.selectValue.includes(selectionKey);
}
isAllSelected() {
return Array.from(this.tableRows)
.filter(tr => !(tr as BlTableRow).disabled)
- .every(tr => this.selectValue.includes((tr as BlTableRow).index));
+ .every(tr => this.selectValue.includes((tr as BlTableRow).selectionKey));
}
isAnySelected() {
@@ -139,35 +146,28 @@ export default class BlTable extends LitElement {
!this.isAllSelected() &&
Array.from(this.tableRows)
.filter(tr => !(tr as BlTableRow).disabled)
- .some(tr => this.selectValue.includes((tr as BlTableRow).index))
+ .some(tr => this.selectValue.includes((tr as BlTableRow).selectionKey))
);
}
- onSelectionChange(index: number, selected: boolean, isHeader = false) {
+ onSelectionChange(isHeader = false, selected: boolean, selectionKey: string) {
if (isHeader) {
if (selected) {
this.selectValue = Array.from(this.tableRows)
.filter(tr => !(tr as BlTableRow).disabled)
- .map(tr => (tr as BlTableRow).index);
+ .map(tr => (tr as BlTableRow).selectionKey);
} else {
this.selectValue = [];
}
} else {
- if (this.selectValue.includes(index) && !selected) {
- this.selectValue = this.selectValue.filter(v => v !== index);
- } else if (!this.selectValue.includes(index) && selected) {
- this.selectValue = [...this.selectValue, index];
+ if (this.selectValue.includes(selectionKey) && !selected) {
+ this.selectValue = this.selectValue.filter(v => v !== selectionKey);
+ } else if (!this.selectValue.includes(selectionKey) && selected) {
+ this.selectValue = [...this.selectValue, selectionKey];
}
}
this.onRowSelect(this.selectValue);
- this.updateComplete.then(() => {
- Array.from(this.querySelectorAll("bl-table-header-cell,bl-table-cell,bl-table-row")).map(
- com => {
- (com as BlTableHeaderCell | BlTableCell | BlTableRow).requestUpdate();
- }
- );
- });
}
onSortChange(sortKey: string, sortDirection: string) {
this._sortKey = sortKey;
diff --git a/src/components/table/table-cell/bl-table-cell.css b/src/components/table/table-cell/bl-table-cell.css
index 545a560d..080cd136 100644
--- a/src/components/table/table-cell/bl-table-cell.css
+++ b/src/components/table/table-cell/bl-table-cell.css
@@ -28,6 +28,18 @@
box-shadow: 8px 0 16px 0 rgb(39 49 66 / 10%);;
}
+.table-cell.shadow-left::before{
+ content: '';
+ position: absolute;
+ left: -1px;
+ top: 0;
+ width: 16px;
+ height: 100%;
+ z-index: -1;
+ border-left: 1px solid var(--bl-color-neutral-lighter);
+ box-shadow: -8px 0 16px 0 rgb(39 49 66 / 10%);
+}
+
bl-checkbox {
margin-right: var(--bl-size-m);
}
diff --git a/src/components/table/table-cell/bl-table-cell.test.ts b/src/components/table/table-cell/bl-table-cell.test.ts
index 3463e49c..ef10f44e 100644
--- a/src/components/table/table-cell/bl-table-cell.test.ts
+++ b/src/components/table/table-cell/bl-table-cell.test.ts
@@ -9,7 +9,7 @@ describe("bl-table-cell", () => {
//then
expect(el).instanceOf(BlTableCell);
expect(el.index).to.equal(-1);
- expect(el.rowIndex).to.equal(-1);
+ expect(el.selectionKey).to.equal("");
});
it("should be rendered with default values", async () => {
diff --git a/src/components/table/table-cell/bl-table-cell.ts b/src/components/table/table-cell/bl-table-cell.ts
index 7626b5a7..93f4903c 100644
--- a/src/components/table/table-cell/bl-table-cell.ts
+++ b/src/components/table/table-cell/bl-table-cell.ts
@@ -33,7 +33,7 @@ export default class BlTableCell extends LitElement {
return this.disableSelection;
}
get selectable() {
- return this.index === 0 && !!this._table?.isSelectable(false);
+ return this.index === 0 && !!this._table?.isSelectable(false) && this.selectionKey;
}
get index() {
const parent = this.parentNode;
@@ -43,8 +43,8 @@ export default class BlTableCell extends LitElement {
}
return [...parent.children].indexOf(this);
}
- get rowIndex(): number {
- return this._tableRow ? this._tableRow.index : -1;
+ get selectionKey(): string {
+ return this._tableRow ? this._tableRow.selectionKey : "";
}
get checked() {
return !!this._tableRow?.checked;
@@ -68,7 +68,7 @@ export default class BlTableCell extends LitElement {
}
onChange(event: CustomEvent) {
- this._table?.onSelectionChange(this.rowIndex, event.detail);
+ this._table?.onSelectionChange(false, event.detail, this.selectionKey);
}
private _renderCheckbox() {
@@ -85,7 +85,6 @@ export default class BlTableCell extends LitElement {
render(): TemplateResult {
const className = this.shadowRight ? "shadow-right" : this.shadowLeft ? "shadow-left" : "";
- // disable text color —bl-color-neutral-light
return html`
${this._renderCheckbox()}
diff --git a/src/components/table/table-header-cell/bl-table-header-cell.css b/src/components/table/table-header-cell/bl-table-header-cell.css
index 702e7243..574c5769 100644
--- a/src/components/table/table-header-cell/bl-table-header-cell.css
+++ b/src/components/table/table-header-cell/bl-table-header-cell.css
@@ -4,7 +4,7 @@
display: table-cell;
border: 1px solid var(--bl-color-neutral-lighter);
- background-color: var(--bl-color-tertiary-background);
+ background-color: var(--bl-color-neutral-lightest);
padding: var(--bl-size-m);
font: var(--bl-font-title-3-medium);
color: var(--bl-color-neutral-darker);
@@ -32,6 +32,18 @@
box-shadow: 8px 0 16px 0 rgb(39 49 66 / 10%);;
}
+.table-header-cell.shadow-left::before{
+ content: '';
+ position: absolute;
+ left: -1px;
+ top: 0;
+ width: 16px;
+ height: 100%;
+ z-index: -1;
+ border-left: 1px solid var(--bl-color-neutral-lighter);
+ box-shadow: -8px 0 16px 0 rgb(39 49 66 / 10%);
+}
+
bl-checkbox {
margin-right: var(--bl-size-m);
}
diff --git a/src/components/table/table-header-cell/bl-table-header-cell.ts b/src/components/table/table-header-cell/bl-table-header-cell.ts
index 2aa37949..e36890cd 100644
--- a/src/components/table/table-header-cell/bl-table-header-cell.ts
+++ b/src/components/table/table-header-cell/bl-table-header-cell.ts
@@ -90,7 +90,7 @@ export default class BlTableHeaderCell extends LitElement {
}
onChange(event: CustomEvent) {
- this._table?.onSelectionChange(this.index, event.detail, true);
+ this._table?.onSelectionChange(true, event.detail, "");
}
onSort() {
diff --git a/src/components/table/table-row/bl-table-row.css b/src/components/table/table-row/bl-table-row.css
index fb7b411f..e8ce60d1 100644
--- a/src/components/table/table-row/bl-table-row.css
+++ b/src/components/table/table-row/bl-table-row.css
@@ -10,6 +10,7 @@
:host([disabled]),
:host([disabled]) ::slotted(bl-table-cell) {
background-color: var(--bl-color-neutral-lightest);
+ color: var(--bl-color-neutral-light);
}
:host(:not([checked], [disabled]):hover),
diff --git a/src/components/table/table-row/bl-table-row.test.ts b/src/components/table/table-row/bl-table-row.test.ts
index 13e07160..c80869ae 100644
--- a/src/components/table/table-row/bl-table-row.test.ts
+++ b/src/components/table/table-row/bl-table-row.test.ts
@@ -8,7 +8,6 @@ describe("bl-table-row", () => {
//then
expect(el).instanceOf(BlTableRow);
- expect(el.index).to.equal(-1);
});
it("should be rendered with default values", async () => {
diff --git a/src/components/table/table-row/bl-table-row.ts b/src/components/table/table-row/bl-table-row.ts
index de5e2fd2..e59af3dc 100644
--- a/src/components/table/table-row/bl-table-row.ts
+++ b/src/components/table/table-row/bl-table-row.ts
@@ -1,10 +1,12 @@
-import { html, LitElement, TemplateResult } from "lit";
-import { customElement } from "lit/decorators.js";
+import { html, LitElement, PropertyValues, TemplateResult } from "lit";
+import { customElement, property } from "lit/decorators.js";
import { CSSResultGroup } from "lit/development";
import "element-internals-polyfill";
import "../../checkbox-group/checkbox/bl-checkbox";
import { blTableBodyTag } from "../table-body/bl-table-body";
import type BlTableBody from "../table-body/bl-table-body";
+import BlTableCell from "../table-cell/bl-table-cell";
+import BlTableHeaderCell from "../table-header-cell/bl-table-header-cell";
import { blTableHeaderTag } from "../table-header/bl-table-header";
import type BlTableHeader from "../table-header/bl-table-header";
import style from "../table-row/bl-table-row.css";
@@ -21,6 +23,12 @@ export default class BlTableRow extends LitElement {
return [style];
}
+ /**
+ * selection key for table row
+ */
+ @property({ type: String, reflect: true, attribute: "selection-key" })
+ selectionKey: string = "";
+
connectedCallback(): void {
super.connectedCallback();
if (
@@ -38,7 +46,8 @@ export default class BlTableRow extends LitElement {
super.disconnectedCallback();
}
- updated() {
+ updated(_changedProperties: PropertyValues) {
+ super.updated(_changedProperties);
this.removeAttribute("checked");
this.removeAttribute("disabled");
this.removeAttribute("sticky-first-column");
@@ -55,6 +64,13 @@ export default class BlTableRow extends LitElement {
} else if (this.disabled) {
this.setAttribute("disabled", "true");
}
+ if (_changedProperties.has("selectionKey")) {
+ this.updateComplete.then(() => {
+ Array.from(this.querySelectorAll("bl-table-header-cell,bl-table-cell")).map(com => {
+ (com as BlTableHeaderCell | BlTableCell).requestUpdate();
+ });
+ });
+ }
}
private get _table() {
@@ -67,17 +83,9 @@ export default class BlTableRow extends LitElement {
get disabled() {
return !!this._firstTableCell?.disabled;
}
- get index() {
- const parent = this.parentNode;
-
- if (!parent) {
- return -1;
- }
- return [...parent.children].indexOf(this);
- }
get checked() {
- return !!this._table?.isRowSelected(this.index);
+ return !!this._table?.isRowSelected(this.selectionKey);
}
get stickyFirstColumn() {