element-react-codish
Version:
Element UI for React
77 lines (65 loc) • 2 kB
JavaScript
import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
import _inherits from 'babel-runtime/helpers/inherits';
import React from 'react';
import { Component, PropTypes, Transition, View } from '../../libs';
var Tag = function (_Component) {
_inherits(Tag, _Component);
function Tag(props) {
_classCallCheck(this, Tag);
var _this = _possibleConstructorReturn(this, _Component.call(this, props));
_this.state = {
visible: true
};
return _this;
}
Tag.prototype.handleClose = function handleClose() {
if (this.props.onClose) {
if (this.props.onClose()) {
this.setState({
visible: false
});
}
} else {
this.setState({
visible: false
});
}
};
Tag.prototype.render = function render() {
var _props = this.props,
type = _props.type,
hit = _props.hit,
closable = _props.closable,
closeTransition = _props.closeTransition,
color = _props.color;
return React.createElement(
Transition,
{ name: closeTransition ? '' : 'el-zoom-in-center', duration: '200' },
React.createElement(
View,
{ key: this.state.visible, show: this.state.visible },
React.createElement(
'span',
{ style: this.style({
backgroundColor: color
}), className: this.className('el-tag', type && 'el-tag--' + type, {
'is-hit': hit
}) },
this.props.children,
closable && React.createElement('i', { className: 'el-tag__close el-icon-close', onClick: this.handleClose.bind(this) })
)
)
);
};
return Tag;
}(Component);
export default Tag;
Tag.propTypes = {
closable: PropTypes.bool,
type: PropTypes.string,
hit: PropTypes.bool,
color: PropTypes.string,
closeTransition: PropTypes.bool,
onClose: PropTypes.func
};