|
|
@@ -2,11 +2,13 @@ import React, { Component } from 'react';
|
|
|
import styled from 'styled-components';
|
|
|
|
|
|
import TabSelector from './TabSelector';
|
|
|
+import Loading from './Loading';
|
|
|
|
|
|
type PropsType = {
|
|
|
options: { label: string, value: string }[],
|
|
|
tabContents: any,
|
|
|
- defaultTab?: string
|
|
|
+ defaultTab?: string,
|
|
|
+ addendum?: any,
|
|
|
};
|
|
|
|
|
|
type StateType = {
|
|
|
@@ -14,6 +16,7 @@ type StateType = {
|
|
|
};
|
|
|
|
|
|
// Manages a tab selector and renders the associated view
|
|
|
+// TODO: consider rearchitecturing to support standard re-render
|
|
|
export default class TabRegion extends Component<PropsType, StateType> {
|
|
|
state = {
|
|
|
currentTab: this.props.defaultTab
|
|
|
@@ -30,7 +33,7 @@ export default class TabRegion extends Component<PropsType, StateType> {
|
|
|
}
|
|
|
|
|
|
componentDidUpdate(prevProps: PropsType) {
|
|
|
- if (prevProps.options !== this.props.options) {
|
|
|
+ if (prevProps.options !== this.props.options && !this.state.currentTab) {
|
|
|
this.setDefaultTab();
|
|
|
}
|
|
|
}
|
|
|
@@ -42,21 +45,48 @@ export default class TabRegion extends Component<PropsType, StateType> {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- render() {
|
|
|
+ renderContents = () => {
|
|
|
+ if (!this.state.currentTab) {
|
|
|
+ return (
|
|
|
+ <Loading />
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
return (
|
|
|
- <StyledTabRegion>
|
|
|
+ <Div>
|
|
|
<TabSelector
|
|
|
options={this.props.options}
|
|
|
currentTab={this.state.currentTab}
|
|
|
setCurrentTab={(x: string) => this.setState({ currentTab: x })}
|
|
|
+ addendum={this.props.addendum}
|
|
|
/>
|
|
|
<Gap />
|
|
|
- {this.renderTabContents()}
|
|
|
+ <TabContents>
|
|
|
+ {this.renderTabContents()}
|
|
|
+ </TabContents>
|
|
|
+ </Div>
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ render() {
|
|
|
+ return (
|
|
|
+ <StyledTabRegion>
|
|
|
+ {this.renderContents()}
|
|
|
</StyledTabRegion>
|
|
|
);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+const Div = styled.div`
|
|
|
+ width: 100%;
|
|
|
+ height: 100%;
|
|
|
+ animation: fadeIn 0.25s 0s;
|
|
|
+`;
|
|
|
+
|
|
|
+const TabContents = styled.div`
|
|
|
+ height: calc(100% - 60px);
|
|
|
+`;
|
|
|
+
|
|
|
const Gap = styled.div`
|
|
|
width: 100%;
|
|
|
background: none;
|
|
|
@@ -66,6 +96,6 @@ const Gap = styled.div`
|
|
|
const StyledTabRegion = styled.div`
|
|
|
width: 100%;
|
|
|
height: 100%;
|
|
|
- padding-bottom: 70px;
|
|
|
position: relative;
|
|
|
+ overflow-y: auto;
|
|
|
`;
|