cpui-components
Version:
77 lines (61 loc) • 3.08 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.Tag = undefined;
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
var _react = require("react");
var _react2 = _interopRequireDefault(_react);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var Tag = exports.Tag = function (_Component) {
_inherits(Tag, _Component);
function Tag(props) {
_classCallCheck(this, Tag);
var _this = _possibleConstructorReturn(this, (Tag.__proto__ || Object.getPrototypeOf(Tag)).call(this, props));
_this.onClickHandler = function (e) {
if (_this.props.onRemove) {
_this.props.onRemove(e);
}
};
_this.render = function () {
var tagType = _this.state.type + "";
var tagIsRemovable = _this.state.isRemovable;
var data = {};
_this.props.data && Object.keys(_this.props.data).forEach(function (dataField) {
data["data-" + dataField] = _this.props.data[dataField];
});
return _react2.default.createElement(
"div",
_extends({}, data, {
className: "cp-tag " + (tagType.toLowerCase() === "contenttype" ? "cp-tag--contentType" : tagType.toLowerCase() === "super" || tagType.toLowerCase() === "supertag" ? "cp-tag--superTag" : "") + " " + (tagIsRemovable ? "cp-tag--removable" : "") + " " + (_this.state.isDraggable ? "cp-tag--draggable" : "")
}),
_this.props.children,
tagIsRemovable ? _react2.default.createElement(
"button",
{
onClick: _this.onClickHandler,
className: "cp-tag-remove",
"aria-label": "Remove Tag",
title: "Remove Tag"
},
_react2.default.createElement(
"svg",
null,
_react2.default.createElement("use", { xlinkHref: "#iconClose" })
)
) : ""
);
};
_this.state = {
isRemovable: _this.props.removable,
isDraggable: _this.props.draggable,
type: _this.props.type
};
return _this;
}
return Tag;
}(_react.Component);
exports.default = Tag;
;