-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add card with vertical tabs. * Add border, grid, remove ripple.
- Loading branch information
1 parent
0f32248
commit 04abeeb
Showing
2 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import React from 'react'; | ||
import { Story, Meta } from '@storybook/react'; | ||
|
||
import { | ||
CardWithVerticalTabs, | ||
CardWithVerticalTabsProps, | ||
} from './CardWithVerticalTabs'; | ||
|
||
export default { | ||
title: 'Cards/Card with Vertical Tabs', | ||
component: CardWithVerticalTabs, | ||
} as Meta; | ||
|
||
const Template: Story<CardWithVerticalTabsProps> = args => { | ||
const { items } = args; | ||
return <CardWithVerticalTabs items={items} />; | ||
}; | ||
|
||
export const SampleCardWithVerticalTabs = Template.bind({}); | ||
SampleCardWithVerticalTabs.args = { | ||
items: [ | ||
{ title: 'Title 1', element: <h1>Title 1</h1> }, | ||
{ title: 'Title 2', element: <h1>Title 2</h1> }, | ||
{ title: 'Title 3', element: <h1>Title 3</h1> }, | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import React, { useState } from 'react'; | ||
import { | ||
Grid, | ||
Tabs as MuiTabs, | ||
Tab as MuiTab, | ||
makeStyles, | ||
Theme, | ||
} from '@material-ui/core'; | ||
|
||
import { Card } from './Card'; | ||
|
||
export interface CardWithVerticalTabsProps { | ||
items: { title: string; element: JSX.Element }[]; | ||
} | ||
|
||
const useStyles = makeStyles((theme: Theme) => ({ | ||
tabs: { borderRight: `1px solid ${theme.palette.divider}` }, | ||
})); | ||
|
||
export function CardWithVerticalTabs({ items }: CardWithVerticalTabsProps) { | ||
const [index, setIndex] = useState(0); | ||
const classes = useStyles(); | ||
|
||
const handleChange = (_: React.ChangeEvent<unknown>, newValue: number) => { | ||
setIndex(newValue); | ||
}; | ||
|
||
const tabElements: JSX.Element[] = items.map(item => ( | ||
<MuiTab disableRipple label={item.title} key={item.title} /> | ||
)); | ||
|
||
return ( | ||
<Card> | ||
<Grid container spacing={2}> | ||
<Grid item> | ||
<MuiTabs | ||
orientation='vertical' | ||
value={index} | ||
onChange={handleChange} | ||
className={classes.tabs} | ||
> | ||
{tabElements} | ||
</MuiTabs> | ||
</Grid> | ||
<Grid item>{items[index].element}</Grid> | ||
</Grid> | ||
</Card> | ||
); | ||
} |