This repository has been archived by the owner on Sep 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New tabs taken from publish-shared-components with new style
- Loading branch information
James Morris
committed
Nov 6, 2017
1 parent
7cc1f46
commit 8444c13
Showing
5 changed files
with
135 additions
and
1 deletion.
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,63 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import HoverableText from '../HoverableText'; | ||
import Link from '../Link'; | ||
import { | ||
curiousBlueUltraLight, | ||
} from '../style/color'; | ||
import { | ||
calculateStyles, | ||
} from '../lib/utils'; | ||
|
||
const Tab = ({ | ||
children, | ||
selected, | ||
tabId, | ||
onClick, | ||
}) => { | ||
const style = calculateStyles({ | ||
default: { | ||
display: 'inline-block', | ||
padding: '0.75rem 1rem', | ||
borderRadius: '4px', | ||
}, | ||
selected: { | ||
backgroundColor: curiousBlueUltraLight, | ||
}, | ||
}, { | ||
selected, | ||
}); | ||
return ( | ||
<Link | ||
href={'#'} | ||
unstyled | ||
onClick={(e) => { | ||
e.preventDefault(); | ||
onClick(tabId); | ||
}} | ||
> | ||
<span style={style}> | ||
<HoverableText | ||
color="shuttleGray" | ||
hoverColor="black" | ||
weight={selected ? 'bold' : null} | ||
> | ||
{children} | ||
</HoverableText> | ||
</span> | ||
</Link> | ||
); | ||
}; | ||
|
||
Tab.propTypes = { | ||
children: PropTypes.node, | ||
selected: PropTypes.bool, | ||
onClick: PropTypes.func, | ||
tabId: PropTypes.string, | ||
}; | ||
|
||
Tab.defaultProps = { | ||
selected: false, | ||
}; | ||
|
||
export default Tab; |
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,27 @@ | ||
import React from 'react'; | ||
import { | ||
storiesOf, | ||
action, | ||
} from '@storybook/react'; | ||
import { checkA11y } from 'storybook-addon-a11y'; | ||
import Tab from './index'; | ||
|
||
storiesOf('Tab') | ||
.addDecorator(checkA11y) | ||
.add('default', () => ( | ||
<Tab | ||
tabId={'tabId'} | ||
onClick={action('tab-click')} | ||
> | ||
Tab | ||
</Tab> | ||
)) | ||
.add('selected', () => ( | ||
<Tab | ||
tabId={'selectedTabId'} | ||
onClick={action('tab-click')} | ||
selected | ||
> | ||
Tab | ||
</Tab> | ||
)); |
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,23 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
const Tabs = ({ | ||
children, | ||
selectedTabId, | ||
onTabClick, | ||
}) => ( | ||
<div> | ||
{React.Children.map(children, tab => React.cloneElement(tab, { | ||
selected: selectedTabId === tab.props.tabId, | ||
onClick: onTabClick, | ||
}))} | ||
</div> | ||
); | ||
|
||
Tabs.propTypes = { | ||
children: PropTypes.node, | ||
selectedTabId: PropTypes.string, | ||
onTabClick: PropTypes.func, | ||
}; | ||
|
||
export default Tabs; |
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,21 @@ | ||
import React from 'react'; | ||
import { | ||
storiesOf, | ||
action, | ||
} from '@storybook/react'; | ||
import { checkA11y } from 'storybook-addon-a11y'; | ||
import Tabs from './index'; | ||
import Tab from '../Tab'; | ||
|
||
|
||
storiesOf('Tabs') | ||
.addDecorator(checkA11y) | ||
.add('default', () => ( | ||
<Tabs | ||
selectedTabId={'tabId'} | ||
onTabClick={action('tab-click')} | ||
> | ||
<Tab tabId={'tabId'}>Tab 1</Tab> | ||
<Tab tabId={'tabId2'}>Tab 2</Tab> | ||
</Tabs> | ||
)); |
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