Skip to content

Commit

Permalink
#337 Button用のComponentを仮実装
Browse files Browse the repository at this point in the history
  • Loading branch information
keitakn committed Aug 17, 2024
1 parent b03e1a8 commit c8978bc
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/app/_components/Button.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import type { Meta, StoryObj } from '@storybook/react';
import { Button } from './Button';

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

View check run for this annotation

Codecov / codecov/patch

src/app/_components/Button.stories.tsx#L2

Added line #L2 was not covered by tests

const meta = {
component: Button,
} satisfies Meta<typeof Button>;

Check warning on line 6 in src/app/_components/Button.stories.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/_components/Button.stories.tsx#L4-L6

Added lines #L4 - L6 were not covered by tests

export default meta;

Check warning on line 8 in src/app/_components/Button.stories.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/_components/Button.stories.tsx#L8

Added line #L8 was not covered by tests

type Story = StoryObj<typeof meta>;

export const Default: Story = {
args: {
type: 'button',
displayText: 'Button',
},
};

Check warning on line 17 in src/app/_components/Button.stories.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/_components/Button.stories.tsx#L12-L17

Added lines #L12 - L17 were not covered by tests

export const WithGithubIcon: Story = {
args: {
type: 'button',
displayText: 'Login',
showGithubIcon: true,
},
};

Check warning on line 25 in src/app/_components/Button.stories.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/_components/Button.stories.tsx#L19-L25

Added lines #L19 - L25 were not covered by tests

export const WithGithubIconPressed: Story = {
args: {
type: 'button',
displayText: 'Login',
showGithubIcon: true,
isPressed: true,
},
};

Check warning on line 34 in src/app/_components/Button.stories.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/_components/Button.stories.tsx#L27-L34

Added lines #L27 - L34 were not covered by tests
33 changes: 33 additions & 0 deletions src/app/_components/Button.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import type { ComponentProps, JSX } from 'react';
import { Button as ReactAriaButton, Text } from 'react-aria-components';
import { FaGithub } from 'react-icons/fa';

Check warning on line 3 in src/app/_components/Button.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/_components/Button.tsx#L2-L3

Added lines #L2 - L3 were not covered by tests

type Props = ComponentProps<'button'> & {
displayText: string;
showGithubIcon?: boolean;
isPressed?: boolean;
};

export const Button = ({
type,
displayText,
showGithubIcon,
isPressed,
}: 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';
const stateClasses =
isPressed === true ? 'bg-amber-500' : 'bg-amber-300 hover:bg-amber-100';
const focusClasses =
'focus:outline-none focus:ring-2 focus:ring-amber-500 focus:ring-offset-2';

Check warning on line 22 in src/app/_components/Button.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/_components/Button.tsx#L11-L22

Added lines #L11 - L22 were not covered by tests

return (
<ReactAriaButton
type={type}
className={`${baseClasses} ${stateClasses} ${focusClasses}`}

Check warning on line 27 in src/app/_components/Button.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/_components/Button.tsx#L24-L27

Added lines #L24 - L27 were not covered by tests
>
{showGithubIcon != null && <FaGithub className="size-5" />}
<Text>{displayText}</Text>

Check warning on line 30 in src/app/_components/Button.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/_components/Button.tsx#L29-L30

Added lines #L29 - L30 were not covered by tests
</ReactAriaButton>
);
};

Check warning on line 33 in src/app/_components/Button.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/_components/Button.tsx#L33

Added line #L33 was not covered by tests

0 comments on commit c8978bc

Please sign in to comment.