-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathGoodByeProvider.js
58 lines (48 loc) · 1.23 KB
/
GoodByeProvider.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
import React from 'react';
import PropTypes from 'prop-types';
import invariant from 'invariant';
import GoodByeContext from './GoodByeContext';
class Provider extends React.Component {
constructor(props) {
super(props);
this.state = {
isShow: false,
handleOk: this.handleOk,
handleCancel: this.handleCancel,
handlePass: this.handlePass
};
this.pass = undefined;
invariant(
React.createContext,
'react-goodbye only support React 16.3+ context api, please upgrade your react to the latest version.'
)
}
handleGetUserConfirm = (message, pass) => {
this.pass = pass;
this.setState({ isShow: true });
};
handleOk = () => {
this.setState({ isShow: false });
this.pass(true);
};
handleCancel = () => {
this.setState({ isShow: false });
this.pass(false);
};
handlePass = bool => {
this.setState({ isShow: false });
this.pass(bool);
};
render() {
const { children } = this.props;
return (
<GoodByeContext.Provider value={this.state}>
{children({ handleGetUserConfirm: this.handleGetUserConfirm })}
</GoodByeContext.Provider>
);
}
}
Provider.propTypes = {
children: PropTypes.func
}
export default Provider;