ant-design/components/skeleton/Paragraph.tsx
Rustin 13fda44fb1
refactor(skeleton): rewrite with hook (#23206)
* refactor(skeleton): rewrite with hook

* fix(skeleton): refine lint and compile issues

* fix(skeleton): refine compile issues

* chore: ignore eslint warning
2020-04-14 10:30:14 +08:00

39 lines
943 B
TypeScript

import * as React from 'react';
import classNames from 'classnames';
type widthUnit = number | string;
export interface SkeletonParagraphProps {
prefixCls?: string;
className?: string;
style?: object;
width?: widthUnit | Array<widthUnit>;
rows?: number;
}
const Paragraph = (props: SkeletonParagraphProps) => {
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;
};
const { prefixCls, className, style, rows } = props;
const rowList = [...Array(rows)].map((_, index) => (
// eslint-disable-next-line react/no-array-index-key
<li key={index} style={{ width: getWidth(index) }}/>
));
return (
<ul className={classNames(prefixCls, className)} style={style}>
{rowList}
</ul>
);
};
export default Paragraph;