2018-08-22 23:34:36 +08:00
|
|
|
import classNames from 'classnames';
|
2022-06-22 14:57:09 +08:00
|
|
|
import * as React from 'react';
|
2018-08-22 23:34:36 +08:00
|
|
|
|
|
|
|
type widthUnit = number | string;
|
|
|
|
|
|
|
|
export interface SkeletonParagraphProps {
|
|
|
|
prefixCls?: string;
|
|
|
|
className?: string;
|
2021-01-21 17:16:51 +08:00
|
|
|
style?: React.CSSProperties;
|
2018-08-22 23:34:36 +08:00
|
|
|
width?: widthUnit | Array<widthUnit>;
|
|
|
|
rows?: number;
|
|
|
|
}
|
|
|
|
|
2020-04-14 10:30:14 +08:00
|
|
|
const Paragraph = (props: SkeletonParagraphProps) => {
|
|
|
|
const getWidth = (index: number) => {
|
|
|
|
const { width, rows = 2 } = props;
|
2018-09-02 16:02:02 +08:00
|
|
|
if (Array.isArray(width)) {
|
|
|
|
return width[index];
|
2018-08-22 23:34:36 +08:00
|
|
|
}
|
2018-09-02 16:02:02 +08:00
|
|
|
// last paragraph
|
|
|
|
if (rows - 1 === index) {
|
|
|
|
return width;
|
|
|
|
}
|
|
|
|
return undefined;
|
2020-04-14 10:30:14 +08:00
|
|
|
};
|
|
|
|
const { prefixCls, className, style, rows } = props;
|
|
|
|
const rowList = [...Array(rows)].map((_, index) => (
|
|
|
|
// eslint-disable-next-line react/no-array-index-key
|
2020-10-21 10:35:06 +08:00
|
|
|
<li key={index} style={{ width: getWidth(index) }} />
|
2020-04-14 10:30:14 +08:00
|
|
|
));
|
|
|
|
return (
|
|
|
|
<ul className={classNames(prefixCls, className)} style={style}>
|
|
|
|
{rowList}
|
|
|
|
</ul>
|
|
|
|
);
|
|
|
|
};
|
2018-08-22 23:34:36 +08:00
|
|
|
|
|
|
|
export default Paragraph;
|