Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: gitify logo icon #1275

Merged
merged 7 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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',
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm new to this clsx package

What's your thoughts on

size === 'small' && 'size-5', size === 'medium' && 'size-10', size === 'large' && 'size-16'

)}
onClick={() => onClick?.()}
xmlns="http://www.w3.org/2000/svg"
xmlnsXlink="http://www.w3.org/1999/xlink"
Expand Down
Loading
Loading