Skip to content

Commit

Permalink
feat(link): add left-facing chevron link
Browse files Browse the repository at this point in the history
- add fake left-facing chevron glyph to Icon component
  • Loading branch information
theetrain committed Aug 15, 2017
1 parent a1767fd commit 312a360
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 26 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ coverage
# IDE project files
.idea
*.iws
.vscode

# TDS build artifacts
dist
Expand Down
4 changes: 2 additions & 2 deletions config/styleguide.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ module.exports = {
components() {
return [
path.resolve('src/components/Card/Card.jsx'),
// path.resolve('src/components/Link/Link.jsx'),
// path.resolve('src/components/Link/ChevronLink/ChevronLink.jsx')
path.resolve('src/components/Link/Link.jsx'),
path.resolve('src/components/Link/ChevronLink/ChevronLink.jsx')
]
},
sections: [
Expand Down
1 change: 1 addition & 0 deletions src/components/Icon/Icon.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Icon.propTypes = {
'caret-up',
'checkmark',
'chevron',
'left-chevron',
'exclamation-point-circle',
'expander',
'hamburger',
Expand Down
20 changes: 7 additions & 13 deletions src/components/Link/ChevronLink/ChevronLink.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,11 @@ const getClassName = (variant) => {
}
};

const getIcon = (direction) => {
if (direction === 'left') {
return (<span className={styles.chevron}>
<Icon glyph="chevron" aria-hidden="true" />
</span>)
}

return (<span className={styles.chevron}>
<Icon glyph="chevron" aria-hidden="true" />
</span>)
};
const getIcon = (glyph, className) => (
<span className={className}>
<Icon glyph={glyph} aria-hidden="true" />
</span>
);

const ChevronLink = ({ variant, direction, children, ...rest }) => (
React.createElement(
Expand All @@ -38,9 +32,9 @@ const ChevronLink = ({ variant, direction, children, ...rest }) => (
...safeRest(rest),
className: getClassName(variant)
},
direction === 'left' ? getIcon(direction) : undefined,
direction === 'left' ? getIcon('left-chevron', styles.leftChevron) : undefined,
children,
direction === 'right' ? getIcon(direction) : undefined
direction === 'right' ? getIcon('chevron', styles.rightChevron) : undefined
)
);
ChevronLink.propTypes = {
Expand Down
26 changes: 26 additions & 0 deletions src/components/Link/ChevronLink/ChevronLink.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,29 @@
### Minimal Usage

```
<Link.Chevron href="https://telus.com">Go to Telus.com</Link.Chevron>
```

### Colours

```
<div>
<div>
<Link.Chevron href="https://telus.com" variant="primary">See latest devices</Link.Chevron>
</div>
<div>
<Link.Chevron href="https://telus.com" variant="secondary">Get great deals</Link.Chevron>
</div>
<div>
<Link.Chevron href="https://telus.com" variant="inverted">Find out how</Link.Chevron>
</div>
</div>
```

### Left-facing chevron

```
<Link.Chevron href="https://telus.com" direction="left">Plans</Link.Chevron>
```
18 changes: 16 additions & 2 deletions src/components/Link/ChevronLink/ChevronLink.modules.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
font-size: $body-medium-text-size;

&:hover {
.chevron {
.rightChevron {
transform: translateX(0.25rem);
}
.leftChevron {
transform: translateX(-0.25rem);
}
}
}

Expand All @@ -33,6 +36,17 @@

.chevron {
display: inline-block;
margin-left: 0.5rem;
transition: transform 300ms;
}

.rightChevron {
composes: chevron;

margin-left: 0.5rem;
}

.leftChevron {
composes: chevron;

margin-right: 0.5rem;
}
22 changes: 13 additions & 9 deletions src/components/Link/ChevronLink/__tests__/ChevronLink.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,19 @@ describe('Link.Chevron', () => {
});

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

expect(link).toContainReact(<Icon glyph="chevron" aria-hidden="true" />);
let link = doShallow({ href: 'https://telus.com' });
expect(link).toContainReact(
<span className="rightChevron">
<Icon glyph="chevron" aria-hidden="true" />
</span>
);

link = doShallow({ href: 'https://telus.com', direction: 'left' });
expect(link).toContainReact(
<span className="leftChevron">
<Icon glyph="left-chevron" aria-hidden="true" />
</span>
);
});

it('can have specific variants', () => {
Expand All @@ -51,12 +61,6 @@ describe('Link.Chevron', () => {
expect(link).toHaveClassName('inverted');
});

it('can face leftward', () => {
const link = doShallow({ href: 'https://telus.com' });

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

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

Expand Down
9 changes: 9 additions & 0 deletions src/scss/foundation/_core-icons.scss
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,12 @@
.icon-core-question-mark-circle {
@include icon-fixed-color($color-shuttle-grey);
}

.icon-core-left-chevron {
@include core-icon(chevron);

&::before {
display: inline-block;
transform: rotate(-180deg) translateY(1.5px);
}
}

0 comments on commit 312a360

Please sign in to comment.