ant-design-vue/components/skeleton/Paragraph.tsx
Garret MH a2f7d6d062
feat: Vue 3 Migration Build support (#5973), close #5765
closes vueComponent/ant-design-vue#5765

Add `compatConfig: { MODE: 3 }` to all component definitions to signal to `@vue/compat` not to use any Vue 2 compatibility features.
2022-09-26 21:33:41 +08:00

45 lines
1.2 KiB
Vue

import type { ExtractPropTypes, PropType } from 'vue';
import { defineComponent } from 'vue';
type widthUnit = number | string;
export const skeletonParagraphProps = () => ({
prefixCls: String,
width: { type: [Number, String, Array] as PropType<widthUnit[] | widthUnit> },
rows: Number,
});
export type SkeletonParagraphProps = Partial<
ExtractPropTypes<ReturnType<typeof skeletonParagraphProps>>
>;
const SkeletonParagraph = defineComponent({
compatConfig: { MODE: 3 },
name: 'SkeletonParagraph',
props: skeletonParagraphProps(),
setup(props) {
const getWidth = (index: number) => {
const { width, rows = 2 } = props;
if (Array.isArray(width)) {
return width[index];
}
// last paragraph
if (rows - 1 === index) {
return width;
}
return undefined;
};
return () => {
const { prefixCls, rows } = props;
const rowList = [...Array(rows)].map((_, index) => {
const width = getWidth(index);
return (
<li key={index} style={{ width: typeof width === 'number' ? `${width}px` : width }} />
);
});
return <ul class={prefixCls}>{rowList}</ul>;
};
},
});
export default SkeletonParagraph;