Skip to content

Commit

Permalink
feat(about): Add image modal
Browse files Browse the repository at this point in the history
  • Loading branch information
1ilsang committed Jun 1, 2024
1 parent fddf31e commit a9fc5ca
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 7 deletions.
5 changes: 5 additions & 0 deletions src/app/about/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import { NextPage } from 'next';

import AboutContainer from '~/about/Container';
import Footer from '~/shared/components/Footer';
import ImageModal from '~/shared/components/modal/ImageModal';
import Navbar from '~/shared/components/nav/Navbar';
import usePrint from '~/shared/hooks/usePrint';
import { Portal } from '~/shared/portal/Container';

const About: NextPage = () => {
const { print } = usePrint();
Expand All @@ -14,6 +16,9 @@ const About: NextPage = () => {
{!print && <Navbar />}
<AboutContainer />
{!print && <Footer />}
<Portal>
<ImageModal />
</Portal>
</main>
);
};
Expand Down
11 changes: 10 additions & 1 deletion src/features/about/work/card/content/ProjectDetail.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
import { FunctionComponent, memo } from 'react';
import { useAtom } from 'jotai';
import { type FunctionComponent, type MouseEventHandler, memo } from 'react';

import { Project } from '~/about/work/models';
import DynamicImage from '~/shared/components/DynamicImage';
import { imageSrcAtom } from '~/shared/components/modal/atoms';
import usePrint from '~/shared/hooks/usePrint';

type ProjectDetailProps = Project;

const ProjectDetail: FunctionComponent<ProjectDetailProps> = memo(
({ summary, body, img }) => {
const { print } = usePrint();
const [, setImageSrc] = useAtom(imageSrcAtom);

const handleImageClick: MouseEventHandler<HTMLImageElement> = (e) => {
if (!(e.target instanceof HTMLImageElement)) return;
setImageSrc(e.target.src);
};

return (
<>
Expand All @@ -18,6 +26,7 @@ const ProjectDetail: FunctionComponent<ProjectDetailProps> = memo(
width={img.width}
src={img.url}
alt={img.alt}
onClick={handleImageClick}
/>
)}
<div className="text">
Expand Down
17 changes: 15 additions & 2 deletions src/features/shared/components/DynamicImage.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import classNames from 'classnames';
import { FunctionComponent, useState } from 'react';
import {
type FunctionComponent,
type MouseEventHandler,
useState,
} from 'react';

type DynamicImageProps = {
src: string;
Expand All @@ -8,6 +12,7 @@ type DynamicImageProps = {
loading?: boolean;
width?: number;
height?: number;
onClick?: MouseEventHandler<HTMLImageElement>;
};

const DynamicImage: FunctionComponent<DynamicImageProps> = ({
Expand All @@ -17,6 +22,7 @@ const DynamicImage: FunctionComponent<DynamicImageProps> = ({
src,
alt,
loading = false,
onClick,
}) => {
const [min, setMin] = useState(true);
const handleMinClick = () => setMin(!min);
Expand All @@ -30,7 +36,14 @@ const DynamicImage: FunctionComponent<DynamicImageProps> = ({
style={{ width, height }}
>
<button className={min ? 'min' : 'max'} onClick={handleMinClick} />
<img src={src} alt={alt} width={width} height={height} />
<img
className={onClick ? 'zoom' : undefined}
src={src}
alt={alt}
width={width}
height={height}
onClick={onClick}
/>
</div>
);
};
Expand Down
4 changes: 4 additions & 0 deletions src/features/styles/common.scss
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ $target: #e73c7e;
font-size: 3rem;
}
}

.zoom {
cursor: zoom-in;
}
}

.dynamic-image.min {
Expand Down
18 changes: 14 additions & 4 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
"display": "blog",
"compilerOptions": {
"target": "ES2017",
"lib": ["dom", "dom.iterable", "esnext"],
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": false,
"skipLibCheck": true,
"strict": false,
Expand All @@ -17,8 +21,12 @@
"moduleResolution": "node",
"baseUrl": ".",
"paths": {
"~/*": ["src/features/*"],
"~/app/*": ["src/app/*"]
"~/*": [
"src/features/*"
],
"~/app/*": [
"src/app/*"
]
},
"plugins": [
{
Expand All @@ -33,5 +41,7 @@
"e2e/**/*.ts",
".next/types/**/*.ts"
],
"exclude": ["node_modules"]
"exclude": [
"node_modules"
]
}

0 comments on commit a9fc5ca

Please sign in to comment.