Skip to content

Commit

Permalink
feat(link): replace invert prop with inverted variant
Browse files Browse the repository at this point in the history
  • Loading branch information
lzcabrera committed Aug 18, 2017
1 parent 510f4ba commit b1054fe
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
20 changes: 13 additions & 7 deletions src/components/Link/Link.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,23 @@ import { warn } from '../../warn'

import styles from './Link.modules.scss'

const getClassName = invert => (invert ? styles.inverted : styles.base)
const getClassName = (variant) => {
return styles[variant]
}

/**
* <span class="docs--badge green">new!</span> <span class="docs--badge purple">v0.21.0</span>
*/
const Link = ({ reactRouterLinkComponent, invert, children, ...rest }) => {
if (!(reactRouterLinkComponent && rest.to)) {
const Link = ({ reactRouterLinkComponent, variant, children, ...rest }) => {
if (!(reactRouterLinkComponent && rest.to) && (reactRouterLinkComponent || rest.to)) {
warn('Link', 'The props `reactRouterLinkComponent` and `to` must be used together.')
}

return React.createElement(
reactRouterLinkComponent || 'a',
{
...safeRest(rest),
className: getClassName(invert)
className: getClassName(variant)
},
children
)
Expand All @@ -40,9 +43,12 @@ Link.propTypes = {
*/
reactRouterLinkComponent: PropTypes.func,
/**
* Whether to invert the component styles.
* The style variations.
*/
invert: PropTypes.bool,
variant: PropTypes.oneOf([
'base',
'inverted'
]),
/**
* Link text.
*/
Expand All @@ -52,7 +58,7 @@ Link.defaultProps = {
to: null,
href: null,
reactRouterLinkComponent: null,
invert: false
variant: 'base'
}

Link.Chevron = ChevronLink
Expand Down
2 changes: 1 addition & 1 deletion src/components/Link/Link.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
const PurpleBlock = require('../__docs__/PurpleBlock').default;
<PurpleBlock>
<Link href="https://www.telus.com" invert>Go to TELUS.com</Link>
<Link href="https://www.telus.com" variant="inverted">Go to TELUS.com</Link>
</PurpleBlock>
```

Expand Down
6 changes: 3 additions & 3 deletions src/components/Link/__tests__/Link.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ describe('Link', () => {
})

it('can be inverted', () => {
let link = doShallow({ invert: true })
let link = doShallow({ variant: 'inverted' })
expect(link).toHaveClassName('inverted')

link = doShallow({ invert: false })
expect(link).not.toHaveClassName('inverted')
link = doShallow({ variant: 'base' })
expect(link).toHaveClassName('base')
})

it('passes additional attributes to the link element', () => {
Expand Down

0 comments on commit b1054fe

Please sign in to comment.