diff --git a/components/_util/toReactive.ts b/components/_util/toReactive.ts new file mode 100644 index 000000000..0fa7f3277 --- /dev/null +++ b/components/_util/toReactive.ts @@ -0,0 +1,42 @@ +import { isRef, reactive } from 'vue'; +import type { Ref } from 'vue'; +type MaybeRef = T | Ref; +/** + * Converts ref to reactive. + * + * @see https://vueuse.org/toReactive + * @param objectRef A ref of object + */ +export function toReactive(objectRef: MaybeRef): T { + if (!isRef(objectRef)) return reactive(objectRef) as T; + + const proxy = new Proxy( + {}, + { + get(_, p, receiver) { + return Reflect.get(objectRef.value, p, receiver); + }, + set(_, p, value) { + (objectRef.value as any)[p] = value; + return true; + }, + deleteProperty(_, p) { + return Reflect.deleteProperty(objectRef.value, p); + }, + has(_, p) { + return Reflect.has(objectRef.value, p); + }, + ownKeys() { + return Object.keys(objectRef.value); + }, + getOwnPropertyDescriptor() { + return { + enumerable: true, + configurable: true, + }; + }, + }, + ); + + return reactive(proxy) as T; +} diff --git a/components/table/Table.tsx b/components/table/Table.tsx index 0c3bd182b..89b389aad 100644 --- a/components/table/Table.tsx +++ b/components/table/Table.tsx @@ -50,6 +50,7 @@ import { useLocaleReceiver } from '../locale-provider/LocaleReceiver'; import classNames from '../_util/classNames'; import omit from '../_util/omit'; import { initDefaultProps } from '../_util/props-util'; +import { ContextSlots, useProvideSlots } from './context'; export type { ColumnsType, TablePaginationConfig }; @@ -106,46 +107,78 @@ export interface TableProps sortDirections?: SortOrder[]; showSorterTooltip?: boolean | TooltipProps; } - const tableProps = () => { return { - prefixCls: { type: String as PropType }, - columns: { type: Array as PropType }, - rowKey: { type: [String, Function] as PropType }, - tableLayout: { type: String as PropType }, - rowClassName: { type: String as PropType }, - title: { type: Function as PropType }, - footer: { type: Function as PropType }, - id: { type: String as PropType }, - showHeader: { type: Boolean as PropType }, - components: { type: Object as PropType }, - customRow: { type: Function as PropType }, - customHeaderRow: { type: Function as PropType }, - direction: { type: String as PropType }, - expandFixed: { type: Boolean as PropType }, - expandColumnWidth: { type: Number as PropType }, - expandedRowKeys: { type: Array as PropType }, - defaultExpandedRowKeys: { type: Array as PropType }, - expandedRowRender: { type: Function as PropType }, - expandRowByClick: { type: Boolean as PropType }, - expandIcon: { type: Function as PropType }, - onExpand: { type: Function as PropType }, - onExpandedRowsChange: { type: Function as PropType }, - defaultExpandAllRows: { type: Boolean as PropType }, - indentSize: { type: Number as PropType }, - expandIconColumnIndex: { type: Number as PropType }, - expandedRowClassName: { type: Function as PropType }, - childrenColumnName: { type: String as PropType }, - rowExpandable: { type: Function as PropType }, - sticky: { type: String as PropType }, + prefixCls: { type: String as PropType, default: undefined }, + columns: { type: Array as PropType, default: undefined }, + rowKey: { type: [String, Function] as PropType, default: undefined }, + tableLayout: { type: String as PropType, default: undefined }, + rowClassName: { type: String as PropType, default: undefined }, + title: { type: Function as PropType, default: undefined }, + footer: { type: Function as PropType, default: undefined }, + id: { type: String as PropType, default: undefined }, + showHeader: { type: Boolean as PropType, default: undefined }, + components: { type: Object as PropType, default: undefined }, + customRow: { type: Function as PropType, default: undefined }, + customHeaderRow: { + type: Function as PropType, + default: undefined, + }, + direction: { type: String as PropType, default: undefined }, + expandFixed: { type: Boolean as PropType, default: undefined }, + expandColumnWidth: { + type: Number as PropType, + default: undefined, + }, + expandedRowKeys: { type: Array as PropType, default: undefined }, + defaultExpandedRowKeys: { + type: Array as PropType, + default: undefined, + }, + expandedRowRender: { + type: Function as PropType, + default: undefined, + }, + expandRowByClick: { + type: Boolean as PropType, + default: undefined, + }, + expandIcon: { type: Function as PropType, default: undefined }, + onExpand: { type: Function as PropType, default: undefined }, + onExpandedRowsChange: { + type: Function as PropType, + default: undefined, + }, + defaultExpandAllRows: { + type: Boolean as PropType, + default: undefined, + }, + indentSize: { type: Number as PropType, default: undefined }, + expandIconColumnIndex: { + type: Number as PropType, + default: undefined, + }, + expandedRowClassName: { + type: Function as PropType, + default: undefined, + }, + childrenColumnName: { + type: String as PropType, + default: undefined, + }, + rowExpandable: { type: Function as PropType, default: undefined }, + sticky: { type: String as PropType, default: undefined }, dropdownPrefixCls: String, - dataSource: { type: Array as PropType }, - pagination: { type: [Boolean, Object] as PropType }, - loading: { type: [Boolean, Object] as PropType }, - size: { type: String as PropType }, + dataSource: { type: Array as PropType, default: undefined }, + pagination: { + type: [Boolean, Object] as PropType, + default: undefined, + }, + loading: { type: [Boolean, Object] as PropType, default: undefined }, + size: { type: String as PropType, default: undefined }, bordered: Boolean, - locale: { type: Object as PropType }, + locale: { type: Object as PropType, default: undefined }, onChange: { type: Function as PropType< @@ -156,30 +189,53 @@ const tableProps = () => { extra: TableCurrentDataSource, ) => void >, + default: undefined, }, - rowSelection: { type: Object as PropType }, - getPopupContainer: { type: Function as PropType }, + rowSelection: { type: Object as PropType, default: undefined }, + getPopupContainer: { type: Function as PropType, default: undefined }, scroll: { type: Object as PropType< RcTableProps['scroll'] & { scrollToFirstRowOnChange?: boolean; } >, + default: undefined, + }, + sortDirections: { type: Array as PropType, default: undefined }, + showSorterTooltip: { + type: [Boolean, Object] as PropType, + default: undefined, + }, + contextSlots: { + type: Object as PropType, }, - sortDirections: { type: Array as PropType }, - showSorterTooltip: { type: [Boolean, Object] as PropType }, }; }; -const InteralTable = defineComponent({ +const InteralTable = defineComponent< + TableProps & { + contextSlots: ContextSlots; + } +>({ name: 'InteralTable', props: initDefaultProps(tableProps(), { rowKey: 'key', }) as any, inheritAttrs: false, emits: [], - slots: ['emptyText', 'expandIcon', 'title', 'footer', 'summary'], + slots: [ + 'emptyText', + 'expandIcon', + 'title', + 'footer', + 'summary', + 'expandedRowRender', + 'bodyCell', + 'headerCell', + 'customFilterIcon', + 'customFilterDropdown', + ], setup(props, { attrs, slots, emit }) { devWarning( !(typeof props.rowKey === 'function' && props.rowKey.length > 1), @@ -187,6 +243,8 @@ const InteralTable = defineComponent({ '`index` parameter of `rowKey` function is deprecated. There is no guarantee that it will work as expected.', ); + useProvideSlots(computed(() => props.contextSlots)); + const screens = useBreakpoint(); const mergedColumns = computed(() => { @@ -339,7 +397,7 @@ const InteralTable = defineComponent({ const columnTitleProps = computed(() => ({ ...sorterTitleProps.value, })); - const [transformTitleColumns] = useTitleColumns(columnTitleProps); + const [transformTitleColumns] = useTitleColumns(columnTitleProps, toRef(props, 'contextSlots')); // ========================== Pagination ========================== const onPaginationChange = (current: number, pageSize: number) => { @@ -445,10 +503,12 @@ const InteralTable = defineComponent({ return typeof props.indentSize === 'number' ? props.indentSize : 15; }); - const transformColumns = (innerColumns: ColumnsType): ColumnsType => - transformTitleColumns( + const transformColumns = (innerColumns: ColumnsType): ColumnsType => { + const res = transformTitleColumns( transformSelectionColumns(transformFilterColumns(transformSorterColumns(innerColumns))), ); + return res; + }; return () => { const { @@ -522,6 +582,7 @@ const InteralTable = defineComponent({ {topPaginationNode} ({ setup(_props, { attrs, slots }) { return () => { const columns = (attrs.columns || convertChildrenToColumns(slots.default?.())) as ColumnsType; - return ; + console.log('slots', slots); + return ( + + ); }; }, }); diff --git a/components/table/context.ts b/components/table/context.ts new file mode 100644 index 000000000..e9d1528a4 --- /dev/null +++ b/components/table/context.ts @@ -0,0 +1,29 @@ +import type { ComputedRef, InjectionKey } from 'vue'; +import { computed } from 'vue'; +import { inject, provide } from 'vue'; + +export type ContextSlots = { + emptyText?: (...args: any[]) => void; + expandIcon?: (...args: any[]) => void; + title?: (...args: any[]) => void; + footer?: (...args: any[]) => void; + summary?: (...args: any[]) => void; + bodyCell?: (...args: any[]) => void; + headerCell?: (...args: any[]) => void; + customFilterIcon?: (...args: any[]) => void; + customFilterDropdown?: (...args: any[]) => void; + // 兼容 2.x 的 columns slots 配置 + [key: string]: (...args: any[]) => void; +}; + +export type ContextProps = ComputedRef; + +export const ContextKey: InjectionKey = Symbol('ContextProps'); + +export const useProvideSlots = (props: ContextProps) => { + provide(ContextKey, props); +}; + +export const useInjectSlots = () => { + return inject(ContextKey, computed(() => ({})) as ContextProps); +}; diff --git a/components/table/hooks/useFilter/FilterDropdown.tsx b/components/table/hooks/useFilter/FilterDropdown.tsx index 9d7fa41e5..68deb1b52 100644 --- a/components/table/hooks/useFilter/FilterDropdown.tsx +++ b/components/table/hooks/useFilter/FilterDropdown.tsx @@ -18,6 +18,7 @@ import type { FilterState } from '.'; import { computed, defineComponent, onBeforeUnmount, ref } from 'vue'; import classNames from '../../../_util/classNames'; import useConfigInject from '../../../_util/hooks/useConfigInject'; +import { useInjectSlots } from '../../context'; const { SubMenu, Item: MenuItem } = Menu; @@ -119,6 +120,7 @@ export default defineComponent>({ 'getPopupContainer', ] as any, setup(props, { slots }) { + const contextSlots = useInjectSlots(); const filterDropdownVisible = computed(() => props.column.filterDropdownVisible); const visible = ref(false); const filtered = computed( @@ -294,9 +296,11 @@ export default defineComponent>({ let filterIcon; if (typeof column.filterIcon === 'function') { - filterIcon = column.filterIcon(filtered.value); + filterIcon = column.filterIcon({ filtered: filtered.value, column }); } else if (column.filterIcon) { filterIcon = column.filterIcon; + } else if (contextSlots.value.customFilterIcon) { + filterIcon = contextSlots.value.customFilterIcon({ filtered: filtered.value, column }); } else { filterIcon = ; } diff --git a/components/table/hooks/useFilter/index.tsx b/components/table/hooks/useFilter/index.tsx index ba2934769..823294bb2 100644 --- a/components/table/hooks/useFilter/index.tsx +++ b/components/table/hooks/useFilter/index.tsx @@ -143,6 +143,7 @@ function generateFilterInfo(filterStates: FilterState[]) const currentFilters: Record = {}; filterStates.forEach(({ key, filteredKeys, column }) => { + console.log(column); const { filters, filterDropdown } = column; if (filterDropdown) { currentFilters[key] = filteredKeys || null; diff --git a/components/table/hooks/useLazyKVMap.ts b/components/table/hooks/useLazyKVMap.ts index 017305799..4c13ecda3 100644 --- a/components/table/hooks/useLazyKVMap.ts +++ b/components/table/hooks/useLazyKVMap.ts @@ -41,6 +41,7 @@ export default function useLazyKVMap( }, { deep: false, + immediate: true, }, ); function getRecordByKey(key: Key): RecordType { diff --git a/components/table/hooks/useSelection.tsx b/components/table/hooks/useSelection.tsx index b3c2df542..82fef6cc4 100644 --- a/components/table/hooks/useSelection.tsx +++ b/components/table/hooks/useSelection.tsx @@ -81,17 +81,19 @@ export default function useSelection( ): [TransformColumns, Ref>] { // ======================== Caches ======================== const preserveRecordsRef = ref(new Map()); - + const mergedRowSelection = computed(() => rowSelectionRef.value || {}); // ========================= Keys ========================= const [mergedSelectedKeys, setMergedSelectedKeys] = useMergedState( - rowSelectionRef.value.selectedRowKeys || rowSelectionRef.value.defaultSelectedRowKeys || [], + mergedRowSelection.value.selectedRowKeys || + mergedRowSelection.value.defaultSelectedRowKeys || + [], { - value: computed(() => rowSelectionRef.value.selectedRowKeys), + value: computed(() => mergedRowSelection.value.selectedRowKeys), }, ); const keyEntities = computed(() => - rowSelectionRef.value.checkStrictly + mergedRowSelection.value.checkStrictly ? { keyEntities: null } : convertDataToEntities(configRef.data.value as unknown as DataNode[], { externalGetKey: configRef.getRowKey.value as any, @@ -108,7 +110,7 @@ export default function useSelection( const checkboxPropsMap = computed(() => { const map = new Map>(); const getRowKey = configRef.getRowKey.value; - const getCheckboxProps = rowSelectionRef.value.getCheckboxProps; + const getCheckboxProps = mergedRowSelection.value.getCheckboxProps; flattedData.value.forEach((record, index) => { const key = getRowKey(record, index); const checkboxProps = (getCheckboxProps ? getCheckboxProps(record) : null) || {}; @@ -132,13 +134,13 @@ export default function useSelection( !!checkboxPropsMap.value.get(configRef.getRowKey.value(r))?.disabled; const selectKeysState = computed(() => { - if (rowSelectionRef.value.checkStrictly) { + if (mergedRowSelection.value.checkStrictly) { return [mergedSelectedKeys.value || [], []]; } const { checkedKeys, halfCheckedKeys } = conductCheck( mergedSelectedKeys.value, true, - keyEntities as any, + keyEntities.value, isCheckboxDisabled as any, ); return [checkedKeys || [], halfCheckedKeys]; @@ -149,13 +151,13 @@ export default function useSelection( const derivedSelectedKeySet = computed>(() => { const keys = - rowSelectionRef.value.type === 'radio' + mergedRowSelection.value.type === 'radio' ? derivedSelectedKeys.value.slice(0, 1) : derivedSelectedKeys.value; return new Set(keys); }); const derivedHalfSelectedKeySet = computed(() => - rowSelectionRef.value.type === 'radio' ? new Set() : new Set(derivedHalfSelectedKeys.value), + mergedRowSelection.value.type === 'radio' ? new Set() : new Set(derivedHalfSelectedKeys.value), ); // Save last selected key to enable range selection @@ -171,7 +173,7 @@ export default function useSelection( const setSelectedKeys = (keys: Key[]) => { let availableKeys: Key[]; let records: RecordType[]; - const { preserveSelectedRowKeys, onChange: onSelectionChange } = rowSelectionRef.value || {}; + const { preserveSelectedRowKeys, onChange: onSelectionChange } = mergedRowSelection.value; const { getRecordByKey } = configRef; if (preserveSelectedRowKeys) { // Keep key if mark as preserveSelectedRowKeys @@ -213,7 +215,7 @@ export default function useSelection( // ====================== Selections ====================== // Trigger single `onSelect` event const triggerSingleSelection = (key: Key, selected: boolean, keys: Key[], event: Event) => { - const { onSelect } = rowSelectionRef.value || {}; + const { onSelect } = mergedRowSelection.value; const { getRecordByKey } = configRef || {}; if (onSelect) { const rows = keys.map(k => getRecordByKey(k)); @@ -224,7 +226,7 @@ export default function useSelection( }; const mergedSelections = computed(() => { - const { onSelectInvert, onSelectNone, selections, hideSelectAll } = rowSelectionRef.value || {}; + const { onSelectInvert, onSelectNone, selections, hideSelectAll } = mergedRowSelection.value; const { data, pageData, getRowKey, locale: tableLocale } = configRef; @@ -300,7 +302,7 @@ export default function useSelection( renderCell: customizeRenderCell, hideSelectAll, checkStrictly = true, - } = rowSelectionRef.value || {}; + } = mergedRowSelection.value; const { prefixCls, @@ -376,7 +378,7 @@ export default function useSelection( ); customizeSelections = ( -
+
@@ -401,7 +403,7 @@ export default function useSelection( const allDisabledSomeChecked = allDisabled && allDisabledData.some(({ checked }) => checked); title = !hideSelectAll && ( -
+
( const result = conductCheck( [...originCheckedKeys, key], true, - keyEntities as any, + keyEntities.value, isCheckboxDisabled as any, ); const { checkedKeys, halfCheckedKeys } = result; @@ -552,7 +554,7 @@ export default function useSelection( nextCheckedKeys = conductCheck( Array.from(tempKeySet), { checked: false, halfCheckedKeys }, - keyEntities as any, + keyEntities.value, isCheckboxDisabled as any, ).checkedKeys; } @@ -583,15 +585,15 @@ export default function useSelection( // Columns const selectionColumn = { width: selectionColWidth, - className: `${prefixCls}-selection-column`, - title: rowSelectionRef.value.columnTitle || title, + className: `${prefixCls.value}-selection-column`, + title: mergedRowSelection.value.columnTitle || title, render: renderSelectionCell, [INTERNAL_COL_DEFINE]: { - class: `${prefixCls}-selection-col`, + class: `${prefixCls.value}-selection-col`, }, }; - if (expandType.value === 'row' && columns.length && !expandIconColumnIndex) { + if (expandType.value === 'row' && columns.length && !expandIconColumnIndex.value) { const [expandColumn, ...restColumns] = columns; const selectionFixed = fixed || getFixedType(restColumns[0]); if (selectionFixed) { diff --git a/components/table/hooks/useTitleColumns.tsx b/components/table/hooks/useTitleColumns.tsx index 6c33693da..924b1855c 100644 --- a/components/table/hooks/useTitleColumns.tsx +++ b/components/table/hooks/useTitleColumns.tsx @@ -1,18 +1,28 @@ import type { Ref } from 'vue'; +import { ContextSlots } from '../context'; import type { TransformColumns, ColumnTitleProps, ColumnsType } from '../interface'; import { renderColumnTitle } from '../util'; function fillTitle( columns: ColumnsType, columnTitleProps: ColumnTitleProps, + contextColumns: Ref, ) { + const $slots = contextColumns.value; return columns.map(column => { const cloneColumn = { ...column }; + const { slots = {} } = cloneColumn; - cloneColumn.title = renderColumnTitle(column.title, columnTitleProps); + Object.keys(slots).forEach(key => { + const name = slots[key]; + if (cloneColumn[key] === undefined && $slots[name]) { + cloneColumn[key] = $slots[name]; + } + }); + cloneColumn.title = renderColumnTitle(cloneColumn.title, columnTitleProps); if ('children' in cloneColumn) { - cloneColumn.children = fillTitle(cloneColumn.children, columnTitleProps); + cloneColumn.children = fillTitle(cloneColumn.children, columnTitleProps, contextColumns); } return cloneColumn; @@ -21,9 +31,10 @@ function fillTitle( export default function useTitleColumns( columnTitleProps: Ref>, + contextColumns: Ref, ): [TransformColumns] { const filledColumns = (columns: ColumnsType) => - fillTitle(columns, columnTitleProps.value); + fillTitle(columns, columnTitleProps.value, contextColumns); return [filledColumns]; } diff --git a/components/table/interface.tsx b/components/table/interface.tsx index c4cb46d34..55648ebe0 100644 --- a/components/table/interface.tsx +++ b/components/table/interface.tsx @@ -106,7 +106,7 @@ export interface ColumnType extends RcColumnType filterMultiple?: boolean; filteredValue?: FilterValue | null; defaultFilteredValue?: FilterValue | null; - filterIcon?: VueNode | ((filtered: boolean) => VueNode); + filterIcon?: VueNode | ((opt: { filtered: boolean; column: ColumnType }) => VueNode); onFilter?: (value: string | number | boolean, record: RecordType) => boolean; filterDropdownVisible?: boolean; onFilterDropdownVisibleChange?: (visible: boolean) => void; diff --git a/components/vc-table/Body/BodyRow.tsx b/components/vc-table/Body/BodyRow.tsx index c23a54ffc..9e60d9f82 100644 --- a/components/vc-table/Body/BodyRow.tsx +++ b/components/vc-table/Body/BodyRow.tsx @@ -149,6 +149,7 @@ export default defineComponent>({ return ( >({ // ======================== Expand Row ========================= let expandRowNode; if (rowSupportExpand.value && (expandRended.value || expanded.value)) { - const expandContent = expandedRowRender(record, index, indent + 1, expanded.value); + const expandContent = expandedRowRender({ + record, + index, + indent: indent + 1, + expanded: expanded.value, + }); const computedExpandedRowClassName = expandedRowClassName && expandedRowClassName(record, index, indent); expandRowNode = ( diff --git a/components/vc-table/Cell/index.tsx b/components/vc-table/Cell/index.tsx index 637a5df6c..6feb94483 100644 --- a/components/vc-table/Cell/index.tsx +++ b/components/vc-table/Cell/index.tsx @@ -14,6 +14,7 @@ import type { CellEllipsisType, } from '../interface'; import { getPathValue, validateValue } from '../utils/valueUtil'; +import { useInjectSlots } from '../../table/context'; function isRenderCell( data: RenderedCell, @@ -53,6 +54,8 @@ export interface CellProps { isSticky?: boolean; column?: ColumnType; + + cellType?: 'header' | 'body'; } export default defineComponent({ name: 'Cell', @@ -62,7 +65,6 @@ export default defineComponent({ 'index', 'dataIndex', 'customRender', - 'children', 'component', 'colSpan', 'rowSpan', @@ -79,9 +81,11 @@ export default defineComponent({ 'rowType', 'isSticky', 'column', + 'cellType', ] as any, slots: ['appendNode'], setup(props, { slots }) { + const contextSlots = useInjectSlots(); return () => { const { prefixCls, @@ -105,6 +109,7 @@ export default defineComponent({ rowType, isSticky, column, + cellType, } = props; const cellPrefixCls = `${prefixCls}-cell`; @@ -112,8 +117,11 @@ export default defineComponent({ let cellProps: CellType; let childNode; const children = slots.default?.(); - if (validateValue(children)) { + if (validateValue(children) || cellType === 'header') { childNode = children; + if (cellType === 'header' && contextSlots.value.headerCell) { + childNode = contextSlots.value.headerCell({ title: column.title, index, column }); + } } else { const value = getPathValue(record, dataIndex); @@ -129,6 +137,10 @@ export default defineComponent({ childNode = renderData; } } + + if (cellType === 'body' && contextSlots.value.bodyCell) { + childNode = contextSlots.value.bodyCell({ text: value, value, record, index, column }); + } } // Not crash if final `childNode` is not validate ReactNode diff --git a/components/vc-table/Header/Header.tsx b/components/vc-table/Header/Header.tsx index 37cbf6b60..2f8b26d14 100644 --- a/components/vc-table/Header/Header.tsx +++ b/components/vc-table/Header/Header.tsx @@ -92,6 +92,7 @@ export interface HeaderProps { export default defineComponent({ name: 'Header', + inheritAttrs: false, props: ['columns', 'flattenColumns', 'stickyOffsets', 'customHeaderRow'] as any, setup(props) { const tableContext = useInjectTable(); diff --git a/components/vc-table/Header/HeaderRow.tsx b/components/vc-table/Header/HeaderRow.tsx index ae256c039..785203528 100644 --- a/components/vc-table/Header/HeaderRow.tsx +++ b/components/vc-table/Header/HeaderRow.tsx @@ -77,6 +77,7 @@ export default defineComponent({ return ( ({ 'internalRefs', 'canExpandable', ] as any, - setup(props, { slots, emit }) { + inheritAttrs: false, + setup(props, { attrs, slots, emit }) { const mergedData = computed(() => props.data || EMPTY_DATA); const hasData = computed(() => !!mergedData.value.length); @@ -749,9 +751,10 @@ export default defineComponent({
); } - + const ariaProps = getDataAndAriaProps(attrs); let fullTable = (
({ [`${prefixCls}-has-fix-right`]: flattenColumns.value[columnCount.value - 1] && flattenColumns.value[columnCount.value - 1].fixed === 'right', + [attrs.class as string]: attrs.class, })} + style={attrs.style} id={id} ref={fullTableRef} > diff --git a/components/vc-table/context/TableContext.tsx b/components/vc-table/context/TableContext.tsx index a7584553b..01ebd8b74 100644 --- a/components/vc-table/context/TableContext.tsx +++ b/components/vc-table/context/TableContext.tsx @@ -20,12 +20,12 @@ export interface TableContextProps { summaryCollect: (uniKey: string, fixed: boolean | string) => void; } -export const BodyContextKey: InjectionKey = Symbol('TableContextProps'); +export const TableContextKey: InjectionKey = Symbol('TableContextProps'); export const useProvideTable = (props: TableContextProps) => { - provide(BodyContextKey, props); + provide(TableContextKey, props); }; export const useInjectTable = () => { - return inject(BodyContextKey, {} as TableContextProps); + return inject(TableContextKey, {} as TableContextProps); }; diff --git a/components/vc-table/interface.ts b/components/vc-table/interface.ts index 2557845dc..a9ac04e4e 100644 --- a/components/vc-table/interface.ts +++ b/components/vc-table/interface.ts @@ -66,6 +66,14 @@ interface ColumnSharedType { customHeaderCell?: GetComponentProps[number]>; ellipsis?: CellEllipsisType; align?: AlignType; + + /** @deprecated Please use `v-slot:filterIcon` `v-slot:bodyCell` `v-slot:headerCell` instead */ + slots?: { + filterIcon?: string; + filterDropdown?: string; + customRender?: string; + title?: string; + }; } export interface ColumnGroupType extends ColumnSharedType { @@ -176,12 +184,12 @@ export interface LegacyExpandableProps { rowExpandable?: (record: RecordType) => boolean; } -export type ExpandedRowRender = ( - record: ValueType, - index: number, - indent: number, - expanded: boolean, -) => any; +export type ExpandedRowRender = (opt: { + record: ValueType; + index: number; + indent: number; + expanded: boolean; +}) => any; export interface RenderExpandIconProps { prefixCls: string; diff --git a/components/vc-tree/TreeNode.tsx b/components/vc-tree/TreeNode.tsx index 1f10c1084..18b6d8840 100644 --- a/components/vc-tree/TreeNode.tsx +++ b/components/vc-tree/TreeNode.tsx @@ -421,8 +421,8 @@ export default defineComponent({ let titleNode: any; if (typeof title === 'function') { titleNode = title(renderArgsData.value); - } else if (contextSlots.titleRender) { - titleNode = contextSlots.titleRender(renderArgsData.value); + } else if (contextSlots.valuetitleRender) { + titleNode = contextSlots.valuetitleRender(renderArgsData.value); } else { titleNode = title; } diff --git a/examples/App.vue b/examples/App.vue index d70095398..a57385d1c 100644 --- a/examples/App.vue +++ b/examples/App.vue @@ -1,8 +1,5 @@