-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* ✨ : #488 - share 아이콘 추가 * ♻️ : #488 - 카카오버튼 null check 추가 * ✨ : #488 - TooltipButton 추가 * ♻️ : #488 - plan 페이지 TooltipButton 적용 * ♻️ : #488 - index export 적용 * ♻️ : #488 - 불필요한 함수 제거 * ♻️ : #488 - 컴포넌트 설명 주석 추가 * 💄 : #488 - trigger 배경색 변경 * ♻️ : #488 - optionsPosition props로 변경
- Loading branch information
Showing
9 changed files
with
215 additions
and
8 deletions.
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,116 @@ | ||
'use client'; | ||
|
||
import { useModalClose } from '@/hooks'; | ||
import classNames from 'classnames'; | ||
import { | ||
ReactElement, | ||
createContext, | ||
useContext, | ||
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[]; | ||
optionsPosition: Position; | ||
} | ||
|
||
const Main = ({ children, className, optionsPosition }: MainProps) => { | ||
const [isOpen, setIsOpen] = useState<boolean>(false); | ||
|
||
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'; |