@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.
49 lines (45 loc) • 1.34 kB
JavaScript
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import { SIZE_OPTIONS, TOKENS } from "./consts";
import { rtlSpacing } from "../../../utils/rtl";
import { getSize } from "../../../Icon";
import { ICON_SIZES } from "../../../Icon/consts";
const getIconSpacing = (onlyIcon, size, theme) => {
if (onlyIcon) {
return null;
}
const tokens = {
[TOKENS.marginRightIcon]: {
[SIZE_OPTIONS.LARGE]: theme.orbit.marginButtonIconLarge,
[SIZE_OPTIONS.NORMAL]: theme.orbit.marginButtonIconNormal,
[SIZE_OPTIONS.SMALL]: theme.orbit.marginButtonIconSmall
}
};
return {
leftMargin: rtlSpacing(`0 ${tokens[TOKENS.marginRightIcon][size]} 0 0`)({
theme
}),
rightMargin: rtlSpacing(`0 0 0 ${tokens[TOKENS.marginRightIcon][size]}`)({
theme
})
};
};
const getIconContainer = ({
iconLeft,
children,
theme,
size = SIZE_OPTIONS.NORMAL,
iconForeground
}) => {
const onlyIcon = Boolean(iconLeft && !children);
const sizeIcon = size === ICON_SIZES.SMALL ? ICON_SIZES.SMALL : ICON_SIZES.MEDIUM;
const computedSize = getSize(sizeIcon)({
theme
});
return {
icons: _objectSpread(_objectSpread({
height: computedSize,
width: computedSize
}, getIconSpacing(onlyIcon, size, theme)), iconForeground)
};
};
export default getIconContainer;