You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1 lines
9.2 KiB

{"ast":null,"code":"import { inject } from 'vue';\nimport { getFixedColumnOffset, ensurePosition, getFixedColumnsClass } from '../util.mjs';\nimport { TABLE_INJECTION_KEY } from '../tokens.mjs';\nimport { useNamespace } from '../../../../hooks/use-namespace/index.mjs';\nimport { isFunction, isString } from '@vue/shared';\nfunction useStyle(props) {\n const parent = inject(TABLE_INJECTION_KEY);\n const ns = useNamespace(\"table\");\n const getHeaderRowStyle = rowIndex => {\n const headerRowStyle = parent == null ? void 0 : parent.props.headerRowStyle;\n if (isFunction(headerRowStyle)) {\n return headerRowStyle.call(null, {\n rowIndex\n });\n }\n return headerRowStyle;\n };\n const getHeaderRowClass = rowIndex => {\n const classes = [];\n const headerRowClassName = parent == null ? void 0 : parent.props.headerRowClassName;\n if (isString(headerRowClassName)) {\n classes.push(headerRowClassName);\n } else if (isFunction(headerRowClassName)) {\n classes.push(headerRowClassName.call(null, {\n rowIndex\n }));\n }\n return classes.join(\" \");\n };\n const getHeaderCellStyle = (rowIndex, columnIndex, row, column) => {\n var _a;\n let headerCellStyles = (_a = parent == null ? void 0 : parent.props.headerCellStyle) != null ? _a : {};\n if (isFunction(headerCellStyles)) {\n headerCellStyles = headerCellStyles.call(null, {\n rowIndex,\n columnIndex,\n row,\n column\n });\n }\n const fixedStyle = getFixedColumnOffset(columnIndex, column.fixed, props.store, row);\n ensurePosition(fixedStyle, \"left\");\n ensurePosition(fixedStyle, \"right\");\n return Object.assign({}, headerCellStyles, fixedStyle);\n };\n const getHeaderCellClass = (rowIndex, columnIndex, row, column) => {\n const fixedClasses = getFixedColumnsClass(ns.b(), columnIndex, column.fixed, props.store, row);\n const classes = [column.id, column.order, column.headerAlign, column.className, column.labelClassName, ...fixedClasses];\n if (!column.children) {\n classes.push(\"is-leaf\");\n }\n if (column.sortable) {\n classes.push(\"is-sortable\");\n }\n const headerCellClassName = parent == null ? void 0 : parent.props.headerCellClassName;\n if (isString(headerCellClassName)) {\n classes.push(headerCellClassName);\n } else if (isFunction(headerCellClassName)) {\n classes.push(headerCellClassName.call(null, {\n rowIndex,\n columnIndex,\n row,\n column\n }));\n }\n classes.push(ns.e(\"cell\"));\n return classes.filter(className => Boolean(className)).join(\" \");\n };\n return {\n getHeaderRowStyle,\n getHeaderRowClass,\n getHeaderCellStyle,\n getHeaderCellClass\n };\n}\nexport { useStyle as default };","map":{"version":3,"names":["useStyle","props","parent","inject","TABLE_INJECTION_KEY","ns","useNamespace","getHeaderRowStyle","rowIndex","headerRowStyle","isFunction","call","getHeaderRowClass","classes","headerRowClassName","isString","push","join","getHeaderCellStyle","columnIndex","row","column","_a","headerCellStyles","headerCellStyle","fixedStyle","getFixedColumnOffset","fixed","store","ensurePosition","Object","assign","getHeaderCellClass","fixedClasses","getFixedColumnsClass","b","id","order","headerAlign","className","labelClassName","children","sortable","headerCellClassName","e","filter","Boolean"],"sources":["../../../../../../../packages/components/table/src/table-header/style.helper.ts"],"sourcesContent":["import { inject } from 'vue'\nimport { useNamespace } from '@element-plus/hooks'\nimport { isFunction, isString } from '@element-plus/utils'\n\nimport {\n ensurePosition,\n getFixedColumnOffset,\n getFixedColumnsClass,\n} from '../util'\nimport { TABLE_INJECTION_KEY } from '../tokens'\nimport type { TableColumnCtx } from '../table-column/defaults'\nimport type { TableHeaderProps } from '.'\n\nfunction useStyle<T>(props: TableHeaderProps<T>) {\n const parent = inject(TABLE_INJECTION_KEY)\n const ns = useNamespace('table')\n\n const getHeaderRowStyle = (rowIndex: number) => {\n const headerRowStyle = parent?.props.headerRowStyle\n if (isFunction(headerRowStyle)) {\n return headerRowStyle.call(null, { rowIndex })\n }\n return headerRowStyle\n }\n\n const getHeaderRowClass = (rowIndex: number): string => {\n const classes: string[] = []\n const headerRowClassName = parent?.props.headerRowClassName\n if (isString(headerRowClassName)) {\n classes.push(headerRowClassName)\n } else if (isFunction(headerRowClassName)) {\n classes.push(headerRowClassName.call(null, { rowIndex }))\n }\n\n return classes.join(' ')\n }\n\n const getHeaderCellStyle = (\n rowIndex: number,\n columnIndex: number,\n row: T,\n column: TableColumnCtx<T>\n ) => {\n let headerCellStyles = parent?.props.headerCellStyle ?? {}\n if (isFunction(headerCellStyles)) {\n headerCellStyles = headerCellStyles.call(null, {\n rowIndex,\n columnIndex,\n row,\n column,\n })\n }\n const fixedStyle = getFixedColumnOffset<T>(\n columnIndex,\n column.fixed,\n props.store,\n row as unknown as TableColumnCtx<T>[]\n )\n ensurePosition(fixedStyle, 'left')\n ensurePosition(fixedStyle, 'right')\n return Object.assign({}, headerCellStyles, fixedStyle)\n }\n\n const getHeaderCellClass = (\n rowIndex: number,\n columnIndex: number,\n row: T,\n column: TableColumnCtx<T>\n ) => {\n const fixedClasses = getFixedColumnsClass<T>(\n ns.b(),\n columnIndex,\n column.fixed,\n props.store,\n row as unknown as TableColumnCtx<T>[]\n )\n const classes = [\n column.id,\n column.order,\n column.headerAlign,\n column.className,\n column.labelClassName,\n ...fixedClasses,\n ]\n\n if (!column.children) {\n classes.push('is-leaf')\n }\n\n if (column.sortable) {\n classes.push('is-sortable')\n }\n\n const headerCellClassName = parent?.props.headerCellClassName\n if (isString(headerCellClassName)) {\n classes.push(headerCellClassName)\n } else if (isFunction(headerCellClassName)) {\n classes.push(\n headerCellClassName.call(null, {\n rowIndex,\n columnIndex,\n row,\n column,\n })\n )\n }\n\n classes.push(ns.e('cell'))\n\n return classes.filter((className) => Boolean(className)).join(' ')\n }\n\n return {\n getHeaderRowStyle,\n getHeaderRowClass,\n getHeaderCellStyle,\n getHeaderCellClass,\n }\n}\n\nexport default useStyle\n"],"mappings":";;;;;AASA,SAASA,QAAQA,CAACC,KAAK,EAAE;EACvB,MAAMC,MAAM,GAAGC,MAAM,CAACC,mBAAmB,CAAC;EAC1C,MAAMC,EAAE,GAAGC,YAAY,CAAC,OAAO,CAAC;EAChC,MAAMC,iBAAiB,GAAIC,QAAQ,IAAK;IACtC,MAAMC,cAAc,GAA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