-
Notifications
You must be signed in to change notification settings - Fork 6
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(toks-components, quiz): Image Preview 기능 구현 #403
Changes from 6 commits
87656b4
a0cc2ca
5259bd3
92f9290
a2e1c61
03f87a6
40a8a69
dfa9684
d9a068b
07c8748
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,15 @@ | ||
'use client'; | ||
|
||
import Image from 'next/image'; | ||
import { HTMLAttributes } from 'react'; | ||
|
||
import { ICON_URL, bgColor, cn } from '@/common'; | ||
|
||
import { QuizButtonProps } from './type'; | ||
|
||
interface ThumbnailProps | ||
extends Pick<QuizButtonProps, 'OXType' | 'imageUrl' | 'className'> { | ||
extends Pick<QuizButtonProps, 'OXType' | 'imageUrl' | 'className'>, | ||
HTMLAttributes<HTMLDivElement> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 혹시 onClick이 필요해서 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 근데 썸네일 컴포넌트 내부로 모달 컴포넌트를 종속시키면 해당 attribute extends는 더이상 필요 없을 것 같네요! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 아아 그러네요 그나저나 저렇게 하면 안되는군요 흠흠 |
||
name?: string; | ||
} | ||
|
||
|
@@ -14,9 +18,11 @@ export function Thumbnail({ | |
imageUrl, | ||
name = '퀴즈', | ||
className, | ||
...rest | ||
}: ThumbnailProps) { | ||
return ( | ||
<div | ||
{...rest} | ||
className={cn( | ||
'relative flex aspect-square w-140px items-center justify-center overflow-hidden rounded-8px', | ||
OXType && | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
'use client'; | ||
|
||
import clsx from 'clsx'; | ||
import { useState } from 'react'; | ||
|
||
import { Text, bgColor } from '@/common'; | ||
import { Modal } from '@/common/components/Modal'; | ||
|
||
import { ProgressBar } from './ProgressBar'; | ||
import { Thumbnail } from './Thumbnail'; | ||
|
@@ -20,19 +22,35 @@ export function QuizButton({ | |
name, | ||
...rest | ||
}: QuizButtonProps) { | ||
const [isShow, setIsShow] = useState(false); | ||
return ( | ||
<button | ||
className={clsx(className, 'flex flex-1 flex-col items-center')} | ||
disabled={isSubmitted} | ||
{...rest} | ||
> | ||
<div className={clsx(className, 'flex flex-1 flex-col items-center')}> | ||
{(OXType || imageUrl) && ( | ||
<Thumbnail | ||
className="mb-24px w-full" | ||
OXType={OXType} | ||
imageUrl={imageUrl} | ||
name={name} | ||
/> | ||
<> | ||
<Thumbnail | ||
className="mb-24px w-full" | ||
OXType={OXType} | ||
imageUrl={imageUrl} | ||
name={name} | ||
onClick={() => { | ||
setIsShow(true); | ||
}} | ||
/> | ||
{!OXType && ( | ||
<Modal isShow={isShow} onClose={() => setIsShow(false)}> | ||
<img | ||
className="rounded-8px" | ||
src={imageUrl} | ||
alt={`${name}사진`} | ||
style={{ | ||
width: '100%', | ||
objectFit: 'cover', | ||
objectPosition: 'center', | ||
}} | ||
/> | ||
</Modal> | ||
)} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 썸네일 클릭 => 모달 등장이 서비스 내 고정적인 스펙이라면 해당 썸네일 확대용 모달을 썸네일 컴포넌트 안에 종속시키면 어떨까요? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 저도 같은 의견으로 Preview + Modal은 세트로 가져가도 좋을 것 같습니다 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 넵넵 썸네일과 모달 컴포넌트 하나로 합쳐볼게요~! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 40a8a69 썸네일 컴포넌트에 모달 컴포넌트 종속시키는 방식으로 수정했습니다! |
||
</> | ||
)} | ||
<div | ||
className={clsx( | ||
|
@@ -43,11 +61,15 @@ export function QuizButton({ | |
{isSubmitted && ( | ||
<ProgressBar percentage={percentage} isSelected={isSelected} /> | ||
)} | ||
<div className="absolute z-10 flex h-full w-full items-center justify-center"> | ||
<button | ||
className="absolute z-10 flex h-full w-full items-center justify-center" | ||
disabled={isSubmitted} | ||
{...rest} | ||
> | ||
<Text typo="bodyBold" color="gray10"> | ||
{name} | ||
</Text> | ||
</div> | ||
</button> | ||
</div> | ||
{isSubmitted && participationLabel && ( | ||
<Text | ||
|
@@ -58,6 +80,6 @@ export function QuizButton({ | |
{participationLabel} | ||
</Text> | ||
)} | ||
</button> | ||
</div> | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
'use client'; | ||
|
||
import Image from 'next/image'; | ||
import { PropsWithChildren, ReactNode } from 'react'; | ||
|
||
import { ICON_URL } from '@/common'; | ||
import { cn } from '@/common/utils'; | ||
|
||
import { GlobalPortal } from '../GlobalPortal'; | ||
|
||
type ModalProp = { | ||
isShow: boolean; | ||
onClose: VoidFunction; | ||
}; | ||
|
||
export const Modal = ({ | ||
isShow, | ||
onClose, | ||
children, | ||
}: PropsWithChildren<ModalProp>) => { | ||
return ( | ||
<GlobalPortal.Consumer> | ||
<Dimmer isShow={isShow} onClose={onClose} children={children} /> | ||
</GlobalPortal.Consumer> | ||
); | ||
}; | ||
|
||
const Dimmer = ({ | ||
isShow, | ||
onClose, | ||
children, | ||
}: { | ||
isShow: boolean; | ||
onClose: VoidFunction; | ||
children: ReactNode; | ||
}) => { | ||
return ( | ||
<div | ||
onClick={() => { | ||
onClose(); | ||
}} | ||
className={cn( | ||
'fixed left-0 top-0 z-50 flex h-full w-full items-center justify-center bg-gray-120/80 p-20px', | ||
{ | ||
hidden: !isShow, | ||
'animate-fade-in-back-drop': isShow, | ||
} | ||
)} | ||
> | ||
<div className="flex flex-col"> | ||
<button className="flex justify-end pb-16px" onClick={() => onClose()}> | ||
<Image src={ICON_URL.CLOSE} alt="close" width={24} height={24} /> | ||
</button> | ||
{children} | ||
</div> | ||
</div> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이거 framer-motion 라이브러리 있는데 요거로 바꾸면 좋을 것 같습니다. AnimationPresence 등 유용한 유틸을 추후에 추가하기 편할 것 같아서 제시해봅니당 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. dfa9684 framer 적용했습니다 ~! |
||
); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
요거 무슨 차이인가요??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
next Image를 사용할 때 콘솔에
src has either width or height modified, but not the other. If you use CSS to change the size of your image, also include the styles 'width: "auto"' or 'height: "auto"' to maintain the aspect ratio.
warning이 여러번 떴었는데요, 해당 warning을 해결하기 위해서는 width나 height 둘 중 하나를 auto로 설정해서 ratio를 맞춰야하는데 next Image를 사용할 때에는 width와 height 두 속성 모두 지정을 해줘야만했기 때문에 위와 같은 방식으로 작성하게 되었습니다!next/image