2 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
13 * or implied. See the License for the specific language governing
14 * permissions and limitations under the License.
16 import React from 'react';
17 import ReactDOM from 'react-dom';
18 import classNames from 'classnames';
19 import Checkbox from 'react-bootstrap/lib/Checkbox.js';
20 import Radio from 'react-bootstrap/lib/Radio.js';
21 import FormGroup from 'react-bootstrap/lib/FormGroup.js';
22 import FormControl from 'react-bootstrap/lib/FormControl.js';
24 class InputWrapper extends React.Component {
27 value: this.props.value,
28 checked: this.props.checked,
33 const {label, hasError, validations = {}, isReadOnlyMode, value, onBlur, onKeyDown, type, disabled, checked, name} = this.props;
34 const {groupClassName, ...inputProps} = this.props;
36 <FormGroup className={classNames('form-group', [groupClassName], {'required' : validations.required , 'has-error' : hasError})} >
37 {(label && (type !== 'checkbox' && type !== 'radio')) && <label className='control-label'>{label}</label>}
38 {(type === 'text' || type === 'number') &&
40 bsClass={'form-control input-options-other'}
41 onChange={(e) => this.onChange(e)}
42 disabled={isReadOnlyMode || Boolean(disabled)}
46 ref={(input) => this.inputWrapper = input}
48 data-test-id={this.props['data-test-id']}/>}
50 {type === 'textarea' &&
52 className='form-control input-options-other'
53 disabled={isReadOnlyMode || Boolean(disabled)}
58 onChange={(e) => this.onChange(e)}
59 data-test-id={this.props['data-test-id']}/>}
61 {type === 'checkbox' &&
63 className={classNames({'required' : validations.required , 'has-error' : hasError})}
64 onChange={(e)=>this.onChangeCheckBox(e)}
65 disabled={isReadOnlyMode || Boolean(disabled)}
67 data-test-id={this.props['data-test-id']}>{label}</Checkbox>}
72 disabled={isReadOnlyMode || Boolean(disabled)}
74 onChange={(e)=>this.onChangeRadio(e)}
75 data-test-id={this.props['data-test-id']}>{label}</Radio>}
77 <FormControl onClick={ (e) => this.optionSelect(e) }
79 name={name} {...inputProps}
80 data-test-id={this.props['data-test-id']}/>}
88 return this.props.type !== 'select' ? this.state.value : this.state.selectedValues;
92 return this.state.checked;
96 let selectedValues = [];
98 selectedValues.push(e.target.value);
106 let {onChange} = this.props;
108 value: e.target.value
110 onChange(e.target.value);
113 onChangeCheckBox(e) {
114 let {onChange} = this.props;
116 checked: e.target.checked
118 onChange(e.target.checked);
122 let {onChange} = this.props;
124 checked: e.target.checked
126 onChange(this.state.value);
130 ReactDOM.findDOMNode(this.inputWrapper).focus();
134 export default InputWrapper;