Skip to content

Commit

Permalink
revert: 14f8279
Browse files Browse the repository at this point in the history
  • Loading branch information
Wxh16144 committed May 7, 2024
1 parent 73adedb commit 68227f8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 35 deletions.
44 changes: 16 additions & 28 deletions components/button/LoadingIcon.tsx
Original file line number Diff line number Diff line change
@@ -1,39 +1,35 @@
import React, { forwardRef } from 'react';
import LoadingOutlined from '@ant-design/icons/LoadingOutlined';
import classNames from 'classnames';
import CSSMotion from 'rc-motion';

import type { ButtonProps } from './button';
import React, { forwardRef } from 'react';
import IconWrapper from './IconWrapper';

type InnerLoadingIconProps = {
prefixCls: string;
className?: string;
style?: React.CSSProperties;
iconClassName?: string;
} & Pick<ButtonProps, 'iconPosition'>;
};

const InnerLoadingIcon = forwardRef<HTMLSpanElement, InnerLoadingIconProps>((props, ref) => {
const { prefixCls, className, style, iconClassName, iconPosition = 'start' } = props;
const mergedIconCls = classNames(className, {
[`${prefixCls}-loading-icon-end`]: iconPosition === 'end',
[`${prefixCls}-loading-icon`]: iconPosition === 'start',
});
const InnerLoadingIcon = forwardRef<HTMLSpanElement, InnerLoadingIconProps>(
({ prefixCls, className, style, iconClassName }, ref) => {
const mergedIconCls = classNames(`${prefixCls}-loading-icon`, className);

return (
<IconWrapper prefixCls={prefixCls} className={mergedIconCls} style={style} ref={ref}>
<LoadingOutlined className={iconClassName} />
</IconWrapper>
);
});
return (
<IconWrapper prefixCls={prefixCls} className={mergedIconCls} style={style} ref={ref}>
<LoadingOutlined className={iconClassName} />
</IconWrapper>
);
},
);

export type LoadingIconProps = {
export interface LoadingIconProps {
prefixCls: string;
existIcon: boolean;
loading?: boolean | object;
className?: string;
style?: React.CSSProperties;
} & Pick<ButtonProps, 'iconPosition'>;
}

const getCollapsedWidth = (): React.CSSProperties => ({
width: 0,
Expand All @@ -48,18 +44,11 @@ const getRealWidth = (node: HTMLElement): React.CSSProperties => ({
});

const LoadingIcon: React.FC<LoadingIconProps> = (props) => {
const { prefixCls, loading, existIcon, className, style, iconPosition } = props;
const { prefixCls, loading, existIcon, className, style } = props;
const visible = !!loading;

if (existIcon) {
return (
<InnerLoadingIcon
prefixCls={prefixCls}
className={className}
style={style}
iconPosition={iconPosition}
/>
);
return <InnerLoadingIcon prefixCls={prefixCls} className={className} style={style} />;
}

return (
Expand All @@ -83,7 +72,6 @@ const LoadingIcon: React.FC<LoadingIconProps> = (props) => {
style={{ ...style, ...motionStyle }}
ref={ref}
iconClassName={motionCls}
iconPosition={iconPosition}
/>
)}
</CSSMotion>
Expand Down
8 changes: 1 addition & 7 deletions components/button/style/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export type { ComponentToken };
// ============================== Shared ==============================
const genSharedButtonStyle: GenerateStyle<ButtonToken, CSSObject> = (token): CSSObject => {
const { componentCls, iconCls, fontWeight } = token;

return {
[componentCls]: {
outline: 'none',
Expand Down Expand Up @@ -40,10 +41,6 @@ const genSharedButtonStyle: GenerateStyle<ButtonToken, CSSObject> = (token): CSS

[`${componentCls}-icon`]: {
lineHeight: 0,
// iconPosition in end
[`&-end`]: {
marginInlineStart: token.marginXS,
},
},

// Leave a space between icon and text.
Expand All @@ -55,9 +52,6 @@ const genSharedButtonStyle: GenerateStyle<ButtonToken, CSSObject> = (token): CSS
[`&${componentCls}-loading-icon, &:not(:last-child)`]: {
marginInlineEnd: token.marginXS,
},
[`&${componentCls}-loading-icon-end`]: {
marginInlineStart: token.marginXS,
},
},

'> a': {
Expand Down

0 comments on commit 68227f8

Please sign in to comment.