-
Notifications
You must be signed in to change notification settings - Fork 54
/
index.js
122 lines (105 loc) · 3.61 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import React from "react";
import { withStyles } from "@material-ui/core/styles";
import { Grid } from "@material-ui/core";
import Section from "../Section";
import { getTagValue } from "../utils";
import { DashboardContext } from "../App/context";
const styles = (theme) => ({
layoutFill: {
height: "calc(100vh - 64px - 16px - 5px)", // header + dashboard padding + extra room
maxHeight: "calc(100vh - 64px - 16px - 5px)",
display: "flex",
flexDirection: "column",
},
layoutScroll: {},
page: {
maxWidth: "100%",
height: "100%",
maxHeight: "100%",
margin: 0,
padding: 0,
},
});
class Page extends React.Component {
constructor(props) {
super(props);
const {
tags,
dashboardOrientation,
dashboardVerticalLayout,
} = this.props;
// Vertical layout defaults to the dashboard one and its overwriten by tag
let verticalLayout = dashboardVerticalLayout;
const layoutTag = getTagValue(tags, "layout");
if (layoutTag) {
verticalLayout = layoutTag;
}
// Orientation defaults to the dashboard and its overwriten by tag
let orientation = dashboardOrientation;
const orientationTag = getTagValue(tags, "orientation");
if (orientationTag) {
orientation = orientationTag;
}
this.state = {
orientation: orientation,
verticalLayout: verticalLayout,
};
}
componentDidMount() {
// Iterate sections and see if one is tagged as sidebar
const { sections } = this.props;
let localSidebar = null;
sections.forEach((section) => {
if (section.tags && section.tags.includes("sidebar")) {
localSidebar = section;
}
});
// Add this sidebar to the context
this.context.updateValue("sidebarLocal", localSidebar);
this.context.updateValue("sidebarLocalExists", localSidebar !== null);
}
render() {
const { classes, sections, tags } = this.props;
const { orientation, verticalLayout } = this.state;
let sectionComponents = [];
if (sections && sections.length > 0) {
sections.forEach((section, i) => {
if (!(section.tags && section.tags.includes("sidebar"))) {
sectionComponents.push(
<Section
key={i}
verticalLayout={verticalLayout}
pageOrientation={orientation}
{...section}
/>
);
}
});
}
// Variables
const customClsNames = getTagValue(tags, "class", " ");
// Flip orientation for flex
let flexDirection =
this.state.orientation == "columns" ? "row" : "column";
const layoutClsName =
verticalLayout == "scroll"
? classes.layoutScroll
: classes.layoutFill;
return (
<div
className={`page layout-${verticalLayout} ${layoutClsName} ${customClsNames}`}
>
<Grid
container
spacing={2}
direction={flexDirection}
className={`${classes.page}`}
>
{sectionComponents}
</Grid>
</div>
);
}
}
Page.contextType = DashboardContext;
export default withStyles(styles, { withTheme: true })(Page);