@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.
156 lines (134 loc) • 5.63 kB
JavaScript
"use strict";
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
exports.__esModule = true;
exports.default = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var React = _interopRequireWildcard(require("react"));
var _styledComponents = _interopRequireWildcard(require("styled-components"));
var _mediaQuery = _interopRequireDefault(require("../../utils/mediaQuery"));
var _Minus = _interopRequireDefault(require("../../icons/Minus"));
var _Plus = _interopRequireDefault(require("../../icons/Plus"));
var _defaultTheme = _interopRequireDefault(require("../../defaultTheme"));
var _ButtonPrimitive = _interopRequireDefault(require("../../primitives/ButtonPrimitive"));
var _useTheme = _interopRequireDefault(require("../../hooks/useTheme"));
const getMaxWidth = ({
maxWidth
}) => {
if (typeof maxWidth === "string") return maxWidth;
return `${parseInt(maxWidth, 10)}px`;
};
const StyledStepper = _styledComponents.default.div.withConfig({
displayName: "StepperStateless__StyledStepper",
componentId: "sc-er9xml-0"
})(["display:flex;width:100%;max-width:", ";flex:1 1 auto;"], getMaxWidth);
const iconMixin = (0, _styledComponents.css)(["", ""], ({
theme,
isActive,
isDisabled
}) => (0, _styledComponents.css)(["padding:2px;height:20px;width:20px;background:", ";border-radius:", ";", ";", ";"], isActive ? theme.orbit.paletteBlueNormal : theme.orbit.paletteCloudDark, theme.orbit.borderRadiusCircle, _mediaQuery.default.desktop((0, _styledComponents.css)(["height:16px;width:16px;"])), !isDisabled && (0, _styledComponents.css)(["&:hover{background:", ";}&:focus,&:active{box-shadow:inset 0 0 0 2px ", ";}"], isActive ? theme.orbit.paletteBlueNormalHover : theme.orbit.paletteCloudNormalHover, isActive ? theme.orbit.paletteBlueLightActive : theme.orbit.paletteCloudNormalActive)));
const StyledMinusIcon = (0, _styledComponents.default)(_Minus.default).withConfig({
displayName: "StepperStateless__StyledMinusIcon",
componentId: "sc-er9xml-1"
})(["", ";"], iconMixin); // $FlowFixMe: https://github.com/flow-typed/flow-typed/issues/3653#issuecomment-568539198
StyledMinusIcon.defaultProps = {
theme: _defaultTheme.default
};
const StyledPlusIcon = (0, _styledComponents.default)(_Plus.default).withConfig({
displayName: "StepperStateless__StyledPlusIcon",
componentId: "sc-er9xml-2"
})(["", ";"], iconMixin); // $FlowFixMe: https://github.com/flow-typed/flow-typed/issues/3653#issuecomment-568539198
StyledPlusIcon.defaultProps = {
theme: _defaultTheme.default
};
const StyledStepperInput = _styledComponents.default.input.withConfig({
displayName: "StepperStateless__StyledStepperInput",
componentId: "sc-er9xml-3"
})(["", ""], ({
theme,
disabled
}) => (0, _styledComponents.css)(["width:100%;height:44px;padding:0;border:0;font-size:", ";font-weight:", ";color:", ";text-align:center;min-width:0;opacity:", ";background-color:", ";&::-webkit-inner-spin-button,&::-webkit-outer-spin-button{-webkit-appearance:none;margin:0;}&:focus{outline:none;}"], theme.orbit.fontSizeTextLarge, theme.orbit.fontWeightMedium, theme.orbit.paletteInkNormal, disabled ? "0.5" : "1", disabled && "transparent")); // $FlowFixMe: https://github.com/flow-typed/flow-typed/issues/3653#issuecomment-568539198
StyledStepperInput.defaultProps = {
theme: _defaultTheme.default
};
const StepperStateless = ({
maxWidth = "120px",
disabled,
dataTest,
id,
value,
active,
name,
minValue,
maxValue,
onKeyDown,
onBlur,
onFocus,
onIncrement,
onDecrement,
titleIncrement,
titleDecrement,
disabledIncrement,
disabledDecrement
}) => {
const theme = (0, _useTheme.default)();
const commonButtonStyles = {
background: "transparent",
width: "44px"
};
const iconStyles = {
foreground: active ? theme.orbit.paletteWhite : theme.orbit.paletteInkNormal
};
const isMinusDisabled = disabled || disabledDecrement || typeof value === "number" && value <= +minValue;
const isPlusDisabled = disabled || disabledIncrement || typeof value === "number" && value >= +maxValue;
return /*#__PURE__*/React.createElement(StyledStepper, {
"data-test": dataTest,
id: id,
maxWidth: maxWidth
}, /*#__PURE__*/React.createElement(_ButtonPrimitive.default, (0, _extends2.default)({
disabled: isMinusDisabled,
iconLeft: /*#__PURE__*/React.createElement(StyledMinusIcon, {
size: "small",
isActive: active,
isDisabled: isMinusDisabled
}),
onClick: ev => {
if (onDecrement && !disabled) {
onDecrement(ev);
}
},
title: titleDecrement,
icons: iconStyles
}, commonButtonStyles)), /*#__PURE__*/React.createElement(StyledStepperInput, {
name: name,
disabled: disabled,
type: "text",
value: value || 0,
min: minValue,
max: maxValue,
onKeyDown: ev => {
if (onKeyDown) {
onKeyDown(ev);
}
},
onBlur: onBlur,
onFocus: onFocus,
readOnly: true
}), /*#__PURE__*/React.createElement(_ButtonPrimitive.default, (0, _extends2.default)({
disabled: isPlusDisabled,
iconLeft: /*#__PURE__*/React.createElement(StyledPlusIcon, {
size: "small",
isActive: active,
isDisabled: isPlusDisabled
}),
onClick: ev => {
if (onIncrement && !disabled) {
onIncrement(ev);
}
},
title: titleIncrement,
icons: iconStyles
}, commonButtonStyles)));
};
var _default = StepperStateless;
exports.default = _default;