UNPKG

@kiwicom/orbit-components

Version:

<div align="center"> <a href="https://orbit.kiwi" target="_blank"> <img alt="orbit-components" src="https://orbit.kiwi/wp-content/uploads/2018/08/orbit-components.png" srcset="https://orbit.kiwi/wp-content/uploads/2018/08/orbit-components@2x.png 2x"

310 lines (271 loc) 12.3 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Input = exports.InputContainer = exports.FakeInput = undefined; var _react = require("react"); var React = _interopRequireWildcard(_react); var _styledComponents = require("styled-components"); var _styledComponents2 = _interopRequireDefault(_styledComponents); var _defaultTokens = require("../defaultTokens"); var _defaultTokens2 = _interopRequireDefault(_defaultTokens); var _consts = require("./consts"); var _FormFeedback = require("../FormFeedback"); var _FormFeedback2 = _interopRequireDefault(_FormFeedback); var _FormLabel = require("../FormLabel"); var _FormLabel2 = _interopRequireDefault(_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)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; } 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 = _styledComponents2.default.label.withConfig({ displayName: "InputField__Field" })(["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: _defaultTokens2.default }; var FakeInput = exports.FakeInput = (0, _styledComponents2.default)(function (_ref3) { var children = _ref3.children, className = _ref3.className; return React.createElement( "div", { className: className }, children ); }).withConfig({ displayName: "InputField__FakeInput" })(["width:100%;position:absolute;z-index:1;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 theme.orbit.borderWidthInput + " " + (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; }); FakeInput.defaultProps = { theme: _defaultTokens2.default }; var InputContainer = exports.InputContainer = (0, _styledComponents2.default)(function (_ref8) { var children = _ref8.children, className = _ref8.className; return React.createElement( "div", { className: className }, children ); }).withConfig({ displayName: "InputField__InputContainer" })(["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 " + theme.orbit.borderWidthInput + " " + (error ? theme.orbit.borderColorInputErrorHover : theme.orbit.borderColorInputHover); }); InputContainer.defaultProps = { theme: _defaultTokens2.default }; var StyledInlineLabel = _styledComponents2.default.div.withConfig({ displayName: "InputField__StyledInlineLabel" })(["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; }, _FormLabel2.default, getToken(_consts.TOKENS.fontSizeInput)); StyledInlineLabel.defaultProps = { theme: _defaultTokens2.default }; var Prefix = (0, _styledComponents2.default)(function (_ref14) { var children = _ref14.children, className = _ref14.className; return React.createElement( "div", { className: className }, children ); }).withConfig({ displayName: "InputField__Prefix" })(["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; }); Prefix.defaultProps = { theme: _defaultTokens2.default }; var Suffix = (0, _styledComponents2.default)(function (_ref18) { var children = _ref18.children, className = _ref18.className; return React.createElement( "div", { className: className }, children ); }).withConfig({ displayName: "InputField__Suffix" })(["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: _defaultTokens2.default }; var Input = (0, _styledComponents2.default)(function (_ref23) { var theme = _ref23.theme, size = _ref23.size, suffix = _ref23.suffix, error = _ref23.error, help = _ref23.help, props = _objectWithoutProperties(_ref23, ["theme", "size", "suffix", "error", "help"]); return React.createElement("input", props); }).withConfig({ displayName: "InputField__Input" })(["appearance:none;font-family:inherit;border:none;padding:0 0 ", ";font-size:inherit;color:inherit;background-color:inherit;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:", ";}"], getToken(_consts.TOKENS.paddingInput), getToken(_consts.TOKENS.heightInput), function (_ref24) { var theme = _ref24.theme; return theme.orbit.borderRadiusNormal; }, FakeInput, function (_ref25) { var theme = _ref25.theme; return theme.orbit.borderWidthInputFocus + " " + theme.orbit.borderColorInputFocus; }, function (_ref26) { var theme = _ref26.theme; return theme.orbit.colorPlaceholderInput; }, function (_ref27) { var theme = _ref27.theme; return theme.orbit.colorPlaceholderInput; }, function (_ref28) { var theme = _ref28.theme; return theme.orbit.colorPlaceholderInput; }); exports.Input = Input; Input.defaultProps = { theme: _defaultTokens2.default }; var FormLabel = function FormLabel(_ref29) { var label = _ref29.label, isFilled = _ref29.isFilled, required = _ref29.required; return React.createElement( _FormLabel2.default, { filled: isFilled, required: required }, label ); }; var InputField = function InputField(_ref30) { var disabled = _ref30.disabled, _ref30$size = _ref30.size, size = _ref30$size === undefined ? _consts.SIZE_OPTIONS.NORMAL : _ref30$size, _ref30$type = _ref30.type, type = _ref30$type === undefined ? _consts.TYPE_OPTIONS.TEXT : _ref30$type, label = _ref30.label, inlineLabel = _ref30.inlineLabel, dataTest = _ref30.dataTest, required = _ref30.required, error = _ref30.error, name = _ref30.name, prefix = _ref30.prefix, onChange = _ref30.onChange, onFocus = _ref30.onFocus, onBlur = _ref30.onBlur, placeholder = _ref30.placeholder, minValue = _ref30.minValue, maxValue = _ref30.maxValue, minLength = _ref30.minLength, maxLength = _ref30.maxLength, suffix = _ref30.suffix, help = _ref30.help, value = _ref30.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 ), inlineLabel && React.createElement( StyledInlineLabel, { size: size }, React.createElement(FormLabel, { label: label, isFilled: !!value, required: required }) ), React.createElement(Input, { onChange: onChange, onFocus: onFocus, onBlur: onBlur, name: name, type: type, value: value, placeholder: placeholder, disabled: disabled, min: minValue, max: maxValue, minLength: minLength, maxLength: maxLength, size: size, error: error }), suffix && React.createElement( Suffix, { size: size }, suffix ), React.createElement(FakeInput, { size: size, disabled: disabled, error: error }) ), help && !error && React.createElement( _FormFeedback2.default, { type: "help" }, help ), error && React.createElement( _FormFeedback2.default, { type: "error" }, error ) ); }; exports.default = InputField;