mirror of
https://github.com/ant-design/ant-design.git
synced 2026-02-09 02:49:18 +08:00
* refactor: uninstall classnames & install clsx * refactor: uninstall classnames & install clsx * test: rename test fn * test: update snap * update * update * update * update * update snap * update * update --------- Signed-off-by: lijianan <574980606@qq.com> Co-authored-by: thinkasany <480968828@qq.com>
40 lines
986 B
TypeScript
40 lines
986 B
TypeScript
import * as React from 'react';
|
|
import { clsx } from 'clsx';
|
|
|
|
type widthUnit = number | string;
|
|
|
|
export interface SkeletonParagraphProps {
|
|
prefixCls?: string;
|
|
className?: string;
|
|
style?: React.CSSProperties;
|
|
width?: widthUnit | Array<widthUnit>;
|
|
rows?: number;
|
|
}
|
|
|
|
const getWidth = (index: number, props: SkeletonParagraphProps) => {
|
|
const { width, rows = 2 } = props;
|
|
if (Array.isArray(width)) {
|
|
return width[index];
|
|
}
|
|
// last paragraph
|
|
if (rows - 1 === index) {
|
|
return width;
|
|
}
|
|
return undefined;
|
|
};
|
|
|
|
const Paragraph: React.FC<SkeletonParagraphProps> = (props) => {
|
|
const { prefixCls, className, style, rows = 0 } = props;
|
|
const rowList = Array.from({ length: rows }).map((_, index) => (
|
|
// eslint-disable-next-line react/no-array-index-key
|
|
<li key={index} style={{ width: getWidth(index, props) }} />
|
|
));
|
|
return (
|
|
<ul className={clsx(prefixCls, className)} style={style}>
|
|
{rowList}
|
|
</ul>
|
|
);
|
|
};
|
|
|
|
export default Paragraph;
|