Skip to content

Commit

Permalink
refactor: gitify logo icon (#1275)
Browse files Browse the repository at this point in the history
Co-authored-by: Afonso Jorge Ramos <afonsojorgeramos@gmail.com>
  • Loading branch information
setchy and afonsojramos authored Jun 19, 2024
1 parent 92f28c1 commit da0e94f
Show file tree
Hide file tree
Showing 9 changed files with 224 additions and 64 deletions.
25 changes: 0 additions & 25 deletions src/components/Logo.test.tsx

This file was deleted.

6 changes: 3 additions & 3 deletions src/components/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
} from '@primer/octicons-react';
import { type FC, useContext, useMemo } from 'react';
import { useLocation, useNavigate } from 'react-router-dom';
import { Logo } from '../components/Logo';
import { AppContext } from '../context/App';
import { quitApp } from '../utils/comms';
import {
Expand All @@ -19,6 +18,7 @@ import {
} from '../utils/links';
import { getNotificationCount } from '../utils/notifications';
import { SidebarButton } from './buttons/SidebarButton';
import { LogoIcon } from './icons/LogoIcon';

export const Sidebar: FC = () => {
const navigate = useNavigate();
Expand Down Expand Up @@ -49,12 +49,12 @@ export const Sidebar: FC = () => {
<div className="flex flex-1 flex-col items-center py-4">
<button
type="button"
className="mx-auto my-3 w-5 cursor-pointer outline-none"
className="mx-auto my-3 cursor-pointer outline-none"
title="Open Gitify on GitHub"
onClick={() => openGitifyRepository()}
data-testid="gitify-logo"
>
<Logo aria-label="Open Gitify" />
<LogoIcon size="small" aria-label="Open Gitify" />
</button>

<SidebarButton
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions src/components/__snapshots__/Sidebar.test.tsx.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions src/components/icons/LogoIcon.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { fireEvent, render, screen } from '@testing-library/react';
import { LogoIcon } from './LogoIcon';

describe('components/icons/LogoIcon.tsx', () => {
it('renders correctly (light)', () => {
const tree = render(<LogoIcon />);

expect(tree).toMatchSnapshot();
});

it('renders correctly (dark)', () => {
const tree = render(<LogoIcon isDark />);

expect(tree).toMatchSnapshot();
});

it('should click on the logo', () => {
const onClick = jest.fn();
render(<LogoIcon onClick={onClick} size="small" />);

fireEvent.click(screen.getByLabelText('Gitify Logo'));

expect(onClick).toHaveBeenCalledTimes(1);
});

it('should render a different size', () => {
const tree = render(<LogoIcon size="large" />);

expect(tree).toMatchSnapshot();
});
});
15 changes: 9 additions & 6 deletions src/components/Logo.tsx → src/components/icons/LogoIcon.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import type { FC } from 'react';
import { cn } from '../../utils/cn';

interface ILogo {
interface ILogoIcon {
isDark?: boolean;
onClick?: () => void;
className?: string;
size?: 'small' | 'medium' | 'large';
}

const LIGHT_GRADIENT_START = '#CCCCCC';
Expand All @@ -12,14 +13,16 @@ const LIGHT_GRADIENT_END = '#FFFFFF';
const DARK_GRADIENT_START = '#22283B';
const DARK_GRADIENT_END = '#555B6E';

export const Logo: FC<ILogo> = ({
export const LogoIcon: FC<ILogoIcon> = ({
isDark,
onClick,
className = '',
size = 'medium',
...props
}: ILogo) => (
}: ILogoIcon) => (
<svg
className={className}
className={cn(
size === 'small' ? 'size-5' : size === 'medium' ? 'size-10' : 'size-16',
)}
onClick={() => onClick?.()}
xmlns="http://www.w3.org/2000/svg"
xmlnsXlink="http://www.w3.org/1999/xlink"
Expand Down
Loading

0 comments on commit da0e94f

Please sign in to comment.