blob: 7aaa658bdbd45fd5a5b71004663aa97344348965 [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 {
pineafanaa9c4fd2022-06-10 19:58:10 +01007 constructor(props) {
8 super(props);
9 }
pineafan15b813d2022-02-13 10:06:09 +000010
pineafanaa9c4fd2022-06-10 19:58:10 +010011 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 }
pineafan15b813d2022-02-13 10:06:09 +000017
pineafanaa9c4fd2022-06-10 19:58:10 +010018 render() {
19 return <div className={Styles.panel} style={this.getStyle()} id={this.props.id} tabIndex={0}>
20 {
21 react.Children.toArray(this.props.children).map((child, index) => {
22 return child;
23 })
24 }
25 </div>
26 }
pineafan15b813d2022-02-13 10:06:09 +000027}
28
29
30class AutoLayout extends Component {
pineafanaa9c4fd2022-06-10 19:58:10 +010031 constructor(props) {
32 super(props);
33 this.children = react.Children.toArray(this.props.children)
34 this.validity = []
35 this.calculateValidity()
36 }
pineafan15b813d2022-02-13 10:06:09 +000037
pineafanaa9c4fd2022-06-10 19:58:10 +010038 calculateValidity() {
39 this.children.map((item, index) => {
pineafan9babd752022-10-21 21:47:52 +010040 if ( index > 0 && item.props.halfSize && this.validity[index - 1] === 'half1' ) {
pineafanaa9c4fd2022-06-10 19:58:10 +010041 this.validity[index] = 'half2';
pineafan9babd752022-10-21 21:47:52 +010042 } else if ( index > 0 && !item.props.halfSize && this.validity[index - 1] === 'half1' ) {
pineafanaa9c4fd2022-06-10 19:58:10 +010043 this.validity[index] = 'full';
44 this.validity[index - 1] = 'full';
pineafan9babd752022-10-21 21:47:52 +010045 } else if ( item.props.halfSize && !(index === this.props.children.length - 1) ) {
pineafanaa9c4fd2022-06-10 19:58:10 +010046 this.validity[index] = 'half1';
pineafan9babd752022-10-21 21:47:52 +010047 } else if ( index === this.props.children.length - 1 && this.validity[index - 1] === 'half1' ) {
pineafanaa9c4fd2022-06-10 19:58:10 +010048 this.validity[index] = 'full';
49 this.validity[index - 1] = 'full';
pineafan9babd752022-10-21 21:47:52 +010050 } else if ( index === this.props.children.length - 1 && this.validity[index - 1] === 'half2' ) {
pineafanaa9c4fd2022-06-10 19:58:10 +010051 this.validity[index] = 'full';
52 } else {
53 this.validity[index] = 'full';
54 }
55 })
56 }
pineafan15b813d2022-02-13 10:06:09 +000057
pineafanaa9c4fd2022-06-10 19:58:10 +010058 render() {
59 return (
pineafan15b813d2022-02-13 10:06:09 +000060 <div className={Styles.container}>
pineafanaa9c4fd2022-06-10 19:58:10 +010061 {
62 this.children.map((item, index) => {
pineafan9babd752022-10-21 21:47:52 +010063 if ( this.validity[index] === 'full' ) {
pineafanaa9c4fd2022-06-10 19:58:10 +010064 return this.children[index]
pineafan9babd752022-10-21 21:47:52 +010065 } else if ( this.validity[index] === 'half1' ) {
pineafanaa9c4fd2022-06-10 19:58:10 +010066 return <div key={index} className={Styles.doublePanel}>
67 {this.children[index]}
68 {this.children[index + 1]}
69 </div>
70 }
71 })
72 }
73 </div>
pineafan15b813d2022-02-13 10:06:09 +000074 )
pineafanaa9c4fd2022-06-10 19:58:10 +010075 }
pineafan15b813d2022-02-13 10:06:09 +000076}
77
78
79class Title extends Component {
pineafanaa9c4fd2022-06-10 19:58:10 +010080 render() {
81 return <h1 className={Styles.title}>{this.props.children}</h1>
82 }
pineafan15b813d2022-02-13 10:06:09 +000083}
84
85class Subtitle extends Component {
pineafanaa9c4fd2022-06-10 19:58:10 +010086 render() {
87 return <h2 className={Styles.subtitle}>{this.props.children}</h2>
88 }
pineafan15b813d2022-02-13 10:06:09 +000089}
90
91class Text extends Component {
pineafanaa9c4fd2022-06-10 19:58:10 +010092 render() {
93 return <p className={Styles.text}>{this.props.children}</p>
94 }
pineafan15b813d2022-02-13 10:06:09 +000095}
96
97class Divider extends Component {
pineafanaa9c4fd2022-06-10 19:58:10 +010098 constructor(props) {
99 super(props);
100 }
pineafanff3d4522022-05-06 19:51:02 +0100101
pineafanaa9c4fd2022-06-10 19:58:10 +0100102 render() {
103 let highlighted = this.props.toHighlight === this.props.name;
104 return <div className={Styles.divider} style={{
105 backgroundColor: (highlighted && this.props.highlightColour) ? ("#" + this.props.highlightColour) : "var(--theme-ui-colors-hint)"
106 }}>{this.props.forceHighlight}</div>
107 }
pineafan15b813d2022-02-13 10:06:09 +0000108}
109
110const Panel = handleViewport(PanelClass, { rootMargin: '-1.0px' });
111
112export { AutoLayout, Panel, Title, Subtitle, Text, Divider };