5 changed files with 86 additions and 0 deletions
@ -0,0 +1,50 @@ |
|||
// @flow
|
|||
|
|||
import React, { Fragment } from 'react' |
|||
import { Collapse } from 'react-collapse' |
|||
import styled from 'styled-components' |
|||
|
|||
import type { Element } from 'react' |
|||
|
|||
import Box, { Tabbable } from 'components/base/Box' |
|||
|
|||
const Tab = styled(Tabbable).attrs({ |
|||
flex: 1, |
|||
pb: 1, |
|||
align: 'center', |
|||
justify: 'center', |
|||
})` |
|||
border-bottom: 2px solid transparent; |
|||
border-bottom-color: ${p => (p.isActive ? p.theme.colors.blue : '')}; |
|||
color: ${p => (p.isActive ? p.theme.colors.blue : p.theme.colors.steel)}; |
|||
font-weight: ${p => (p.isActive ? 'bold' : '')}; |
|||
margin-bottom: -1px; |
|||
outline: none; |
|||
` |
|||
|
|||
type Item = { |
|||
key: string | number, |
|||
title: string | Element<any>, |
|||
render: () => Element<any>, |
|||
} |
|||
|
|||
type Props = { |
|||
items: Array<Item>, |
|||
index: number, |
|||
onTabClick: number => void, |
|||
} |
|||
|
|||
const Tabs = ({ items, index, onTabClick }: Props) => ( |
|||
<Fragment> |
|||
<Box horizontal borderBottom borderWidth={1} borderColor="argile"> |
|||
{items.map((item, i) => ( |
|||
<Tab key={item.key} isActive={index === i} onClick={() => onTabClick(i)}> |
|||
{item.title} |
|||
</Tab> |
|||
))} |
|||
</Box> |
|||
{items[index] && <Collapse isOpened>{items[index].render()}</Collapse>} |
|||
</Fragment> |
|||
) |
|||
|
|||
export default Tabs |
@ -0,0 +1,28 @@ |
|||
import React from 'react' |
|||
|
|||
import { number } from '@storybook/addon-knobs' |
|||
import { action } from '@storybook/addon-actions' |
|||
import { storiesOf } from '@storybook/react' |
|||
|
|||
import Tabs from 'components/base/Tabs' |
|||
|
|||
const stories = storiesOf('Tabs', module) |
|||
|
|||
stories.add('basic', () => ( |
|||
<Tabs |
|||
index={number('index', 0)} |
|||
onTabClick={action('onTabClick')} |
|||
items={[ |
|||
{ |
|||
key: 'first', |
|||
title: 'first tab', |
|||
render: () => <div>{'first tab content'}</div>, |
|||
}, |
|||
{ |
|||
key: 'second', |
|||
title: 'second tab', |
|||
render: () => <div>{'second tab content'}</div>, |
|||
}, |
|||
]} |
|||
/> |
|||
)) |
Loading…
Reference in new issue