Skip to content

Commit

Permalink
feat(layout): add button component
Browse files Browse the repository at this point in the history
  • Loading branch information
RCVZ committed May 4, 2021
1 parent 0eb01a3 commit c1ba8e2
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 0 deletions.
50 changes: 50 additions & 0 deletions src/components/Button/Button.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
@use '../../styles/variables';
@use '../../styles/theme';
@use "../../styles/mixins/responsive";

.button {
@include responsive.mobile-only() {
padding: 12px 16px;
}

@include responsive.tablet-and-larger() {
@media (hover: hover) and (pointer: fine) {
&:hover {
z-index: 1;
background: rgba(var(--background-color), 0.7);
box-shadow: 0 0 0 3px var(--highlight-color),
0 8px 10px rgb(0 0 0 / 14%), 0 3px 14px rgb(0 0 0 / 12%),
0 4px 5px rgb(0 0 0 / 20%);
opacity: 1;
}
}
}
position: relative;
display: inline-flex;
display: flex;
justify-content: inherit;
align-items: center;
align-items: baseline;
min-height: 38px;
margin: 0 5px;
padding: 9px 16px;
color: variables.$white;
font-family: theme.$body-alt-font-family;
font-weight: 700;
text-align: center;
text-decoration: none;
background: transparent;
border-radius: 4px;
cursor: pointer;
opacity: 0.7;
transition: background 0.1s ease, transform 0.1s ease;

&.active {
color: variables.$white;
background: rgba(variables.$black, 0.7);
opacity: 1;
}
> h2 {
font-size: 24px;
}
}
12 changes: 12 additions & 0 deletions src/components/Button/Button.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import React from 'react';
import { render } from '@testing-library/react';

import Button from './Button';

describe('<Button>', () => {
test('renders and matches snapshot', () => {
const { container } = render(<Button />);

expect(container).toMatchSnapshot();
});
});
25 changes: 25 additions & 0 deletions src/components/Button/Button.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import React from 'react';
import classNames from 'classnames';

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

type Props = {
label: string;
active: boolean;
onClick: () => void;
};

const Button: React.FC<Props> = ({ label, active, onClick }: Props) => {
return (
<button
className={classNames(styles.button, {
[styles.active]: active,
})}
onClick={onClick}
>
<span className={styles.buttonLabel}>{label}</span>
</button>
);
};

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

exports[`<Button> renders and matches snapshot 1`] = `
<div>
<button
class="button"
>
<span />
</button>
</div>
`;

0 comments on commit c1ba8e2

Please sign in to comment.