-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Link): Initial commit of unstyled Chevron Link component.
- Loading branch information
1 parent
da558cf
commit 277372a
Showing
5 changed files
with
76 additions
and
5 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,16 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
import { Link as ReactRouterLink } from 'react-router-dom'; | ||
|
||
import safeRest from '../../../safeRest'; | ||
|
||
const ChevronLink = ({ children, ...rest }) => ( | ||
React.createElement(rest.to ? ReactRouterLink : 'a', { ...safeRest(rest) }, children) | ||
); | ||
ChevronLink.propTypes = { | ||
children: PropTypes.node.isRequired | ||
}; | ||
ChevronLink.displayName = 'Link.Chevron'; | ||
|
||
export default ChevronLink; |
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,3 @@ | ||
``` | ||
<Link.Chevron>Hello world</Link.Chevron> | ||
``` |
48 changes: 48 additions & 0 deletions
48
src/components/Link/ChevronLink/__tests__/ChevronLink.spec.jsx
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,48 @@ | ||
import React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
|
||
import { MemoryRouter } from 'react-router-dom'; | ||
|
||
import Link from '../../Link'; | ||
|
||
describe('Link.Chevron', () => { | ||
const doShallow = (overrides = {}) => shallow( | ||
<Link.Chevron {...overrides}>Go home</Link.Chevron> | ||
); | ||
const doShallowWithRouter = (overrides = {}) => shallow( | ||
<MemoryRouter> | ||
<Link.Chevron {...overrides}>Go home</Link.Chevron> | ||
</MemoryRouter> | ||
); | ||
|
||
it('is an anchor HTML element when using the href attribute', () => { | ||
const link = doShallow({ href: 'http://telus.com' }); | ||
|
||
expect(link).toHaveTagName('a'); | ||
expect(link).toHaveProp('href', 'http://telus.com'); | ||
}); | ||
|
||
it('is a React Router Link when using the to attribute', () => { | ||
const link = doShallowWithRouter({ to: '/about' }); | ||
|
||
const reactRouterLink = link.find('Router').dive().dive(); | ||
expect(reactRouterLink).toMatchSelector('Link'); | ||
expect(reactRouterLink).toHaveProp('to', '/about'); | ||
}); | ||
|
||
it('can be variants'); | ||
|
||
it('passes additional attributes to the link element', () => { | ||
const link = doShallow({ id: 'the-link', role: 'button' }); | ||
|
||
expect(link).toHaveProp('id', 'the-link'); | ||
expect(link).toHaveProp('role', 'button'); | ||
}); | ||
|
||
it('does not allow custom CSS', () => { | ||
const link = doShallow({ className: 'my-custom-class', style: { color: 'hotpink' } }); | ||
|
||
expect(link).not.toHaveProp('className', 'my-custom-class'); | ||
expect(link).not.toHaveProp('style'); | ||
}); | ||
}); |
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
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