This repository was archived by the owner on Jul 19, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 524
Expand file tree
/
Copy pathapp.js
More file actions
79 lines (74 loc) · 2.63 KB
/
app.js
File metadata and controls
79 lines (74 loc) · 2.63 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
import React from 'react'
import DOM from 'react-dom'
import Autocomplete from '../../lib/index'
import { fakeCategorizedRequest } from '../../lib/utils'
class App extends React.Component {
constructor(props) {
super(props)
this.state = {
value: '',
unitedStates: [],
loading: false
}
this.requestTimer = null
}
render() {
return (
<div>
<h1>Custom Menu</h1>
<p>
While Autocomplete ships with a decent looking menu, you can control the
look as well as the rendering of it. In this example we'll group the states
into the region where they belong.
</p>
<label htmlFor="states-autocomplete">Choose a state from the US</label>
<Autocomplete
value={this.state.value}
inputProps={{ id: 'states-autocomplete' }}
items={this.state.unitedStates}
getItemValue={(item) => item.name}
onSelect={(value, state) => this.setState({ value, unitedStates: [state] }) }
onChange={(event, value) => {
this.setState({ value, loading: true, unitedStates: [] })
clearTimeout(this.requestTimer)
this.requestTimer = fakeCategorizedRequest(value, (items) => {
this.setState({ unitedStates: items, loading: false })
})
}}
renderItem={(item, isHighlighted) => (
item.header ?
<div
className="item item-header"
key={item.header}
>{item.header}</div>
: <div
className={`item ${isHighlighted ? 'item-highlighted' : ''}`}
key={item.abbr}
>{item.name}</div>
)}
renderMenu={(items, value) => (
<div className="menu">
{value === '' ? (
<div className="item">Type of the name of a United State</div>
) : this.state.loading ? (
<div className="item">Loading...</div>
) : items.length === 0 ? (
<div className="item">No matches for {value}</div>
) : items}
</div>
)}
renderWrapper={(wrapperStyles, wrapperProps, renderedInput, renderedMenu, renderedDebugInfo) => (
<span style = {{ ...wrapperStyles }} {...wrapperProps}>
Enter value here: {renderedInput}
{renderedMenu}
{renderedDebugInfo}
</span>
)}
isItemSelectable={(item) => !item.header}
/>
</div>
)
}
}
DOM.render(<App/>, document.getElementById('container'))
if (module.hot) { module.hot.accept() }