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.

69 lines (58 loc) 3.6 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 _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } 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; } 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 { string, object, func, oneOf } from "prop-types"; import { Block, withTheme } from "../block"; var TEXT_INPUT_TYPES = { TELEPHONE: "tel", TEXT: "text", EMAIL: "email", SEARCH: "search", PASSWORD: "password", NUMBER: "number" }; var defaultStyles = { display: "block", fontSize: "15px", fontFamily: "Volvo Novum Regular, sans-serif", margin: "0", padding: "18px 24px", border: "1px solid #f0f0f0", color: "#333", boxSizing: "border-box", width: "100%" }; var TextInputComponent = function TextInputComponent(_ref) { var onChange = _ref.onChange, theme = _ref.theme, props = _objectWithoutProperties(_ref, ["onChange", "theme"]); return React.createElement(Block, _extends({ as: "input", onChange: onChange, extend: _objectSpread({}, defaultStyles, theme.textInput) }, props)); }; var propTypes = { /** TextInput type. Use `TEXT_INPUT_TYPES` to set this.*/ type: 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: func.isRequired, /** Value of the textInput. This should be stored in the * state of the parent component */ value: string.isRequired, /** @ignore This is pass when using the ThemeProvider */ theme: object }; var defaultProps = { type: TEXT_INPUT_TYPES.TEXT, value: "" }; TextInputComponent.propTypes = propTypes; TextInputComponent.defaultProps = defaultProps; TextInputComponent.displayName = "TextInput"; var TextInput = withTheme(TextInputComponent); export { TextInput, TEXT_INPUT_TYPES };