File tree Expand file tree Collapse file tree 2 files changed +29
-21
lines changed Expand file tree Collapse file tree 2 files changed +29
-21
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,14 @@ import React from 'react';
33import Modal from '../components/Modal' ;
44import GoodBye from 'react-goodbye' ;
55
6+ const styles = {
7+ btnStyle : {
8+ color : 'white' ,
9+ marginRight : '8px' ,
10+ padding : '8px 12px'
11+ }
12+ }
13+
614class Settings extends React . Component {
715 constructor ( props ) {
816 super ( props ) ;
@@ -32,18 +40,19 @@ class Settings extends React.Component {
3240 </ p >
3341 < div style = { { textAlign : 'right' } } >
3442 < button
43+ onClick = { handleOk }
3544 style = { {
36- color : 'white' ,
37- backgroundColor : 'red' ,
38- marginRight : '8px' ,
39- padding : '8px 12px'
40- } } onClick = { handleOk } >
45+ ...styles . btnStyle ,
46+ backgroundColor : 'red'
47+ } }
48+ >
4149 Leave
4250 </ button >
4351 < button
4452 onClick = { handleCancel }
4553 style = { {
46- padding : '8px 12px'
54+ ...styles . btnStyle ,
55+ color : 'black'
4756 } }
4857 >
4958 Stay
Original file line number Diff line number Diff line change @@ -8,9 +8,13 @@ class Provider extends React.Component {
88 constructor ( props ) {
99 super ( props ) ;
1010 this . state = {
11- isShow : false
11+ isShow : false ,
12+ handleOk : this . handleOk ,
13+ handleCancel : this . handleCancel ,
14+ handlePass : this . handlePass
1215 } ;
1316 this . pass = undefined ;
17+
1418 invariant (
1519 React . createContext ,
1620 'react-goodbye only support React 16.3+ context api, please upgrade your react to the latest version.'
@@ -19,9 +23,7 @@ class Provider extends React.Component {
1923
2024 handleGetUserConfirm = ( message , pass ) => {
2125 this . pass = pass ;
22- this . setState ( {
23- isShow : true
24- } ) ;
26+ this . setState ( { isShow : true } ) ;
2527 } ;
2628
2729 handleOk = ( ) => {
@@ -34,19 +36,16 @@ class Provider extends React.Component {
3436 this . setState ( { isShow : false } ) ;
3537 } ;
3638
39+ handlePass = bool => {
40+ this . pass ( bool ) ;
41+ this . setState ( { isShow : false } ) ;
42+ }
43+
3744 render ( ) {
45+ const { children } = this . props ;
3846 return (
39- < GoodByeContext . Provider
40- value = { {
41- isShow : this . state . isShow ,
42- handleOk : this . handleOk ,
43- handleCancel : this . handleCancel ,
44- pass : this . pass
45- } }
46- >
47- { this . props . children ( {
48- handleGetUserConfirm : this . handleGetUserConfirm
49- } ) }
47+ < GoodByeContext . Provider value = { this . state } >
48+ { children ( { handleGetUserConfirm : this . handleGetUserConfirm } ) }
5049 </ GoodByeContext . Provider >
5150 ) ;
5251 }
You can’t perform that action at this time.
0 commit comments