11import React from 'react' ;
2+ import Group from 'react-group' ;
23import 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' ;
38import Editor from 'rsg-components/Editor' ;
49import Link from 'rsg-components/Link' ;
510import Preview from 'rsg-components/Preview' ;
@@ -13,51 +18,43 @@ const styles = ({ space, color, fontFamily, fontSize, borderRadius }) => ({
1318 border : [ [ 1 , color . border , 'solid' ] ] ,
1419 borderRadius : [ [ borderRadius , borderRadius , 0 , borderRadius ] ] ,
1520 marginTop : space [ 0 ] ,
16- '&:hover $isolatedLink' : {
17- isolate : false ,
18- opacity : 1 ,
19- } ,
2021 } ,
2122 preview : {
2223 marginBottom : space [ 0 ] ,
2324 padding : space [ 2 ] ,
2425 } ,
2526 codeToggle : {
26- position : 'absolute' ,
27- right : - 1 ,
28- margin : 0 ,
29- padding : [ [ space [ 0 ] , space [ 1 ] ] ] ,
27+ border : 'none' ,
3028 fontFamily : fontFamily . base ,
3129 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' ,
3832 cursor : 'pointer' ,
39- '&:hover, &:active' : {
33+ '&:not(:focus)' : {
34+ isolate : false ,
35+ outline : 'none' ,
36+ } ,
37+ '&:hover' : {
4038 isolate : false ,
4139 color : color . linkHover ,
4240 } ,
4341 } ,
44- showCode : {
45- composes : '$codeToggle ' ,
46- backgroundColor : color . baseBackground ,
42+ toolbar : {
43+ display : 'flex ' ,
44+ padding : [ [ space [ 0 ] , space [ 2 ] ] ] ,
4745 } ,
48- hideCode : {
49- composes : '$codeToggle' ,
50- backgroundColor : color . codeBackground ,
46+ toolbarItem : {
47+ marginRight : space [ 1 ] ,
5148 } ,
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+ } ,
6158 } ,
6259} ) ;
6360
@@ -75,29 +72,31 @@ export function PlaygroundRenderer({
7572 return (
7673 < div className = { classes . root } >
7774 < 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 >
8775 < Preview code = { code } evalInContext = { evalInContext } />
8876 </ 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+ }
9496 </ button >
9597 </ 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 } /> }
101100 </ div >
102101 ) ;
103102}
0 commit comments