Skip to content

Commit

Permalink
feat: use clsx to merge classNames
Browse files Browse the repository at this point in the history
  • Loading branch information
afonsojramos committed Jun 13, 2024
1 parent e30e5cf commit c012556
Show file tree
Hide file tree
Showing 14 changed files with 53 additions and 21 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
"@electron/remote": "2.1.2",
"@primer/octicons-react": "19.9.0",
"axios": "1.7.2",
"clsx": "2.1.1",
"date-fns": "3.6.0",
"electron-updater": "6.2.1",
"final-form": "4.20.10",
Expand Down
9 changes: 9 additions & 0 deletions pnpm-lock.yaml

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

8 changes: 5 additions & 3 deletions src/components/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { useLocation, useNavigate } from 'react-router-dom';
import { Logo } from '../components/Logo';
import { AppContext } from '../context/App';
import { BUTTON_SIDEBAR_CLASS_NAME } from '../styles/gitify';
import { cn } from '../utils/cn';
import { quitApp } from '../utils/comms';
import { openGitHubNotifications, openGitifyRepository } from '../utils/links';
import { getNotificationCount } from '../utils/notifications';
Expand Down Expand Up @@ -47,9 +48,10 @@ export const Sidebar: FC = () => {

<button
type="button"
className={`flex justify-around self-stretch items-center my-1 py-1 px-2 text-xs font-extrabold cursor-pointer ${
notificationsCount > 0 ? 'text-green-500' : 'text-white'
}`}
className={cn(
'flex justify-around self-stretch items-center my-1 py-1 px-2 text-xs font-extrabold cursor-pointer',
notificationsCount > 0 ? 'text-green-500' : 'text-white',
)}
onClick={() => openGitHubNotifications()}
title={`${notificationsCount} Unread Notifications`}
>
Expand Down
3 changes: 2 additions & 1 deletion src/components/buttons/PillButton.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { Icon } from '@primer/octicons-react';
import type { FC } from 'react';
import type { IconColor } from '../../types';
import { cn } from '../../utils/cn';

export interface IPillButton {
key?: string;
Expand All @@ -19,7 +20,7 @@ export const PillButton: FC<IPillButton> = (props: IPillButton) => {
>
<props.icon
size={12}
className={`mr-1 ${props.color}`}
className={cn('mr-1', props.color)}
aria-label={props.title}
/>
{props.metric}
Expand Down
5 changes: 3 additions & 2 deletions src/components/fields/Button.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import type { Icon } from '@primer/octicons-react';
import type { FC } from 'react';
import { cn } from '../../utils/cn';
import { openExternalLink } from '../../utils/comms';

export interface IButton {
name: string;
label: string;
class?: string;
className?: string;
icon?: Icon;
size?: number;
url?: string;
Expand All @@ -22,7 +23,7 @@ export const Button: FC<IButton> = (props: IButton) => {
type={props.type ?? 'button'}
title={props.label}
aria-label={props.label}
className={`${props.class} ${baseClass}`}
className={cn(props.className, baseClass)}
disabled={props.disabled}
onClick={() => {
if (props.url) {
Expand Down
8 changes: 4 additions & 4 deletions src/components/fields/__snapshots__/Button.test.tsx.snap

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

4 changes: 2 additions & 2 deletions src/routes/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ export const LoginRoute: FC = () => {
name="Personal Access Token"
icon={KeyIcon}
label="Login with Personal Access Token"
class="py-2 mt-2"
className="py-2 mt-2"
onClick={() => navigate('/login-personal-access-token')}
/>
<Button
name="OAuth App"
icon={PersonIcon}
label="Login with OAuth App"
class="py-2 mt-2"
className="py-2 mt-2"
onClick={() => navigate('/login-oauth-app')}
/>
</div>
Expand Down
4 changes: 2 additions & 2 deletions src/routes/LoginWithOAuthApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export const LoginWithOAuthApp: FC = () => {
<Button
name="Docs"
label="GitHub Docs"
class="mt-2"
className="mt-2"
icon={BookIcon}
size={12}
url={Constants.GITHUB_DOCS.OAUTH_URL}
Expand All @@ -105,7 +105,7 @@ export const LoginWithOAuthApp: FC = () => {
<Button
name="Login"
label="Login"
class="px-4 py-2 mt-2 !text-sm"
className="px-4 py-2 mt-2 !text-sm"
icon={SignInIcon}
size={16}
disabled={submitting || pristine}
Expand Down
4 changes: 2 additions & 2 deletions src/routes/LoginWithPersonalAccessToken.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,15 @@ export const LoginWithPersonalAccessToken: FC = () => {
<Button
name="Docs"
label="GitHub Docs"
class="mt-2"
className="mt-2"
icon={BookIcon}
size={12}
url={Constants.GITHUB_DOCS.PAT_URL}
/>
<Button
name="Login"
label="Login"
class="px-4 py-2 mt-2 !text-sm"
className="px-4 py-2 mt-2 !text-sm"
icon={SignInIcon}
size={16}
disabled={submitting || pristine}
Expand Down
4 changes: 2 additions & 2 deletions src/routes/__snapshots__/LoginWithOAuthApp.test.tsx.snap

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

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

13 changes: 13 additions & 0 deletions src/utils/cn.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { cn } from './cn';

describe('utils/cn.ts', () => {
it('should return a string', () => {
expect(cn('foo', true && 'bar', false && 'baz')).toBe('foo bar');
});

it('should ignore anything that is not a string', () => {
expect(cn('foo', null, undefined, 1, '', ['bar'], { baz: 'qux' })).toBe(
'foo',
);
});
});
5 changes: 5 additions & 0 deletions src/utils/cn.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { type ClassValue, clsx } from 'clsx/lite';

export function cn(...inputs: ClassValue[]) {
return clsx(...inputs);
}
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"compilerOptions": {
"module": "es6",
"moduleResolution": "node",
"moduleResolution": "Bundler",
"target": "es2022",
"outDir": "./build/",
"sourceMap": true,
Expand Down

0 comments on commit c012556

Please sign in to comment.