blob: 3c1d2e6240c8a9ef0b8ffd2cdf49e321fb51d13b [file] [log] [blame]
pineafan15b813d2022-02-13 10:06:09 +00001import react, { Component } from "react";
2import Styles from '../styles/Components/panels.module.css';
3import handleViewport from 'react-in-viewport';
4
5
6class PanelClass extends Component {
7 constructor(props) {
8 super(props);
9 }
10
11 getStyle() {
12 const { inViewport, enterCount } = this.props;
13 if (inViewport && enterCount === 1) { return { WebkitTransition: 'all 0.75s ease-in-out', opacity: '1', transform: "translateY(0px)" };
14 } else if (!inViewport && enterCount < 1) { return { WebkitTransition: 'none', opacity: '0', transform: "translateY(20px)" };
15 } else { return {}; }
16 }
17
18 render() {
19 return <div className={Styles.panel} style={this.getStyle()} id={this.props.id}>
20 {
21 react.Children.toArray(this.props.children).map((child, index) => {
22 return child;
23 })
24 }
25 </div>
26 }
27}
28
29
30class AutoLayout extends Component {
31 constructor(props) {
32 super(props);
33 this.children = react.Children.toArray(this.props.children)
34 this.validity = []
35 this.calculateValidity()
36 }
37
38 calculateValidity() {
39 this.children.map((item, index) => {
40 if ( index > 0 && item.props.halfSize && this.validity[index - 1] == 'half1' ) {
41 this.validity[index] = 'half2';
42 } else if ( index > 0 && !item.props.halfSize && this.validity[index - 1] == 'half1' ) {
43 this.validity[index] = 'full';
44 this.validity[index - 1] = 'full';
45 } else if ( item.props.halfSize && !(index == this.props.children.length - 1) ) {
46 this.validity[index] = 'half1';
47 } else if ( index == this.props.children.length - 1 && this.validity[index - 1] == 'half1' ) {
48 this.validity[index] = 'full';
49 this.validity[index - 1] = 'full';
50 } else if ( index == this.props.children.length - 1 && this.validity[index - 1] == 'half2' ) {
51 this.validity[index] = 'full';
52 } else {
53 this.validity[index] = 'full';
54 }
55 })
56 }
57
58 render() {
59 return (
60 <div className={Styles.container}>
61 {
62 this.children.map((item, index) => {
63 if ( this.validity[index] == 'full' ) {
64 return this.children[index]
65 } else if ( this.validity[index] == 'half1' ) {
66 return <div key={index} className={Styles.doublePanel}>
67 {this.children[index]}
68 {this.children[index + 1]}
69 </div>
70 }
71 })
72 }
73 </div>
74 )
75 }
76}
77
78
79class Title extends Component {
80 render() {
81 return <h1 className={Styles.title}>{this.props.children}</h1>
82 }
83}
84
85class Subtitle extends Component {
86 render() {
87 return <h2 className={Styles.subtitle}>{this.props.children}</h2>
88 }
89}
90
91class Text extends Component {
92 render() {
93 return <p className={Styles.text}>{this.props.children}</p>
94 }
95}
96
97class Divider extends Component {
98 render() {
99 return <div className={Styles.divider}></div>
100 }
101}
102
103const Panel = handleViewport(PanelClass, { rootMargin: '-1.0px' });
104
105export { AutoLayout, Panel, Title, Subtitle, Text, Divider };