File tree 3 files changed +33
-6
lines changed
packages/react-scripts/template/src
3 files changed +33
-6
lines changed Original file line number Diff line number Diff line change 3
3
bottom : 0 ;
4
4
left : 0 ;
5
5
right : 0 ;
6
- max-width : 100% ;
7
- width : 240px ;
8
6
padding : 16px ;
9
7
margin : auto;
10
8
transition : 250ms ;
11
9
background : # 222 ;
12
10
color : white;
13
- text-align : center;
14
11
line-height : 24px ;
15
12
border-top-left-radius : 2px ;
16
13
border-top-right-radius : 2px ;
14
+ display : flex;
17
15
}
18
16
19
17
.Toast .active {
22
20
23
21
.Toast .inactive {
24
22
transform : translateY (100% );
23
+ }
24
+
25
+ .Toast-button {
26
+ padding : 0 ;
27
+ background : transparent;
28
+ border : 0 ;
29
+ display : inline-block;
30
+ color : # 61dafb ;
31
+ font-size : inherit;
32
+ line-height : inherit;
33
+ text-transform : uppercase;
34
+ flex : 0 0 0 ;
35
+ }
36
+
37
+ .Toast-text {
38
+ flex : 1 ;
25
39
}
Original file line number Diff line number Diff line change @@ -5,8 +5,15 @@ export default class Toast extends React.Component {
5
5
state = {
6
6
active : true ,
7
7
} ;
8
+
9
+ close = ( ) => {
10
+ clearTimeout ( this . timeout ) ;
11
+ this . setState ( {
12
+ active : false ,
13
+ } ) ;
14
+ } ;
8
15
componentDidMount ( ) {
9
- setTimeout (
16
+ this . timeout = setTimeout (
10
17
( ) => {
11
18
this . setState ( {
12
19
active : false ,
@@ -15,10 +22,16 @@ export default class Toast extends React.Component {
15
22
this . props . timeout
16
23
) ;
17
24
}
25
+ componentWillUnmount ( ) {
26
+ clearTimeout ( this . timeout ) ;
27
+ }
18
28
render ( ) {
19
29
return (
20
30
< div className = { `Toast ${ this . state . active ? 'active' : 'inactive' } ` } >
21
- { this . props . children }
31
+ < span className = "Toast-text" >
32
+ { this . props . children }
33
+ </ span >
34
+ < button className = "Toast-button" onClick = { this . close } > Dismiss</ button >
22
35
</ div >
23
36
) ;
24
37
}
Original file line number Diff line number Diff line change @@ -24,7 +24,7 @@ if (!dom) {
24
24
function showMessage ( message ) {
25
25
if ( useToast ) {
26
26
ReactDOM . render (
27
- < Toast timeout = { 3000 } >
27
+ < Toast >
28
28
{ message }
29
29
</ Toast > ,
30
30
dom
You can’t perform that action at this time.
0 commit comments