@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.
114 lines (99 loc) • 3.07 kB
JavaScript
;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = exports.getSize = void 0;
var React = _interopRequireWildcard(require("react"));
var _styledComponents = _interopRequireWildcard(require("styled-components"));
var _consts = require("./consts");
var _defaultTheme = _interopRequireDefault(require("../defaultTheme"));
const getSize = size => ({
theme
}) => {
const tokens = {
[_consts.ICON_SIZES.SMALL]: theme.orbit.widthIconSmall,
[_consts.ICON_SIZES.MEDIUM]: theme.orbit.widthIconMedium,
[_consts.ICON_SIZES.LARGE]: theme.orbit.widthIconLarge
};
return tokens[size] || tokens[_consts.ICON_SIZES.MEDIUM];
};
exports.getSize = getSize;
const getColor = () => ({
theme,
color
}) => {
const tokens = {
[_consts.ICON_COLORS.PRIMARY]: theme.orbit.colorIconPrimary,
[_consts.ICON_COLORS.SECONDARY]: theme.orbit.colorIconSecondary,
[_consts.ICON_COLORS.TERTIARY]: theme.orbit.colorIconTertiary,
[_consts.ICON_COLORS.INFO]: theme.orbit.colorIconInfo,
[_consts.ICON_COLORS.SUCCESS]: theme.orbit.colorIconSuccess,
[_consts.ICON_COLORS.WARNING]: theme.orbit.colorIconWarning,
[_consts.ICON_COLORS.CRITICAL]: theme.orbit.colorIconCritical
};
return tokens[color];
};
const reverse = ({
reverseOnRtl,
theme
}) => reverseOnRtl && theme.rtl && (0, _styledComponents.css)(["transform:scale(-1,1);"]);
const StyledIcon = (0, _styledComponents.default)(({
className,
viewBox,
dataTest,
children,
ariaHidden,
ariaLabel
}) => /*#__PURE__*/React.createElement("svg", {
className: className,
viewBox: viewBox,
"data-test": dataTest,
preserveAspectRatio: "xMidYMid meet",
"aria-hidden": ariaHidden ? "true" : undefined,
"aria-label": ariaLabel
}, children)).withConfig({
displayName: "Icon__StyledIcon",
componentId: "sc-1det6wr-0"
})(["display:inline-block;width:", ";height:", ";flex-shrink:0;vertical-align:middle;fill:currentColor;color:", ";", ";"], ({
size
}) => getSize(size), ({
size
}) => getSize(size), ({
color,
customColor
}) => customColor || color && getColor(), reverse); // $FlowFixMe: https://github.com/flow-typed/flow-typed/issues/3653#issuecomment-568539198
StyledIcon.defaultProps = {
theme: _defaultTheme.default
};
const OrbitIcon = props => {
const {
size,
color,
customColor,
className,
children,
viewBox,
dataTest,
ariaHidden,
reverseOnRtl,
ariaLabel
} = props;
return /*#__PURE__*/React.createElement(StyledIcon, {
viewBox: viewBox,
size: size,
className: className,
dataTest: dataTest,
customColor: customColor,
color: color,
ariaHidden: ariaHidden,
reverseOnRtl: reverseOnRtl,
ariaLabel: ariaLabel
}, children);
};
OrbitIcon.defaultProps = {
size: _consts.ICON_SIZES.MEDIUM
};
var _default = OrbitIcon;
exports.default = _default;