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.

96 lines (90 loc) 2.49 kB
import * as React from "react"; import styled, { css } from "styled-components"; import { ICON_SIZES, ICON_COLORS } from "./consts"; import defaultTheme from "../defaultTheme"; export const getSize = size => ({ theme }) => { const tokens = { [ICON_SIZES.SMALL]: theme.orbit.widthIconSmall, [ICON_SIZES.MEDIUM]: theme.orbit.widthIconMedium, [ICON_SIZES.LARGE]: theme.orbit.widthIconLarge }; return tokens[size] || tokens[ICON_SIZES.MEDIUM]; }; const getColor = () => ({ theme, color }) => { const tokens = { [ICON_COLORS.PRIMARY]: theme.orbit.colorIconPrimary, [ICON_COLORS.SECONDARY]: theme.orbit.colorIconSecondary, [ICON_COLORS.TERTIARY]: theme.orbit.colorIconTertiary, [ICON_COLORS.INFO]: theme.orbit.colorIconInfo, [ICON_COLORS.SUCCESS]: theme.orbit.colorIconSuccess, [ICON_COLORS.WARNING]: theme.orbit.colorIconWarning, [ICON_COLORS.CRITICAL]: theme.orbit.colorIconCritical }; return tokens[color]; }; const reverse = ({ reverseOnRtl, theme }) => reverseOnRtl && theme.rtl && css(["transform:scale(-1,1);"]); const StyledIcon = styled(({ 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 }; 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: ICON_SIZES.MEDIUM }; export default OrbitIcon;