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.

112 lines (109 loc) 3.79 kB
import * as React from "react"; import styled from "styled-components"; import defaultTokens from "../defaultTokens"; import FormFeedback from "../FormFeedback"; import FormLabel from "../FormLabel"; import { SIZE_OPTIONS, RESIZE_OPTIONS, TOKENS } from "./consts"; const Field = styled.label.withConfig({ displayName: "Textarea__Field", componentId: "sc-1ezoqgy-0" })(["font-family:", ";display:flex;width:100%;height:", ";flex-direction:column;position:relative;flex:", ";"], ({ theme }) => theme.orbit.fontFamily, ({ fullHeight }) => fullHeight && "100%", ({ fullHeight }) => fullHeight && "1"); Field.defaultProps = { theme: defaultTokens }; const getTokens = name => ({ theme, size }) => { const tokens = { [TOKENS.fontSizeInput]: { [SIZE_OPTIONS.SMALL]: theme.orbit.fontSizeInputSmall, [SIZE_OPTIONS.NORMAL]: theme.orbit.fontSizeInputNormal }, [TOKENS.paddingInput]: { [SIZE_OPTIONS.SMALL]: theme.orbit.paddingTextareaSmall, [SIZE_OPTIONS.NORMAL]: theme.orbit.paddingTextareaNormal } }; return tokens[name][size]; }; const StyledTextArea = styled.textarea.withConfig({ displayName: "Textarea__StyledTextArea", componentId: "sc-1ezoqgy-1" })(["appearance:none;box-sizing:border-box;display:block;width:100%;height:", ";padding:", ";border-radius:", ";box-shadow:inset 0 0 0 ", ";background-color:", ";color:", ";font-size:", ";line-height:", ";cursor:", ";font-family:inherit;resize:", ";transition:box-shadow ", " ease-in-out;flex:", ";border:1px solid transparent;overflow:auto;&::placeholder{color:", ";}&:hover{box-shadow:", ";}&:focus{box-shadow:", ";outline:none;}"], ({ fullHeight }) => fullHeight && "100%", getTokens(TOKENS.paddingInput), ({ theme }) => theme.orbit.borderRadiusNormal, ({ theme, error }) => `${theme.orbit.borderWidthInput} ${error ? theme.orbit.borderColorInputError : theme.orbit.borderColorInput}`, ({ disabled, theme }) => disabled ? theme.orbit.backgroundInputDisabled : theme.orbit.backgroundInput, ({ disabled, theme }) => disabled ? theme.orbit.colorTextInputDisabled : theme.orbit.colorTextInput, getTokens(TOKENS.fontSizeInput), ({ theme }) => theme.orbit.lineHeightText, ({ disabled }) => disabled ? "not-allowed" : "text", ({ resize }) => resize, ({ theme }) => theme.orbit.durationFast, ({ fullHeight }) => fullHeight && "1", ({ theme }) => theme.orbit.colorPlaceholderInput, ({ disabled, theme, error }) => !disabled && `inset 0 0 0 ${theme.orbit.borderWidthInput} ${error ? theme.orbit.borderColorInputErrorHover : theme.orbit.borderColorInputHover}`, ({ theme, disabled }) => !disabled && `inset 0 0 0 2px ${theme.orbit.borderColorInputFocus}`); StyledTextArea.defaultProps = { theme: defaultTokens }; // $FlowExpected const Textarea = React.forwardRef((props, ref) => { const { size = SIZE_OPTIONS.NORMAL, disabled, resize = RESIZE_OPTIONS.VERTICAL, dataTest } = props; return React.createElement(Field, { "data-test": dataTest, fullHeight: props.fullHeight }, props.label && React.createElement(FormLabel, { filled: !!props.value, disabled: disabled }, props.label), React.createElement(StyledTextArea, { name: props.name, value: props.value, size: size, fullHeight: props.fullHeight, disabled: disabled, error: props.error, placeholder: props.placeholder, maxLength: props.maxLength, onChange: props.onChange, onFocus: props.onFocus, onBlur: props.onBlur, resize: resize, ref: ref }), props.help && !props.error && React.createElement(FormFeedback, { type: "help" }, props.help), props.error && React.createElement(FormFeedback, { type: "error" }, props.error)); }); Textarea.display = "Textarea"; export default Textarea;