@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.
155 lines (149 loc) • 8.31 kB
JavaScript
import _extends from "@babel/runtime/helpers/esm/extends";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
import * as React from "react";
import styled, { css } from "styled-components";
import defaultTheme from "../../defaultTheme";
import Loading, { StyledSpinner } from "../../Loading";
import getSpacingToken from "../../common/getSpacingToken";
import ButtonPrimitiveContent from "./components/ButtonPrimitiveContent";
import ButtonPrimitiveIconContainer, { StyledButtonPrimitiveIconContainer } from "./components/ButtonPrimitiveIconContainer";
import ButtonPrimitiveContentChildren from "./components/ButtonPrimitiveContentChildren";
import mq from "../../utils/mediaQuery";
import createRel from "./common/createRel";
import onKeyDown from "../../utils/handleKeyDown";
var iconContainerColor = function iconContainerColor(color) {
var important = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
return css(["", "{color:", " ", ";}"], StyledButtonPrimitiveIconContainer, color, important && "!important");
};
export var StyledButtonPrimitive = styled( /*#__PURE__*/React.forwardRef(function (_ref, ref) {
var _ref$asComponent = _ref.asComponent,
asComponent = _ref$asComponent === void 0 ? "button" : _ref$asComponent,
dataTest = _ref.dataTest,
submit = _ref.submit,
disabled = _ref.disabled,
ariaControls = _ref.ariaControls,
ariaExpanded = _ref.ariaExpanded,
ariaLabelledby = _ref.ariaLabelledby,
ariaCurrent = _ref.ariaCurrent,
title = _ref.title,
className = _ref.className,
rel = _ref.rel,
href = _ref.href,
target = _ref.target,
external = _ref.external,
tabIndex = _ref.tabIndex,
onClick = _ref.onClick,
role = _ref.role,
props = _objectWithoutProperties(_ref, ["asComponent", "dataTest", "submit", "disabled", "ariaControls", "ariaExpanded", "ariaLabelledby", "ariaCurrent", "title", "className", "rel", "href", "target", "external", "tabIndex", "onClick", "role"]);
var isButtonWithHref = asComponent === "button" && href;
var Component = isButtonWithHref ? "a" : asComponent;
var buttonType = submit ? "submit" : "button";
var handleKeyDown = function handleKeyDown(ev) {
return asComponent === "div" ? onKeyDown(onClick)(ev) : undefined;
};
return /*#__PURE__*/React.createElement(Component, {
ref: ref,
"data-test": dataTest,
"aria-controls": ariaControls,
"aria-current": ariaCurrent,
"aria-expanded": ariaExpanded,
"aria-label": title,
"aria-labelledby": ariaLabelledby,
type: !isButtonWithHref ? buttonType : undefined,
className: className,
disabled: disabled,
onKeyDown: handleKeyDown,
href: !disabled ? href : null,
target: !disabled && href && external ? "_blank" : undefined,
rel: createRel({
external: external,
href: href,
rel: rel
}),
tabIndex: tabIndex,
onClick: !disabled ? onClick : null,
role: role
}, props.children);
})).withConfig({
displayName: "ButtonPrimitive__StyledButtonPrimitive",
componentId: "q2qrvj-0"
})(["", "};"], function (_ref2) {
var foreground = _ref2.foreground,
disabled = _ref2.disabled,
fullWidth = _ref2.fullWidth,
href = _ref2.href,
theme = _ref2.theme,
asComponent = _ref2.asComponent,
circled = _ref2.circled,
padding = _ref2.padding,
background = _ref2.background,
fontWeight = _ref2.fontWeight,
fontSize = _ref2.fontSize,
height = _ref2.height,
width = _ref2.width,
onlyIcon = _ref2.onlyIcon,
icons = _ref2.icons,
foregroundHover = _ref2.foregroundHover,
foregroundActive = _ref2.foregroundActive,
foregroundFocus = _ref2.foregroundFocus,
backgroundHover = _ref2.backgroundHover,
backgroundActive = _ref2.backgroundActive,
backgroundFocus = _ref2.backgroundFocus,
boxShadow = _ref2.boxShadow,
boxShadowHover = _ref2.boxShadowHover,
boxShadowFocus = _ref2.boxShadowFocus,
boxShadowActive = _ref2.boxShadowActive,
underlined = _ref2.underlined;
return css(["height:", ";position:relative;display:", ";justify-content:space-between;align-items:center;box-sizing:border-box;appearance:none;text-align:center;text-decoration:", ";flex:", ";max-width:100%;background:", ";color:", "!important;border:0;padding:", ";border-radius:", ";font-family:", ";font-weight:", ";font-size:", ";line-height:1.4;cursor:", ";transition:all ", " ease-in-out !important;outline:0;opacity:", ";margin-bottom:", ";width:", ";box-shadow:", ";", " ", ";", "{width:", ";height:", ";}&:hover{", ";}&:active{", ";}:focus{box-shadow:", ";background:", ";color:", "!important;text-decoration:none;", ";}:focus:not(:focus-visible){box-shadow:none;background:", ";color:", "!important;text-decoration:none;", ";}:-moz-focusring,:focus-visible{box-shadow:", ";background:", ";color:", "!important;text-decoration:none;", ";}"], height, href || asComponent === "a" ? "inline-flex" : "flex", underlined ? "underline" : "none", fullWidth ? "1 1 auto" : "0 0 auto", background, foreground, padding, circled ? height : "6px", theme.orbit.fontFamily, fontWeight || theme.orbit.fontWeightMedium, fontSize, disabled ? "not-allowed" : "pointer", theme.orbit.durationFast, disabled && theme.orbit.opacityButtonDisabled, getSpacingToken, fullWidth ? "100%" : width || onlyIcon && height || "auto", boxShadow, mq.tablet(css(["border-radius:", ";"], circled ? height : theme.orbit.borderRadiusNormal)), iconContainerColor(icons && icons.foreground, false), StyledSpinner, icons && icons.width, icons && icons.height, !disabled && css(["background:", ";color:", "!important;box-shadow:", ";text-decoration:none;", ";"], backgroundHover, foregroundHover, boxShadowHover, iconContainerColor(icons && icons.foregroundHover)), !disabled && css(["background:", ";box-shadow:", ";color:", "!important;text-decoration:none;", ";"], backgroundActive, boxShadowActive, foregroundActive, iconContainerColor(icons && icons.foregroundActive)), boxShadowFocus, backgroundFocus, foregroundFocus, iconContainerColor(icons && icons.foregroundFocus), background, foregroundFocus, iconContainerColor(icons && icons.foregroundFocus), boxShadowFocus, backgroundFocus, foregroundFocus, iconContainerColor(icons && icons.foregroundFocus));
}); // $FlowFixMe: https://github.com/flow-typed/flow-typed/issues/3653#issuecomment-568539198
StyledButtonPrimitive.defaultProps = {
theme: defaultTheme
};
var ButtonPrimitive = /*#__PURE__*/React.forwardRef(function (props, ref) {
var loading = props.loading,
disabled = props.disabled,
children = props.children,
iconLeft = props.iconLeft,
iconRight = props.iconRight,
_props$icons = props.icons,
icons = _props$icons === void 0 ? {
width: null,
height: null,
leftMargin: null,
rightMargin: null
} : _props$icons,
_props$contentAlign = props.contentAlign,
contentAlign = _props$contentAlign === void 0 ? "center" : _props$contentAlign,
contentWidth = props.contentWidth;
var width = icons.width,
height = icons.height,
leftMargin = icons.leftMargin,
rightMargin = icons.rightMargin;
var isDisabled = loading || disabled;
var onlyIcon = Boolean(iconLeft && !children);
return /*#__PURE__*/React.createElement(StyledButtonPrimitive, _extends({
ref: ref,
onlyIcon: onlyIcon
}, props, {
disabled: isDisabled,
className: undefined
}), loading && /*#__PURE__*/React.createElement(Loading, {
type: "buttonLoader"
}), /*#__PURE__*/React.createElement(ButtonPrimitiveContent, {
loading: loading,
contentAlign: contentAlign
}, iconLeft && /*#__PURE__*/React.createElement(ButtonPrimitiveIconContainer, {
width: width,
height: height,
margin: leftMargin
}, iconLeft), children && /*#__PURE__*/React.createElement(ButtonPrimitiveContentChildren, {
hasIcon: Boolean(iconLeft || iconRight),
contentWidth: contentWidth
}, children), iconRight && /*#__PURE__*/React.createElement(ButtonPrimitiveIconContainer, {
width: width,
height: height,
margin: rightMargin
}, iconRight)));
});
ButtonPrimitive.displayName = "ButtonPrimitive";
export default ButtonPrimitive;