Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/カードコンポーネントサイズ変更 #59

Merged
merged 12 commits into from
Mar 27, 2024
5 changes: 2 additions & 3 deletions src/components/Card/Card.module.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

.card {
width: 100%;
.card {
max-width: 100%;
border: 1px solid #ccc;
background-color: #fff;
text-decoration: none;
Expand Down
2 changes: 2 additions & 0 deletions src/components/Card/Card.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export default {
to: { control: 'text' },
imageSrc: { control: 'text' },
imageAlt: { control: 'text' },
cardWidth: { control: 'text' },
},
} as Meta;

Expand All @@ -28,4 +29,5 @@ Default.args = {
to: '/',
imageSrc: '/images/maximum-card.png',
imageAlt: 'maximum',
cardWidth: '100%',
};
12 changes: 11 additions & 1 deletion src/components/Card/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ interface CardProps {
to: string;
imageSrc: string;
imageAlt: string;
cardWidth: string;
}
const Card: React.FC<CardProps> = ({
title,
Expand All @@ -19,9 +20,18 @@ const Card: React.FC<CardProps> = ({
to,
imageSrc,
imageAlt,
cardWidth,
}) => {
//widthとして当てはまらない値の場合100%にする
const width =
/^(\d+(\.\d+)?(%|px|em|rem|cm|mm|in|pt|pc)|auto|inherit|initial|unset|fit-content|max-content|min-content)$/.test(
cardWidth,
)
? cardWidth
: '100%';

return (
<Link href={to} className={style.card}>
<Link href={to} className={style.card} style={{ width }}>
nakamuraitsuki marked this conversation as resolved.
Show resolved Hide resolved
<div className={style.img}>
<img className={style.img} src={imageSrc} alt={imageAlt} />
<div className={style.box}>
Expand Down