| 1 |
/** |
| 2 |
* External dependencies |
| 3 |
*/ |
| 4 |
import Select from 'react-select'; |
| 5 |
import selectStyles from 'gutenberg-react-select-styles'; |
| 6 |
import classnames from 'classnames/dedupe'; |
| 7 |
import { AutoSizer, List } from 'react-virtualized'; |
| 8 |
|
| 9 |
/** |
| 10 |
* WordPress dependencies |
| 11 |
*/ |
| 12 |
const { Component } = wp.element; |
| 13 |
|
| 14 |
const rowHeight = 26; |
| 15 |
|
| 16 |
function MenuList(props) { |
| 17 |
const { children, maxHeight } = props; |
| 18 |
|
| 19 |
if (!children.length) { |
| 20 |
return null; |
| 21 |
} |
| 22 |
|
| 23 |
return ( |
| 24 |
<AutoSizer disableHeight> |
| 25 |
{({ width }) => { |
| 26 |
return ( |
| 27 |
<List |
| 28 |
height={maxHeight} |
| 29 |
rowCount={children.length} |
| 30 |
rowHeight={rowHeight} |
| 31 |
// eslint-disable-next-line react/no-unstable-nested-components |
| 32 |
rowRenderer={({ index, key, style }) => { |
| 33 |
return ( |
| 34 |
<div key={key} style={style}> |
| 35 |
{children[index]} |
| 36 |
</div> |
| 37 |
); |
| 38 |
}} |
| 39 |
width={width} |
| 40 |
/> |
| 41 |
); |
| 42 |
}} |
| 43 |
</AutoSizer> |
| 44 |
); |
| 45 |
} |
| 46 |
|
| 47 |
/** |
| 48 |
* Component Class |
| 49 |
*/ |
| 50 |
export default class SelectComponent extends Component { |
| 51 |
render() { |
| 52 |
const props = { |
| 53 |
...(this.props.grouped |
| 54 |
? { |
| 55 |
groupHeaderHeight: 50, |
| 56 |
} |
| 57 |
: {}), |
| 58 |
...this.props, |
| 59 |
}; |
| 60 |
|
| 61 |
return ( |
| 62 |
<Select |
| 63 |
styles={selectStyles} |
| 64 |
components={{ MenuList }} |
| 65 |
{...props} |
| 66 |
className={classnames(props.className, 'ghostkit-control-select')} |
| 67 |
/> |
| 68 |
); |
| 69 |
} |
| 70 |
} |
| 71 |
|