Skip to content

Commit

Permalink
fix(link): remove disable function for anchors
Browse files Browse the repository at this point in the history
- add custom styles wip
  • Loading branch information
theetrain committed Aug 17, 2017
1 parent 0c612f7 commit 0f00046
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 20 deletions.
4 changes: 2 additions & 2 deletions src/components/Button/Button.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import safeRest from '../../safeRest'

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

export const getClassName = (variant, invert) => {
const getClassName = (variant, invert) => {
if (variant === 'primary' && invert) {
warn('Button', 'Primary buttons cannot be inverted.')

Expand All @@ -20,7 +20,7 @@ export const getClassName = (variant, invert) => {
return styles[variant]
}

export const preventDisabling = ({ disabled, ...props }) => {
const preventDisabling = ({ disabled, ...props }) => {
if (disabled) {
warn('Button', 'Buttons are not able to be disabled.')
}
Expand Down
29 changes: 21 additions & 8 deletions src/components/Link/ButtonLink/ButtonLink.jsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,39 @@
import React from 'react'
import PropTypes from 'prop-types'

import { Link as ReactRouterLink } from 'react-router-dom'

import { warn } from '../../../warn'
import safeRest from '../../../safeRest'
import { getClassName, preventDisabling } from '../../Button/Button'

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

const getClassName = (variant, invert) => {
if (variant === 'primary' && invert) {
warn('Button', 'Primary buttons cannot be inverted.')

return styles.primary
}

if (invert) {
return styles[`${variant}Inverted`]
}

return styles[variant]
}

/**
* <span class="docs--badge green">new!</span> <span class="docs--badge purple">v0.21.0</span>
*/
const ButtonLink = ({ variant, invert, children, ...rest }) => {
const restNoDisabled = preventDisabling(rest)

return React.createElement(
const ButtonLink = ({ variant, invert, children, ...rest }) => (
React.createElement(
rest.to ? ReactRouterLink : 'a',
{
...safeRest(restNoDisabled),
...safeRest(rest),
className: getClassName(variant, invert)
},
children
)
}
)
ButtonLink.propTypes = {
/**
* The style.
Expand Down
17 changes: 17 additions & 0 deletions src/components/Link/ButtonLink/ButtonLink.modules.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
@import '../../Button/Button.modules.scss';

.button {
composes: button from '../../Button/Button.modules.scss';
}

.primary {
&:visited {
color: inherit;
}
}

.inverted {
&:visited {
color: $text-color;
}
}
11 changes: 2 additions & 9 deletions src/components/Link/ButtonLink/__tests__/ButtonLink.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,9 @@ describe('Link.Button', () => {
})

it('can not be inverted for primary variant', () => {
const button = doShallow({ variant: 'primary', invert: true })
const primaryButton = doShallow({ variant: 'primary', invert: true })

expect(button).toHaveClassName('primary')
expect(warn).toHaveBeenCalled()
})

it('can not be disabled', () => {
const button = doShallow({ disabled: true })

expect(button).not.toHaveProp('disabled')
expect(primaryButton).toHaveClassName('primary')
expect(warn).toHaveBeenCalled()
})

Expand Down
2 changes: 1 addition & 1 deletion src/components/Link/ChevronLink/ChevronLink.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const PurpleBlock = require('../../__docs__/PurpleBlock').default;

### Using Chevron Link for navigation in a multi-step operation

Chevron Link can be used as a "back" button by specifying the `direction`.
Chevron Link can be used as a "back" button by specifying the `direction`. These are not suitable for breadcrumb navigation due to the chevron's hover animation.

```
<Link.Chevron href="http://tds.telus.com" direction="left">Plans</Link.Chevron>
Expand Down

0 comments on commit 0f00046

Please sign in to comment.