@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.
51 lines (42 loc) • 2.63 kB
JavaScript
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
import { SIZE_OPTIONS, TOKENS } from "./consts";
import { rtlSpacing } from "../../../utils/rtl";
import { getSize } from "../../../Icon";
import { ICON_SIZES } from "../../../Icon/consts";
var getIconSpacing = function getIconSpacing(onlyIcon, size, theme) {
var _TOKENS$marginRightIc;
if (onlyIcon) {
return null;
}
var tokens = _defineProperty({}, TOKENS.marginRightIcon, (_TOKENS$marginRightIc = {}, _defineProperty(_TOKENS$marginRightIc, SIZE_OPTIONS.LARGE, theme.orbit.marginButtonIconLarge), _defineProperty(_TOKENS$marginRightIc, SIZE_OPTIONS.NORMAL, theme.orbit.marginButtonIconNormal), _defineProperty(_TOKENS$marginRightIc, SIZE_OPTIONS.SMALL, theme.orbit.marginButtonIconSmall), _TOKENS$marginRightIc));
return {
leftMargin: rtlSpacing("0 ".concat(tokens[TOKENS.marginRightIcon][size], " 0 0"))({
theme: theme
}),
rightMargin: rtlSpacing("0 0 0 ".concat(tokens[TOKENS.marginRightIcon][size]))({
theme: theme
})
};
};
var getIconContainer = function getIconContainer(_ref) {
var iconLeft = _ref.iconLeft,
children = _ref.children,
theme = _ref.theme,
_ref$size = _ref.size,
size = _ref$size === void 0 ? SIZE_OPTIONS.NORMAL : _ref$size,
iconForeground = _ref.iconForeground;
var onlyIcon = Boolean(iconLeft && !children);
var sizeIcon = size === ICON_SIZES.SMALL ? ICON_SIZES.SMALL : ICON_SIZES.MEDIUM;
var computedSize = getSize(sizeIcon)({
theme: theme
});
return {
icons: _objectSpread(_objectSpread({
height: computedSize,
width: computedSize
}, getIconSpacing(onlyIcon, size, theme)), iconForeground)
};
};
export default getIconContainer;