@bigbinary/neetoui
Version:
neetoUI drives the experience at all neeto products
90 lines (87 loc) • 3.76 kB
JavaScript
import _extends from '@babel/runtime/helpers/extends';
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
import React__default, { forwardRef, Fragment } from 'react';
import classnames from 'classnames';
import { Close } from '@bigbinary/neeto-icons';
var _excluded = ["style", "indicatorStyle", "label", "icon", "className", "onClose", "disabled", "size", "type", "children"];
var SIZES = {
small: "small",
large: "large"
};
var TYPES = {
outline: "outline",
solid: "solid"
};
var STYLES = {
primary: "primary",
secondary: "secondary",
info: "info",
success: "success",
warning: "warning",
danger: "danger"
};
var Tag = /*#__PURE__*/forwardRef(function (_ref, ref) {
var _ref$style = _ref.style,
style = _ref$style === void 0 ? STYLES.primary : _ref$style,
indicatorStyle = _ref.indicatorStyle,
_ref$label = _ref.label,
label = _ref$label === void 0 ? "" : _ref$label,
_ref$icon = _ref.icon,
icon = _ref$icon === void 0 ? null : _ref$icon,
_ref$className = _ref.className,
className = _ref$className === void 0 ? "" : _ref$className,
_ref$onClose = _ref.onClose,
onClose = _ref$onClose === void 0 ? null : _ref$onClose,
_ref$disabled = _ref.disabled,
disabled = _ref$disabled === void 0 ? false : _ref$disabled,
_ref$size = _ref.size,
size = _ref$size === void 0 ? SIZES.small : _ref$size,
_ref$type = _ref.type,
type = _ref$type === void 0 ? TYPES.outline : _ref$type,
children = _ref.children,
otherProps = _objectWithoutProperties(_ref, _excluded);
var Icon = typeof icon === "string" ? function () {
return /*#__PURE__*/React__default.createElement("i", {
className: icon
});
} : icon || Fragment;
var renderLabel = label || children;
return /*#__PURE__*/React__default.createElement("div", _extends({
ref: ref,
"data-cy": "tag-container",
"data-testid": "tag-container",
className: classnames("neeto-ui-tag", {
"neeto-ui-tag--size-large": size === SIZES.large,
"neeto-ui-tag--size-small": size === SIZES.small,
"neeto-ui-tag--type-outline": type === TYPES.outline,
"neeto-ui-tag--type-solid": type === TYPES.solid,
"neeto-ui-tag--style-primary": style === STYLES.primary,
"neeto-ui-tag--style-secondary": style === STYLES.secondary,
"neeto-ui-tag--style-success": style === STYLES.success,
"neeto-ui-tag--style-info": style === STYLES.info,
"neeto-ui-tag--style-warning": style === STYLES.warning,
"neeto-ui-tag--style-danger": style === STYLES.danger
}, className)
}, otherProps), indicatorStyle && /*#__PURE__*/React__default.createElement("span", {
"data-testid": "tag-indicator",
className: classnames("neeto-ui-tag__indicator", {
"neeto-ui-bg-error-500": indicatorStyle === STYLES.danger,
"neeto-ui-bg-info-500": indicatorStyle === STYLES.info,
"neeto-ui-bg-warning-500": indicatorStyle === STYLES.warning,
"neeto-ui-bg-success-500": indicatorStyle === STYLES.success,
"neeto-ui-bg-primary-500": indicatorStyle === STYLES.primary,
"neeto-ui-bg-gray-500": indicatorStyle === STYLES.secondary
})
}), icon && /*#__PURE__*/React__default.createElement("span", {
className: "neeto-ui-tag__icon",
"data-testid": "class-icon"
}, /*#__PURE__*/React__default.createElement(Icon, null)), renderLabel, onClose && /*#__PURE__*/React__default.createElement("span", {
className: "neeto-ui-tag__close",
"data-cy": "tag-close-icon",
"data-testid": "tag-close-button",
onClick: !disabled ? onClose : null
}, /*#__PURE__*/React__default.createElement(Close, null)));
});
Tag.displayName = "Tag";
export { Tag as default };
//# sourceMappingURL=Tag.js.map