import React, {Component} from 'react'
|
import PropTypes from 'prop-types'
|
import { is, fromJS } from 'immutable'
|
import { Modal, Icon, Row, Col, Button } from 'antd'
|
|
import { minkeIconSystem } from '@/utils/option.js'
|
import './index.scss'
|
|
class MkIcon extends Component {
|
static propTpyes = {
|
onChange: PropTypes.func
|
}
|
|
state = {
|
selectIcon: '',
|
allowClear: false,
|
icons: [...minkeIconSystem.direction, ...minkeIconSystem.edit, ...minkeIconSystem.normal, ...minkeIconSystem.trademark, ...minkeIconSystem.data, ...minkeIconSystem.hint],
|
visible: false
|
}
|
|
UNSAFE_componentWillMount () {
|
let val = ''
|
if (this.props['data-__meta']) {
|
val = this.props['data-__meta'].initialValue || ''
|
}
|
|
this.setState({selectIcon: val, allowClear: this.props.allowClear === true})
|
}
|
|
shouldComponentUpdate (nextProps, nextState) {
|
return !is(fromJS(this.state), fromJS(nextState))
|
}
|
|
checkIcon = (val) => {
|
this.setState({selectIcon: val, visible: false})
|
this.props.onChange(val)
|
}
|
|
render() {
|
const { selectIcon, visible, icons, allowClear } = this.state
|
|
return (
|
<div className="mk-icon-box">
|
{selectIcon ? <Icon type={selectIcon}/> : <Icon style={{opacity: 0}} type="plus"/>}
|
<Icon className="trigger" onClick={() => this.setState({visible: true})} type="swap"/>
|
{allowClear && selectIcon ? <Icon className="close" onClick={() => this.checkIcon('')} theme="filled" type="close-circle"/> : null}
|
<Modal
|
wrapClassName="popview-modal mk-icon-wrap"
|
title={'图标选择'}
|
visible={visible}
|
width={800}
|
maskClosable={false}
|
onCancel={() => { this.setState({ visible: false }) }}
|
footer={[
|
<Button key="close" onClick={() => { this.setState({ visible: false }) }}>关闭</Button>
|
]}
|
destroyOnClose
|
>
|
<Row>
|
{icons.map(icon => <Col className={icon === selectIcon ? 'active' : ''} key={icon} span={4}>
|
<Icon onClick={() => this.checkIcon(icon)} type={icon} />
|
</Col>)}
|
</Row>
|
</Modal>
|
</div>
|
)
|
}
|
}
|
|
export default MkIcon
|