-
Notifications
You must be signed in to change notification settings - Fork 501
/
Copy pathObjectKeyModal.js
94 lines (84 loc) · 3.07 KB
/
ObjectKeyModal.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import React from 'react';
import dispatcher from './../../helpers/dispatcher';
import {CheckCircle, Add as Cancel} from './../icons';
//global theme
import Theme from './../../themes/getStyle';
//this input appears when adding a new value to an object
export default class extends React.PureComponent {
constructor(props) {
super(props);
this.state = {
input: ''
};
}
componentDidMount() {
this.setState({ input: this.props.input });
}
render() {
const {theme, rjvId, isValid} = this.props;
const {input} = this.state;
const valid = isValid(input);
return (
<div
class="key-modal-request"
{...Theme(theme, 'key-modal-request')}
onClick={this.closeModal}
>
<div
{...Theme(theme, 'key-modal')}
onClick={(e)=>{e.stopPropagation();}}
>
<div {...Theme(theme, 'key-modal-label')}>
Key Name:
</div>
<div style={{position: 'relative'}}>
<input {...Theme(theme, 'key-modal-input')}
class="key-modal-input"
ref={el => el && el.focus()}
spellCheck={false}
value={input}
placeholder="..."
onChange={(e)=>{
this.setState({
input: e.target.value
});
}}
onKeyPress={(e)=>{
if (valid && e.key === 'Enter') {
this.submit();
} else if (e.key === 'Escape') {
this.closeModal();
}
}}
/>
{valid
? <CheckCircle {...Theme(theme, 'key-modal-submit')}
class="key-modal-submit"
onClick={e => this.submit()}
/>
: null}
</div>
<span {...Theme(theme, 'key-modal-cancel')}>
<Cancel {...Theme(theme, 'key-modal-cancel-icon')}
class="key-modal-cancel"
onClick={()=>{
dispatcher.dispatch({
rjvId: rjvId,
name: 'RESET'
});
}} />
</span>
</div>
</div>
);
}
closeModal = () => {
dispatcher.dispatch({
rjvId: this.props.rjvId,
name: 'RESET'
});
}
submit = () => {
this.props.submit(this.state.input);
}
}