element-plus
Version:
A Component Library for Vue 3
1 lines • 6.65 kB
Source Map (JSON)
{"version":3,"file":"styles-helper.mjs","sources":["../../../../../../../packages/components/table/src/table-body/styles-helper.ts"],"sourcesContent":["import { getCurrentInstance } from 'vue'\n\nimport type { TableColumnCtx } from '../table-column/defaults'\nimport type { Table } from '../table/defaults'\nimport type { TableBodyProps } from './defaults'\n\nfunction useStyles<T>(props: Partial<TableBodyProps<T>>) {\n const instance = getCurrentInstance()\n const parent = instance.parent as Table<T>\n const isColumnHidden = (index) => {\n if (props.fixed === 'left') {\n return index >= props.store.states.fixedLeafColumnsLength.value\n } else if (props.fixed === 'right') {\n return (\n index <\n props.store.states.columns.value.length -\n props.store.states.rightFixedLeafColumnsLength.value\n )\n } else {\n return (\n index < props.store.states.fixedLeafColumnsLength.value ||\n index >=\n props.store.states.columns.value.length -\n props.store.states.rightFixedLeafColumnsLength.value\n )\n }\n }\n const getRowStyle = (row: T, rowIndex: number) => {\n const rowStyle = parent.props.rowStyle\n if (typeof rowStyle === 'function') {\n return rowStyle.call(null, {\n row,\n rowIndex,\n })\n }\n return rowStyle || null\n }\n\n const getRowClass = (row: T, rowIndex: number) => {\n const classes = ['el-table__row']\n if (\n parent.props.highlightCurrentRow &&\n row === props.store.states.currentRow.value\n ) {\n classes.push('current-row')\n }\n\n if (props.stripe && rowIndex % 2 === 1) {\n classes.push('el-table__row--striped')\n }\n const rowClassName = parent.props.rowClassName\n if (typeof rowClassName === 'string') {\n classes.push(rowClassName)\n } else if (typeof rowClassName === 'function') {\n classes.push(\n rowClassName.call(null, {\n row,\n rowIndex,\n })\n )\n }\n\n if (props.store.states.expandRows.value.indexOf(row) > -1) {\n classes.push('expanded')\n }\n\n return classes\n }\n\n const getCellStyle = (\n rowIndex: number,\n columnIndex: number,\n row: T,\n column: TableColumnCtx<T>\n ) => {\n const cellStyle = parent.props.cellStyle\n if (typeof cellStyle === 'function') {\n return cellStyle.call(null, {\n rowIndex,\n columnIndex,\n row,\n column,\n })\n }\n return cellStyle\n }\n\n const getCellClass = (\n rowIndex: number,\n columnIndex: number,\n row: T,\n column: TableColumnCtx<T>\n ) => {\n const classes = [column.id, column.align, column.className]\n\n if (isColumnHidden(columnIndex)) {\n classes.push('is-hidden')\n }\n\n const cellClassName = parent.props.cellClassName\n if (typeof cellClassName === 'string') {\n classes.push(cellClassName)\n } else if (typeof cellClassName === 'function') {\n classes.push(\n cellClassName.call(null, {\n rowIndex,\n columnIndex,\n row,\n column,\n })\n )\n }\n\n classes.push('el-table__cell')\n\n return classes.join(' ')\n }\n const getSpan = (\n row: T,\n column: TableColumnCtx<T>,\n rowIndex: number,\n columnIndex: number\n ) => {\n let rowspan = 1\n let colspan = 1\n const fn = parent.props.spanMethod\n if (typeof fn === 'function') {\n const result = fn({\n row,\n column,\n rowIndex,\n columnIndex,\n })\n if (Array.isArray(result)) {\n rowspan = result[0]\n colspan = result[1]\n } else if (typeof result === 'object') {\n rowspan = result.rowspan\n colspan = result.colspan\n }\n }\n return { rowspan, colspan }\n }\n const getColspanRealWidth = (\n columns: TableColumnCtx<T>[],\n colspan: number,\n index: number\n ): number => {\n if (colspan < 1) {\n return columns[index].realWidth\n }\n const widthArr = columns\n .map(({ realWidth, width }) => realWidth || width)\n .slice(index, index + colspan)\n return Number(\n widthArr.reduce((acc, width) => Number(acc) + Number(width), -1)\n )\n }\n\n return {\n getRowStyle,\n getRowClass,\n getCellStyle,\n getCellClass,\n getSpan,\n getColspanRealWidth,\n isColumnHidden,\n }\n}\n\nexport default useStyles\n"],"names":[],"mappings":";;AAMA,mBAAsB,OAAmC;AACvD,QAAM,WAAW;AACjB,QAAM,SAAS,SAAS;AACxB,QAAM,iBAAiB,CAAC,UAAU;AAChC,QAAI,MAAM,UAAU,QAAQ;AAC1B,aAAO,SAAS,MAAM,MAAM,OAAO,uBAAuB;AAAA,eACjD,MAAM,UAAU,SAAS;AAClC,aACE,QACA,MAAM,MAAM,OAAO,QAAQ,MAAM,SAC/B,MAAM,MAAM,OAAO,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