forked from dnnsoftware/Dnn.Platform
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathFolderPicker.jsx
More file actions
106 lines (90 loc) · 3.64 KB
/
Copy pathFolderPicker.jsx
File metadata and controls
106 lines (90 loc) · 3.64 KB
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
95
96
97
98
99
100
101
102
103
104
105
106
import React, { Component } from "react";
import PropTypes from "prop-types";
import Folders from "./Folders";
import { Scrollbars } from "react-custom-scrollbars";
import SearchIcon from "./img/search.svg";
export default class FolderPicker extends Component {
constructor() {
super();
this.state = {
showFolderPicker: false,
searchFolderText: ""
};
this.timeOut = null;
this.handleClick = this.handleClick.bind(this);
}
componentDidMount() {
document.addEventListener("click", this.handleClick, false);
this._isMounted = true;
}
componentWillUnmount() {
document.removeEventListener("click", this.handleClick, false);
this._isMounted = false;
}
handleClick(e) {
if (!this._isMounted) { return; }
if (this.node && this.node.contains(e.target) || e.target.className === "clear-button") {
return;
}
this.hide();
}
hide() {
this.setState({ showFolderPicker: false});
}
onFolderClick(folder) {
this.hide();
this.props.onFolderClick(folder);
}
onChangeSearchFolderText(e) {
const searchFolderText = e.target.value ? e.target.value : "";
this.setState({ searchFolderText });
clearTimeout(this.timeOut);
this.timeOut = setTimeout(() => {this.props.searchFolder(searchFolderText.toLowerCase());}, 500);
}
clearSearch(e) {
e.preventDefault();
this.setState({ searchFolderText: "" });
this.props.searchFolder();
}
onFoldersClick() {
const {showFolderPicker} = this.state;
this.setState({ showFolderPicker: !showFolderPicker });
}
render() {
const selectedFolderText = this.props.selectedFolder ? this.props.selectedFolder.value : this.props.notSpecifiedText;
return <div className="drop-down" ref={node => this.node = node}>
<div className="selected-item" onClick={this.onFoldersClick.bind(this) }>
{selectedFolderText}
</div>
<div className={"item-picker-container" + (this.state.showFolderPicker ? " show" : "") } >
<div className="inner-box">
<div className="search">
<input type="text" value={this.state.searchFolderText} onChange={this.onChangeSearchFolderText.bind(this) } placeholder={this.props.searchFoldersPlaceHolderText} aria-label="Search" />
{this.state.searchFolderText && <div onClick={this.clearSearch.bind(this)} className="clear-button">×</div>}
<div className="search-icon"><SearchIcon /></div>
</div>
<div className="items">
<Scrollbars className="scrollArea content-vertical"
autoHeight
autoHeightMin={0}
autoHeightMax={200}>
<Folders
folders={this.props.folders}
getChildren={this.props.getChildren}
onFolderClick={this.onFolderClick.bind(this) }/>
</Scrollbars>
</div>
</div>
</div>
</div>;
}
}
FolderPicker.propTypes = {
folders: PropTypes.object.isRequired,
onFolderClick: PropTypes.func.isRequired,
getChildren: PropTypes.func.isRequired,
selectedFolder: PropTypes.object.isRequired,
searchFolder: PropTypes.func.isRequired,
notSpecifiedText: PropTypes.string,
searchFoldersPlaceHolderText: PropTypes.string
};