File tree Expand file tree Collapse file tree 6 files changed +1891
-13
lines changed Expand file tree Collapse file tree 6 files changed +1891
-13
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ import Select from 'react-select';
6
6
7
7
import Contributors from './components/Contributors' ;
8
8
import CustomComponents from './components/CustomComponents' ;
9
+ import CustomMenuComponent from './components/CustomMenuComponent' ;
9
10
import CustomRender from './components/CustomRender' ;
10
11
import Multiselect from './components/Multiselect' ;
11
12
import NumericSelect from './components/NumericSelect' ;
@@ -19,6 +20,7 @@ ReactDOM.render(
19
20
< NumericSelect label = "Numeric Values" />
20
21
< CustomRender label = "Custom Render Methods" />
21
22
< CustomComponents label = "Custom Placeholder, Option and Value Components" />
23
+ < CustomMenuComponent label = "Custom Menu Component" />
22
24
{ /*
23
25
<SelectedValuesField label="Option Creation (tags mode)" options={FLAVOURS} allowCreate hint="Enter a value that's NOT in the list, then hit return" />
24
26
*/ }
Original file line number Diff line number Diff line change
1
+ import React from 'react' ;
2
+ import Select from 'react-select' ;
3
+ import { VirtualScroll } from 'react-virtualized' ;
4
+
5
+ const PEOPLE = require ( '../data/large' ) ;
6
+
7
+ const InfiniteList = React . createClass ( {
8
+ render ( ) {
9
+ let { children, style, ...props } = this . props ;
10
+
11
+ return (
12
+ < VirtualScroll
13
+ height = { 200 }
14
+ { ...props }
15
+ rowRenderer = { this . renderRow }
16
+ rowsCount = { children . length }
17
+ rowHeight = { 35 }
18
+ children = { children /* Pass this so the list re-renders when children are hovered/change */ }
19
+ />
20
+ ) ;
21
+ } ,
22
+
23
+ renderRow ( index ) {
24
+ let { children } = this . props ;
25
+ return children [ index ] ;
26
+ }
27
+ } ) ;
28
+
29
+ const CustomMenuComponent = React . createClass ( {
30
+ propTypes : {
31
+ hint : React . PropTypes . string ,
32
+ label : React . PropTypes . string ,
33
+ } ,
34
+ getInitialState ( ) {
35
+ return { } ;
36
+ } ,
37
+ setValue ( value ) {
38
+ this . setState ( { value } ) ;
39
+ } ,
40
+ render ( ) {
41
+ return (
42
+ < div className = "section" >
43
+ < h3 className = "section-heading" > { this . props . label } </ h3 >
44
+ < Select
45
+ onChange = { this . setValue }
46
+ menuComponent = { InfiniteList }
47
+ placeholder = { `Select one of these ${ PEOPLE . length } people...` }
48
+ options = { PEOPLE }
49
+ value = { this . state . value }
50
+ labelKey = "name"
51
+ valueKey = "id"
52
+ />
53
+ < div className = "hint" >
54
+ This example implements a custom Menu components to render a an infinite list using a react-list.
55
+ </ div >
56
+ </ div >
57
+ ) ;
58
+ }
59
+ } ) ;
60
+
61
+ module . exports = CustomMenuComponent ;
You can’t perform that action at this time.
0 commit comments