-
Notifications
You must be signed in to change notification settings - Fork 82
/
NoData.js
70 lines (63 loc) · 1.6 KB
/
NoData.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
import React from 'react';
import styled from '@emotion/styled';
import { Heading } from './components/Heading';
import Select from '../../../src';
export class NoData extends React.Component {
state = {
options: [],
loading: false
};
async componentDidMount() {
this.setState({ loading: true });
await fetch("https://jsonplaceholder.typicode.com/users")
.then(responce => responce.json())
.then(result => {
this.setState({
options: result.map(user => ({
label: user.username,
value: user.email
})),
loading: false
});
});
}
customNoDataRenderer = ({ props, state }) => (
<StyledNoData>
Ooops! nothing found for <strong>{state.search}</strong>, search{" "}
<a
href={`https://www.google.com/search?q=${state.search}`}
target="_blank"
>
Google
</a>{" "}
instead
</StyledNoData>
);
render() {
return (
<div>
<Heading
title={this.props.title}
source="https://github.com/sanusart/react-dropdown-select/tree/master/docs/src/examples/NoData.js"
/>
<Select
placeholder="Type to match nothing 😱"
multi
loading={this.state.loading}
noDataRenderer={this.customNoDataRenderer}
onChange={() => undefined}
values={[]}
options={this.state.options}
/>
</div>
);
}
}
export default NoData;
const StyledNoData = styled.div`
padding: 10px;
color: #555;
background: #f2f2f2;
border-radius: 5px;
margin: 3px;
`;