UNPKG

vcc-ui

Version:

VCC UI is a collection of React UI Components that can be used for developing front-end applications at Volvo Car Corporation.

88 lines (79 loc) 3.38 kB
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; } function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; } import React from 'react'; import { bool, string, func } from 'prop-types'; import { useFela } from 'react-fela'; import { Block } from '../block'; import { getThemeStyle } from '../../get-theme-style'; var defaultStyles = function defaultStyles(_ref) { var theme = _ref.theme, isValid = _ref.isValid; return { appearance: 'none', borderWidth: 1, borderStyle: 'solid', borderRadius: 0, boxSizing: 'border-box', display: 'block', width: '100%', margin: 0, outline: 0, padding: "".concat(theme.tokens.inputPaddingVertical, "px ").concat(theme.tokens.inputPaddingHorizontal, "px"), borderColor: theme.tokens.inputBorder, color: theme.tokens.inputForeground, background: theme.tokens.inputBackground, extend: [{ condition: !isValid, style: { borderColor: theme.color.foreground.alert } }, { condition: isValid, style: { ':focus': { borderColor: theme.tokens.inputBorderFocus } } }], '::placeholder': { color: theme.tokens.inputPlaceholder }, '[disabled]': { cursor: 'not-allowed', color: theme.tokens.inputDisabledForeground, borderColor: theme.tokens.inputDisabledBorder } }; }; export var TextArea = React.forwardRef(function (_ref2, ref) { var onChange = _ref2.onChange, _ref2$isValid = _ref2.isValid, isValid = _ref2$isValid === void 0 ? true : _ref2$isValid, _ref2$value = _ref2.value, value = _ref2$value === void 0 ? '' : _ref2$value, props = _objectWithoutProperties(_ref2, ["onChange", "isValid", "value"]); var _useFela = useFela(), theme = _useFela.theme; var styleProps = { isValid: isValid, theme: theme }; return React.createElement(Block, _extends({ ref: ref }, props, { value: value, as: "textarea", onChange: onChange, extend: [defaultStyles(styleProps), getThemeStyle('textArea', theme)] })); }); TextArea.displayName = 'TextArea'; TextArea.propTypes = { onChange: func.isRequired, /** Value of the input. This should be stored in the * state of the parent component */ value: string.isRequired, /** Renders the input as valid or invalid */ isValid: bool };