UNPKG

@kiwicom/orbit-components

Version:

Orbit-components is a React component library which provides developers with the easiest possible way of building Kiwi.com’s products.

174 lines (148 loc) 6.94 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = exports.StyledTag = void 0; var React = _interopRequireWildcard(require("react")); var _styledComponents = _interopRequireDefault(require("styled-components")); var _defaultTheme = _interopRequireDefault(require("../defaultTheme")); var _rtl = require("../utils/rtl"); var _CloseCircle = _interopRequireDefault(require("../icons/CloseCircle")); var _consts = require("./consts"); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } } function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } var getFontSize = function getFontSize(_ref) { var _tokens; var theme = _ref.theme, size = _ref.size; var tokens = (_tokens = {}, _defineProperty(_tokens, _consts.SIZES.SMALL, theme.orbit.fontSizeTextSmall), _defineProperty(_tokens, _consts.SIZES.NORMAL, theme.orbit.fontSizeTextNormal), _tokens); return tokens[size]; }; var getBackgroundColor = function getBackgroundColor(state) { return function (_ref2) { var _states; var selected = _ref2.selected, theme = _ref2.theme; var states = (_states = {}, _defineProperty(_states, _consts.STATES.DEFAULT, selected ? theme.orbit.backgroundTagSelected : theme.orbit.backgroundTag), _defineProperty(_states, _consts.STATES.HOVER, selected ? theme.orbit.backgroundTagSelectedHover : theme.orbit.backgroundTagHover), _defineProperty(_states, _consts.STATES.ACTIVE, selected ? theme.orbit.backgroundTagSelectedActive : theme.orbit.backgroundTagActive), _states); return states[state]; }; }; var getSpacing = function getSpacing(_ref3) { var icon = _ref3.icon, removable = _ref3.removable, theme = _ref3.theme; var padding = removable && icon && theme.orbit.paddingTagRemovableWithIcon || removable && !icon && theme.orbit.paddingTagRemovable || !removable && icon && theme.orbit.paddingTagWithIcon || !removable && !icon && theme.orbit.paddingTag; return (0, _rtl.rtlSpacing)(padding); }; var StyledTag = _styledComponents.default.div.withConfig({ displayName: "Tag__StyledTag", componentId: "e565ij-0" })(["font-family:", ";color:", ";background:", ";display:inline-flex;cursor:pointer;box-sizing:border-box;justify-content:center;align-items:center;font-size:", ";font-weight:", ";border-radius:", ";box-shadow:", ";padding:", ";transition:color ", " ease-in-out,box-shadow ", " ease-in-out,background ", " ease-in-out;&:hover{background:", ";box-shadow:none;}&:active{background:", ";box-shadow:none;}&:focus{box-shadow:", ";outline:0;}"], function (_ref4) { var theme = _ref4.theme; return theme.orbit.fontFamily; }, function (_ref5) { var theme = _ref5.theme, selected = _ref5.selected; return selected ? theme.orbit.colorTextTagSelected : theme.orbit.colorTextTag; }, getBackgroundColor(_consts.STATES.DEFAULT), getFontSize, function (_ref6) { var theme = _ref6.theme; return theme.orbit.fontWeightMedium; }, function (_ref7) { var theme = _ref7.theme; return theme.orbit.borderRadiusNormal; }, function (_ref8) { var theme = _ref8.theme, selected = _ref8.selected; return !selected && "inset 0 0 0 1px ".concat(theme.orbit.borderColorTag); }, getSpacing, function (_ref9) { var theme = _ref9.theme; return theme.orbit.durationFast; }, function (_ref10) { var theme = _ref10.theme; return theme.orbit.durationFast; }, function (_ref11) { var theme = _ref11.theme; return theme.orbit.durationFast; }, getBackgroundColor(_consts.STATES.HOVER), getBackgroundColor(_consts.STATES.ACTIVE), function (_ref12) { var theme = _ref12.theme; return "inset 0 0 0 2px ".concat(theme.orbit.borderColorTagFocus); }); exports.StyledTag = StyledTag; StyledTag.defaultProps = { theme: _defaultTheme.default }; var IconContainer = _styledComponents.default.div.withConfig({ displayName: "Tag__IconContainer", componentId: "e565ij-1" })(["display:flex;margin-", ":8px;svg{height:", ";width:", ";}"], _rtl.right, function (_ref13) { var theme = _ref13.theme; return theme.orbit.widthIconSmall; }, function (_ref14) { var theme = _ref14.theme; return theme.orbit.heightIconSmall; }); IconContainer.defaultProps = { theme: _defaultTheme.default }; var CloseContainer = _styledComponents.default.div.withConfig({ displayName: "Tag__CloseContainer", componentId: "e565ij-2" })(["display:flex;margin-", ":8px;color:", ";cursor:pointer;transition:color ", " ease-in-out;&:hover{color:", ";}&:active{color:", ";}"], _rtl.left, function (_ref15) { var theme = _ref15.theme; return theme.orbit.paletteInkLighter; }, function (_ref16) { var theme = _ref16.theme; return theme.orbit.durationFast; }, function (_ref17) { var theme = _ref17.theme; return theme.orbit.paletteInkLighterHover; }, function (_ref18) { var theme = _ref18.theme; return theme.orbit.paletteInkLighterActive; }); CloseContainer.defaultProps = { theme: _defaultTheme.default }; var StyledClose = _styledComponents.default.div.withConfig({ displayName: "Tag__StyledClose", componentId: "e565ij-3" })(["display:flex;border-radius:100%;&:focus{outline:none;box-shadow:0px 0 0px 2px ", ";}"], function (_ref19) { var theme = _ref19.theme; return theme.orbit.paletteCloudNormalActive; }); StyledClose.defaultProps = { theme: _defaultTheme.default }; var Tag = function Tag(props) { var icon = props.icon, selected = props.selected, children = props.children, _props$size = props.size, size = _props$size === void 0 ? _consts.SIZES.NORMAL : _props$size, onClick = props.onClick, onRemove = props.onRemove, dataTest = props.dataTest; return React.createElement(StyledTag, { "data-test": dataTest, size: size, onClick: onClick, removable: !!onRemove, selected: selected, icon: !!icon }, icon && React.createElement(IconContainer, null, icon), children, (!!onRemove || selected) && React.createElement(CloseContainer, { onClick: function onClick(ev) { ev.stopPropagation(); if (onRemove) { onRemove(); } } }, React.createElement(StyledClose, { tabIndex: "0", role: "button" }, React.createElement(_CloseCircle.default, { size: "small" })))); }; var _default = Tag; exports.default = _default;