mirror of
https://github.com/ant-design/ant-design.git
synced 2025-06-11 11:32:52 +08:00
refactor: use useContext in skeleton (#34699)
* feat: use useContext in skeleton * feat: use useContext in skeleton * feat: update for lint
This commit is contained in:
parent
1935ece582
commit
9af935f7d3
@ -1,7 +1,7 @@
|
||||
import * as React from 'react';
|
||||
import omit from 'rc-util/lib/omit';
|
||||
import classNames from 'classnames';
|
||||
import { ConfigConsumer, ConfigConsumerProps } from '../config-provider';
|
||||
import { ConfigContext } from '../config-provider';
|
||||
import Element, { SkeletonElementProps } from './Element';
|
||||
|
||||
export interface AvatarProps extends Omit<SkeletonElementProps, 'shape'> {
|
||||
@ -9,9 +9,10 @@ export interface AvatarProps extends Omit<SkeletonElementProps, 'shape'> {
|
||||
}
|
||||
|
||||
const SkeletonAvatar = (props: AvatarProps) => {
|
||||
const renderSkeletonAvatar = ({ getPrefixCls }: ConfigConsumerProps) => {
|
||||
const { prefixCls: customizePrefixCls, className, active } = props;
|
||||
const { getPrefixCls } = React.useContext(ConfigContext);
|
||||
const prefixCls = getPrefixCls('skeleton', customizePrefixCls);
|
||||
|
||||
const otherProps = omit(props, ['prefixCls', 'className']);
|
||||
const cls = classNames(
|
||||
prefixCls,
|
||||
@ -26,8 +27,6 @@ const SkeletonAvatar = (props: AvatarProps) => {
|
||||
<Element prefixCls={`${prefixCls}-avatar`} {...otherProps} />
|
||||
</div>
|
||||
);
|
||||
};
|
||||
return <ConfigConsumer>{renderSkeletonAvatar}</ConfigConsumer>;
|
||||
};
|
||||
|
||||
SkeletonAvatar.defaultProps = {
|
||||
|
@ -2,7 +2,7 @@ import * as React from 'react';
|
||||
import omit from 'rc-util/lib/omit';
|
||||
import classNames from 'classnames';
|
||||
import Element, { SkeletonElementProps } from './Element';
|
||||
import { ConfigConsumer, ConfigConsumerProps } from '../config-provider';
|
||||
import { ConfigContext } from '../config-provider';
|
||||
|
||||
export interface SkeletonButtonProps extends Omit<SkeletonElementProps, 'size'> {
|
||||
size?: 'large' | 'small' | 'default';
|
||||
@ -10,9 +10,10 @@ export interface SkeletonButtonProps extends Omit<SkeletonElementProps, 'size'>
|
||||
}
|
||||
|
||||
const SkeletonButton = (props: SkeletonButtonProps) => {
|
||||
const renderSkeletonButton = ({ getPrefixCls }: ConfigConsumerProps) => {
|
||||
const { prefixCls: customizePrefixCls, className, active, block = false } = props;
|
||||
const { getPrefixCls } = React.useContext(ConfigContext);
|
||||
const prefixCls = getPrefixCls('skeleton', customizePrefixCls);
|
||||
|
||||
const otherProps = omit(props, ['prefixCls']);
|
||||
const cls = classNames(
|
||||
prefixCls,
|
||||
@ -28,8 +29,6 @@ const SkeletonButton = (props: SkeletonButtonProps) => {
|
||||
<Element prefixCls={`${prefixCls}-button`} {...otherProps} />
|
||||
</div>
|
||||
);
|
||||
};
|
||||
return <ConfigConsumer>{renderSkeletonButton}</ConfigConsumer>;
|
||||
};
|
||||
|
||||
SkeletonButton.defaultProps = {
|
||||
|
@ -1,7 +1,7 @@
|
||||
import * as React from 'react';
|
||||
import classNames from 'classnames';
|
||||
import { SkeletonElementProps } from './Element';
|
||||
import { ConfigConsumer, ConfigConsumerProps } from '../config-provider';
|
||||
import { ConfigContext } from '../config-provider';
|
||||
|
||||
export interface SkeletonImageProps
|
||||
extends Omit<SkeletonElementProps, 'size' | 'shape' | 'active'> {}
|
||||
@ -10,8 +10,8 @@ const path =
|
||||
'M365.714286 329.142857q0 45.714286-32.036571 77.677714t-77.677714 32.036571-77.677714-32.036571-32.036571-77.677714 32.036571-77.677714 77.677714-32.036571 77.677714 32.036571 32.036571 77.677714zM950.857143 548.571429l0 256-804.571429 0 0-109.714286 182.857143-182.857143 91.428571 91.428571 292.571429-292.571429zM1005.714286 146.285714l-914.285714 0q-7.460571 0-12.873143 5.412571t-5.412571 12.873143l0 694.857143q0 7.460571 5.412571 12.873143t12.873143 5.412571l914.285714 0q7.460571 0 12.873143-5.412571t5.412571-12.873143l0-694.857143q0-7.460571-5.412571-12.873143t-12.873143-5.412571zM1097.142857 164.571429l0 694.857143q0 37.741714-26.843429 64.585143t-64.585143 26.843429l-914.285714 0q-37.741714 0-64.585143-26.843429t-26.843429-64.585143l0-694.857143q0-37.741714 26.843429-64.585143t64.585143-26.843429l914.285714 0q37.741714 0 64.585143 26.843429t26.843429 64.585143z';
|
||||
|
||||
const SkeletonImage = (props: SkeletonImageProps) => {
|
||||
const renderSkeletonImage = ({ getPrefixCls }: ConfigConsumerProps) => {
|
||||
const { prefixCls: customizePrefixCls, className, style } = props;
|
||||
const { getPrefixCls } = React.useContext(ConfigContext);
|
||||
const prefixCls = getPrefixCls('skeleton', customizePrefixCls);
|
||||
const cls = classNames(prefixCls, `${prefixCls}-element`, className);
|
||||
|
||||
@ -28,8 +28,6 @@ const SkeletonImage = (props: SkeletonImageProps) => {
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
return <ConfigConsumer>{renderSkeletonImage}</ConfigConsumer>;
|
||||
};
|
||||
|
||||
export default SkeletonImage;
|
||||
|
@ -2,7 +2,7 @@ import * as React from 'react';
|
||||
import omit from 'rc-util/lib/omit';
|
||||
import classNames from 'classnames';
|
||||
import Element, { SkeletonElementProps } from './Element';
|
||||
import { ConfigConsumer, ConfigConsumerProps } from '../config-provider';
|
||||
import { ConfigContext } from '../config-provider';
|
||||
|
||||
export interface SkeletonInputProps extends Omit<SkeletonElementProps, 'size' | 'shape'> {
|
||||
size?: 'large' | 'small' | 'default';
|
||||
@ -10,9 +10,10 @@ export interface SkeletonInputProps extends Omit<SkeletonElementProps, 'size' |
|
||||
}
|
||||
|
||||
const SkeletonInput = (props: SkeletonInputProps) => {
|
||||
const renderSkeletonInput = ({ getPrefixCls }: ConfigConsumerProps) => {
|
||||
const { prefixCls: customizePrefixCls, className, active, block } = props;
|
||||
const { getPrefixCls } = React.useContext(ConfigContext);
|
||||
const prefixCls = getPrefixCls('skeleton', customizePrefixCls);
|
||||
|
||||
const otherProps = omit(props, ['prefixCls']);
|
||||
const cls = classNames(
|
||||
prefixCls,
|
||||
@ -28,8 +29,6 @@ const SkeletonInput = (props: SkeletonInputProps) => {
|
||||
<Element prefixCls={`${prefixCls}-input`} {...otherProps} />
|
||||
</div>
|
||||
);
|
||||
};
|
||||
return <ConfigConsumer>{renderSkeletonInput}</ConfigConsumer>;
|
||||
};
|
||||
|
||||
SkeletonInput.defaultProps = {
|
||||
|
@ -2,7 +2,7 @@ import * as React from 'react';
|
||||
import classNames from 'classnames';
|
||||
import Title, { SkeletonTitleProps } from './Title';
|
||||
import Paragraph, { SkeletonParagraphProps } from './Paragraph';
|
||||
import { ConfigConsumer, ConfigConsumerProps } from '../config-provider';
|
||||
import { ConfigContext } from '../config-provider';
|
||||
import Element from './Element';
|
||||
import SkeletonAvatar, { AvatarProps } from './Avatar';
|
||||
import SkeletonButton from './Button';
|
||||
@ -72,7 +72,6 @@ function getParagraphBasicProps(hasAvatar: boolean, hasTitle: boolean): Skeleton
|
||||
}
|
||||
|
||||
const Skeleton = (props: SkeletonProps) => {
|
||||
const renderSkeleton = ({ getPrefixCls, direction }: ConfigConsumerProps) => {
|
||||
const {
|
||||
prefixCls: customizePrefixCls,
|
||||
loading,
|
||||
@ -86,6 +85,7 @@ const Skeleton = (props: SkeletonProps) => {
|
||||
round,
|
||||
} = props;
|
||||
|
||||
const { getPrefixCls, direction } = React.useContext(ConfigContext);
|
||||
const prefixCls = getPrefixCls('skeleton', customizePrefixCls);
|
||||
|
||||
if (loading || !('loading' in props)) {
|
||||
@ -161,10 +161,7 @@ const Skeleton = (props: SkeletonProps) => {
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return children;
|
||||
};
|
||||
return <ConfigConsumer>{renderSkeleton}</ConfigConsumer>;
|
||||
return React.isValidElement(children) ? children : null;
|
||||
};
|
||||
|
||||
Skeleton.defaultProps = {
|
||||
|
Loading…
Reference in New Issue
Block a user