-
-
Save hafbau/1a332cf84455aafc2dcd2716ee14fcc1 to your computer and use it in GitHub Desktop.
import React from 'react'; | |
import Tabs from '@material-ui/core/Tabs' | |
import Tab from '@material-ui/core/Tab' | |
import Typography from '@material-ui/core/Typography' | |
import { withStyles } from '@material-ui/core/withStyles'; | |
class ProfileTabs extends React.PureComponent { | |
state = { activeIndex: 0 } | |
handleChange = (_, activeIndex) => this.setState({ activeIndex }) | |
render() { | |
const { activeIndex } = this.state; | |
return ( | |
<div | |
style={{ | |
display: 'flex', | |
}} | |
> | |
<VerticalTabs | |
value={activeIndex} | |
onChange={this.handleChange} | |
> | |
<MyTab label='item one' /> | |
<MyTab label='item two' /> | |
<MyTab label='item three' /> | |
</VerticalTabs> | |
{ activeIndex === 0 && <TabContainer>Item One</TabContainer> } | |
{ activeIndex === 1 && <TabContainer>Item Two</TabContainer> } | |
{ activeIndex === 2 && <TabContainer>Item Three</TabContainer> } | |
</div> | |
) | |
} | |
} | |
const VerticalTabs = withStyles(theme => ({ | |
flexContainer: { | |
flexDirection: 'column' | |
}, | |
indicator: { | |
display: 'none', | |
} | |
}))(Tabs) | |
const MyTab = withStyles(theme => ({ | |
selected: { | |
color: 'tomato', | |
borderBottom: '2px solid tomato' | |
} | |
}))(Tab); | |
function TabContainer(props) { | |
return ( | |
<Typography component="div" style={{ padding: 24 }}> | |
{props.children} | |
</Typography> | |
); | |
} | |
export default ProfileTabs; |
frankieali
commented
Jul 3, 2019
via email
Your article is very helpful to this new-to-react developer. Maybe you can help with one thing: I need a react vertical tab component that takes images rather than text labels. Do you know how to do it? If not, at least your article gives me the idea to make my own react component for the left-hand navigation I need; I'll just have to work out the tie to show the right tab container on click.
Hey @dalepres, I made this gist when material UI didn't have a way to make vertical tabs. They have now incorporated the idea in the library it self. They have an orientation
prop that you could set to vertical. See api here: https://material-ui.com/api/tabs/
As regards your question, what you want to achieve is so that you click on the images and the content of the page changes? Is that what you're thinking?
hafbau, I did get a Material-UI tabs working with images with some great help on stackoverflow.com. There were several undocumented features and steps required to make it happen. I'm learning that material-ui is a great and maturing package but may not as mature as I had initially thought. That's not an issue and I appreciate all the great work from those who create and support it. I'm looking forward to learning it more thoroughly.
Thank you.
Thanks so much. this is what i really needed 😁