ant-design-vue/components/skeleton/Paragraph.tsx

43 lines
1.2 KiB
Vue
Raw Normal View History

2020-10-18 14:03:57 +00:00
import { defineComponent, ExtractPropTypes } from 'vue';
2019-01-12 03:33:27 +00:00
import PropTypes from '../_util/vue-types';
2018-12-10 03:34:51 +00:00
2019-01-12 03:33:27 +00:00
const widthUnit = PropTypes.oneOfType([PropTypes.number, PropTypes.string]);
2018-12-10 03:34:51 +00:00
2021-05-28 05:16:59 +00:00
export const skeletonParagraphProps = {
2018-12-10 03:34:51 +00:00
prefixCls: PropTypes.string,
2019-01-12 03:33:27 +00:00
width: PropTypes.oneOfType([widthUnit, PropTypes.arrayOf(widthUnit)]),
2018-12-10 03:34:51 +00:00
rows: PropTypes.number,
2019-01-12 03:33:27 +00:00
};
2018-12-10 03:34:51 +00:00
2021-05-28 05:16:59 +00:00
export type SkeletonParagraphProps = Partial<ExtractPropTypes<typeof skeletonParagraphProps>>;
2018-12-10 03:34:51 +00:00
2021-05-28 05:16:59 +00:00
const SkeletonParagraph = defineComponent({
name: 'SkeletonParagraph',
2021-05-30 13:39:25 +00:00
props: skeletonParagraphProps,
2021-05-28 05:16:59 +00:00
setup(props) {
const getWidth = (index: number) => {
const { width, rows = 2 } = props;
2018-12-10 03:34:51 +00:00
if (Array.isArray(width)) {
2019-01-12 03:33:27 +00:00
return width[index];
2018-12-10 03:34:51 +00:00
}
// last paragraph
if (rows - 1 === index) {
2019-01-12 03:33:27 +00:00
return width;
2018-12-10 03:34:51 +00:00
}
2019-01-12 03:33:27 +00:00
return undefined;
2021-05-28 05:16:59 +00:00
};
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>;
};
2018-12-10 03:34:51 +00:00
},
2020-10-18 14:03:57 +00:00
});
2018-12-10 03:34:51 +00:00
2021-05-28 05:16:59 +00:00
export default SkeletonParagraph;