Skip to content

Commit 946442f

Browse files
committed
extracted dropdown as a component
1 parent f27a34b commit 946442f

File tree

2 files changed

+30
-30
lines changed

2 files changed

+30
-30
lines changed

src/app/components/Dropdown.jsx

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
1-
import React, { Component } from 'React'
2-
import Dropdown from 'react-16-dropdown';
1+
import React from 'react';
2+
import Select from 'react-select';
3+
import PropTypes from 'prop-types';
34

4-
const options = [{
5-
label: 'Prestige 🎩',
6-
value: 'prestige',
7-
}, {
8-
label: 'Inception 😴',
9-
value: 'inception',
10-
}];
5+
const Dropdown = (props) => {
6+
const { options, handleChangeSpeed, selectedOption } = props;
7+
return (
8+
<Select
9+
className="react-select-container"
10+
classNamePrefix="react-select"
11+
value={selectedOption}
12+
onChange={handleChangeSpeed}
13+
options={options}
14+
menuPlacement="top"
15+
/>
16+
);
17+
};
18+
Dropdown.propTypes = {
19+
selectedOption: PropTypes.shape({ value: PropTypes.number, label: PropTypes.string }).isRequired,
20+
options: PropTypes.arrayOf(PropTypes.object).isRequired,
21+
handleChangeSpeed: PropTypes.func.isRequired,
22+
};
1123

12-
<Dropdown
13-
align='left'
14-
className='custom-classname'
15-
closeOnEscape={true}
16-
options={options}
17-
triggerLabel='Movies'
18-
onClick={val => console.log(val)}
19-
/>
20-
21-
export default Dropdown;
24+
export default Dropdown;

src/app/containers/TravelContainer.jsx

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import React, { Component } from 'react';
22
import PropTypes from 'prop-types';
3-
import Select from 'react-select';
43
import MainSlider from '../components/MainSlider';
4+
import Dropdown from '../components/Dropdown';
55

66
const options = [
7-
{ value: '2000', label: '0.5x' },
8-
{ value: '1000', label: '1.0x' },
9-
{ value: '500', label: '2.0x' },
7+
{ value: 2000, label: '0.5x' },
8+
{ value: 1000, label: '1.0x' },
9+
{ value: 500, label: '2.0x' },
1010
];
1111

1212
class TravelContainer extends Component {
@@ -17,7 +17,7 @@ class TravelContainer extends Component {
1717
}
1818

1919
handleChangeSpeed(selectedOption) {
20-
const playSpeed = parseInt(selectedOption.value, 10);
20+
const playSpeed = selectedOption.value;
2121
this.setState({ selectedOption, playSpeed });
2222
}
2323

@@ -53,13 +53,10 @@ class TravelContainer extends Component {
5353
<div className="forward-button" role="button" onClick={moveForward}>
5454
{'>'}
5555
</div>
56-
<Select
57-
className="react-select-container"
58-
classNamePrefix="react-select"
59-
value={selectedOption}
60-
onChange={this.handleChangeSpeed}
56+
<Dropdown
6157
options={options}
62-
menuPlacement="top"
58+
selectedOption={selectedOption}
59+
handleChangeSpeed={this.handleChangeSpeed}
6360
/>
6461
</div>
6562
);

0 commit comments

Comments
 (0)