|
1 | 1 | import React, { Component } from 'react';
|
2 |
| -import './App.css'; |
| 2 | +import Panel from './Panel'; |
3 | 3 | import FontAwesomeIcon from '@fortawesome/react-fontawesome';
|
4 |
| -import faChevronDown from '@fortawesome/fontawesome-free-solid/faChevronDown'; |
5 | 4 | import faReact from '@fortawesome/fontawesome-free-brands/faReact';
|
6 | 5 |
|
7 |
| - |
8 |
| -// HEADER |
9 |
| -// |
10 |
| -class Header extends Component { |
11 |
| - render () { |
12 |
| - const { collapsible, preTools, postTools, |
13 |
| - title, toggleCollapse } = this.props; |
14 |
| - return ( |
15 |
| - <div className="header"> |
16 |
| - {title} |
17 |
| - <div style={{flex: 1}}></div> |
18 |
| - {preTools} |
19 |
| - {collapsible && |
20 |
| - <FontAwesomeIcon |
21 |
| - className="collapse-tool header-tool" |
22 |
| - icon={faChevronDown} |
23 |
| - onClick={toggleCollapse} |
24 |
| - /> |
25 |
| - } |
26 |
| - {postTools} |
27 |
| - </div> |
28 |
| - ); |
29 |
| - } |
30 |
| -} |
31 |
| - |
32 |
| -// EXPANDER |
33 |
| -// |
34 |
| -class Expander extends Component { |
35 |
| - static defaultProps = { |
36 |
| - expanded: true |
37 |
| - } |
38 |
| - componentDidMount = () => { |
39 |
| - this.setHeight(this.props.expanded); |
40 |
| - this.forceUpdate(); |
41 |
| - } |
42 |
| - componentWillReceiveProps = ({ expanded }) => { |
43 |
| - this.setHeight(expanded); |
44 |
| - } |
45 |
| - setHeight = (expanded) => { |
46 |
| - const { scrollHeight } = this.expandWrap; |
47 |
| - this.wrapHeight = expanded ? scrollHeight + 'px' : 0; |
48 |
| - } |
49 |
| - render () { |
50 |
| - const { className = 'expander-wrap', style = {} } = this.props; |
51 |
| - Object.assign(style, { |
52 |
| - height: this.wrapHeight |
53 |
| - }) |
54 |
| - return ( |
55 |
| - <div |
56 |
| - ref={el => this.expandWrap = el} |
57 |
| - className={className} |
58 |
| - style={style} |
59 |
| - > |
60 |
| - {this.props.render(this.props)} |
61 |
| - </div> |
62 |
| - ); |
63 |
| - } |
64 |
| -} |
65 |
| - |
66 |
| - |
67 |
| -// PANEL |
68 |
| -// |
69 |
| -class Panel extends Component { |
70 |
| - static defaultProps = { |
71 |
| - expanded: true |
72 |
| - } |
73 |
| - state = { |
74 |
| - expanded: this.props.expanded |
75 |
| - } |
76 |
| - componentWillReceiveProps = ({ expanded }) => { |
77 |
| - this.setState({expanded}); |
78 |
| - } |
79 |
| - toggleCollapse = () => { |
80 |
| - this.setState({ |
81 |
| - expanded: !this.state.expanded |
82 |
| - }); |
83 |
| - } |
84 |
| - render() { |
85 |
| - const { collapsible, expandDir, preTools, |
86 |
| - postTools, style = {}, title } = this.props; |
87 |
| - const { expanded } = this.state; |
88 |
| - const showHeader = title.length || collapsible; |
89 |
| - const className = `panel${expanded ? ' expanded' : ''}`; |
90 |
| - return ( |
91 |
| - <div className={className} style={style}> |
92 |
| - {showHeader && |
93 |
| - <Header |
94 |
| - title={title} |
95 |
| - collapsible={collapsible} |
96 |
| - toggleCollapse={this.toggleCollapse} |
97 |
| - preTools={preTools} |
98 |
| - postTools={postTools} |
99 |
| - /> |
100 |
| - } |
101 |
| - <Expander expanded={expanded} expandDir={expandDir} render={() => ( |
102 |
| - <div className="body-el"> |
103 |
| - {this.props.children} |
104 |
| - </div> |
105 |
| - )} /> |
106 |
| - </div> |
107 |
| - ); |
108 |
| - } |
109 |
| -} |
110 |
| - |
111 |
| -// PANEL INSTANCE |
112 |
| -// |
113 | 6 | class App extends Component {
|
114 | 7 | render() {
|
115 | 8 | return (
|
|
0 commit comments