UNPKG

ivue-material-plus

Version:

A high quality UI components Library with Vue.js

116 lines (111 loc) 3.58 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var vue = require('vue'); var utils = require('../utils.js'); var defaults = require('../table/defaults.js'); const prefixCls = "ivue-table"; function useStyles(props) { const IvueTable = vue.inject(defaults.TableContextKey); const getRowStyle = (row, rowIndex) => { const rowStyle = IvueTable == null ? void 0 : IvueTable.props.rowStyle; if (typeof rowStyle === "function") { return rowStyle.call(null, { row, rowIndex }); } return rowStyle || null; }; const getRowClass = (row, rowIndex) => { var _a; const classes = [ `${prefixCls}-row`, { [`${prefixCls}-row--stripe`]: props.stripe && rowIndex % 2 === 1, ["highlight-current-row"]: (IvueTable == null ? void 0 : IvueTable.props.highlightCurrentRow) && row === ((_a = props.store) == null ? void 0 : _a.states.currentRow.value) } ]; const rowClassName = IvueTable == null ? void 0 : IvueTable.props.rowClassName; if (typeof rowClassName === "string") { classes.push(rowClassName); } else if (typeof rowClassName === "function") { classes.push( rowClassName.call(null, { row, rowIndex }) ); } return classes; }; const getTableSpan = (row, column, rowIndex, columnIndex) => { let rowspan = 1; let colspan = 1; const spanMethod = IvueTable == null ? void 0 : IvueTable.props.spanMethod; if (typeof spanMethod === "function") { const result = spanMethod({ row, column, rowIndex, columnIndex }); if (Array.isArray(result)) { rowspan = result[0]; colspan = result[1]; } else if (typeof result === "object") { rowspan = result.rowspan; colspan = result.colspan; } } return { rowspan, colspan }; }; const getCellClass = (rowIndex, columnIndex, row, column) => { const fixedClasses = column.isSubColumn ? [] : utils.getFixedColumnsClass(prefixCls, columnIndex, props == null ? void 0 : props.fixed, props.store); const classes = [ column.id, column.align, column.className, ...fixedClasses ]; const cellClassName = IvueTable == null ? void 0 : IvueTable.props.cellClassName; if (typeof cellClassName === "string") { classes.push(cellClassName); } else if (typeof cellClassName === "function") { classes.push( cellClassName.call(null, { rowIndex, columnIndex, row, column }) ); } classes.push("ivue-table-cell"); return classes.filter((className) => Boolean(className)).join(" "); }; const getCellStyle = (rowIndex, columnIndex, row, column) => { const cellStyle = IvueTable == null ? void 0 : IvueTable.props.cellStyle; let cellStyles = cellStyle != null ? cellStyle : {}; if (typeof cellStyle === "function") { cellStyles = cellStyle.call(null, { rowIndex, columnIndex, row, column }); } const fixedStyle = column.isSubColumn ? null : utils.getFixedColumnOffset(columnIndex, props == null ? void 0 : props.fixed, props.store); utils.ensurePosition(fixedStyle, "left"); utils.ensurePosition(fixedStyle, "right"); return Object.assign({}, cellStyles, fixedStyle); }; return { getRowClass, getRowStyle, getTableSpan, getCellClass, getCellStyle }; } exports["default"] = useStyles; //# sourceMappingURL=styles.js.map