forked from alibaba-fusion/next
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.jsx
109 lines (101 loc) · 2.66 KB
/
index.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import cx from 'classnames';
import ConfigProvider from '../config-provider';
import createFromIconfontCN from './icon-font';
import { obj } from '../util';
/**
* Icon
*/
class Icon extends Component {
static propTypes = {
...ConfigProvider.propTypes,
/**
* 指定显示哪种图标
*/
type: PropTypes.string,
children: PropTypes.node,
/**
* 指定图标大小
* <br/>**可选值**<br/> xxs, xs, small, medium, large, xl, xxl, xxxl, inherit
*/
size: PropTypes.oneOfType([
PropTypes.oneOf([
'xxs',
'xs',
'small',
'medium',
'large',
'xl',
'xxl',
'xxxl',
'inherit',
]),
PropTypes.number,
]),
className: PropTypes.string,
style: PropTypes.object,
};
static defaultProps = {
prefix: 'next-',
size: 'medium',
};
static _typeMark = 'icon';
render() {
/* eslint-disable no-unused-vars*/
const {
prefix,
type,
size,
className,
rtl,
style,
children,
} = this.props;
const others = obj.pickOthers(
Object.assign({}, Icon.propTypes),
this.props
);
const classes = cx({
[`${prefix}icon`]: true,
[`${prefix}icon-${type}`]: !!type,
[`${prefix}${size}`]: !!size && typeof size === 'string',
[className]: !!className,
});
if (
rtl &&
[
'arrow-left',
'arrow-right',
'arrow-double-left',
'arrow-double-right',
'switch',
'sorting',
'descending',
'ascending',
].indexOf(type) !== -1
) {
others.dir = 'rtl';
}
const sizeStyle =
typeof size === 'number'
? {
width: size,
height: size,
lineHeight: `${size}px`,
fontSize: size,
}
: {};
return (
<i
{...others}
style={{ ...sizeStyle, ...style }}
className={classes}
>
{children}
</i>
);
}
}
Icon.createFromIconfontCN = createFromIconfontCN;
export default ConfigProvider.config(Icon);