-
Notifications
You must be signed in to change notification settings - Fork 2
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
[노철] - TooltipButton 구현 #489
Merged
Merged
Changes from 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
f6730cd
✨ : #488 - share 아이콘 추가
qkdl60 f28deba
♻️ : #488 - 카카오버튼 null check 추가
qkdl60 8da743b
✨ : #488 - TooltipButton 추가
qkdl60 946b8a8
♻️ : #488 - plan 페이지 TooltipButton 적용
qkdl60 041a99d
♻️ : #488 - index export 적용
qkdl60 d8d5fd1
♻️ : #488 - 불필요한 함수 제거
qkdl60 2e55fa1
♻️ : #488 - 컴포넌트 설명 주석 추가
qkdl60 fe53d54
💄 : #488 - trigger 배경색 변경
qkdl60 deebf04
Merge branch 'dev' of https://github.com/New-Barams/this-year-ajaja-f…
qkdl60 6d46c70
♻️ : #488 - optionsPosition props로 변경
qkdl60 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
'use client'; | ||
|
||
import { useModalClose } from '@/hooks'; | ||
import classNames from 'classnames'; | ||
import { | ||
ReactElement, | ||
createContext, | ||
useContext, | ||
useEffect, | ||
useRef, | ||
useState, | ||
} from 'react'; | ||
import './index.scss'; | ||
|
||
//TooltipButton컴포넌트 내에서 공유할 상태, 함수 | ||
const contextDefaultValue = { | ||
isOpen: false, // 툴팁 열림 여부 | ||
handleSetIsOpen: () => {}, //툴팁 상태 변경 함수 | ||
handleCloseTooltip: () => {}, //툴팁 닫기 함수 | ||
optionsPosition: 'top' as Position, //Options컴포넌트 위치(열림 방향을 위해서 필요) | ||
}; | ||
|
||
type Position = 'top' | 'bottom'; | ||
|
||
const TooltipButtonContext = createContext<{ | ||
isOpen: boolean; | ||
handleSetIsOpen: () => void; | ||
handleCloseTooltip: () => void; | ||
optionsPosition: Position; | ||
}>(contextDefaultValue); | ||
|
||
interface MainProps { | ||
className?: string; // 위치조정이이나, css 스탕일링을 위한 className | ||
children: ReactElement[]; | ||
} | ||
|
||
const Main = ({ children, className }: MainProps) => { | ||
const [isOpen, setIsOpen] = useState<boolean>(false); | ||
const [optionsPosition, setOptionsPosition] = useState<Position>('top'); | ||
useEffect(() => { | ||
setOptionsPosition(children[0]?.type !== Options ? 'bottom' : 'top'); | ||
}, [children]); | ||
|
||
const handleCloseTooltip = () => { | ||
setIsOpen(false); | ||
}; | ||
const handleSetIsOpen = () => { | ||
setIsOpen(!isOpen); | ||
}; | ||
|
||
return ( | ||
<div className={classNames('tooltip-button__main', className)}> | ||
<TooltipButtonContext.Provider | ||
value={{ | ||
handleCloseTooltip, | ||
optionsPosition, | ||
isOpen, | ||
handleSetIsOpen, | ||
}}> | ||
{children} | ||
</TooltipButtonContext.Provider> | ||
</div> | ||
); | ||
}; | ||
|
||
interface TriggerProps { | ||
children: ReactElement; | ||
className?: string; | ||
} | ||
//열고 닫힘 trigger 역할을 할 컴푸넌트 children을 넣얼줄때 외부에서 직접 스타일링 가능, 그외 부분 클릭시 Tooltip 닫힘 | ||
const Trigger = ({ children, className }: TriggerProps) => { | ||
const { handleSetIsOpen, handleCloseTooltip } = | ||
useContext(TooltipButtonContext); | ||
const triggerRef = useRef(null); | ||
useModalClose(triggerRef, handleCloseTooltip); | ||
return ( | ||
<button | ||
ref={triggerRef} | ||
onClick={handleSetIsOpen} | ||
className={classNames(className, 'tooltip-button__trigger')}> | ||
{children} | ||
</button> | ||
); | ||
}; | ||
|
||
interface OptionsProps { | ||
className?: string; | ||
children: ReactElement[] | ReactElement; | ||
} | ||
//열렸을때 보여줄 아이템들 | ||
const Options = ({ className, children }: OptionsProps) => { | ||
const { isOpen, optionsPosition } = useContext(TooltipButtonContext); | ||
return ( | ||
<ul | ||
className={classNames( | ||
className, | ||
'tooltip-button__list', | ||
`position-${optionsPosition}`, | ||
isOpen ? 'open' : 'close', | ||
)}> | ||
{Array.isArray(children) ? ( | ||
children.map((component, index) => ( | ||
<li | ||
data-order={index + 1} | ||
className={classNames( | ||
'tooltip-button__list__item', | ||
isOpen ? 'open' : 'close', | ||
)} | ||
key={index}> | ||
{component} | ||
</li> | ||
)) | ||
) : ( | ||
<li className="tooltip-button__list__item ">{children}</li> | ||
)} | ||
</ul> | ||
); | ||
}; | ||
|
||
export { Main, Options, Trigger }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
.tooltip-button { | ||
&__main { | ||
overflow: visible; | ||
position: relative; | ||
} | ||
|
||
&__trigger { | ||
background-color: transparent; | ||
} | ||
|
||
&__list { | ||
display: flex; | ||
flex-direction: column; | ||
background-color: transparent; | ||
gap: 0.75rem; | ||
position: absolute; | ||
transition: all 0.3s; | ||
text-wrap: nowrap; | ||
|
||
&__item { | ||
background-color: transparent; | ||
transition: all 0.2s; | ||
} | ||
&.position-top { | ||
bottom: 140%; | ||
} | ||
|
||
&.position-top &__item { | ||
&.close { | ||
transform: translateY(100%); | ||
opacity: 0; | ||
visibility: hidden; | ||
} | ||
&.open { | ||
transform: translateY(0); | ||
opacity: 1; | ||
} | ||
} | ||
|
||
&.position-bottom { | ||
top: 125%; | ||
} | ||
|
||
&.position-bottom &__item { | ||
&.close { | ||
transform: translateY(-100%); | ||
opacity: 0; | ||
visibility: hidden; | ||
} | ||
&.open { | ||
transform: translateY(0); | ||
opacity: 1; | ||
} | ||
} | ||
//순차적으로 나타나고 사라지는 애니메이션을 위한 delay | ||
$n: 5; | ||
|
||
@for $i from 1 through $n { | ||
&__item:nth-child(#{$i}) { | ||
transition-delay: calc(0.1s * $i); | ||
} | ||
} | ||
} | ||
&__list.close { | ||
visibility: hidden; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * as TooltipButton from '@components/TooltipButton/TooltipButton'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,4 +36,5 @@ export type IconName = | |
| 'COPY' | ||
| 'HELP' | ||
| 'ARROW_RIGHT' | ||
| 'CANCEL'; | ||
| 'CANCEL' | ||
| 'SHARE'; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
top일때는 위로 카카오톡, 링크 복사하기 이렇게 두 개가 보이는 것이고
bottom일 때는 툴팁이 닫히는 방식으로 작동하는 건가요?
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.
컴포넌트 넣어주는 순서에 따라서 팝업이 열리는 위치를 정하도록 해주었습니다
Options의 위치가 top일때는 카카오톡, 링크 복사하기가 위에 나오고, bottom 일때는 아래에 나오도록 설정한겁니다.
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.
작성 위치에 따라 변경되는 부분 너무 좋은 것 같은데 처음 보는 사람은 이해하기가 좀 어려운것 같습니다..!
props로 받아와 변경해주는게 좀 더 사용하기 편할것 같아요 😄