ant-design-vue/components/vc-virtual-list/Item.tsx

26 lines
621 B
Vue
Raw Permalink Normal View History

2021-06-26 09:35:40 +08:00
import type { FunctionalComponent, PropType } from 'vue';
import { cloneVNode } from 'vue';
2021-12-27 15:40:48 +08:00
import { flattenChildren } from '../_util/props-util';
2020-10-01 17:20:10 +08:00
export interface ItemProps {
setRef: (element: HTMLElement) => void;
}
const Item: FunctionalComponent<ItemProps> = ({ setRef }, { slots }) => {
2021-12-27 15:40:48 +08:00
const children = flattenChildren(slots.default?.());
2020-10-01 17:20:10 +08:00
return children && children.length
? cloneVNode(children[0], {
2020-10-17 12:14:13 +08:00
ref: setRef as any,
2020-10-01 17:20:10 +08:00
})
: children;
};
2020-10-07 22:49:01 +08:00
Item.props = {
setRef: {
type: Function as PropType<(element: HTMLElement) => void>,
default: () => {},
},
};
2020-10-17 12:14:13 +08:00
2020-10-01 17:20:10 +08:00
export default Item;