Skip to content

Commit

Permalink
🎨 #303 style を直接渡すのは Tailwind CSS のクラスと競合するのでクラス名を受け取るStyleに変更
Browse files Browse the repository at this point in the history
  • Loading branch information
keitakn committed Aug 23, 2024
1 parent f47d7b9 commit 4e46991
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
14 changes: 8 additions & 6 deletions src/app/_components/IconButton.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ export default meta;

type Story = StoryObj<typeof meta>;

const responsiveWidthClass = 'w-[220px] sm:w-[240px]';

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

View check run for this annotation

Codecov / codecov/patch

src/app/_components/IconButton.stories.tsx#L12

Added line #L12 was not covered by tests

export const Default: Story = {
args: {
type: 'button',
Expand Down Expand Up @@ -38,7 +40,7 @@ export const WithRepeatIcon: Story = {
type: 'button',
displayText: 'ランダムコピー',
showRepeatIcon: true,
style: { width: '240px' },
className: responsiveWidthClass,
},
};

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

View check run for this annotation

Codecov / codecov/patch

src/app/_components/IconButton.stories.tsx#L38-L45

Added lines #L38 - L45 were not covered by tests

Expand All @@ -48,7 +50,7 @@ export const WithRepeatIconPressed: Story = {
displayText: 'ランダムコピー',
showRepeatIcon: true,
isPressed: true,
style: { width: '240px' },
className: responsiveWidthClass,
},
};

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

View check run for this annotation

Codecov / codecov/patch

src/app/_components/IconButton.stories.tsx#L47-L55

Added lines #L47 - L55 were not covered by tests

Expand All @@ -57,7 +59,7 @@ export const WithRandomIcon: Story = {
type: 'button',
displayText: 'ねこリフレッシュ',
showRandomIcon: true,
style: { width: '240px' },
className: responsiveWidthClass,
},
};

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

View check run for this annotation

Codecov / codecov/patch

src/app/_components/IconButton.stories.tsx#L57-L64

Added lines #L57 - L64 were not covered by tests

Expand All @@ -67,7 +69,7 @@ export const WithRandomIconPressed: Story = {
displayText: 'ねこリフレッシュ',
showRandomIcon: true,
isPressed: true,
style: { width: '240px' },
className: responsiveWidthClass,
},
};

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

View check run for this annotation

Codecov / codecov/patch

src/app/_components/IconButton.stories.tsx#L66-L74

Added lines #L66 - L74 were not covered by tests

Expand All @@ -76,7 +78,7 @@ export const WithCatIcon: Story = {
type: 'button',
displayText: 'ねこ新着順',
showCatIcon: true,
style: { width: '240px' },
className: responsiveWidthClass,
},
};

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

View check run for this annotation

Codecov / codecov/patch

src/app/_components/IconButton.stories.tsx#L76-L83

Added lines #L76 - L83 were not covered by tests

Expand All @@ -86,6 +88,6 @@ export const WithCatIconPressed: Story = {
displayText: 'ねこ新着順',
showCatIcon: true,
isPressed: true,
style: { width: '240px' },
className: responsiveWidthClass,
},
};

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

View check run for this annotation

Codecov / codecov/patch

src/app/_components/IconButton.stories.tsx#L85-L93

Added lines #L85 - L93 were not covered by tests
9 changes: 4 additions & 5 deletions src/app/_components/IconButton.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ComponentProps, CSSProperties, JSX } from 'react';
import type { ComponentProps, JSX } from 'react';
import { Button, Text } from 'react-aria-components';

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

const GithubIcon = () => {
Expand Down Expand Up @@ -76,7 +76,7 @@ type Props = ComponentProps<'button'> & {
showRandomIcon?: boolean;
showCatIcon?: boolean;
isPressed?: boolean;
style?: CSSProperties;
className?: string;
};

export const IconButton = ({
Expand All @@ -87,7 +87,7 @@ export const IconButton = ({
showRandomIcon,
showCatIcon,
isPressed,
style,
className,
}: 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 @@ -99,10 +99,9 @@ export const IconButton = ({
return (
<Button
type={type}
className={`${baseClasses} ${stateClasses} ${focusClasses}`}
className={`${baseClasses} ${stateClasses} ${focusClasses} ${className ?? ''}`}
isDisabled={isPressed}
aria-pressed={isPressed}

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

View check run for this annotation

Codecov / codecov/patch

src/app/_components/IconButton.tsx#L99-L104

Added lines #L99 - L104 were not covered by tests
style={style}
>
{showGithubIcon != null && <GithubIcon />}
{showRepeatIcon != null && <RepeatIcon />}
Expand Down

0 comments on commit 4e46991

Please sign in to comment.