UNPKG

v4web-components

Version:
234 lines (233 loc) 10.4 kB
import { h } from '@stencil/core'; export class LabDsTable { constructor() { this.data = undefined; this.actionField = false; this.loading = false; this.headerPosition = 'left'; this.sortConfig = undefined; } handleSortAsc(d) { if (d === null || d === void 0 ? void 0 : d.sortable) { if (d.customSort) { this.sortAsc.emit(d.colKey); return; } this.sortConfig = { key: d.colKey, direction: 'asc' }; } } handleSortDesc(d) { if (d === null || d === void 0 ? void 0 : d.sortable) { if (d.customSort) { this.sortDesc.emit(d.colKey); return; } this.sortConfig = { key: d.colKey, direction: 'desc' }; } } sortData(sortConfig) { if (!sortConfig) { return; } const { key, direction } = sortConfig; this.data.rows.sort((a, b) => { var _a, _b; let aSort = ((_a = a[key].number) === null || _a === void 0 ? void 0 : _a.title) ? a[key].number.title : a[key].text.title; let bSort = ((_b = b[key].number) === null || _b === void 0 ? void 0 : _b.title) ? b[key].number.title : b[key].text.title; if (direction === 'asc') { return aSort > bSort ? 1 : -1; } if (direction === 'desc') { return aSort < bSort ? 1 : -1; } }); } componentDidRender() { const scroll = this.el.querySelector('.v4-table'); scroll.addEventListener('scroll', () => { if (Math.abs(scroll.scrollHeight - scroll.clientHeight - scroll.scrollTop) < 1) { this.finalLineNextPage.emit(true); } }, { passive: true, }); } render() { var _a, _b, _c, _d; return (h("div", { class: `v4-table scroll-customized header-${this.headerPosition}` }, h("table", null, h("thead", null, h("tr", { class: "table-header" }, (_b = (_a = this.data) === null || _a === void 0 ? void 0 : _a.headers) === null || _b === void 0 ? void 0 : _b.map(d => (h("th", { class: "header-cell" }, this.headerPosition === 'right' || d.type === 'number' ? (h("div", { class: "cell-container" }, d.sortable && (h("div", { class: "cell-order" }, h("lab-ds-icon-selectable", { onClick: () => { this.handleSortAsc(d); }, size: "x-small", icon: "expand_less" }), h("lab-ds-icon-selectable", { onClick: () => { this.handleSortDesc(d); }, size: "x-small", icon: "expand_more" }))), h("div", { class: `cell-content ${d.type === 'number' ? 'cell-number' : ''} ${d.sortable ? 'sortable' : ''}` }, d.icon && !d.sortable && h("lab-ds-icon-not-selectable", { class: "header-cell-icon", size: "small", icon: d.icon }), h("span", { class: "header-title" }, d.title)))) : (h("div", { class: "cell-container" }, h("div", { class: "cell-content" }, h("span", { class: "header-title" }, d.title), d.icon && !d.sortable && h("lab-ds-icon-not-selectable", { class: "header-cell-icon", size: "small", icon: d.icon })), d.sortable && (h("div", { class: "cell-order" }, h("lab-ds-icon-selectable", { onClick: () => { this.handleSortAsc(d); }, size: "x-small", icon: "expand_less" }), h("lab-ds-icon-selectable", { onClick: () => { this.handleSortDesc(d); }, size: "x-small", icon: "expand_more" })))))))), this.actionField && h("th", { class: "header-cell" }))), !this.loading && (h("tbody", null, (_d = (_c = this.data) === null || _c === void 0 ? void 0 : _c.rows) === null || _d === void 0 ? void 0 : _d.map((row, index) => { var _a; return (h("tr", { key: index, tabIndex: 0, class: "row" }, this.data.headers.map(header => { var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v; return (h("td", { onClick: e => { var _a, _b; if (header.type === 'text' || 'number') { e.preventDefault(); ((_a = row[header.colKey]) === null || _a === void 0 ? void 0 : _a.handleRow) && ((_b = row[header.colKey]) === null || _b === void 0 ? void 0 : _b.handleRow()); } else { return; } }, style: { width: `${100 / this.data.headers.length}%` }, class: `cell-row ${header.type === 'text' || 'number' ? 'cell-row-clickable' : ''}` }, header.type === 'text' && (h("div", { class: "cell-row-container" }, h("div", { class: "cell-row-container-avatar" }, ((_b = (_a = row[header.colKey]) === null || _a === void 0 ? void 0 : _a.text) === null || _b === void 0 ? void 0 : _b.avatar) && h("lab-ds-avatar", { size: "small", imageSRC: (_d = (_c = row[header.colKey]) === null || _c === void 0 ? void 0 : _c.text) === null || _d === void 0 ? void 0 : _d.avatarImgSRC }), h("div", { class: "cell-row-container-text" }, h("span", { title: ((_f = (_e = row[header.colKey]) === null || _e === void 0 ? void 0 : _e.text) === null || _f === void 0 ? void 0 : _f.title) || '-', class: "cell-row-text" }, ((_h = (_g = row[header.colKey]) === null || _g === void 0 ? void 0 : _g.text) === null || _h === void 0 ? void 0 : _h.title) || '-'))), h("div", { class: "cell-row-text-icon" }, ((_k = (_j = row[header.colKey]) === null || _j === void 0 ? void 0 : _j.text) === null || _k === void 0 ? void 0 : _k.icon) && h("lab-ds-icon-not-selectable", { class: "cell-row-text-icon", icon: (_m = (_l = row[header.colKey]) === null || _l === void 0 ? void 0 : _l.text) === null || _m === void 0 ? void 0 : _m.icon, size: "small" })))), header.type === 'number' && h("span", { class: "cell-row-number" }, ((_p = (_o = row[header.colKey]) === null || _o === void 0 ? void 0 : _o.number) === null || _p === void 0 ? void 0 : _p.title) || '-'), header.type === 'badge' && (h("div", { class: "cell-row-components" }, h("lab-ds-badge", Object.assign({}, (_q = row[header.colKey]) === null || _q === void 0 ? void 0 : _q.badge)))), header.type === 'select' && (h("div", { class: "cell-row-components" }, h("lab-ds-select", Object.assign({ style: { width: '100%' } }, (_r = row[header.colKey]) === null || _r === void 0 ? void 0 : _r.select)))), header.type === 'quantify' && (h("div", { class: "cell-row-components" }, h("lab-ds-quantify", Object.assign({}, (_s = row[header.colKey]) === null || _s === void 0 ? void 0 : _s.quantify)))), header.type === 'customize' && (h("div", { class: "cell-row-components" }, h("div", Object.assign({}, (_u = (_t = row[header.colKey]) === null || _t === void 0 ? void 0 : _t.customize) === null || _u === void 0 ? void 0 : _u.props.props, { innerHTML: (_v = row[header.colKey]) === null || _v === void 0 ? void 0 : _v.customize.component })))))); }), this.actionField && (h("td", { class: "cell-row" }, h("lab-ds-context-menu", Object.assign({ listPosition: "right" }, (_a = row === null || row === void 0 ? void 0 : row.action) === null || _a === void 0 ? void 0 : _a.action)))))); })))), this.loading && (h("div", { class: "table-loading" }, h("lab-ds-skeleton", null))))); } static get is() { return "lab-ds-table"; } static get originalStyleUrls() { return { "$": ["lab-ds-table.css"] }; } static get styleUrls() { return { "$": ["lab-ds-table.css"] }; } static get properties() { return { "data": { "type": "unknown", "mutable": false, "complexType": { "original": "IData", "resolved": "IData", "references": { "IData": { "location": "local", "path": "/home/runner/work/v4web-component/v4web-component/packages/stencil-library/src/components/layout/lab-ds-table/lab-ds-table.tsx" } } }, "required": true, "optional": false, "docs": { "tags": [], "text": "" } }, "actionField": { "type": "boolean", "mutable": false, "complexType": { "original": "boolean", "resolved": "boolean", "references": {} }, "required": false, "optional": false, "docs": { "tags": [], "text": "" }, "attribute": "action-field", "reflect": false, "defaultValue": "false" }, "loading": { "type": "boolean", "mutable": false, "complexType": { "original": "boolean", "resolved": "boolean", "references": {} }, "required": false, "optional": false, "docs": { "tags": [], "text": "" }, "attribute": "loading", "reflect": false, "defaultValue": "false" }, "headerPosition": { "type": "string", "mutable": false, "complexType": { "original": "'left' | 'right'", "resolved": "\"left\" | \"right\"", "references": {} }, "required": false, "optional": false, "docs": { "tags": [], "text": "" }, "attribute": "header-position", "reflect": false, "defaultValue": "'left'" } }; } static get states() { return { "sortConfig": {} }; } static get events() { return [{ "method": "finalLineNextPage", "name": "finalLineNextPage", "bubbles": true, "cancelable": true, "composed": true, "docs": { "tags": [], "text": "" }, "complexType": { "original": "boolean", "resolved": "boolean", "references": {} } }, { "method": "sortAsc", "name": "sortAsc", "bubbles": true, "cancelable": true, "composed": true, "docs": { "tags": [], "text": "" }, "complexType": { "original": "string", "resolved": "string", "references": {} } }, { "method": "sortDesc", "name": "sortDesc", "bubbles": true, "cancelable": true, "composed": true, "docs": { "tags": [], "text": "" }, "complexType": { "original": "string", "resolved": "string", "references": {} } }]; } static get elementRef() { return "el"; } static get watchers() { return [{ "propName": "sortConfig", "methodName": "sortData" }]; } } //# sourceMappingURL=lab-ds-table.js.map