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 PropTypes from 'prop-types';
18 import ReactDOM from 'react-dom';
19 import SVGIcon from 'sdc-ui/lib/react/SVGIcon.js';
20 import Input from 'nfvo-components/input/validation/InputWrapper.jsx';
22 const ExpandableInputClosed = ({ iconType, onClick }) => (
24 className="expandable-input-wrapper closed"
25 data-test-id="expandable-input-closed"
31 class ExpandableInputOpened extends React.Component {
33 this.rawDomNode = ReactDOM.findDOMNode(
34 this.searchInputNode.inputWrapper
36 this.rawDomNode.focus();
39 componentWillReceiveProps(newProps) {
40 if (!newProps.value) {
41 if (!(document.activeElement === this.rawDomNode)) {
42 this.props.handleBlur();
48 this.props.onChange('');
49 this.rawDomNode.focus();
53 if (e.key === 'Escape') {
55 if (this.props.value) {
58 this.rawDomNode.blur();
64 let { iconType, value, onChange, handleBlur } = this.props;
66 <div className="expandable-input-wrapper opened" key="expandable">
69 data-test-id="expandable-input-opened"
71 ref={input => (this.searchInputNode = input)}
72 className="expandable-active"
73 groupClassName="expandable-input-control"
74 onChange={e => onChange(e)}
75 onKeyDown={e => this.handleKeyDown(e)}
80 data-test-id="expandable-input-close-btn"
81 onClick={() => this.handleClose()}
85 {!value && <SVGIcon name={iconType} onClick={handleBlur} />}
91 class ExpandableInput extends React.Component {
93 iconType: PropTypes.string,
94 onChange: PropTypes.func,
95 value: PropTypes.string
98 state = { showInput: false };
101 if (!this.props.value) {
102 this.setState({ showInput: false });
107 return this.props.value;
111 let { iconType, value, onChange = false } = this.props;
113 <div className="expandable-input-top">
114 {this.state.showInput && (
115 <ExpandableInputOpened
120 handleKeyDown={e => this.handleKeyDown(e)}
121 handleBlur={() => this.closeInput()}
124 {!this.state.showInput && (
125 <ExpandableInputClosed
128 onClick={() => this.setState({ showInput: true })}
136 export default ExpandableInput;