/
index.js
76 lines (66 loc) · 2.29 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import React, { Fragment } from "react";
import Section from "../Section";
import Sidebar from "../Sidebar";
import { getTagValue, slugify } from "../utils";
class Page extends React.Component {
constructor(props) {
super(props);
const { tags, dashboardOrientation } = this.props;
// elOrientation means the element orientation of this page is ___
let elOrientation;
const orientationTag = getTagValue(tags, "orientation");
if (orientationTag) {
elOrientation = orientationTag;
} else {
elOrientation = dashboardOrientation;
}
this.state = {
pageSlug: slugify(this.props.title),
elOrientation: elOrientation,
classNames: getTagValue(tags, "class", " "),
loading: false,
};
}
render() {
const { sections } = this.props;
// Flip orientation for flex
let flexDirection =
this.state.elOrientation == "columns" ? "row" : "column";
let sidebar;
let sectionComponents = [];
if (sections && sections.length > 0) {
sections.forEach((section, i) => {
if (section.tags && section.tags.includes("sidebar")) {
sidebar = <Sidebar {...section} />;
} else {
sectionComponents.push(
<Section
key={i}
pageOrientation={this.state.elOrientation}
{...section}
/>
);
}
});
}
return (
<Fragment>
<div
className={`page container-fluid ${this.state.classNames}`}
>
{sidebar}
<div
className={
sidebar
? `section-wrapper d-flex flex-${flexDirection} col-md-9 ml-sm-auto col-lg-10`
: `section-wrapper d-flex flex-${flexDirection}`
}
>
{sectionComponents}
</div>
</div>
</Fragment>
);
}
}
export default Page;