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: Dynamic hero image #71

Merged
merged 13 commits into from
Apr 10, 2024
5 changes: 0 additions & 5 deletions src/app/page.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,6 @@
}

/* 共通 */
.heroImage {
width: 100%;
object-fit: cover;
}

.main {
flex-direction: column;
background-color: variables.$background-color;
Expand Down
3 changes: 2 additions & 1 deletion src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import clsx from 'clsx';
import Link from 'next/link';
import { HeroImage } from '../components/HeroImage';
import { LinkButton } from '../components/LinkButton';
import style from './page.module.scss';
import { NewsList } from '@/components/news-list';
Expand All @@ -9,7 +10,7 @@ export default function Home() {
<div className={style.container}>
<main className={style.main}>
<div className={style.hero}>
<img src='/images/hero.png' alt='Hero' className={style.heroImage} />
<HeroImage type='thumbnail' />
<div className={style.breadcrumb}>
<Link href='/' className={style.breadcrumbLink}>
Top
Expand Down
42 changes: 42 additions & 0 deletions src/components/HeroImage/HeroImage.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
@use 'src/app/variables';
$heroImage-change-width: 1280px;

.heroImagesContainer {
position: relative;
width: 100%;
}

.heroImage {
display: block;
width: 100%;
object-fit: cover;
}


.blur {
filter: blur(9px);
}

.heroTitle {
white-space: nowrap;
color: #455749;
font-weight: bold;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
font-size: calc((100vw + 320px) / 40);
}

/* heroImageとヘッダーのpadding調整 */
@media (min-width: $heroImage-change-width) {
.heroImage {
height: 60vh;
}
}

@media (max-width: $heroImage-change-width) {
.heroImage {
height: 100%;
}
}
16 changes: 16 additions & 0 deletions src/components/HeroImage/HeroImage.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { StoryFn, Meta } from '@storybook/react';
import React from 'react';
import { HeroImage } from './HeroImage';

export default {
title: 'Components/HeroImage',
component: HeroImage,
} as Meta;

const Template: StoryFn<typeof HeroImage> = (args) => <HeroImage {...args} />;

export const Default = Template.bind({});
Default.args = {
title: 'Maximumの活動について',
blur: false,
};
31 changes: 31 additions & 0 deletions src/components/HeroImage/HeroImage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import clsx from 'clsx';
import React from 'react';
import style from './HeroImage.module.scss';

interface Props {
title?: string;
blur?: boolean;
type?: 'default' | 'thumbnail';
}

export const HeroImage: React.FC<Props> = ({
title,
blur = false,
type = 'default',
}) => {
return (
<div className={style.heroImagesContainer}>
<img
src={type === 'default' ? '/images/hero2.png' : '/images/hero.png'}
batora9 marked this conversation as resolved.
Show resolved Hide resolved
alt='hero'
className={clsx(
style.heroImage,
blur && style.blur,
type === 'default' && style.default,
type === 'thumbnail' && style.thumbnail,
)}
/>
<div className={style.heroTitle}>{title}</div>
</div>
);
};
1 change: 1 addition & 0 deletions src/components/HeroImage/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './HeroImage';