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.

158 lines (157 loc) 7.72 kB
"use strict"; var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default; exports.__esModule = true; exports.default = exports.StyledButtonPrimitive = void 0; var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")); var React = _interopRequireWildcard(require("react")); var _styledComponents = _interopRequireWildcard(require("styled-components")); var _defaultTheme = _interopRequireDefault(require("../../defaultTheme")); var _Loading = _interopRequireWildcard(require("../../Loading")); var _getSpacingToken = _interopRequireDefault(require("../../common/getSpacingToken")); var _ButtonPrimitiveContent = _interopRequireDefault(require("./components/ButtonPrimitiveContent")); var _ButtonPrimitiveIconContainer = _interopRequireWildcard(require("./components/ButtonPrimitiveIconContainer")); var _ButtonPrimitiveContentChildren = _interopRequireDefault(require("./components/ButtonPrimitiveContentChildren")); var _mediaQuery = _interopRequireDefault(require("../../utils/mediaQuery")); var _createRel = _interopRequireDefault(require("./common/createRel")); var _handleKeyDown = _interopRequireDefault(require("../../utils/handleKeyDown")); const iconContainerColor = (color, important = true) => (0, _styledComponents.css)(["", "{color:", " ", ";}"], _ButtonPrimitiveIconContainer.StyledButtonPrimitiveIconContainer, color, important && "!important"); const StyledButtonPrimitive = (0, _styledComponents.default)( /*#__PURE__*/React.forwardRef(({ asComponent = "button", id, dataTest, submit, disabled, ariaControls, ariaExpanded, ariaLabelledby, ariaCurrent, title, className, rel, href, external, tabIndex, onClick, role, download, ...props }, ref) => { const isButtonWithHref = asComponent === "button" && href; const Component = isButtonWithHref ? "a" : asComponent; const buttonType = submit ? "submit" : "button"; const handleKeyDown = ev => asComponent === "div" ? (0, _handleKeyDown.default)(onClick)(ev) : undefined; return /*#__PURE__*/React.createElement(Component, { ref: ref, id: id, "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: (0, _createRel.default)({ external, href, rel }), tabIndex: tabIndex, onClick: !disabled ? onClick : null, role: role, download: download }, props.children); })).withConfig({ displayName: "ButtonPrimitive__StyledButtonPrimitive", componentId: "sc-j8pavp-0" })(["", ";"], ({ foreground, disabled, fullWidth, href, theme, asComponent, circled, padding, background, fontWeight, fontSize, height, width, onlyIcon, icons, foregroundHover, foregroundActive, foregroundFocus, backgroundHover, backgroundActive, backgroundFocus, boxShadow, boxShadowHover, boxShadowFocus, boxShadowActive, underlined }) => (0, _styledComponents.css)(["height:", ";position:relative;display:", ";justify-content:space-between;align-items:center;box-sizing:border-box;appearance:none !important;text-align:center;text-decoration:", ";flex:", ";max-width:100%;background:", ";color:", "!important;border:0;outline:", ";padding:", ";border-radius:", ";font-family:", ";font-weight:", ";font-size:", ";cursor:", ";transition:all ", " ease-in-out !important;opacity:", ";margin-bottom:", ";width:", ";box-shadow:", ";& > *{vertical-align:middle;}", " ", ";", "{width:", ";height:", ";}&:hover{", ";}: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;", ";}&:hover:focus{background:", ";}&:active,&:active:focus{", ";}"], height, href || asComponent === "a" ? "inline-flex" : "flex", underlined ? "underline" : "none", fullWidth ? "1 1 auto" : "0 0 auto", background, foreground, boxShadowFocus && "0", padding, circled ? height : "6px", theme.orbit.fontFamily, fontWeight || theme.orbit.fontWeightMedium, fontSize, disabled ? "not-allowed" : "pointer", theme.orbit.durationFast, disabled && theme.orbit.opacityButtonDisabled, _getSpacingToken.default, fullWidth ? "100%" : width || onlyIcon && height || "auto", boxShadow, _mediaQuery.default.tablet((0, _styledComponents.css)(["border-radius:", ";"], circled ? height : theme.orbit.borderRadiusNormal)), icons && icons.foreground && iconContainerColor(icons.foreground, false), _Loading.StyledSpinner, icons && icons.width, icons && icons.height, !disabled && (0, _styledComponents.css)(["background:", ";color:", "!important;box-shadow:", ";text-decoration:none;", ";"], backgroundHover, foregroundHover, boxShadowHover, icons && icons.foregroundHover && iconContainerColor(icons.foregroundHover)), boxShadowFocus, backgroundFocus, foregroundFocus, icons && icons.foregroundFocus && iconContainerColor(icons.foregroundFocus), background, foregroundFocus, icons && icons.foregroundFocus && iconContainerColor(icons.foregroundFocus), boxShadowFocus, backgroundFocus, foregroundFocus, icons && icons.foregroundFocus && iconContainerColor(icons.foregroundFocus), backgroundHover, !disabled && (0, _styledComponents.css)(["background:", ";box-shadow:", ";color:", "!important;text-decoration:none;", ";"], backgroundActive, boxShadowActive, foregroundActive, icons && icons.foregroundActive && iconContainerColor(icons.foregroundActive)))); exports.StyledButtonPrimitive = StyledButtonPrimitive; StyledButtonPrimitive.defaultProps = { theme: _defaultTheme.default }; const ButtonPrimitive = /*#__PURE__*/React.forwardRef((props, ref) => { const { loading, disabled, children, iconLeft, iconRight, // Need to setup null values so the object exits by default icons = { width: null, height: null, leftMargin: null, rightMargin: null }, contentAlign = "center", contentWidth, fullWidth, centered } = props; const { width, height, leftMargin, rightMargin } = icons; const isDisabled = loading || disabled; const onlyIcon = Boolean(iconLeft && !children); return /*#__PURE__*/React.createElement(StyledButtonPrimitive, (0, _extends2.default)({ ref: ref, onlyIcon: onlyIcon }, props, { disabled: isDisabled }), loading && /*#__PURE__*/React.createElement(_Loading.default, { type: "buttonLoader" }), /*#__PURE__*/React.createElement(_ButtonPrimitiveContent.default, { loading: loading, contentAlign: contentAlign }, iconLeft && /*#__PURE__*/React.createElement(_ButtonPrimitiveIconContainer.default, { width: width, height: height, margin: leftMargin }, iconLeft), children && /*#__PURE__*/React.createElement(_ButtonPrimitiveContentChildren.default, { hasIcon: Boolean(iconLeft || iconRight), contentWidth: contentWidth, centered: fullWidth && centered }, children), iconRight && /*#__PURE__*/React.createElement(_ButtonPrimitiveIconContainer.default, { width: width, height: height, margin: rightMargin }, iconRight))); }); ButtonPrimitive.displayName = "ButtonPrimitive"; var _default = ButtonPrimitive; exports.default = _default;