Newer
Older
import React from 'react'
import PropTypes from 'prop-types'
import { withStyles } from '@material-ui/core/styles'
import Tabs from '@material-ui/core/Tabs'
import Tab from '@material-ui/core/Tab'
import { Link } from 'react-router-dom'
import Paper from '@material-ui/core/Paper'
import intl from 'react-intl-universal'
},
tabRoot: {
paddingTop: theme.spacing(0.5),
paddingBottom: theme.spacing(0.5)
},
tabLabelIcon: props => ({
minHeight: props.layoutConfig.tabHeight
})
/**
* A component for generating view tabs for a faceted search perspective or an entity landing page.
*/
constructor (props) {
super(props)
const value = this.pathnameToValue(this.props.routeProps.location.pathname)
this.state = { value }
}
componentDidUpdate = prevProps => {
const newPath = this.props.routeProps.location.pathname
const oldPath = prevProps.routeProps.location.pathname
if (newPath !== oldPath) {
this.setState({ value: this.pathnameToValue(newPath) })
}
// Fix tabs indicator not showing on first load
// https://stackoverflow.com/a/61205108
const evt = document.createEvent('UIEvents')
evt.initUIEvent('resize', true, false, window, 0)
window.dispatchEvent(evt)
}
pathnameToValue = pathname => {
const activeID = pathname.split('/').pop()
let value = 0
if (tab.id === activeID) {
value = tab.value
const { classes, tabs } = this.props
// const largeScreen = screenSize === 'xl'
const variant = tabs.length > 3 ? 'scrollable' : 'fullWidth'
const scrollButtons = tabs.length > 3 ? 'auto' : 'on'
<Grow in>
<Tabs
value={this.state.value}
onChange={this.handleChange}
indicatorColor='secondary'
textColor='secondary'
variant={variant}
scrollButtons={scrollButtons}
>
{tabs.map(tab =>
<Tab
classes={{
root: classes.tabRoot,
labelIcon: classes.tabLabelIcon,
wrapper: classes.tabWrapper
}}
key={tab.id}
icon={tab.icon}
label={intl.get(`tabs.${tab.id}`)}
component={Link}
to={tab.id}
wrapped
/>
)}
</Tabs>
</Grow>
tabs: PropTypes.array.isRequired,
screenSize: PropTypes.string.isRequired,
layoutConfig: PropTypes.object.isRequired
export default withStyles(styles)(PerspectiveTabs)