): void {
super.willUpdate(changedProperties);
if (!this.role) this.role = "cell";
}
render() {
return html`
${this.selectable === "multiple"
? html` event.stopPropagation()}
@input=${this.handleSelection}
>`
: nothing}
${this.selectable === "single"
? html` event.stopPropagation()}
class="cell-radio"
>`
: nothing}
${this.expandIcon && this.expandIconPosition === "left"
? html`
`
: nothing}
${this.renderActions()}
${this.expandIcon && this.expandIconPosition === "right"
? html`
`
: nothing}
`;
}
setSelection(value = false, isDisabled = false) {
this.isDisabled = isDisabled;
if (value) {
if (this.checkbox) {
this.checkbox.value = "checked";
}
if (this.radio) {
this.radio.value = "selected";
}
} else {
if (this.checkbox) {
this.checkbox.value = "unchecked";
}
if (this.radio) {
this.radio.value = "unselected";
}
}
}
handleSelection(event: CustomEvent) {
const toggle = new CustomEvent("update-row-selection", {
detail: event.detail.value === "checked" || event.detail.value === "selected",
bubbles: true,
composed: true
});
this.dispatchEvent(toggle);
}
toggleDetails() {
const toggle = new CustomEvent("toggle-row", {
detail: { value: this.chevron?.icon === "i-chevron-down" },
bubbles: true,
composed: true
});
this.dispatchEvent(toggle);
}
protected updated(changedProperties: PropertyValueMap | Map) {
super.updated(changedProperties);
this.onmouseover = () => this.toggleColumnHighlight("add");
this.onmouseleave = () => this.toggleColumnHighlight("remove");
this.onclick = this.toggleColumnSelection;
if (this.width) {
this.style.minWidth = this.width;
this.style.display = "block";
}
}
toggleColumnSelection() {
const row = this.closest("f-trow");
if (row?.getAttribute("slot") === "header") {
const columnIndex = Array.from(this.parentNode?.children ?? []).indexOf(this);
const toggle = new CustomEvent("selected-column", {
detail: { columnIndex },
bubbles: true,
composed: true
});
this.dispatchEvent(toggle);
}
}
toggleColumnHighlight(type: "add" | "remove") {
const row = this.closest("f-trow");
if (row?.getAttribute("slot") === "header") {
const columnIndex = Array.from(this.parentNode?.children ?? []).indexOf(this);
const toggle = new CustomEvent("highlight-column", {
detail: { columnIndex, type },
bubbles: true,
composed: true
});
this.dispatchEvent(toggle);
}
}
}
/**
* Required for typescript
*/
declare global {
export interface HTMLElementTagNameMap {
"f-tcell": FTcell;
}
}