1
1
import React from 'react' ;
2
+ import Group from 'react-group' ;
2
3
import PropTypes from 'prop-types' ;
4
+ import MdFullscreen from 'react-icons/lib/md/fullscreen' ;
5
+ import MdFullscreenExit from 'react-icons/lib/md/fullscreen-exit' ;
6
+ import MdArrowDropDown from 'react-icons/lib/md/arrow-drop-down' ;
7
+ import MdArrowDropUp from 'react-icons/lib/md/arrow-drop-up' ;
3
8
import Editor from 'rsg-components/Editor' ;
4
9
import Link from 'rsg-components/Link' ;
5
10
import Preview from 'rsg-components/Preview' ;
@@ -13,51 +18,43 @@ const styles = ({ space, color, fontFamily, fontSize, borderRadius }) => ({
13
18
border : [ [ 1 , color . border , 'solid' ] ] ,
14
19
borderRadius : [ [ borderRadius , borderRadius , 0 , borderRadius ] ] ,
15
20
marginTop : space [ 0 ] ,
16
- '&:hover $isolatedLink' : {
17
- isolate : false ,
18
- opacity : 1 ,
19
- } ,
20
21
} ,
21
22
preview : {
22
23
marginBottom : space [ 0 ] ,
23
24
padding : space [ 2 ] ,
24
25
} ,
25
26
codeToggle : {
26
- position : 'absolute' ,
27
- right : - 1 ,
28
- margin : 0 ,
29
- padding : [ [ space [ 0 ] , space [ 1 ] ] ] ,
27
+ border : 'none' ,
30
28
fontFamily : fontFamily . base ,
31
29
fontSize : fontSize . base ,
32
- lineHeight : 1 ,
33
- color : color . link ,
34
- border : [ [ 1 , color . border , 'solid' ] ] ,
35
- borderTop : 0 ,
36
- borderBottomLeftRadius : borderRadius ,
37
- borderBottomRightRadius : borderRadius ,
30
+ color : color . light ,
31
+ transition : 'all 200ms ease' ,
38
32
cursor : 'pointer' ,
39
- '&:hover, &:active' : {
33
+ '&:not(:focus)' : {
34
+ isolate : false ,
35
+ outline : 'none' ,
36
+ } ,
37
+ '&:hover' : {
40
38
isolate : false ,
41
39
color : color . linkHover ,
42
40
} ,
43
41
} ,
44
- showCode : {
45
- composes : '$codeToggle ' ,
46
- backgroundColor : color . baseBackground ,
42
+ toolbar : {
43
+ display : 'flex ' ,
44
+ padding : [ [ space [ 0 ] , space [ 2 ] ] ] ,
47
45
} ,
48
- hideCode : {
49
- composes : '$codeToggle' ,
50
- backgroundColor : color . codeBackground ,
46
+ toolbarItem : {
47
+ marginRight : space [ 1 ] ,
51
48
} ,
52
- isolatedLink : {
53
- position : 'absolute' ,
54
- top : 0 ,
55
- right : 0 ,
56
- padding : [ [ space [ 0 ] , space [ 1 ] ] ] ,
57
- fontFamily : fontFamily . base ,
58
- fontSize : fontSize . base ,
59
- opacity : 0 ,
60
- transition : 'opacity ease-in-out .15s .2s' ,
49
+ icons : {
50
+ width : 20 ,
51
+ height : 20 ,
52
+ color : color . light ,
53
+ transition : 'all 200ms ease' ,
54
+ '&:hover' : {
55
+ isolate : false ,
56
+ color : color . linkHover ,
57
+ } ,
61
58
} ,
62
59
} ) ;
63
60
@@ -75,29 +72,31 @@ export function PlaygroundRenderer({
75
72
return (
76
73
< div className = { classes . root } >
77
74
< div className = { classes . preview } data-preview = { name ? name : '' } >
78
- < div className = { classes . isolatedLink } >
79
- { name && (
80
- isolatedExample ? (
81
- < Link href = { '#!/' + name } > ⇽ Exit Isolation</ Link >
82
- ) : (
83
- < Link href = { '#!/' + name + '/' + index } > Open isolated ⇢</ Link >
84
- )
85
- ) }
86
- </ div >
87
75
< Preview code = { code } evalInContext = { evalInContext } />
88
76
</ div >
89
- { showCode ? (
90
- < div >
91
- < Editor code = { code } onChange = { onChange } />
92
- < button type = "button" className = { classes . hideCode } onClick = { onCodeToggle } >
93
- Hide code
77
+ < Group separator = " " className = { classes . toolbar } >
78
+ < div className = { classes . toolbarItem } >
79
+ { name && (
80
+ isolatedExample ? (
81
+ < Link href = { '/' } > < MdFullscreenExit className = { classes . icons } /> </ Link >
82
+ ) : (
83
+ < Link href = { '#!/' + name + '/' + index } >
84
+ < MdFullscreen className = { classes . icons } />
85
+ </ Link >
86
+ )
87
+ ) }
88
+ </ div >
89
+ < div className = { classes . toolbarItem } >
90
+ < button type = "button" className = { classes . codeToggle } onClick = { onCodeToggle } >
91
+ { showCode ? 'Hide' : 'Show' } code
92
+ { showCode
93
+ ? < MdArrowDropUp className = { classes . icons } />
94
+ : < MdArrowDropDown className = { classes . icons } />
95
+ }
94
96
</ button >
95
97
</ div >
96
- ) : (
97
- < button type = "button" className = { classes . showCode } onClick = { onCodeToggle } >
98
- Show code
99
- </ button >
100
- ) }
98
+ </ Group >
99
+ { showCode && < Editor code = { code } onChange = { onChange } /> }
101
100
</ div >
102
101
) ;
103
102
}
0 commit comments