-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Copy pathSuggestionsList.react.js
73 lines (66 loc) · 1.7 KB
/
SuggestionsList.react.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
/*
* Copyright (c) 2016-present, Parse, LLC
* All rights reserved.
*
* This source code is licensed under the license found in the LICENSE file in
* the root directory of this source tree.
*/
import Popover from 'components/Popover/Popover.react';
import React from 'react';
import styles from 'components/SuggestionsList/SuggestionsList.scss';
export default class Suggestion extends React.Component {
constructor() {
super();
this.state = {
activeSuggestion: 0,
open: false,
position: null
};
this.popoverRef = React.createRef();
}
toggle() {
this.setPosition();
this.setState({ open: !this.state.open });
}
setPosition(position) {
this.popoverRef.current && this.popoverRef.current.setPosition(position);
}
close() {
this.setState({ open: false });
}
render() {
const {
position,
onExternalClick,
suggestions,
suggestionsStyle,
suggestionsItemStyle,
activeSuggestion,
onClick,
onMouseDown,
onKeyDown} = this.props;
return (
<Popover
fixed={false}
position={position}
ref={this.popoverRef}
onExternalClick={onExternalClick}
data-popover-type="inner"
>
<ul style={suggestionsStyle} className={styles.suggestions} onKeyDown={onKeyDown}>
{suggestions.map((suggestion, index) => {
let className;
if (index === activeSuggestion) {
className = styles.active;
}
return (
<li style={suggestionsItemStyle} className={className} key={suggestion} onMouseDown={onMouseDown} onClick={onClick}>
{suggestion}
</li>
);
})}
</ul>
</Popover>
);
}
}