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
18 changes: 0 additions & 18 deletions src/app/page.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,6 @@ $heroImage-change-width: 1280px;
$header-change-width: 1200px;
$background-color: #F1F1F1;

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

@media (max-width: $heroImage-change-width) {
.heroImage {
height: 100%;
}
}

@media (max-width: $header-change-width) {
.main {
padding-top: 64px;
Expand Down Expand Up @@ -204,11 +191,6 @@ $background-color: #F1F1F1;
}

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

.main {
flex-direction: column;
background-color: $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 { DynamicHeroImage } from '../components/DynamicHeroImage';
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} />
<DynamicHeroImage type='thumbnail' />
<div className={style.breadcrumb}>
<Link href='/' className={style.breadcrumbLink}>
Top
Expand Down
42 changes: 42 additions & 0 deletions src/components/DynamicHeroImage/DynamicHeroImage.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%;
}
}
18 changes: 18 additions & 0 deletions src/components/DynamicHeroImage/DynamicHeroImage.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { StoryFn, Meta } from '@storybook/react';
import React from 'react';
import { DynamicHeroImage } from './DynamicHeroImage';

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

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

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

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

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