remove useless jsx prop

This commit is contained in:
HeskeyBaozi 2018-08-07 16:35:26 +08:00
parent f90d32a0ef
commit 15bc92dd3c
5 changed files with 31 additions and 40 deletions

View File

@ -2,6 +2,7 @@ import * as React from 'react';
import classNames from 'classnames';
import { Omit } from '../_util/type';
import { IconProps } from './index';
import { getComputedSvgStyle } from './utils';
export interface CustomIconProps extends Omit<IconProps, 'type'> {
type?: string | SpriteSvgIcon;
@ -58,22 +59,11 @@ const CustomIcon: React.SFC<CustomIconProps> = (props) => {
'anticon-spin': !!spin,
}, className);
const svgClassString = classNames(
svgClassName,
);
const computedSvgStyle: React.CSSProperties = {
transform: `${rotate ? `rotate(${rotate}deg)` : ''} `
+ `${(flip === 'horizontal' || flip === 'both') ? `scaleX(-1)` : ''} `
+ `${(flip === 'vertical' || flip === 'both') ? `scaleY(-1)` : ''}`,
...svgStyle,
};
const innerSvgProps = {
...svgBaseProps,
viewBox,
className: svgClassString,
style: computedSvgStyle,
className: svgClassName,
style: getComputedSvgStyle({ rotate, flip }, svgStyle),
};
let content = (

View File

@ -2,6 +2,7 @@ import { IconProps } from './index';
import * as React from 'react';
import classNames from 'classnames';
import { svgBaseProps } from './CustomIcon';
import { getComputedSvgStyle } from './utils';
const customCache = new Set<string>();
@ -43,22 +44,11 @@ export default function create(options: CustomIconOptions = {}): React.Component
className,
);
const computedSvgStyle: React.CSSProperties = {
transform: `${rotate ? `rotate(${rotate}deg)` : ''} `
+ `${(flip === 'horizontal' || flip === 'both') ? `scaleX(-1)` : ''} `
+ `${(flip === 'vertical' || flip === 'both') ? `scaleY(-1)` : ''}`,
...svgStyle,
};
const svgClassString = classNames(
svgClassName,
);
const innerSvgProps = {
...svgBaseProps,
viewBox,
className: svgClassString,
style: computedSvgStyle,
className: svgClassName,
style: getComputedSvgStyle({ rotate, flip }, svgStyle),
};
return React.createElement(

View File

@ -4,6 +4,7 @@ import { antDesignIcons } from '@ant-design/icons';
import ReactIcon from '@ant-design/icons-react';
import CustomIcon from './CustomIcon';
import create from './IconFont';
import { getComputedSvgStyle } from './utils';
ReactIcon.add(...antDesignIcons);
@ -45,17 +46,6 @@ const Icon: React.SFC<IconProps> = (props: IconProps) => {
className,
);
const svgClassString = classNames(
svgClassName,
);
const computedSvgStyle: React.CSSProperties = {
transform: `${rotate ? `rotate(${rotate}deg)` : ''} `
+ `${(flip === 'horizontal' || flip === 'both') ? `scaleX(-1)` : ''} `
+ `${(flip === 'vertical' || flip === 'both') ? `scaleY(-1)` : ''}`,
...svgStyle,
};
return React.createElement(
tag,
{
@ -64,9 +54,9 @@ const Icon: React.SFC<IconProps> = (props: IconProps) => {
onClick,
},
<ReactIcon
className={svgClassString}
className={svgClassName}
type={type}
style={computedSvgStyle}
style={getComputedSvgStyle({ rotate, flip }, svgStyle)}
/>,
);
};

21
components/icon/utils.ts Normal file
View File

@ -0,0 +1,21 @@
import * as React from 'react';
import { IconProps } from './index';
type TransformInformation = Pick<IconProps, 'rotate' | 'flip'>;
export function getComputedSvgStyle(
{ rotate, flip }: TransformInformation,
svgStyle: React.CSSProperties,
): React.CSSProperties {
if (!(rotate || flip)) {
return { ...svgStyle };
}
return {
transform: `${rotate ? `rotate(${rotate}deg)` : ''} `
+ `${(flip === 'horizontal' || flip === 'both') ? `scaleX(-1)` : ''} `
+ `${(flip === 'vertical' || flip === 'both') ? `scaleY(-1)` : ''}`,
...svgStyle,
};
}

View File

@ -74,7 +74,7 @@
"rc-select": "~8.1.1",
"rc-slider": "~8.6.0",
"rc-steps": "~3.1.0",
"rc-switch": "~1.6.0",
"rc-switch": "~1.7.0",
"rc-table": "~6.2.0",
"rc-tabs": "~9.3.3",
"rc-time-picker": "~3.3.0",