Files
ant-design/components/skeleton/Paragraph.tsx
lijianan 19137493b4 perf: uninstall classnames, install clsx (#55164)
* 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>
2025-10-01 00:45:54 +08:00

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;