element-plus
Version:
A Component Library for Vue 3
1 lines • 6.16 kB
Source Map (JSON)
{"version":3,"file":"cell.mjs","names":["renderSlot","createVNode","_createVNode","mergeProps","_mergeProps","get","isFunction","isObject","ExpandIcon","TableCell","Alignment","placeholderSign","componentToSlot","enforceUnit","tryCall","CellRenderer","columns","column","columnIndex","depth","expandIconProps","isScrolling","rowData","rowIndex","style","expandedRowKeys","ns","t","cellProps","_cellProps","expandColumnKey","indentSize","iconSize","rowKey","slots","cellStyle","em","cellRenderer","dataKey","dataGetter","cellData","extraCellProps","class","e","columnCellRenderer","Cell","kls","align","CENTER","is","RIGHT","expandable","key","expanded","includes","IconOrPlaceholder","iconStyle","join","inheritAttrs"],"sources":["../../../../../../../packages/components/table-v2/src/renderers/cell.tsx"],"sourcesContent":["import { renderSlot } from 'vue'\nimport { get } from 'lodash-unified'\nimport { isFunction, isObject } from '@element-plus/utils'\nimport { ExpandIcon, TableCell } from '../components'\nimport { Alignment } from '../constants'\nimport { placeholderSign } from '../private'\nimport { componentToSlot, enforceUnit, tryCall } from '../utils'\n\nimport type { FunctionalComponent, UnwrapNestedRefs, VNode } from 'vue'\nimport type { TableV2RowCellRenderParam } from '../components'\nimport type { Translator, UseNamespaceReturn } from '@element-plus/hooks'\nimport type { UseTableReturn } from '../use-table'\nimport type { TableV2Props } from '../table'\n\ntype CellRendererProps = TableV2RowCellRenderParam &\n Pick<\n TableV2Props,\n 'cellProps' | 'expandColumnKey' | 'indentSize' | 'iconSize' | 'rowKey'\n > &\n UnwrapNestedRefs<Pick<UseTableReturn, 'expandedRowKeys'>> & {\n ns: UseNamespaceReturn\n t: Translator\n }\n\nconst CellRenderer: FunctionalComponent<CellRendererProps> = (\n {\n // renderer props\n columns,\n column,\n columnIndex,\n depth,\n expandIconProps,\n isScrolling,\n rowData,\n rowIndex,\n // from use-table\n style,\n expandedRowKeys,\n ns,\n t,\n // derived props\n cellProps: _cellProps,\n expandColumnKey,\n indentSize,\n iconSize,\n rowKey,\n },\n { slots }\n) => {\n const cellStyle = enforceUnit(style)\n\n if (column.placeholderSign === placeholderSign) {\n return <div class={ns.em('row-cell', 'placeholder')} style={cellStyle} />\n }\n const { cellRenderer, dataKey, dataGetter } = column\n\n const cellData = isFunction(dataGetter)\n ? dataGetter({ columns, column, columnIndex, rowData, rowIndex })\n : get(rowData, dataKey ?? '')\n\n const extraCellProps = tryCall(_cellProps, {\n cellData,\n columns,\n column,\n columnIndex,\n rowIndex,\n rowData,\n })\n\n const cellProps = {\n class: ns.e('cell-text'),\n columns,\n column,\n columnIndex,\n cellData,\n isScrolling,\n rowData,\n rowIndex,\n }\n const columnCellRenderer = componentToSlot<typeof cellProps>(cellRenderer)\n const Cell = columnCellRenderer\n ? columnCellRenderer(cellProps)\n : renderSlot(slots, 'default', cellProps, () => [\n <TableCell {...cellProps}></TableCell>,\n ])\n\n const kls = [\n ns.e('row-cell'),\n column.class,\n column.align === Alignment.CENTER && ns.is('align-center'),\n column.align === Alignment.RIGHT && ns.is('align-right'),\n ]\n\n const expandable =\n rowIndex >= 0 && expandColumnKey && column.key === expandColumnKey\n const expanded = rowIndex >= 0 && expandedRowKeys.includes(rowData[rowKey])\n\n let IconOrPlaceholder: VNode | undefined\n const iconStyle = `margin-inline-start: ${depth * indentSize}px;`\n if (expandable) {\n if (isObject(expandIconProps)) {\n IconOrPlaceholder = (\n <ExpandIcon\n {...expandIconProps}\n class={[ns.e('expand-icon'), ns.is('expanded', expanded)]}\n size={iconSize}\n expanded={expanded}\n ariaLabel={t(\n expanded ? 'el.table.collapseRowLabel' : 'el.table.expandRowLabel'\n )}\n style={iconStyle}\n expandable\n />\n )\n } else {\n IconOrPlaceholder = (\n <div\n style={[\n iconStyle,\n `width: ${iconSize}px; height: ${iconSize}px;`,\n ].join(' ')}\n />\n )\n }\n }\n\n return (\n <div class={kls} style={cellStyle} {...extraCellProps} role=\"cell\">\n {IconOrPlaceholder}\n {Cell}\n </div>\n )\n}\n\nCellRenderer.inheritAttrs = false\n\nexport default CellRen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