-
Notifications
You must be signed in to change notification settings - Fork 258
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: extract sidebar button component (#1270)
* feat: my quick links * refactor: extract sidebar button into component * refactor: extract sidebar button into component * refactor: extract sidebar button into component * refactor: extract sidebar button into component
- Loading branch information
Showing
7 changed files
with
313 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { MarkGithubIcon } from '@primer/octicons-react'; | ||
import { render } from '@testing-library/react'; | ||
import { type ISidebarButton, SidebarButton } from './SidebarButton'; | ||
|
||
describe('components/buttons/SidebarButton.tsx', () => { | ||
it('should render with metric', () => { | ||
const props: ISidebarButton = { | ||
title: 'Mock Sidebar Button', | ||
metric: 1, | ||
icon: MarkGithubIcon, | ||
}; | ||
const tree = render(<SidebarButton {...props} />); | ||
expect(tree).toMatchSnapshot(); | ||
}); | ||
|
||
it('should render without metric', () => { | ||
const props: ISidebarButton = { | ||
title: 'Mock Sidebar Button', | ||
metric: 0, | ||
icon: MarkGithubIcon, | ||
}; | ||
const tree = render(<SidebarButton {...props} />); | ||
expect(tree).toMatchSnapshot(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import type { Icon } from '@primer/octicons-react'; | ||
import type { FC } from 'react'; | ||
import { IconColor } from '../../types'; | ||
import { cn } from '../../utils/cn'; | ||
|
||
export interface ISidebarButton { | ||
title: string; | ||
metric?: number; | ||
icon: Icon; | ||
onClick?: () => void; | ||
size?: number; | ||
loading?: boolean; | ||
disabled?: boolean; | ||
} | ||
|
||
export const SidebarButton: FC<ISidebarButton> = (props: ISidebarButton) => { | ||
const hasMetric = props?.metric > 0; | ||
|
||
return ( | ||
<button | ||
type="button" | ||
className={cn( | ||
'flex justify-evenly items-center w-full my-1 cursor-pointer text-xs font-extrabold focus:outline-none disabled:text-gray-500 disabled:cursor-default', | ||
hasMetric | ||
? `${IconColor.GREEN} hover:text-green-700` | ||
: `${IconColor.WHITE} hover:text-gray-500`, | ||
props.loading ? 'animate-spin' : undefined, | ||
props.size ? 'py-2' : 'py-1', | ||
)} | ||
onClick={() => props.onClick()} | ||
title={props.title} | ||
disabled={props.disabled} | ||
> | ||
<props.icon size={props.size ?? 12} aria-label={props.title} /> | ||
{hasMetric && props.metric} | ||
</button> | ||
); | ||
}; |
Oops, something went wrong.