|
|
@ -1,10 +1,10 @@ |
|
|
|
import React, { Component } from 'react' |
|
|
|
import React, { PureComponent } from 'react' |
|
|
|
import PropTypes from 'prop-types' |
|
|
|
import PropTypes from 'prop-types' |
|
|
|
|
|
|
|
|
|
|
|
import PageContainerHeader from './page-container-header' |
|
|
|
import PageContainerHeader from './page-container-header' |
|
|
|
import PageContainerFooter from './page-container-footer' |
|
|
|
import PageContainerFooter from './page-container-footer' |
|
|
|
|
|
|
|
|
|
|
|
export default class PageContainer extends Component { |
|
|
|
export default class PageContainer extends PureComponent { |
|
|
|
static propTypes = { |
|
|
|
static propTypes = { |
|
|
|
// PageContainerHeader props
|
|
|
|
// PageContainerHeader props
|
|
|
|
backButtonString: PropTypes.string, |
|
|
|
backButtonString: PropTypes.string, |
|
|
@ -28,25 +28,11 @@ export default class PageContainer extends Component { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
state = { |
|
|
|
state = { |
|
|
|
activeTabIndex: 0, |
|
|
|
activeTabIndex: this.props.defaultActiveTabIndex || 0, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
componentDidMount () { |
|
|
|
handleTabClick (activeTabIndex) { |
|
|
|
const { defaultActiveTabIndex } = this.props |
|
|
|
this.setState({ activeTabIndex }) |
|
|
|
|
|
|
|
|
|
|
|
if (defaultActiveTabIndex) { |
|
|
|
|
|
|
|
this.setState({ activeTabIndex: defaultActiveTabIndex }) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
handleTabClick (tabIndex) { |
|
|
|
|
|
|
|
const { activeTabIndex } = this.state |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (tabIndex !== activeTabIndex) { |
|
|
|
|
|
|
|
this.setState({ |
|
|
|
|
|
|
|
activeTabIndex: tabIndex, |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
renderTabs () { |
|
|
|
renderTabs () { |
|
|
@ -58,12 +44,12 @@ export default class PageContainer extends Component { |
|
|
|
|
|
|
|
|
|
|
|
const numberOfTabs = React.Children.count(tabsComponent.props.children) |
|
|
|
const numberOfTabs = React.Children.count(tabsComponent.props.children) |
|
|
|
|
|
|
|
|
|
|
|
return React.Children.map(tabsComponent.props.children, (child, index) => { |
|
|
|
return React.Children.map(tabsComponent.props.children, (child, tabIndex) => { |
|
|
|
return child && React.cloneElement(child, { |
|
|
|
return child && React.cloneElement(child, { |
|
|
|
onClick: index => this.handleTabClick(index), |
|
|
|
onClick: index => this.handleTabClick(index), |
|
|
|
tabIndex: index, |
|
|
|
tabIndex, |
|
|
|
isActive: numberOfTabs > 1 && index === this.state.activeTabIndex, |
|
|
|
isActive: numberOfTabs > 1 && tabIndex === this.state.activeTabIndex, |
|
|
|
key: index, |
|
|
|
key: tabIndex, |
|
|
|
className: 'page-container__tab', |
|
|
|
className: 'page-container__tab', |
|
|
|
activeClassName: 'page-container__tab--selected', |
|
|
|
activeClassName: 'page-container__tab--selected', |
|
|
|
}) |
|
|
|
}) |
|
|
@ -83,13 +69,12 @@ export default class PageContainer extends Component { |
|
|
|
renderContent () { |
|
|
|
renderContent () { |
|
|
|
const { contentComponent, tabsComponent } = this.props |
|
|
|
const { contentComponent, tabsComponent } = this.props |
|
|
|
|
|
|
|
|
|
|
|
switch (true) { |
|
|
|
if (contentComponent) { |
|
|
|
case Boolean(contentComponent): |
|
|
|
return contentComponent |
|
|
|
return contentComponent |
|
|
|
} else if (tabsComponent) { |
|
|
|
case Boolean(tabsComponent): |
|
|
|
return this.renderActiveTabContent() |
|
|
|
return this.renderActiveTabContent() |
|
|
|
} else { |
|
|
|
default: |
|
|
|
return null |
|
|
|
return null |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|