Skip to content

Commit

Permalink
feat(project): replace buttonlink with variant text buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
royschut committed Jun 9, 2021
1 parent 6e39d63 commit f139924
Show file tree
Hide file tree
Showing 17 changed files with 86 additions and 153 deletions.
17 changes: 13 additions & 4 deletions src/components/Button/Button.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,30 @@
}

&.primary,
&.active {
&.active:not(.text) {
color: var(--highlight-contrast-color, white);
background-color: var(--highlight-color, black);
&.outlined {
border-color: var(--highlight-color, white);
}
}
&.text:not(:hover):not(.active) {
background: none;
&.text {
font-size: 18px;
font-weight: 700;
opacity: 0.7;
&:not(:hover) {
background: none;
}
&.active {
opacity: 1;
}
}

@media (hover: hover) and (pointer: fine) {
&:hover:not(.active),
&:focus:not(.active),
&:hover:is(.text),
&:focus:is(.text),
&:active {
z-index: 1;
opacity: 1;
Expand All @@ -61,7 +70,7 @@
border-color: white;
}
}
&:focus.active {
&:hover &:focus.active {
transform: scale(1.1);
&.fullWidth {
transform: scale(1.04);
Expand Down
39 changes: 24 additions & 15 deletions src/components/Button/Button.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import classNames from 'classnames';
import { NavLink } from 'react-router-dom';

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

Expand All @@ -14,7 +15,8 @@ type Props = {
fullWidth?: boolean;
startIcon?: JSX.Element;
variant?: Variant;
onClick: () => void;
onClick?: () => void;
to?: string;
};
const Button: React.FC<Props> = ({
label,
Expand All @@ -23,20 +25,27 @@ const Button: React.FC<Props> = ({
fullWidth = false,
active = false,
variant = 'outlined',
to,
onClick,
}: Props) => (
<button
className={classNames(styles.button, {
[styles.active]: active,
[styles[color]]: true,
[styles[variant]]: true,
[styles.fullWidth]: fullWidth,
})}
onClick={onClick}
>
{startIcon ? <div className={styles.startIcon}>{startIcon}</div> : null}
<span className={styles.buttonLabel}>{label}</span>
</button>
);
}: Props) => {
const className = classNames(styles.button, [styles[color]], [styles[variant]], {
[styles.active]: active,
[styles.fullWidth]: fullWidth,
});

const icon = startIcon ? <div className={styles.startIcon}>{startIcon}</div> : null;
const span = <span className={styles.buttonLabel}>{label}</span>;

return to ? (
<NavLink className={className} to={to} activeClassName={styles.active} exact>
{icon}
{span}
</NavLink>
) : (
<button className={className} onClick={onClick}>
{icon}
{span}
</button>
);
};
export default Button;
2 changes: 1 addition & 1 deletion src/components/Button/__snapshots__/Button.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
exports[`<Button> renders and matches snapshot 1`] = `
<div>
<button
class="button active undefined outlined"
class="button outlined active"
>
<span>
aa
Expand Down
53 changes: 0 additions & 53 deletions src/components/ButtonLink/ButtonLink.module.scss

This file was deleted.

18 changes: 0 additions & 18 deletions src/components/ButtonLink/ButtonLink.test.tsx

This file was deleted.

19 changes: 0 additions & 19 deletions src/components/ButtonLink/ButtonLink.tsx

This file was deleted.

15 changes: 0 additions & 15 deletions src/components/ButtonLink/__snapshots__/ButtonLink.test.tsx.snap

This file was deleted.

8 changes: 4 additions & 4 deletions src/components/Filter/__snapshots__/Filter.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -80,28 +80,28 @@ exports[`<Filter> renders Filter 1`] = `
class="filterRow"
>
<button
class="button undefined outlined"
class="button outlined"
>
<span>
x
</span>
</button>
<button
class="button undefined outlined"
class="button outlined"
>
<span>
y
</span>
</button>
<button
class="button undefined outlined"
class="button outlined"
>
<span>
z
</span>
</button>
<button
class="button undefined outlined"
class="button outlined"
>
<span>
bb
Expand Down
4 changes: 0 additions & 4 deletions src/components/Header/Header.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,6 @@
.nav {
display: inline-block;
flex: 1;

> a {
margin: 0 6px;
}
}

.search {
Expand Down
6 changes: 3 additions & 3 deletions src/components/Header/Header.test.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import React from 'react';

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

import Header from './Header';

describe('<Header />', () => {
test('renders header', () => {
const playlistMenuItems = [<ButtonLink key="key" label="Home" to="/" />];
const { container } = render(<Header onMenuButtonClick={jest.fn()} playlistMenuItems={playlistMenuItems} />);
const playlistMenuItems = [<Button key="key" label="Home" to="/" />];
const { container } = render(<Header onMenuButtonClick={jest.fn()}>{playlistMenuItems}</Header>);

expect(container).toMatchSnapshot();
});
Expand Down
12 changes: 11 additions & 1 deletion src/components/Header/__snapshots__/Header.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,17 @@ exports[`<Header /> renders header 1`] = `
<nav
aria-label="menu"
class="nav"
/>
>
<a
aria-current="page"
class="button outlined active"
href="/"
>
<span>
Home
</span>
</a>
</nav>
<div
class="search"
/>
Expand Down
8 changes: 4 additions & 4 deletions src/components/Layout/Layout.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { ReactNode, FC, useState, useContext } from 'react';

import ButtonLink from '../ButtonLink/ButtonLink';
import Button from '../Button/Button';
import Header from '../Header/Header';
import Sidebar from '../Sidebar/Sidebar';
import DynamicBlur from '../DynamicBlur/DynamicBlur';
Expand All @@ -24,11 +24,11 @@ const Layout: FC<LayoutProps> = ({ children }) => {
<div className={styles.layout}>
{hasDynamicBlur && blurImage && <DynamicBlur url={blurImage} transitionTime={1} debounceTime={350} />}
<Header onMenuButtonClick={() => setSideBarOpen(true)} logoSrc={assets.banner}>
<ButtonLink label="Home" to="/" />
<Button label="Home" to="/" variant="text" />
{menu.map((item) => (
<ButtonLink key={item.playlistId} label={item.label} to={`/p/${item.playlistId}`} />
<Button key={item.playlistId} label={item.label} to={`/p/${item.playlistId}`} variant="text" />
))}
<ButtonLink label="Settings" to="/u" />
<Button label="Settings" to="/u" variant="text" />
</Header>
<Sidebar isOpen={sideBarOpen} onClose={() => setSideBarOpen(false)}>
<MenuButton label="Home" to="/" tabIndex={sideBarOpen ? 0 : -1} />
Expand Down
4 changes: 2 additions & 2 deletions src/components/Layout/__snapshots__/Layout.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ exports[`<Layout /> renders layout 1`] = `
>
<a
aria-current="page"
class="link active"
class="button text active"
href="/"
>
<span>
Home
</span>
</a>
<a
class="link"
class="button text"
href="/u"
>
<span>
Expand Down
4 changes: 2 additions & 2 deletions src/components/Root/__snapshots__/Root.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ exports[`<Root /> renders and matches snapshot 1`] = `
class="nav"
>
<a
class="link"
class="button text"
href="/"
>
<span>
Home
</span>
</a>
<a
class="link"
class="button text"
href="/u"
>
<span>
Expand Down
10 changes: 7 additions & 3 deletions src/components/Sidebar/Sidebar.test.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import React from 'react';

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

import Sidebar from './Sidebar';

describe('<SideBar />', () => {
const playlistMenuItems = [<ButtonLink key="key" label="Home" to="/" />];
const playlistMenuItems = [<Button key="key" label="Home" to="/" />];
test('renders sideBar', () => {
const { container } = render(<Sidebar isOpen={true} onClose={jest.fn()} playlistMenuItems={playlistMenuItems} />);
const { container } = render(
<Sidebar isOpen={true} onClose={jest.fn()}>
{playlistMenuItems}
</Sidebar>,
);

expect(container).toMatchSnapshot();
});
Expand Down
Loading

0 comments on commit f139924

Please sign in to comment.