UNPKG

@shakthillc/components

Version:

React generic components for shakthi products

220 lines (206 loc) 7.49 kB
import _Object$getPrototypeOf from "babel-runtime/core-js/object/get-prototype-of"; import _classCallCheck from "babel-runtime/helpers/classCallCheck"; import _createClass from "babel-runtime/helpers/createClass"; import _possibleConstructorReturn from "babel-runtime/helpers/possibleConstructorReturn"; import _inherits from "babel-runtime/helpers/inherits"; import React from "react"; import PropTypes from "prop-types"; import style from "./InputText.module.css"; import Icon from "@material-ui/core/Icon"; var InputText = function (_React$Component) { _inherits(InputText, _React$Component); function InputText(props) { _classCallCheck(this, InputText); var _this = _possibleConstructorReturn(this, (InputText.__proto__ || _Object$getPrototypeOf(InputText)).call(this, props)); _this.state = { value: "", passwordIcon: "visibility", passwordField: "password" }; _this.onChange = _this.onChange.bind(_this); _this.handleFocus = _this.handleFocus.bind(_this); _this.handleBlur = _this.handleBlur.bind(_this); _this.handleIcon = _this.handleIcon.bind(_this); return _this; } _createClass(InputText, [{ key: "componentDidMount", value: function componentDidMount() { this.setState({ value: this.props.value }); } }, { key: "onChange", value: function onChange(e) { var onKeyup = this.props.onKeyup; this.setState({ value: e.target.value }); onKeyup && onKeyup(e.target.value); } }, { key: "handleFocus", value: function handleFocus(e) { var onFocus = this.props.onFocus; //console.log("Focus",e.target.value) onFocus && onFocus(e.target.value); } }, { key: "handleBlur", value: function handleBlur(e) { var onBlur = this.props.onBlur; //console.log("blur",e.target.value) onBlur && onBlur(e.target.value); } }, { key: "handleIcon", value: function handleIcon() { var passwordIcon = this.state.passwordIcon === "visibility_off" ? "visibility" : "visibility_off"; var passwordField = passwordIcon === "visibility" ? "password" : "text"; this.setState({ passwordIcon: passwordIcon, passwordField: passwordField }); } }, { key: "render", value: function render() { var _state = this.state, passwordIcon = _state.passwordIcon, passwordField = _state.passwordField; var _props = this.props, _props$placeHolder = _props.placeHolder, placeHolder = _props$placeHolder === undefined ? "Enter text" : _props$placeHolder, _props$isMandatory = _props.isMandatory, isMandatory = _props$isMandatory === undefined ? false : _props$isMandatory, label = _props.label, help = _props.help, icon = _props.icon, _props$type = _props.type, type = _props$type === undefined ? "text" : _props$type, onChange = _props.onChange, value = _props.value, icon_position = _props.icon_position, _props$readOnly = _props.readOnly, readOnly = _props$readOnly === undefined ? false : _props$readOnly, _props$id = _props.id, id = _props$id === undefined ? "defaultTextId" : _props$id; var text_style = "input-area__icon--" + icon_position + readOnly; var text_stylemain = readOnly ? "input-area__readonly" : "input-area"; var borderStyle = isMandatory == true ? style["input-enableborder"] : ""; if (type === "password") { return React.createElement( "div", { className: style["input-holder"] }, label && React.createElement( "p", { "data-id": "label" + id, className: style["input-holder__header"] }, label ), React.createElement( "div", null, React.createElement( "div", { style: { position: "relative" } }, React.createElement( "i", { onClick: this.handleIcon, className: style["input-holder__icon--right"] }, React.createElement( Icon, { style: { fontSize: 18 } }, passwordIcon ) ), React.createElement("input", { type: passwordField, onFocus: this.handleFocus, onBlur: this.handleBlur, onChange: onChange || this.onChange, style: this.props.style, className: icon === undefined ? style[text_stylemain] + " " + borderStyle : style[text_style] + " " + borderStyle, placeholder: placeHolder, value: value === undefined || value === null ? this.state.value : value, readOnly: readOnly, "data-id": id }) ), help && React.createElement( "p", { "data-id": "error" + id, className: isMandatory === true ? style["input-holder__helper--red"] : style["input-holder__helper"] }, help ) ) ); } else { return React.createElement( "div", { className: style["input-holder"] }, label && React.createElement( "p", { "data-id": "label" + id, className: style["input-holder__header"] }, label ), React.createElement( "div", { style: { position: "relative" } }, icon && React.createElement( "i", { className: icon_position === "right" ? style["input-holder__icon--right"] : style["input-holder__icon"] }, React.createElement( Icon, { style: { fontSize: 18 } }, icon ) ), React.createElement("input", { type: type, onFocus: this.handleFocus, onBlur: this.handleBlur, onChange: onChange || this.onChange, style: this.props.style //style={isMandatory === true ? { border: "solid 2px #FA383E" } : {}} , className: icon === undefined ? style[text_stylemain] + " " + borderStyle : style[text_style] + " " + borderStyle, placeholder: placeHolder, value: value === undefined || value === null ? this.state.value : value, readOnly: readOnly, "data-id": id }) ), help && React.createElement( "p", { "data-id": "error" + id, className: isMandatory === true ? style["input-holder__helper--red"] : style["input-holder__helper"] }, help ) ); } } }]); return InputText; }(React.Component); export default InputText; InputText.propTypes = { placeHolder: PropTypes.string, label: PropTypes.string, help: PropTypes.string, icon: PropTypes.string, value: PropTypes.string, onKeyup: PropTypes.func, isMandatory: PropTypes.bool }; InputText.defaultProps = { icon_position: "left", placeHolder: "Enter text", isMandatory: false, type: "text", onKeyup: function onKeyup() { //console.log("keyup"); } };