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.

81 lines (77 loc) 2.02 kB
import * as React from "react"; import styled from "styled-components"; import { ICON_SIZES, ICON_COLORS } from "./consts"; import defaultTokens from "../defaultTokens"; 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.ATTENTION]: theme.orbit.colorIconAttention, [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 StyledIcon = styled(({ className, viewBox, dataTest, children }) => React.createElement("svg", { className: className, viewBox: viewBox, "data-test": dataTest, preserveAspectRatio: "xMidYMid meet" }, children)).withConfig({ displayName: "Icon__StyledIcon", componentId: "sc-1pnzn3g-0" })(["width:", ";height:", ";vertical-align:middle;fill:currentColor;color:", ";"], ({ size }) => getSize(size), ({ size }) => getSize(size), ({ color, customColor }) => customColor || color && getColor()); StyledIcon.defaultProps = { theme: defaultTokens }; const OrbitIcon = props => { const { size, color, customColor, className, children, viewBox, dataTest } = props; return React.createElement(StyledIcon, { viewBox: viewBox, size: size, className: className, dataTest: dataTest, customColor: customColor, color: color }, children); }; OrbitIcon.defaultProps = { size: ICON_SIZES.MEDIUM }; export default OrbitIcon;