Skip to content

Commit

Permalink
feat(link): add icon to chevron link
Browse files Browse the repository at this point in the history
- include test for chevron link icon
- add chevron link and link to styleguide
  • Loading branch information
theetrain committed Aug 11, 2017
1 parent 277372a commit 085be09
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 4 deletions.
6 changes: 4 additions & 2 deletions config/styleguide.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ module.exports = {
name: 'Content',
components() {
return [
path.resolve('src/components/Card/Card.jsx')
path.resolve('src/components/Card/Card.jsx'),
path.resolve('src/components/Link/Link.jsx'),
path.resolve('src/components/Link/ChevronLink/ChevronLink.jsx')
]
},
sections: [
Expand Down Expand Up @@ -153,7 +155,7 @@ module.exports = {
path.resolve('src/components/SelectorCounter/SelectorCounter.jsx')
]
}
},
}
]
}
],
Expand Down
12 changes: 11 additions & 1 deletion src/components/Link/ChevronLink/ChevronLink.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,19 @@ import PropTypes from 'prop-types';
import { Link as ReactRouterLink } from 'react-router-dom';

import safeRest from '../../../safeRest';
import Icon from '../../Icon/Icon';

import styles from './ChevronLink.modules.scss';

const ChevronLink = ({ children, ...rest }) => (
React.createElement(rest.to ? ReactRouterLink : 'a', { ...safeRest(rest) }, children)
React.createElement(
rest.to ? ReactRouterLink : 'a',
{ ...safeRest(rest), className: styles.link },
children,
<span className={styles.chevron}>
<Icon glyph="chevron" aria-hidden="true" />
</span>
)
);
ChevronLink.propTypes = {
children: PropTypes.node.isRequired
Expand Down
13 changes: 13 additions & 0 deletions src/components/Link/ChevronLink/ChevronLink.modules.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.link {
&:hover {
.chevron {
transform: translateX(0.25rem);
}
}
}

.chevron {
display: inline-block;
margin-left: 0.5rem;
transition: transform 300ms;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { shallow } from 'enzyme';
import { MemoryRouter } from 'react-router-dom';

import Link from '../../Link';
import Icon from '../../../Icon/Icon';

describe('Link.Chevron', () => {
const doShallow = (overrides = {}) => shallow(
Expand All @@ -30,6 +31,12 @@ describe('Link.Chevron', () => {
expect(reactRouterLink).toHaveProp('to', '/about');
});

it('has a chevron icon', () => {
const link = doShallow({ href: 'https://telus.com' });

expect(link).toContainReact(<Icon glyph="chevron" aria-hidden="true" />);
});

it('can be variants');

it('passes additional attributes to the link element', () => {
Expand Down
9 changes: 8 additions & 1 deletion src/components/Link/Link.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@ import styles from './Link.modules.scss';
const getClassName = invert => (invert ? styles.inverted : styles.base);

const Link = ({ invert, children, ...rest }) => (
React.createElement(rest.to ? ReactRouterLink : 'a', { ...safeRest(rest), className: getClassName(invert) }, children)
React.createElement(
rest.to ? ReactRouterLink : 'a',
{
...safeRest(rest),
className: getClassName(invert)
},
children
)
);
Link.propTypes = {
to: PropTypes.string,
Expand Down

0 comments on commit 085be09

Please sign in to comment.