-
Notifications
You must be signed in to change notification settings - Fork 8
/
Attach.js
52 lines (43 loc) · 1.24 KB
/
Attach.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
import { decl } from 'bem-react-core';
import React from 'react';
import PropTypes from 'prop-types';
import Stylable from 'b:Stylable';
import File from 'e:File';
import NoFile from 'e:NoFile';
export default decl([Stylable], {
block : 'Attach',
willInit() {
this.state = { value : '' };
this._onChange = this._onChange.bind(this);
this._onClearClick = this._onClearClick.bind(this);
this._setStateValue = this._setStateValue.bind(this);
},
tag : 'span',
content({ noFileText }) {
return this.state.value ?
<File key="file" value={this.state.value} onClearClick={this._onClearClick}/> :
<NoFile key="no-file">{noFileText}</NoFile>;
},
_onChange({ target }) {
this._setStateValue(target.value);
},
_onClearClick() {
this._setStateValue('');
},
_setStateValue(value) {
this.setState(
{ value : value },
() => this.props.onChange(this.state.value));
}
}, {
propTypes : {
switcher : PropTypes.string,
text : PropTypes.string,
noFileText : PropTypes.string,
onChange : PropTypes.func
},
defaultProps : {
switcher : 'button',
onChange() {}
}
});