UNPKG

choerodon-ui

Version:

An enterprise-class UI design language and React-based implementation

176 lines (143 loc) 5.27 kB
import _extends from "@babel/runtime/helpers/extends"; import _objectSpread from "@babel/runtime/helpers/objectSpread2"; import _defineProperty from "@babel/runtime/helpers/defineProperty"; import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties"; import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; import _createClass from "@babel/runtime/helpers/createClass"; import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized"; import _inherits from "@babel/runtime/helpers/inherits"; import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn"; import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf"; function _createSuper(Derived) { function isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } } return function () { var Super = _getPrototypeOf(Derived), result; if (isNativeReflectConstruct()) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } import React, { Component } from 'react'; import { findDOMNode } from 'react-dom'; import classNames from 'classnames'; import omit from 'lodash/omit'; import Icon from '../icon'; import CheckableTag from './CheckableTag'; import Animate from '../animate'; import { isPresetColor as isPresetColorUtil } from '../_util/colors'; import ConfigContext from '../config-provider/ConfigContext'; var Tag = /*#__PURE__*/ function (_Component) { _inherits(Tag, _Component); var _super = _createSuper(Tag); function Tag() { var _this; _classCallCheck(this, Tag); _this = _super.apply(this, arguments); _this.state = { closing: false, closed: false }; _this.close = function (e) { var onClose = _this.props.onClose; if (onClose) { onClose(e); } if (e.defaultPrevented) { return; } var dom = findDOMNode(_assertThisInitialized(_this)); dom.style.width = "".concat(dom.getBoundingClientRect().width, "px"); // It's Magic Code, don't know why dom.style.width = "".concat(dom.getBoundingClientRect().width, "px"); _this.setState({ closing: true }); }; _this.animationEnd = function (_, existed) { var closed = _this.state.closed; if (!existed && !closed) { _this.setState({ closed: true, closing: false }); var afterClose = _this.props.afterClose; if (afterClose) { afterClose(); } } }; return _this; } _createClass(Tag, [{ key: "render", value: function render() { var _classNames; var _this$props = this.props, customizePrefixCls = _this$props.prefixCls, closable = _this$props.closable, color = _this$props.color, className = _this$props.className, children = _this$props.children, style = _this$props.style, otherProps = _objectWithoutProperties(_this$props, ["prefixCls", "closable", "color", "className", "children", "style"]); var getPrefixCls = this.context.getPrefixCls; var prefixCls = getPrefixCls('tag', customizePrefixCls); var _this$state = this.state, closing = _this$state.closing, closed = _this$state.closed; var closeIcon = closable ? React.createElement(Icon, { type: "close", onClick: this.close }) : ''; var isPresetColor = isPresetColorUtil(color); var classString = classNames(prefixCls, (_classNames = {}, _defineProperty(_classNames, "".concat(prefixCls, "-").concat(color), isPresetColor), _defineProperty(_classNames, "".concat(prefixCls, "-has-color"), color && !isPresetColor), _defineProperty(_classNames, "".concat(prefixCls, "-close"), closing), _classNames), className); // fix https://fb.me/react-unknown-prop var divProps = omit(otherProps, ['onClose', 'afterClose']); var tagStyle = _objectSpread({}, style); if (color && !isPresetColor) { tagStyle.backgroundColor = color; } var tag = closed ? null : React.createElement("div", _extends({ hidden: closing }, divProps, { className: classString, style: tagStyle }), children, closeIcon); return React.createElement(Animate, { component: "", hiddenProp: "hidden", transitionName: "".concat(prefixCls, "-zoom"), transitionAppear: true, onEnd: this.animationEnd }, tag); } }], [{ key: "contextType", get: function get() { return ConfigContext; } }]); return Tag; }(Component); export { Tag as default }; Tag.displayName = 'Tag'; Tag.CheckableTag = CheckableTag; Tag.defaultProps = { closable: false }; //# sourceMappingURL=index.js.map