Skip to content

Commit

Permalink
feat(link): add chevron link variants
Browse files Browse the repository at this point in the history
- work in progress (link color)
- add tests for variants
  • Loading branch information
theetrain committed Aug 11, 2017
1 parent 085be09 commit de02a7f
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 4 deletions.
26 changes: 24 additions & 2 deletions src/components/Link/ChevronLink/ChevronLink.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,41 @@ import Icon from '../../Icon/Icon';

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

const ChevronLink = ({ children, ...rest }) => (
const getClassName = (variant) => {
switch (variant) {
case 'secondary':
return styles.secondary;
case 'inverted':
return styles.inverted;
default:
return styles.primary;
}
};

const ChevronLink = ({ variant, children, ...rest }) => (
React.createElement(
rest.to ? ReactRouterLink : 'a',
{ ...safeRest(rest), className: styles.link },
{
...safeRest(rest),
className: getClassName(variant)
},
children,
<span className={styles.chevron}>
<Icon glyph="chevron" aria-hidden="true" />
</span>
)
);
ChevronLink.propTypes = {
variant: PropTypes.oneOf([
'primary',
'secondary',
'inverted'
]),
children: PropTypes.node.isRequired
};
ChevronLink.defaultProps = {
variant: 'primary'
};
ChevronLink.displayName = 'Link.Chevron';

export default ChevronLink;
2 changes: 1 addition & 1 deletion src/components/Link/ChevronLink/ChevronLink.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
```
<Link.Chevron>Hello world</Link.Chevron>
<Link.Chevron href="https://telus.com">Go to Telus.com</Link.Chevron>
```
22 changes: 22 additions & 0 deletions src/components/Link/ChevronLink/ChevronLink.modules.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@import '../../../scss/settings/colours';

.link {
&:hover {
.chevron {
Expand All @@ -6,6 +8,26 @@
}
}

.primary {
composes: link;

&:link {
color: $color-primary;
}
}

.secondary {
composes: link;

color: $color-secondary;
}

.inverted {
composes: link;

color: $color-white;
}

.chevron {
display: inline-block;
margin-left: 0.5rem;
Expand Down
14 changes: 13 additions & 1 deletion src/components/Link/ChevronLink/__tests__/ChevronLink.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,19 @@ describe('Link.Chevron', () => {
expect(link).toContainReact(<Icon glyph="chevron" aria-hidden="true" />);
});

it('can be variants');
it('can have specific variants', () => {
let link = doShallow({ href: 'https://telus.com' });
expect(link).toHaveClassName('primary');

link = doShallow({ href: 'https://telus.com', variant: 'secondary' });
expect(link).toHaveClassName('secondary');

link = doShallow({ href: 'https://telus.com', variant: 'primary' });
expect(link).toHaveClassName('primary');

link = doShallow({ href: 'https://telus.com', variant: 'inverted' });
expect(link).toHaveClassName('inverted');
});

it('passes additional attributes to the link element', () => {
const link = doShallow({ id: 'the-link', role: 'button' });
Expand Down

0 comments on commit de02a7f

Please sign in to comment.