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 SVGIcon from 'nfvo-components/icon/SVGIcon.jsx';
19 import Input from 'nfvo-components/input/validation/InputWrapper.jsx';
21 const ExpandableInputClosed = ({iconType, onClick}) => (
22 <SVGIcon className='expandable-input-wrapper closed' name={iconType} onClick={onClick} />
25 class ExpandableInputOpened extends React.Component {
27 this.rawDomNode = ReactDOM.findDOMNode(this.searchInputNode.inputWrapper);
28 this.rawDomNode.focus();
31 componentWillReceiveProps(newProps){
33 if (!(document.activeElement === this.rawDomNode)){
34 this.props.handleBlur();
40 this.props.onChange('');
41 this.rawDomNode.focus();
45 if (e.key === 'Escape'){
47 if (this.props.value) {
50 this.rawDomNode.blur();
56 let {iconType, value, onChange, handleBlur} = this.props;
58 <div className='expandable-input-wrapper opened' key='expandable'>
62 ref={(input) => this.searchInputNode = input}
63 className='expandable-active'
64 groupClassName='expandable-input-control'
65 onChange={e => onChange(e)}
66 onKeyDown={e => this.handleKeyDown(e)}
68 {value && <SVGIcon onClick={() => this.handleClose()} name='close' />}
69 {!value && <SVGIcon name={iconType} onClick={handleBlur}/>}
75 class ExpandableInput extends React.Component {
78 iconType: React.PropTypes.string,
79 onChange: React.PropTypes.func,
80 value: React.PropTypes.string
83 state = {showInput: false};
86 if (!this.props.value) {
87 this.setState({showInput: false});
92 return this.props.value;
96 let {iconType, value, onChange = false} = this.props;
98 <div className='expandable-input-top'>
99 {this.state.showInput &&
100 <ExpandableInputOpened
105 handleKeyDown={(e) => this.handleKeyDown(e)}
106 handleBlur={() => this.closeInput()}/>
108 {!this.state.showInput && <ExpandableInputClosed key='closed' iconType={iconType} onClick={() => this.setState({showInput: true})} />}
115 export default ExpandableInput;