mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-27 20:49:53 +08:00
add icon features
This commit is contained in:
parent
ccdff565de
commit
535f68dbd0
@ -18,9 +18,11 @@ import { Icon } from 'antd';
|
|||||||
|
|
||||||
ReactDOM.render(
|
ReactDOM.render(
|
||||||
<div>
|
<div>
|
||||||
<Icon type="home" />
|
<Icon type="home" fixedWidth/>
|
||||||
|
<Icon type="message" flip="vertical" rotate={90}/>
|
||||||
<Icon type="setting" />
|
<Icon type="setting" />
|
||||||
<Icon type="smile" />
|
<Icon type="smile" />
|
||||||
|
<Icon type="smile" rotate={180}/>
|
||||||
<Icon type="reload" spin />
|
<Icon type="reload" spin />
|
||||||
</div>,
|
</div>,
|
||||||
mountNode
|
mountNode
|
||||||
|
@ -1,11 +1,14 @@
|
|||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import omit from 'omit.js';
|
|
||||||
import { antDesignIcons } from '@ant-design/icons';
|
import { antDesignIcons } from '@ant-design/icons';
|
||||||
import AntdIcon from '@ant-design/icons-react';
|
import ReactIcon from '@ant-design/icons-react';
|
||||||
import CustomIcon, { create } from './CustomIcon';
|
import CustomIcon, { create } from './CustomIcon';
|
||||||
|
|
||||||
AntdIcon.add(...antDesignIcons);
|
ReactIcon.add(...antDesignIcons);
|
||||||
|
|
||||||
|
export type IconRotateNumber = 15 | 30 | 45 | 60 | 75
|
||||||
|
| 90 | 105 | 120 | 135 | 150 | 165 | 180 | 195 | 210
|
||||||
|
| 225 | 240 | 270 | 285 | 300 | 315 | 330 | 345 | 360;
|
||||||
|
|
||||||
export interface IconProps {
|
export interface IconProps {
|
||||||
type: string;
|
type: string;
|
||||||
@ -14,17 +17,46 @@ export interface IconProps {
|
|||||||
onClick?: React.MouseEventHandler<any>;
|
onClick?: React.MouseEventHandler<any>;
|
||||||
spin?: boolean;
|
spin?: boolean;
|
||||||
style?: React.CSSProperties;
|
style?: React.CSSProperties;
|
||||||
|
svgStyle?: React.CSSProperties;
|
||||||
|
svgClassName?: string;
|
||||||
|
rotate?: IconRotateNumber;
|
||||||
|
flip?: 'horizontal' | 'vertical' | 'both';
|
||||||
|
fixedWidth?: true;
|
||||||
|
prefixCls?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Icon: React.SFC<IconProps> = (props: IconProps) => {
|
const Icon: React.SFC<IconProps> = (props: IconProps) => {
|
||||||
const { type, className = '', spin } = props;
|
const {
|
||||||
const classString = classNames({
|
prefixCls = 'ant-icon',
|
||||||
anticon: true,
|
type, className = '', spin, flip, fixedWidth,
|
||||||
'anticon-spin': !!spin || type === 'loading',
|
svgClassName,
|
||||||
}, className);
|
onClick, style, rotate = 0, svgStyle = {},
|
||||||
|
} = props;
|
||||||
|
const classString = classNames(
|
||||||
|
{
|
||||||
|
[`anticon`]: true,
|
||||||
|
[`anticon-spin`]: !!spin || type === 'loading',
|
||||||
|
|
||||||
|
},
|
||||||
|
className,
|
||||||
|
);
|
||||||
|
|
||||||
|
const svgClassString = classNames(
|
||||||
|
{
|
||||||
|
[`${prefixCls}-rotate-${rotate}`]: rotate,
|
||||||
|
[`${prefixCls}-flip-${flip}`]: flip,
|
||||||
|
[`${prefixCls}-fixed-width`]: fixedWidth,
|
||||||
|
},
|
||||||
|
svgClassName,
|
||||||
|
);
|
||||||
return (
|
return (
|
||||||
<i className={classString}>
|
<i className={classString} style={style}>
|
||||||
<AntdIcon {...omit(props, ['type', 'spin', 'className'])} type={type} />
|
<ReactIcon
|
||||||
|
className={svgClassString}
|
||||||
|
type={type}
|
||||||
|
onClick={onClick}
|
||||||
|
style={svgStyle}
|
||||||
|
/>
|
||||||
</i>
|
</i>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
35
components/icon/style/index.less
Normal file
35
components/icon/style/index.less
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
@import "../../style/themes/default";
|
||||||
|
@import "../../style/mixins/index";
|
||||||
|
|
||||||
|
@icon-prefix-cls: ~"@{ant-prefix}-icon";
|
||||||
|
|
||||||
|
@step-forward: 15;
|
||||||
|
|
||||||
|
.generate-rotation(@count, @i: @step-forward) when (@i <= @count) {
|
||||||
|
&-@{i} {
|
||||||
|
transform: rotate(~'@{i}deg');
|
||||||
|
}
|
||||||
|
.generate-rotation(@count, (@i + @step-forward));
|
||||||
|
}
|
||||||
|
|
||||||
|
.@{icon-prefix-cls} {
|
||||||
|
&-rotate {
|
||||||
|
.generate-rotation(360);
|
||||||
|
}
|
||||||
|
|
||||||
|
&-flip {
|
||||||
|
&-horizontal {
|
||||||
|
transform: scaleX(-1);
|
||||||
|
}
|
||||||
|
&-vertical {
|
||||||
|
transform: scaleY(-1);
|
||||||
|
}
|
||||||
|
&-both {
|
||||||
|
transform: scaleX(-1) scaleY(-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
&-fixed-width {
|
||||||
|
width: 1.25em;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
}
|
@ -1 +1,2 @@
|
|||||||
import '../../style/index.less';
|
import '../../style/index.less';
|
||||||
|
import './index.less';
|
||||||
|
@ -39,8 +39,8 @@
|
|||||||
"react-dom": ">=16.0.0"
|
"react-dom": ">=16.0.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ant-design/icons": "^0.1.0-alpha.2",
|
"@ant-design/icons": "^0.1.2-alpha.1",
|
||||||
"@ant-design/icons-react": "^0.1.0-alpha.6",
|
"@ant-design/icons-react": "^0.1.2-alpha.2",
|
||||||
"array-tree-filter": "^2.0.0",
|
"array-tree-filter": "^2.0.0",
|
||||||
"babel-runtime": "6.x",
|
"babel-runtime": "6.x",
|
||||||
"classnames": "~2.2.0",
|
"classnames": "~2.2.0",
|
||||||
|
Loading…
Reference in New Issue
Block a user