-
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
[Feat] ToolTip 컴포넌트 구현 #285
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
92ec149
docs: svg 추가
rtttr1 8605c2e
feat: ToolTip 공통 컴포넌트 구현
rtttr1 11e126f
style: ToolTip style 구현
rtttr1 c280cc1
feat: storybook 작성
rtttr1 67abfec
Merge branch 'develop' into feature/tiki/#276-tooltip
rtttr1 d3358a8
chore: 사고 수습
rtttr1 cba187a
fix: 코드리뷰 반영
rtttr1 9dfbaa4
Merge branch 'feature/tiki/#276-tooltip' of https://github.com/Team-T…
rtttr1 41d537a
style: UX를 고려한 delay 적용
rtttr1 23a399f
feat: aria 로 접근성 챙기기
rtttr1 ea155f5
feat: state 사용으로 키보드 이벤트까지 구현
rtttr1 c61e881
fix: 네이밍 수정
rtttr1 82bd7b3
fix: 코드리뷰 반영
rtttr1 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,84 @@ | ||
import { css } from '@emotion/react'; | ||
|
||
import { ToolTipProps } from '@/common/component/ToolTip/ToolTip'; | ||
import { theme } from '@/common/style/theme/theme'; | ||
|
||
export const containerStyle = css({ | ||
position: 'relative', | ||
border: '1px solid', | ||
}); | ||
|
||
export const messageStyle = (isVisible: boolean) => | ||
css({ | ||
position: 'absolute', | ||
|
||
width: 'max-content', | ||
padding: '1rem', | ||
borderRadius: '8px', | ||
|
||
backgroundColor: `${theme.colors.gray_900}`, | ||
font: `${theme.text.body08}`, | ||
color: `${theme.colors.white}`, | ||
|
||
visibility: isVisible ? 'visible' : 'hidden', | ||
transitionDelay: '0.2s', | ||
pointerEvents: 'none', | ||
}); | ||
|
||
export const positionStyle = (position: Required<ToolTipProps>['position'], gap: number) => { | ||
const style = { | ||
top: css({ | ||
left: '50%', | ||
bottom: '100%', | ||
transform: `translateX(-50%) translateY(calc(-${gap}rem - 8px) )`, | ||
}), | ||
bottom: css({ | ||
left: '50%', | ||
up: '100%', | ||
transform: `translateX(-50%) translateY(calc(${gap}rem + 8px))`, | ||
}), | ||
left: css({ | ||
top: '50%', | ||
right: '100%', | ||
transform: `translateY(-50%) translateX(calc(-${gap}rem - 8px))`, | ||
}), | ||
right: css({ | ||
top: '50%', | ||
left: '100%', | ||
transform: `translateY(-50%) translateX(calc(${gap}rem + 8px))`, | ||
}), | ||
}; | ||
|
||
return style[position]; | ||
}; | ||
|
||
export const arrowStyle = css({ | ||
position: 'absolute', | ||
}); | ||
|
||
export const arrowPositionStyle = (position: Required<ToolTipProps>['position']) => { | ||
const style = { | ||
top: css({ | ||
left: '50%', | ||
top: 'calc(100%)', | ||
transform: `translateX(-50%) translateY(-1px) rotate(270deg)`, | ||
}), | ||
bottom: css({ | ||
left: '50%', | ||
bottom: 'calc(100%)', | ||
transform: `translateX(-50%) translateY(1px) rotate(90deg)`, | ||
}), | ||
left: css({ | ||
top: '50%', | ||
left: 'calc(100%)', | ||
transform: `translateY(-50%) translateX(-1px) rotate(180deg)`, | ||
}), | ||
right: css({ | ||
top: '50%', | ||
right: 'calc(100%)', | ||
transform: `translateY(-50%) translateX(1px)`, | ||
}), | ||
}; | ||
|
||
return style[position]; | ||
}; |
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,53 @@ | ||
import { HTMLAttributes, useState } from 'react'; | ||
|
||
import Arrow from '@/common/asset/svg/ic_tooltip_arrow.svg?react'; | ||
import { | ||
arrowPositionStyle, | ||
arrowStyle, | ||
containerStyle, | ||
messageStyle, | ||
positionStyle, | ||
} from '@/common/component/ToolTip/ToolTip.style'; | ||
|
||
export interface ToolTipProps extends HTMLAttributes<HTMLSpanElement> { | ||
position?: 'top' | 'right' | 'bottom' | 'left'; | ||
message: string; | ||
gap?: number; | ||
} | ||
|
||
const ToolTip = ({ position = 'right', message, gap = 0, children, ...props }: ToolTipProps) => { | ||
const [isVisible, setIsVisible] = useState(false); | ||
|
||
const handleToolTipVisible = () => { | ||
setIsVisible(true); | ||
}; | ||
const handleToolTipHidden = () => { | ||
setIsVisible(false); | ||
}; | ||
const handleKeyDown = (event: React.KeyboardEvent) => { | ||
if (event.key === 'Escape') { | ||
handleToolTipHidden(); | ||
} | ||
}; | ||
|
||
return ( | ||
<div | ||
aria-describedby={message} | ||
role="button" | ||
css={containerStyle} | ||
tabIndex={0} | ||
onMouseEnter={handleToolTipVisible} | ||
onMouseLeave={handleToolTipHidden} | ||
onKeyDown={handleKeyDown} | ||
onFocus={handleToolTipVisible} | ||
onBlur={handleToolTipHidden}> | ||
{children} | ||
<span role="tooltip" css={[messageStyle(isVisible), positionStyle(position, gap)]} {...props}> | ||
<Arrow css={[arrowStyle, arrowPositionStyle(position)]} /> | ||
{message} | ||
</span> | ||
</div> | ||
); | ||
}; | ||
|
||
export default ToolTip; |
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,47 @@ | ||
import type { Meta, StoryObj } from '@storybook/react'; | ||
|
||
import Flex from '@/common/component/Flex/Flex'; | ||
import ToolTip from '@/common/component/ToolTip/ToolTip'; | ||
import { theme } from '@/common/style/theme/theme'; | ||
|
||
const meta = { | ||
title: 'Common/ToolTip', | ||
component: ToolTip, | ||
parameters: { | ||
layout: 'centered', | ||
}, | ||
tags: ['autodocs'], | ||
argTypes: { | ||
position: { | ||
control: { type: 'radio' }, | ||
options: ['top', 'bottom', 'left', 'right'], | ||
}, | ||
message: { | ||
control: { type: 'text' }, | ||
}, | ||
}, | ||
args: { | ||
position: 'top', | ||
message: 'ToolTip', | ||
gap: 0.8, | ||
}, | ||
} satisfies Meta<typeof ToolTip>; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof meta>; | ||
|
||
export const DefaultToolTip: Story = { | ||
args: { | ||
children: ( | ||
<Flex | ||
style={{ | ||
width: '36px', | ||
height: '36px', | ||
backgroundColor: theme.colors.purple_200, | ||
}} | ||
styles={{ justify: 'center', align: 'center' }}> | ||
호버 | ||
</Flex> | ||
), | ||
}, | ||
}; |
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.
툴팁 내용이 많아지는 경우 svg크기가 줄어들더라고요 !
flexShrink: 0
으로 해결할 수 있을 것 같은데 한 번 수정해보시면 좋을 것 같아요