-
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
SKRF-141 design: 아바타 공통 컴포넌트 구현-리액트 아이콘 미사용 #19
Merged
Merged
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
82d57a5
design: 아바타 공통 컴포넌트 구현-리액트 아이콘 미사용
colorkite10 434f21c
refactor: 클릭하지 못하는 아바타 설정, 편집버튼 크기 조정
colorkite10 703f582
fix: 편집버튼 prop 추가
colorkite10 769d2b0
refactor: profileImage->profileImageSrc
colorkite10 e0cfee4
refactor: util함수 분리, 아바타 모양 타입 분리
colorkite10 44ffb76
fix: 안 쓰는 import 제거
colorkite10 9d767af
conflict: user타입에 User interface추가
colorkite10 7841ca6
Merge branch 'main' into SKRF-141-design-avatar-component
SongInjae db7c52a
refactor: onClick 타입 재설정
colorkite10 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
Empty file.
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,30 @@ | ||
import { AvatarShapeType } from '@/types/user'; | ||
import { getAvatarSize } from '@/utils/getAvatarSize'; | ||
import styled from '@emotion/styled'; | ||
|
||
const AvatarContainerStyled = styled.div` | ||
position: relative; | ||
display: inline-flex; | ||
`; | ||
|
||
const ProfileImageStyled = styled.img<AvatarShapeType>` | ||
position: relative; | ||
width: ${({ avatarShape }) => getAvatarSize(avatarShape)}; | ||
height: ${({ avatarShape }) => getAvatarSize(avatarShape)}; | ||
border-radius: ${({ avatarShape }) => (avatarShape === 'rectangle' ? '1.7rem' : '50%')}; | ||
object-fit: cover; | ||
cursor: ${({ avatarShape }) => (avatarShape === 'large' ? 'default' : 'pointer')}; | ||
`; | ||
|
||
const EditButtonStyled = styled.div<AvatarShapeType>` | ||
width: ${({ avatarShape }) => (avatarShape === 'large' ? '4rem' : '2rem')}; | ||
height: ${({ avatarShape }) => (avatarShape === 'large' ? '4rem' : '2rem')}; | ||
position: absolute; | ||
right: 2%; | ||
bottom: 2%; | ||
border-radius: 50%; | ||
cursor: pointer; | ||
border: 1px solid; | ||
`; | ||
|
||
export { getAvatarSize, AvatarContainerStyled, ProfileImageStyled, EditButtonStyled }; |
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,44 @@ | ||
import { AvatarShapeType } from '@/types/user'; | ||
import { getAvatarSize } from '@/utils/getAvatarSize'; | ||
|
||
import { AvatarContainerStyled, EditButtonStyled, ProfileImageStyled } from './Avatar.style'; | ||
|
||
interface AvatarProps { | ||
avatarShape: AvatarShapeType['avatarShape']; | ||
profileImageSrc?: string; | ||
isEditable?: boolean; | ||
onClick?: () => void; | ||
} | ||
|
||
const Avatar = ({ avatarShape, profileImageSrc, isEditable, onClick }: AvatarProps) => { | ||
const width = getAvatarSize(avatarShape); | ||
|
||
return ( | ||
<div> | ||
<AvatarContainerStyled onClick={onClick}> | ||
{profileImageSrc ? ( | ||
<ProfileImageStyled | ||
avatarShape={avatarShape} | ||
src={profileImageSrc} | ||
alt="profile image" | ||
style={{ width: `${width}`, height: `${width}` }} | ||
/> | ||
) : ( | ||
<ProfileImageStyled | ||
src="https://picsum.photos/200/300" | ||
avatarShape={avatarShape} | ||
style={{ width: `${width}`, height: `${width}` }} | ||
alt="이 부분은 추후 수정 예정입니다." | ||
/> | ||
)} | ||
{isEditable && ( | ||
<EditButtonStyled avatarShape={avatarShape}> | ||
<span>편집아이콘추가예정</span> | ||
</EditButtonStyled> | ||
)} | ||
</AvatarContainerStyled> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Avatar; |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,9 @@ | ||
interface User { | ||
accessToken: string; | ||
} | ||
|
||
interface AvatarShapeType { | ||
avatarShape: 'rectangle' | 'normal' | 'large' | 'small' | 'medium'; | ||
} | ||
|
||
export { User, AvatarShapeType }; |
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,18 @@ | ||
import { AvatarShapeType } from '@/types/user'; | ||
|
||
export const getAvatarSize = (avatarShape: AvatarShapeType['avatarShape']) => { | ||
switch (avatarShape) { | ||
case 'small': | ||
return '1.5rem'; | ||
case 'normal': | ||
return '4rem'; | ||
case 'rectangle': | ||
return '4.5rem'; | ||
case 'medium': | ||
return '6.875rem'; | ||
case 'large': | ||
return '16.3rem'; | ||
default: | ||
return '4rem'; | ||
} | ||
}; |
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.
@colorkite10 p1;
채연님도 onClick에 대한 타입 정의때문에 고민 많이 하셨을 것 같아요!
이렇게 하면 onClick의 타입을 HTMLDivElement에서 상속받아 사용할 수 있습니다!
1.HTMLDivElement 설명 https://developer.mozilla.org/ko/docs/Web/API/HTMLDivElement
2.HTMLDIvElement에 선언된 타입들
https://microsoft.github.io/PowerBI-JavaScript/interfaces/_node_modules_typedoc_node_modules_typescript_lib_lib_dom_d_.htmldivelement.html#onclick
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.
오옹~ 저도 활용해야겠군요! 꿀팁 감사합니다