File tree Expand file tree Collapse file tree 3 files changed +37
-4
lines changed Expand file tree Collapse file tree 3 files changed +37
-4
lines changed Original file line number Diff line number Diff line change @@ -20,4 +20,6 @@ const Expandable = ComposedComponent =>
20
20
{ ...this . state }
21
21
{ ...this . props } />
22
22
}
23
- }
23
+ }
24
+
25
+ export default Expandable ;
Original file line number Diff line number Diff line change
1
+ import React , { Component } from 'react' ;
2
+ class MenuButton extends Component {
3
+ componentWillReceiveProps ( nextProps ) {
4
+ const collapsed = ( nextProps . collapsed && nextProps . collapsed === true ) ?true : false ;
5
+ this . setState ( { collapsed} ) ;
6
+ }
7
+
8
+ render ( ) {
9
+ const { children, collapsed, txt, expandCollapse} = this . props ;
10
+ return (
11
+ < div className = "pop-button" >
12
+ < button onClick = { expandCollapse } > { txt } </ button >
13
+ { ( ! collapsed ) ? < div className = "pop-up" > { children } </ div > : '' }
14
+ </ div >
15
+ )
16
+ }
17
+ }
18
+
19
+ export default MenuButton ;
Original file line number Diff line number Diff line change 1
- import React from 'react' ;
1
+ import React , { Children } from 'react' ;
2
2
import ReactDOM from 'react-dom' ;
3
3
import './index.css' ;
4
- import App from './App' ;
5
4
import * as serviceWorker from './serviceWorker' ;
6
5
import Expandable from './Expandable' ;
6
+ import MenuButton from './MenuButton' ;
7
7
8
+ const Letter = / ./ g
8
9
const ShowHideMessage = ( { children, collapsed, expandCollapse} ) =>
9
10
< p onClick = { expandCollapse } >
10
11
{ ( collapsed ) ? children . replace ( Letter , 'x' ) : children }
11
12
</ p >
12
13
const HiddenMessage = Expandable ( ShowHideMessage ) ;
13
14
14
- ReactDOM . render ( < HiddenMessage /> , document . getElementById ( 'root' ) ) ;
15
+ const PopupButton = Expandable ( MenuButton ) ;
16
+
17
+ ReactDOM . render (
18
+ < React . Fragment >
19
+ < HiddenMessage >
20
+ 방가방가
21
+ </ HiddenMessage >
22
+ < PopupButton hidden = { true } txt = "팝업 토글" >
23
+ < h1 > 숨겨진 콘텐츠</ h1 >
24
+ < p > 이 콘텐츠는 처음에 숨겨져있습니다.</ p >
25
+ </ PopupButton >
26
+ </ React . Fragment > , document . getElementById ( 'root' ) ) ;
15
27
16
28
// If you want your app to work offline and load faster, you can change
17
29
// unregister() to register() below. Note this comes with some pitfalls.
You can’t perform that action at this time.
0 commit comments