@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.
154 lines (147 loc) • 6.01 kB
JavaScript
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
import * as React from "react";
import styled, { css } from "styled-components";
import defaultTheme from "../defaultTheme";
import FormFeedback from "../FormFeedback";
import FormLabel from "../FormLabel";
import { SIZE_OPTIONS, RESIZE_OPTIONS } from "./consts";
import { rtlSpacing } from "../utils/rtl";
import getSpacingToken from "../common/getSpacingToken";
import formElementFocus from "../InputField/helpers/formElementFocus";
import mq from "../utils/mediaQuery";
var Field = styled.label.withConfig({
displayName: "Textarea__Field",
componentId: "sc-1ezoqgy-0"
})(["font-family:", ";display:flex;width:100%;height:", ";flex-direction:column;position:relative;flex:", ";margin-bottom:", ";"], function (_ref) {
var theme = _ref.theme;
return theme.orbit.fontFamily;
}, function (_ref2) {
var fullHeight = _ref2.fullHeight;
return fullHeight && "100%";
}, function (_ref3) {
var fullHeight = _ref3.fullHeight;
return fullHeight && "1";
}, getSpacingToken);
Field.defaultProps = {
theme: defaultTheme
};
var getFontSize = function getFontSize(_ref4) {
var _tokens;
var theme = _ref4.theme,
size = _ref4.size;
var tokens = (_tokens = {}, _defineProperty(_tokens, SIZE_OPTIONS.SMALL, theme.orbit.fontSizeInputSmall), _defineProperty(_tokens, SIZE_OPTIONS.NORMAL, theme.orbit.fontSizeInputNormal), _tokens);
return tokens[size];
};
var getLineHeight = function getLineHeight(_ref5) {
var _tokens2;
var theme = _ref5.theme,
size = _ref5.size;
var tokens = (_tokens2 = {}, _defineProperty(_tokens2, SIZE_OPTIONS.SMALL, theme.orbit.lineHeightTextSmall), _defineProperty(_tokens2, SIZE_OPTIONS.NORMAL, theme.orbit.lineHeightTextNormal), _tokens2);
return tokens[size];
};
var getPadding = function getPadding(_ref6) {
var _tokens3;
var theme = _ref6.theme,
size = _ref6.size;
var tokens = (_tokens3 = {}, _defineProperty(_tokens3, SIZE_OPTIONS.SMALL, theme.orbit.paddingTextareaSmall), _defineProperty(_tokens3, SIZE_OPTIONS.NORMAL, theme.orbit.paddingTextareaNormal), _tokens3);
return rtlSpacing(tokens[size]);
};
var StyledTextArea = styled.textarea.withConfig({
displayName: "Textarea__StyledTextArea",
componentId: "sc-1ezoqgy-1"
})(["appearance:none;box-sizing:border-box;display:block;width:100%;height:", ";padding:", ";box-shadow:inset 0 0 0 ", ";background-color:", ";color:", ";font-size:", ";line-height:", ";cursor:", ";font-family:", ";resize:", ";transition:box-shadow ", " ease-in-out;min-height:44px;border-radius:6px;", ";flex:", ";border:1px solid transparent;overflow:auto;&::placeholder{color:", ";}&:hover{box-shadow:", ";}&:focus{", " outline:none;}"], function (_ref7) {
var fullHeight = _ref7.fullHeight;
return fullHeight && "100%";
}, getPadding, function (_ref8) {
var theme = _ref8.theme,
error = _ref8.error;
return "".concat(theme.orbit.borderWidthInput, " ").concat(error ? theme.orbit.borderColorInputError : theme.orbit.borderColorInput);
}, function (_ref9) {
var disabled = _ref9.disabled,
theme = _ref9.theme;
return disabled ? theme.orbit.backgroundInputDisabled : theme.orbit.backgroundInput;
}, function (_ref10) {
var disabled = _ref10.disabled,
theme = _ref10.theme;
return disabled ? theme.orbit.colorTextInputDisabled : theme.orbit.colorTextInput;
}, getFontSize, getLineHeight, function (_ref11) {
var disabled = _ref11.disabled;
return disabled ? "not-allowed" : "text";
}, function (_ref12) {
var theme = _ref12.theme;
return theme.orbit.fontFamily;
}, function (_ref13) {
var resize = _ref13.resize;
return resize;
}, function (_ref14) {
var theme = _ref14.theme;
return theme.orbit.durationFast;
}, mq.tablet(css(["border-radius:", ";"], function (_ref15) {
var theme = _ref15.theme;
return theme.orbit.borderRadiusNormal;
})), function (_ref16) {
var fullHeight = _ref16.fullHeight;
return fullHeight && "1";
}, function (_ref17) {
var theme = _ref17.theme;
return theme.orbit.colorPlaceholderInput;
}, function (_ref18) {
var disabled = _ref18.disabled,
theme = _ref18.theme,
error = _ref18.error;
return !disabled && "inset 0 0 0 ".concat(theme.orbit.borderWidthInput, " ").concat(error ? theme.orbit.borderColorInputErrorHover : theme.orbit.borderColorInputHover);
}, formElementFocus);
StyledTextArea.defaultProps = {
theme: defaultTheme
};
var Textarea = /*#__PURE__*/React.forwardRef(function (_ref19, ref) {
var _ref19$size = _ref19.size,
size = _ref19$size === void 0 ? SIZE_OPTIONS.NORMAL : _ref19$size,
disabled = _ref19.disabled,
_ref19$resize = _ref19.resize,
resize = _ref19$resize === void 0 ? RESIZE_OPTIONS.VERTICAL : _ref19$resize,
dataTest = _ref19.dataTest,
spaceAfter = _ref19.spaceAfter,
fullHeight = _ref19.fullHeight,
label = _ref19.label,
value = _ref19.value,
name = _ref19.name,
rows = _ref19.rows,
tabIndex = _ref19.tabIndex,
error = _ref19.error,
help = _ref19.help,
placeholder = _ref19.placeholder,
maxLength = _ref19.maxLength,
onChange = _ref19.onChange,
onFocus = _ref19.onFocus,
onBlur = _ref19.onBlur;
return /*#__PURE__*/React.createElement(Field, {
fullHeight: fullHeight,
spaceAfter: spaceAfter
}, label && /*#__PURE__*/React.createElement(FormLabel, {
filled: Boolean(value),
disabled: disabled
}, label), /*#__PURE__*/React.createElement(StyledTextArea, {
"data-test": dataTest,
name: name,
value: value,
rows: rows,
size: size,
fullHeight: fullHeight,
disabled: disabled,
error: error,
placeholder: placeholder,
maxLength: maxLength,
onChange: onChange,
onFocus: onFocus,
onBlur: onBlur,
resize: resize,
tabIndex: tabIndex,
ref: ref
}), /*#__PURE__*/React.createElement(FormFeedback, {
error: error,
help: help
}));
});
Textarea.displayName = "Textarea";
export default Textarea;