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
|
|
|
|
|
|
|
const skeletonParagraphProps = {
|
|
|
|
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-04-27 14:11:31 +00:00
|
|
|
export const SkeletonParagraphProps = PropTypes.shape(skeletonParagraphProps).loose;
|
2018-12-10 03:34:51 +00:00
|
|
|
|
2020-10-18 14:03:57 +00:00
|
|
|
export type ISkeletonParagraphProps = Partial<ExtractPropTypes<typeof skeletonParagraphProps>>;
|
|
|
|
|
|
|
|
const Paragraph = defineComponent({
|
2019-03-18 12:35:24 +00:00
|
|
|
props: skeletonParagraphProps,
|
2018-12-10 03:34:51 +00:00
|
|
|
methods: {
|
2020-10-18 14:03:57 +00:00
|
|
|
getWidth(index: number) {
|
2019-01-12 03:33:27 +00:00
|
|
|
const { width, rows = 2 } = this;
|
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;
|
2018-12-10 03:34:51 +00:00
|
|
|
},
|
|
|
|
},
|
2019-01-12 03:33:27 +00:00
|
|
|
render() {
|
|
|
|
const { prefixCls, rows } = this.$props;
|
2018-12-10 03:34:51 +00:00
|
|
|
const rowList = [...Array(rows)].map((_, index) => {
|
2019-01-12 03:33:27 +00:00
|
|
|
const width = this.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
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
export default Paragraph;
|