UNPKG

yylib-quick-mobile

Version:

yylib-quick-mobile

65 lines (64 loc) 1.99 kB
import React, {Component} from 'react'; import {Icon} from 'antd-mobile'; import {ArrayIndexOf} from '../../utils/lfwUtil' require ('../../common/svg/iconfont'); const iconType = [ 'check-circle', 'check', 'check-circle-o', 'cross-circle', 'cross', 'cross-circle-o', 'up', 'down', 'left', 'right', 'ellipsis', 'loading', ];//内置Icon class YYIcon extends Component{ clickIcon(){ this.props.onClick&&this.props.onClick(); } render() { const {type, size, color,visible,findUI, offline,parentType, uiorigin, RunInDesign, uititle, uitype, uikey, nid,control_event,...restProps} = this.props; let CustomIcon = ({type, className = !visible&&'hidden', size = 'xs', ...restProps}) => ( <svg {...restProps} className={`am-icon am-icon-${type} am-icon-${size} ${className}`} onClick={this.clickIcon.bind(this)}> <use xlinkHref={'#icon-'+type}/> </svg> ); /** * 如果是内置Icon,则使用icon组件 */ if(ArrayIndexOf(iconType,type)){ CustomIcon = ({type, className = !visible&&'hidden', size = 'xs', ...restProps}) => ( <Icon {...restProps} type={type} size={size} color={color} onClick={this.clickIcon.bind(this)} /> ); } return ( <CustomIcon {...restProps} type={type} size={size} color={color}/> ); } } YYIcon.defaultProps = { type:'Home', color: '', size: 'xs', visible: true, //设计器需要的props,不添加会warning findUI:'', offline:false, parentType:'', uiorigin:'', RunInDesign:false, uititle:'', uitype:'', uikey:'', nid:'', control_event:{}, } export default YYIcon; //单个svg引入方式 /*let svg = void 0; if (type) { try { svg = require('../../../svg/' + type + '.svg'); } catch (e) { console.error(e); } finally { } }*/