@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.
280 lines (258 loc) • 12.1 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = exports.Input = exports.Prefix = exports.InputContainer = exports.FakeInput = void 0;
var React = _interopRequireWildcard(require("react"));
var _styledComponents = _interopRequireDefault(require("styled-components"));
var _defaultTokens = _interopRequireDefault(require("../defaultTokens"));
var _consts = require("./consts");
var _FormFeedback = _interopRequireDefault(require("../FormFeedback"));
var _FormLabel = _interopRequireDefault(require("../FormLabel"));
var _ServiceLogo = require("../ServiceLogo");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
var getToken = function getToken(name) {
return function (_ref) {
var _TOKENS$heightInput, _TOKENS$fontSizeInput, _TOKENS$paddingInput, _TOKENS$iconSize, _tokens;
var theme = _ref.theme,
size = _ref.size;
var tokens = (_tokens = {}, _defineProperty(_tokens, _consts.TOKENS.heightInput, (_TOKENS$heightInput = {}, _defineProperty(_TOKENS$heightInput, _consts.SIZE_OPTIONS.SMALL, theme.orbit.heightInputSmall), _defineProperty(_TOKENS$heightInput, _consts.SIZE_OPTIONS.NORMAL, theme.orbit.heightInputNormal), _TOKENS$heightInput)), _defineProperty(_tokens, _consts.TOKENS.fontSizeInput, (_TOKENS$fontSizeInput = {}, _defineProperty(_TOKENS$fontSizeInput, _consts.SIZE_OPTIONS.SMALL, theme.orbit.fontSizeInputSmall), _defineProperty(_TOKENS$fontSizeInput, _consts.SIZE_OPTIONS.NORMAL, theme.orbit.fontSizeInputNormal), _TOKENS$fontSizeInput)), _defineProperty(_tokens, _consts.TOKENS.paddingInput, (_TOKENS$paddingInput = {}, _defineProperty(_TOKENS$paddingInput, _consts.SIZE_OPTIONS.SMALL, theme.orbit.paddingInputSmall), _defineProperty(_TOKENS$paddingInput, _consts.SIZE_OPTIONS.NORMAL, theme.orbit.paddingInputNormal), _TOKENS$paddingInput)), _defineProperty(_tokens, _consts.TOKENS.iconSize, (_TOKENS$iconSize = {}, _defineProperty(_TOKENS$iconSize, _consts.SIZE_OPTIONS.SMALL, theme.orbit.widthIconSmall), _defineProperty(_TOKENS$iconSize, _consts.SIZE_OPTIONS.NORMAL, theme.orbit.widthIconMedium), _TOKENS$iconSize)), _tokens);
return tokens[name][size];
};
};
var Field = _styledComponents.default.label.withConfig({
displayName: "InputField__Field",
componentId: "sc-4opay-0"
})(["font-family:", ";position:relative;display:block;z-index:2;flex:1 1 100%;"], function (_ref2) {
var theme = _ref2.theme;
return theme.orbit.fontFamily;
});
Field.defaultProps = {
theme: _defaultTokens.default
};
var FakeInput = (0, _styledComponents.default)(function (_ref3) {
var children = _ref3.children,
className = _ref3.className;
return React.createElement("div", {
className: className
}, children);
}).withConfig({
displayName: "InputField__FakeInput",
componentId: "sc-4opay-1"
})(["width:100%;position:absolute;z-index:1;top:0;left:0;box-sizing:border-box;height:", ";border-radius:", ";box-shadow:inset 0 0 0 ", ";background-color:", ";font-size:", ";transition:all ", " ease-in-out;"], getToken(_consts.TOKENS.heightInput), function (_ref4) {
var theme = _ref4.theme;
return theme.orbit.borderRadiusNormal;
}, function (_ref5) {
var theme = _ref5.theme,
error = _ref5.error;
return "".concat(theme.orbit.borderWidthInput, " ").concat(error ? theme.orbit.borderColorInputError : theme.orbit.borderColorInput);
}, function (_ref6) {
var disabled = _ref6.disabled,
theme = _ref6.theme;
return disabled ? theme.orbit.backgroundInputDisabled : theme.orbit.backgroundInput;
}, getToken(_consts.TOKENS.fontSizeInput), function (_ref7) {
var theme = _ref7.theme;
return theme.orbit.durationFast;
});
exports.FakeInput = FakeInput;
FakeInput.defaultProps = {
theme: _defaultTokens.default
};
var InputContainer = (0, _styledComponents.default)(function (_ref8) {
var children = _ref8.children,
className = _ref8.className;
return React.createElement("div", {
className: className
}, children);
}).withConfig({
displayName: "InputField__InputContainer",
componentId: "sc-4opay-2"
})(["display:flex;position:relative;flex-direction:row;align-items:center;justify-content:space-between;box-sizing:border-box;width:100%;height:", ";border-radius:", ";color:", ";font-size:", ";cursor:", ";&:hover > ", "{", ";}"], getToken(_consts.TOKENS.heightInput), function (_ref9) {
var theme = _ref9.theme;
return theme.orbit.borderRadiusNormal;
}, function (_ref10) {
var disabled = _ref10.disabled,
theme = _ref10.theme;
return disabled ? theme.orbit.colorTextInputDisabled : theme.orbit.colorTextInput;
}, getToken(_consts.TOKENS.fontSizeInput), function (_ref11) {
var disabled = _ref11.disabled;
return disabled ? "not-allowed" : "text";
}, FakeInput, function (_ref12) {
var disabled = _ref12.disabled,
theme = _ref12.theme,
error = _ref12.error;
return !disabled && "box-shadow: inset 0 0 0 ".concat(theme.orbit.borderWidthInput, " ").concat(error ? theme.orbit.borderColorInputErrorHover : theme.orbit.borderColorInputHover);
});
exports.InputContainer = InputContainer;
InputContainer.defaultProps = {
theme: _defaultTokens.default
};
var StyledInlineLabel = _styledComponents.default.div.withConfig({
displayName: "InputField__StyledInlineLabel",
componentId: "sc-4opay-3"
})(["height:100%;display:flex;align-items:center;pointer-events:none;justify-content:center;padding-left:", ";", "{margin-bottom:0;font-size:", ";line-height:normal;z-index:3;white-space:nowrap;}"], function (_ref13) {
var theme = _ref13.theme;
return theme.orbit.spaceSmall;
}, _FormLabel.default, getToken(_consts.TOKENS.fontSizeInput));
StyledInlineLabel.defaultProps = {
theme: _defaultTokens.default
};
var Prefix = (0, _styledComponents.default)(function (_ref14) {
var children = _ref14.children,
className = _ref14.className;
return React.createElement("div", {
className: className
}, children);
}).withConfig({
displayName: "InputField__Prefix",
componentId: "sc-4opay-4"
})(["height:100%;color:", ";display:flex;align-items:center;pointer-events:none;justify-content:center;padding-left:", ";z-index:3;& > svg{width:", ";height:", ";color:", ";}"], function (_ref15) {
var theme = _ref15.theme;
return theme.orbit.colorTextInputPrefix;
}, function (_ref16) {
var theme = _ref16.theme;
return theme.orbit.spaceSmall;
}, getToken(_consts.TOKENS.iconSize), getToken(_consts.TOKENS.iconSize), function (_ref17) {
var theme = _ref17.theme;
return theme.orbit.colorIconInput;
});
exports.Prefix = Prefix;
Prefix.defaultProps = {
theme: _defaultTokens.default
};
var Suffix = (0, _styledComponents.default)(function (_ref18) {
var children = _ref18.children,
className = _ref18.className;
return React.createElement("div", {
className: className
}, children);
}).withConfig({
displayName: "InputField__Suffix",
componentId: "sc-4opay-5"
})(["height:", ";color:", ";display:flex;align-items:center;justify-content:center;pointer-events:", ";z-index:3;& svg{color:", ";}", "{height:16px;padding-right:", ";}"], getToken(_consts.TOKENS.heightInput), function (_ref19) {
var theme = _ref19.theme;
return theme.orbit.colorIconInput;
}, function (_ref20) {
var disabled = _ref20.disabled;
return disabled && "none";
}, function (_ref21) {
var theme = _ref21.theme;
return theme.orbit.colorIconSecondary;
}, _ServiceLogo.StyledServiceLogo, function (_ref22) {
var theme = _ref22.theme;
return theme.orbit.spaceSmall;
});
Suffix.defaultProps = {
theme: _defaultTokens.default
};
var Input = _styledComponents.default.input.withConfig({
displayName: "InputField__Input",
componentId: "sc-4opay-6"
})(["appearance:none;font-family:inherit;border:none;padding:", ";font-size:inherit;color:inherit;background-color:transparent;cursor:inherit;flex:1 auto;width:100%;height:100%;line-height:", ";border-radius:", ";z-index:2;&:focus{outline:none;& ~ ", "{box-shadow:inset 0 0 0 ", ";}}&::placeholder{color:", ";opacity:1;}&:-ms-input-placeholder{color:", ";}&::-ms-input-placeholder{color:", ";}&::-ms-clear{display:none;}"], getToken(_consts.TOKENS.paddingInput), getToken(_consts.TOKENS.heightInput), function (_ref23) {
var theme = _ref23.theme;
return theme.orbit.borderRadiusNormal;
}, FakeInput, function (_ref24) {
var theme = _ref24.theme;
return "".concat(theme.orbit.borderWidthInputFocus, " ").concat(theme.orbit.borderColorInputFocus);
}, function (_ref25) {
var theme = _ref25.theme;
return theme.orbit.colorPlaceholderInput;
}, function (_ref26) {
var theme = _ref26.theme;
return theme.orbit.colorPlaceholderInput;
}, function (_ref27) {
var theme = _ref27.theme;
return theme.orbit.colorPlaceholderInput;
});
exports.Input = Input;
Input.defaultProps = {
theme: _defaultTokens.default
};
var FormLabel = function FormLabel(_ref28) {
var label = _ref28.label,
isFilled = _ref28.isFilled,
required = _ref28.required;
return React.createElement(_FormLabel.default, {
filled: isFilled,
required: required
}, label);
}; // $FlowExpected
var InputField = React.forwardRef(function (props, ref) {
var disabled = props.disabled,
_props$size = props.size,
size = _props$size === void 0 ? _consts.SIZE_OPTIONS.NORMAL : _props$size,
_props$type = props.type,
type = _props$type === void 0 ? _consts.TYPE_OPTIONS.TEXT : _props$type,
label = props.label,
inlineLabel = props.inlineLabel,
dataTest = props.dataTest,
required = props.required,
error = props.error,
name = props.name,
prefix = props.prefix,
onChange = props.onChange,
onFocus = props.onFocus,
onBlur = props.onBlur,
onKeyUp = props.onKeyUp,
onKeyDown = props.onKeyDown,
placeholder = props.placeholder,
minValue = props.minValue,
maxValue = props.maxValue,
minLength = props.minLength,
maxLength = props.maxLength,
suffix = props.suffix,
help = props.help,
value = props.value;
return React.createElement(Field, {
"data-test": dataTest
}, label && !inlineLabel && React.createElement(FormLabel, {
label: label,
isFilled: !!value,
required: required
}), React.createElement(InputContainer, {
size: size,
disabled: disabled,
error: error
}, prefix && React.createElement(Prefix, {
size: size
}, prefix), label && inlineLabel && React.createElement(StyledInlineLabel, {
size: size
}, React.createElement(FormLabel, {
label: label,
isFilled: !!value,
required: required
})), React.createElement(Input, {
onChange: onChange,
onFocus: onFocus,
onBlur: onBlur,
onKeyUp: onKeyUp,
onKeyDown: onKeyDown,
name: name,
type: type,
value: value,
placeholder: placeholder,
disabled: disabled,
min: minValue,
max: maxValue,
minLength: minLength,
maxLength: maxLength,
size: size,
error: error,
ref: ref
}), suffix && React.createElement(Suffix, {
size: size
}, suffix), React.createElement(FakeInput, {
size: size,
disabled: disabled,
error: error
})), help && !error && React.createElement(_FormFeedback.default, {
type: "help"
}, help), error && React.createElement(_FormFeedback.default, {
type: "error"
}, error));
});
InputField.displayName = "InputField";
var _default = InputField;
exports.default = _default;