Skip to content

Commit

Permalink
feat(project): add buttonlink component
Browse files Browse the repository at this point in the history
  • Loading branch information
RCVZ committed Apr 29, 2021
1 parent 5aa3458 commit 7177e9a
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/components/ButtonLink/ButtonLink.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
@use '../../styles/variables';
@use '../../styles/theme';
@use '../../styles/mixins/responsive';
@use '../../styles/mixins/utils';

//
// Navigation Button
// --------------------------------

.link {
position: relative;
display: inline-flex;
justify-content: center;
align-items: center;
min-height: 38px;
padding: 0 10px;
color: inherit;
font-family: theme.$body-alt-font-family;
text-align: center;
text-decoration: none;
background: transparent;
border-radius: 4px;
cursor: pointer;
font-weight: 700;
opacity: 0.7;
transition: background 0.1s ease, transform 0.1s ease;

@media (hover: hover) and (pointer: fine) {
&:hover,
&:active {
z-index: 1;
background: rgba(variables.$black, 0.7);
transform: scale(1.1);
opacity: 1;
}
}
}

.active {
color: theme.$btn-icon-active-color;
opacity: 1;
}
18 changes: 18 additions & 0 deletions src/components/ButtonLink/ButtonLink.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React from 'react';

import { render } from '../../testUtils';

import ButtonLink from './ButtonLink';

describe('<ButtonLink />', () => {
test('renders link with route label', () => {
const { getByText } = render(<ButtonLink label="home" to="/" />);
expect(getByText(/home/i)).toBeTruthy();
});

it('renders and matches snapshot', () => {
const { container } = render(<ButtonLink label="home" to="/" />);

expect(container).toMatchSnapshot();
});
});
27 changes: 27 additions & 0 deletions src/components/ButtonLink/ButtonLink.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import React from 'react';
import { NavLink } from 'react-router-dom';

import styles from './ButtonLink.module.scss';

type ButtonLinkProps = {
label: string;
to: string;
};

const ButtonLink: React.FC<ButtonLinkProps> = ({
label,
to,
}: ButtonLinkProps) => {
return (
<NavLink
className={styles.link}
activeClassName={styles.active}
to={to}
exact
>
<span className={styles.buttonLabel}>{label}</span>
</NavLink>
);
};

export default ButtonLink;
15 changes: 15 additions & 0 deletions src/components/ButtonLink/__snapshots__/ButtonLink.test.tsx.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`<ButtonLink /> renders and matches snapshot 1`] = `
<div>
<a
aria-current="page"
class="function link() { [native code] } active"
href="/"
>
<span>
home
</span>
</a>
</div>
`;

0 comments on commit 7177e9a

Please sign in to comment.