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.

101 lines (83 loc) 3.91 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.TextInput = TextInput; exports.TEXT_INPUT_TYPES = void 0; var _react = _interopRequireDefault(require("react")); var _propTypes = require("prop-types"); var _reactFela = require("react-fela"); var _block = require("../block"); var _getThemeStyle = require("../../get-theme-style"); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 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; } var TEXT_INPUT_TYPES = { TELEPHONE: "tel", TEXT: "text", EMAIL: "email", SEARCH: "search", PASSWORD: "password", NUMBER: "number" }; exports.TEXT_INPUT_TYPES = TEXT_INPUT_TYPES; var defaultStyles = function defaultStyles(_ref) { var theme = _ref.theme; return { appearance: "none", fontWeight: 400, borderWidth: 1, borderStyle: "solid", borderRadius: 0, boxSizing: "border-box", display: "block", width: "100%", fontSize: 16, margin: 0, outline: 0, padding: "".concat(theme.tokens.inputPaddingVertical, "px ").concat(theme.tokens.inputPaddingHorizontal, "px"), lineHeight: 1, borderColor: theme.tokens.inputBorder, color: theme.tokens.inputText, background: theme.tokens.inputBackground, ":focus": { borderColor: theme.tokens.inputBorderFocus }, "::placeholder": { color: theme.tokens.inputPlaceholder }, "[disabled]": { cursor: "not-allowed", color: theme.tokens.inputDisabledForeground, borderColor: theme.tokens.inputDisabledBorder } }; }; function TextInput(_ref2) { var onChange = _ref2.onChange, _ref2$type = _ref2.type, type = _ref2$type === void 0 ? TEXT_INPUT_TYPES.TEXT : _ref2$type, _ref2$value = _ref2.value, value = _ref2$value === void 0 ? "" : _ref2$value, props = _objectWithoutProperties(_ref2, ["onChange", "type", "value"]); var _useFela = (0, _reactFela.useFela)(), theme = _useFela.theme; return _react.default.createElement(_block.Block, _extends({}, props, { value: value, type: type, as: "input", onChange: onChange, extend: [defaultStyles, (0, _getThemeStyle.getThemeStyle)("textInput", theme)] })); } TextInput.propTypes = { /** TextInput type. Use `TEXT_INPUT_TYPES` to set this.*/ type: (0, _propTypes.oneOf)([TEXT_INPUT_TYPES.TELEPHONE, TEXT_INPUT_TYPES.TEXT, TEXT_INPUT_TYPES.EMAIL, TEXT_INPUT_TYPES.SEARCH, TEXT_INPUT_TYPES.PASSWORD, TEXT_INPUT_TYPES.NUMBER]), /** onChange handler. Triggers on every keyboard and generally * is here where you change the value of the `value` property */ onChange: _propTypes.func.isRequired, /** Value of the textInput. This should be stored in the * state of the parent component */ value: _propTypes.string.isRequired };