Skip to content

Commit

Permalink
🎨 #324 ログインボタン用にボタン要素を Link で構成出来るように変更
Browse files Browse the repository at this point in the history
  • Loading branch information
keitakn committed Sep 21, 2024
1 parent 89591ea commit 1671eb3
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/app/_components/IconButton.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,11 @@ export const WithCatIconPressed: Story = {
className: responsiveWidthClass,
},
};

export const WithLink: Story = {
args: {
displayText: 'ログイン',
showGithubIcon: true,
link: '/',
},
};

Check warning on line 101 in src/app/_components/IconButton.stories.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/_components/IconButton.stories.tsx#L95-L101

Added lines #L95 - L101 were not covered by tests
22 changes: 22 additions & 0 deletions src/app/_components/IconButton.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { IncludeLanguageAppPath } from '@/features/url';
import Link from 'next/link';

Check warning on line 2 in src/app/_components/IconButton.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/_components/IconButton.tsx#L2

Added line #L2 was not covered by tests
import type { ComponentProps, JSX } from 'react';
import { Button, Text } from 'react-aria-components';

Expand Down Expand Up @@ -77,6 +79,7 @@ type Props = ComponentProps<'button'> & {
showCatIcon?: boolean;
isPressed?: boolean;
className?: string;
link?: IncludeLanguageAppPath;
};

export const IconButton = ({
Expand All @@ -88,6 +91,7 @@ export const IconButton = ({
showCatIcon,
isPressed,
className,
link,

Check warning on line 94 in src/app/_components/IconButton.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/_components/IconButton.tsx#L94

Added line #L94 was not covered by tests
}: Props): JSX.Element => {
const baseClasses =
'inline-flex items-center justify-center gap-2 rounded-lg px-7 py-1.5 text-black transition-colors duration-200';
Expand All @@ -96,6 +100,24 @@ export const IconButton = ({
const focusClasses =
'focus:outline-none focus:ring-2 focus:ring-amber-500 focus:ring-offset-2';

if (link != null) {
return (
<Link
className={`${baseClasses} ${stateClasses} ${focusClasses} ${className ?? ''}`}
href={link}
prefetch={false}

Check warning on line 108 in src/app/_components/IconButton.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/_components/IconButton.tsx#L103-L108

Added lines #L103 - L108 were not covered by tests
>
{showGithubIcon != null && <GithubIcon />}
{showRepeatIcon != null && <RepeatIcon />}
{showRandomIcon != null && <RandomIcon />}
{showCatIcon != null && <CatIcon />}
<Text className="text-right font-inter text-lg font-black text-orange-900">
{displayText}

Check warning on line 115 in src/app/_components/IconButton.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/_components/IconButton.tsx#L110-L115

Added lines #L110 - L115 were not covered by tests
</Text>
</Link>
);
}

Check warning on line 119 in src/app/_components/IconButton.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/_components/IconButton.tsx#L119

Added line #L119 was not covered by tests

return (
<Button
type={type}
Expand Down

0 comments on commit 1671eb3

Please sign in to comment.