Skip to content

Commit da0e94f

Browse files
setchyafonsojramos
andauthored
refactor: gitify logo icon (#1275)
Co-authored-by: Afonso Jorge Ramos <[email protected]>
1 parent 92f28c1 commit da0e94f

File tree

9 files changed

+224
-64
lines changed

9 files changed

+224
-64
lines changed

src/components/Logo.test.tsx

Lines changed: 0 additions & 25 deletions
This file was deleted.

src/components/Sidebar.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {
88
} from '@primer/octicons-react';
99
import { type FC, useContext, useMemo } from 'react';
1010
import { useLocation, useNavigate } from 'react-router-dom';
11-
import { Logo } from '../components/Logo';
1211
import { AppContext } from '../context/App';
1312
import { quitApp } from '../utils/comms';
1413
import {
@@ -19,6 +18,7 @@ import {
1918
} from '../utils/links';
2019
import { getNotificationCount } from '../utils/notifications';
2120
import { SidebarButton } from './buttons/SidebarButton';
21+
import { LogoIcon } from './icons/LogoIcon';
2222

2323
export const Sidebar: FC = () => {
2424
const navigate = useNavigate();
@@ -49,12 +49,12 @@ export const Sidebar: FC = () => {
4949
<div className="flex flex-1 flex-col items-center py-4">
5050
<button
5151
type="button"
52-
className="mx-auto my-3 w-5 cursor-pointer outline-none"
52+
className="mx-auto my-3 cursor-pointer outline-none"
5353
title="Open Gitify on GitHub"
5454
onClick={() => openGitifyRepository()}
5555
data-testid="gitify-logo"
5656
>
57-
<Logo aria-label="Open Gitify" />
57+
<LogoIcon size="small" aria-label="Open Gitify" />
5858
</button>
5959

6060
<SidebarButton

src/components/__snapshots__/AccountNotifications.test.tsx.snap

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/__snapshots__/Sidebar.test.tsx.snap

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { fireEvent, render, screen } from '@testing-library/react';
2+
import { LogoIcon } from './LogoIcon';
3+
4+
describe('components/icons/LogoIcon.tsx', () => {
5+
it('renders correctly (light)', () => {
6+
const tree = render(<LogoIcon />);
7+
8+
expect(tree).toMatchSnapshot();
9+
});
10+
11+
it('renders correctly (dark)', () => {
12+
const tree = render(<LogoIcon isDark />);
13+
14+
expect(tree).toMatchSnapshot();
15+
});
16+
17+
it('should click on the logo', () => {
18+
const onClick = jest.fn();
19+
render(<LogoIcon onClick={onClick} size="small" />);
20+
21+
fireEvent.click(screen.getByLabelText('Gitify Logo'));
22+
23+
expect(onClick).toHaveBeenCalledTimes(1);
24+
});
25+
26+
it('should render a different size', () => {
27+
const tree = render(<LogoIcon size="large" />);
28+
29+
expect(tree).toMatchSnapshot();
30+
});
31+
});

src/components/Logo.tsx renamed to src/components/icons/LogoIcon.tsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import type { FC } from 'react';
2+
import { cn } from '../../utils/cn';
23

3-
interface ILogo {
4+
interface ILogoIcon {
45
isDark?: boolean;
56
onClick?: () => void;
6-
className?: string;
7+
size?: 'small' | 'medium' | 'large';
78
}
89

910
const LIGHT_GRADIENT_START = '#CCCCCC';
@@ -12,14 +13,16 @@ const LIGHT_GRADIENT_END = '#FFFFFF';
1213
const DARK_GRADIENT_START = '#22283B';
1314
const DARK_GRADIENT_END = '#555B6E';
1415

15-
export const Logo: FC<ILogo> = ({
16+
export const LogoIcon: FC<ILogoIcon> = ({
1617
isDark,
1718
onClick,
18-
className = '',
19+
size = 'medium',
1920
...props
20-
}: ILogo) => (
21+
}: ILogoIcon) => (
2122
<svg
22-
className={className}
23+
className={cn(
24+
size === 'small' ? 'size-5' : size === 'medium' ? 'size-10' : 'size-16',
25+
)}
2326
onClick={() => onClick?.()}
2427
xmlns="http://www.w3.org/2000/svg"
2528
xmlnsXlink="http://www.w3.org/1999/xlink"

0 commit comments

Comments
 (0)