UNPKG

2.83 kBJavaScriptView Raw
1import _extends from 'babel-runtime/helpers/extends';
2import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
3import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
4import _inherits from 'babel-runtime/helpers/inherits';
5
6var _class, _temp;
7
8import React, { Component } from 'react';
9import PropTypes from 'prop-types';
10import cx from 'classnames';
11import ConfigProvider from '../config-provider';
12import createFromIconfontCN from './icon-font';
13import { obj } from '../util';
14/**
15 * Icon
16 */
17var Icon = (_temp = _class = function (_Component) {
18 _inherits(Icon, _Component);
19
20 function Icon() {
21 _classCallCheck(this, Icon);
22
23 return _possibleConstructorReturn(this, _Component.apply(this, arguments));
24 }
25
26 Icon.prototype.render = function render() {
27 var _cx;
28
29 /* eslint-disable no-unused-vars*/
30 var _props = this.props,
31 prefix = _props.prefix,
32 type = _props.type,
33 size = _props.size,
34 className = _props.className,
35 rtl = _props.rtl,
36 style = _props.style,
37 children = _props.children;
38
39 var others = obj.pickOthers(_extends({}, Icon.propTypes), this.props);
40
41 var classes = cx((_cx = {}, _cx[prefix + 'icon'] = true, _cx[prefix + 'icon-' + type] = !!type, _cx['' + prefix + size] = !!size && typeof size === 'string', _cx[className] = !!className, _cx));
42
43 if (rtl && ['arrow-left', 'arrow-right', 'arrow-double-left', 'arrow-double-right', 'switch', 'sorting', 'descending', 'ascending'].indexOf(type) !== -1) {
44 others.dir = 'rtl';
45 }
46
47 var sizeStyle = typeof size === 'number' ? {
48 width: size,
49 height: size,
50 lineHeight: size + 'px',
51 fontSize: size
52 } : {};
53
54 return React.createElement(
55 'i',
56 _extends({}, others, {
57 style: _extends({}, sizeStyle, style),
58 className: classes
59 }),
60 children
61 );
62 };
63
64 return Icon;
65}(Component), _class.propTypes = _extends({}, ConfigProvider.propTypes, {
66 /**
67 * 指定显示哪种图标
68 */
69 type: PropTypes.string,
70 children: PropTypes.node,
71 /**
72 * 指定图标大小
73 * <br/>**可选值**<br/> xxs, xs, small, medium, large, xl, xxl, xxxl, inherit
74 */
75 size: PropTypes.oneOfType([PropTypes.oneOf(['xxs', 'xs', 'small', 'medium', 'large', 'xl', 'xxl', 'xxxl', 'inherit']), PropTypes.number]),
76 className: PropTypes.string,
77 style: PropTypes.object
78}), _class.defaultProps = {
79 prefix: 'next-',
80 size: 'medium'
81}, _class._typeMark = 'icon', _temp);
82Icon.displayName = 'Icon';
83
84
85Icon.createFromIconfontCN = createFromIconfontCN;
86export default ConfigProvider.config(Icon);
\No newline at end of file