-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/#11/component-avatar' of https://github.com/Tea…
…m-TenTen/LinkHub-FE into feature/#11/component-avatar
- Loading branch information
Showing
3 changed files
with
89 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { CSSProperties } from 'react' | ||
import Image from 'next/image' | ||
|
||
export interface AvatarProps { | ||
src: string | ||
width: number | ||
height: number | ||
alt: string | ||
style?: CSSProperties | ||
} | ||
|
||
const Avatar = ({ src, width, height, alt }: AvatarProps) => { | ||
return ( | ||
<div className="inline-block"> | ||
<Image | ||
src={src} | ||
width={width} | ||
height={height} | ||
alt={alt} | ||
className="rounded-full border border-gray-300 object-cover" | ||
/> | ||
</div> | ||
) | ||
} | ||
|
||
export default Avatar |
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,59 @@ | ||
import React from 'react' | ||
import { AvatarProps } from '../Avatar/Avatar' | ||
import { | ||
DEFAULT_LIMIT, | ||
DEFAULT_SIZE, | ||
MARGIN_LEFT_DIVIDE, | ||
PADDING_LEFT_DIVIDE, | ||
} from './constants' | ||
|
||
export interface AvatarGroupProps { | ||
children: React.ReactNode | ||
size?: number | ||
limit?: number | ||
} | ||
|
||
const AvatarGroup = ({ | ||
children, | ||
size = DEFAULT_SIZE, | ||
limit = DEFAULT_LIMIT, | ||
}: AvatarGroupProps) => { | ||
const allAvatars = React.Children.toArray(children) | ||
const avatars = React.Children.toArray(children) | ||
.filter((element): element is React.ReactElement<AvatarProps> => { | ||
return true | ||
}) | ||
.slice(0, limit) | ||
.map((avatar, index, avatars) => { | ||
return React.cloneElement(avatar, { | ||
style: { | ||
marginLeft: -size / MARGIN_LEFT_DIVIDE, | ||
zIndex: avatars.length - index, | ||
}, | ||
}) | ||
}) | ||
|
||
return ( | ||
<div className="flex items-center gap-0.5"> | ||
<div | ||
className="flex" | ||
style={{ paddingLeft: size / PADDING_LEFT_DIVIDE }}> | ||
{avatars.map((avatar) => ( | ||
<div | ||
className="flex" | ||
key={avatar.key} | ||
style={avatar.props.style}> | ||
{avatar} | ||
</div> | ||
))} | ||
</div> | ||
{allAvatars.length > limit && ( | ||
<div className="text-xs font-normal leading-4 text-gray-600"> | ||
+{allAvatars.length - limit}명 | ||
</div> | ||
)} | ||
</div> | ||
) | ||
} | ||
|
||
export default AvatarGroup |
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,4 @@ | ||
export const MARGIN_LEFT_DIVIDE = 7 | ||
export const PADDING_LEFT_DIVIDE = 7 | ||
export const DEFAULT_SIZE = 60 | ||
export const DEFAULT_LIMIT = 3 |