2019-11-21 20:23:56 +08:00
|
|
|
import classNames from 'classnames';
|
2022-06-22 14:57:09 +08:00
|
|
|
import * as React from 'react';
|
2019-11-21 20:23:56 +08:00
|
|
|
|
|
|
|
export interface SkeletonElementProps {
|
|
|
|
prefixCls?: string;
|
|
|
|
className?: string;
|
2021-01-21 17:16:51 +08:00
|
|
|
style?: React.CSSProperties;
|
2019-11-21 20:23:56 +08:00
|
|
|
size?: 'large' | 'small' | 'default' | number;
|
2022-06-24 12:30:47 +08:00
|
|
|
shape?: 'circle' | 'square' | 'round' | 'default';
|
2019-12-03 13:33:04 +08:00
|
|
|
active?: boolean;
|
2019-11-21 20:23:56 +08:00
|
|
|
}
|
|
|
|
|
2022-09-27 09:57:36 +08:00
|
|
|
const Element: React.FC<SkeletonElementProps> = props => {
|
2020-04-14 10:30:14 +08:00
|
|
|
const { prefixCls, className, style, size, shape } = props;
|
2019-11-21 20:23:56 +08:00
|
|
|
|
2020-04-14 10:30:14 +08:00
|
|
|
const sizeCls = classNames({
|
|
|
|
[`${prefixCls}-lg`]: size === 'large',
|
|
|
|
[`${prefixCls}-sm`]: size === 'small',
|
|
|
|
});
|
2019-11-21 20:23:56 +08:00
|
|
|
|
2020-04-14 10:30:14 +08:00
|
|
|
const shapeCls = classNames({
|
|
|
|
[`${prefixCls}-circle`]: shape === 'circle',
|
|
|
|
[`${prefixCls}-square`]: shape === 'square',
|
|
|
|
[`${prefixCls}-round`]: shape === 'round',
|
|
|
|
});
|
|
|
|
|
2022-09-27 09:57:36 +08:00
|
|
|
const sizeStyle = React.useMemo<React.CSSProperties>(
|
|
|
|
() =>
|
|
|
|
typeof size === 'number'
|
|
|
|
? {
|
|
|
|
width: size,
|
|
|
|
height: size,
|
|
|
|
lineHeight: `${size}px`,
|
|
|
|
}
|
|
|
|
: {},
|
|
|
|
[size],
|
|
|
|
);
|
2020-06-28 22:41:59 +08:00
|
|
|
|
2020-04-14 10:30:14 +08:00
|
|
|
return (
|
|
|
|
<span
|
2020-09-06 13:07:39 +08:00
|
|
|
className={classNames(prefixCls, sizeCls, shapeCls, className)}
|
2020-04-14 10:30:14 +08:00
|
|
|
style={{ ...sizeStyle, ...style }}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|
2019-11-21 20:23:56 +08:00
|
|
|
|
2019-12-03 13:33:04 +08:00
|
|
|
export default Element;
|