UNPKG

hongluan-ui

Version:
199 lines (196 loc) 4.72 kB
import { h } from 'vue'; import { HlCheckbox } from '../../checkbox/index.mjs'; import { HlSpinner } from '../../spinner/index.mjs'; import { HlIcon } from '../../icon/index.mjs'; import '../../system-icon/index.mjs'; import '../../../utils/index.mjs'; import SystemArrowRight from '../../system-icon/src/arrow-right.mjs'; import { getProp } from '../../../utils/objects.mjs'; const defaultClassNames = { selection: "table-column-selection", expand: "table-expand-column" }; const cellStarts = { default: { order: "" }, selection: { width: 48, minWidth: 48, realWidth: 48, order: "" }, expand: { width: 48, minWidth: 48, realWidth: 48, order: "" }, index: { width: 48, minWidth: 48, realWidth: 48, order: "" } }; const getDefaultClassName = (type) => { return defaultClassNames[type] || ""; }; const cellForced = { selection: { renderHeader({ store, column }) { function isDisabled() { return store.states.data.value && store.states.data.value.length === 0; } return h(HlCheckbox, { disabled: isDisabled(), size: store.states.tableSize.value, indeterminate: store.states.selection.value.length > 0 && !store.states.isAllSelected.value, "onUpdate:modelValue": store.toggleAllSelection, modelValue: store.states.isAllSelected.value, ariaLabel: column.label }); }, renderCell({ row, column, store, $index }) { return h(HlCheckbox, { disabled: column.selectable ? !column.selectable.call(null, row, $index) : false, size: store.states.tableSize.value, onChange: () => { store.commit("rowSelectedChanged", row); }, onClick: (event) => event.stopPropagation(), modelValue: store.isSelected(row), ariaLabel: column.label }); }, sortable: false, resizable: false }, index: { renderHeader({ column }) { return column.label || "#"; }, renderCell({ column, $index }) { let i = $index + 1; const index = column.index; if (typeof index === "number") { i = $index + index; } else if (typeof index === "function") { i = index($index); } return h("div", {}, [i]); }, sortable: false }, expand: { renderHeader({ column }) { return column.label || ""; }, renderCell({ row, store, expanded }) { const classes = ["table-expand-icon"]; if (expanded) { classes.push("table-expand-icon-expanded"); } const callback = function(e) { e.stopPropagation(); store.toggleRowExpansion(row); }; return h("div", { class: classes, onClick: callback }, { default: () => { return [ h(HlIcon, null, { default: () => { return [h(SystemArrowRight)]; } }) ]; } }); }, sortable: false, resizable: false } }; function defaultRenderCell({ row, column, $index }) { var _a; const property = column.property; const value = property && getProp(row, property).value; if (column && column.formatter) { return column.formatter(row, column, value, $index); } return ((_a = value == null ? void 0 : value.toString) == null ? void 0 : _a.call(value)) || ""; } function treeCellPrefix({ row, treeNode, store }, createPlaceholder = false) { if (!treeNode) { if (createPlaceholder) { return [ h("span", { class: "table-placeholder" }) ]; } return null; } const ele = []; const callback = function(e) { e.stopPropagation(); if (treeNode.loading) { return; } store.loadOrToggle(row); }; if (treeNode.indent) { ele.push(h("span", { class: "table-indent", style: { "padding-left": `${treeNode.indent}px` } })); } if (typeof treeNode.expanded === "boolean" && !treeNode.noLazyChildren) { const expandClasses = [ "table-expand-icon", treeNode.expanded ? "table-expand-icon-expanded" : "" ]; ele.push(h("div", { class: expandClasses, onClick: callback }, { default: () => { return [ treeNode.loading ? h(HlSpinner) : h(HlIcon, null, { default: () => [h(SystemArrowRight)] }) ]; } })); } else { ele.push(h("span", { class: "table-placeholder" })); } return ele; } export { cellForced, cellStarts, defaultRenderCell, getDefaultClassName, treeCellPrefix }; //# sourceMappingURL=config.mjs.map