-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
909db7c
commit 82e1c67
Showing
10 changed files
with
171 additions
and
141 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,39 @@ | ||
import { CSSObject, useTheme } from '@emotion/react' | ||
import { Artwork, ArtworkProps } from '../artwork' | ||
|
||
import type { AvatarProps } from './types' | ||
type ArtworkInnerProps = Omit<ArtworkProps, 'borderWidth'> | ||
|
||
/* | ||
* The Avatar component is a visual indicator used to quickly identify a | ||
* user’s account. | ||
*/ | ||
export const Avatar = (props: AvatarProps) => { | ||
const { | ||
src, | ||
strokeWidth = 'default', | ||
size = 'auto', | ||
variant = 'default', | ||
className, | ||
children | ||
} = props | ||
const { color } = useTheme() | ||
|
||
const sizeMap = { | ||
auto: '100%', | ||
small: '24px', | ||
medium: '40px', | ||
large: '72px', | ||
xl: '80px' | ||
} | ||
export type AvatarProps = ArtworkInnerProps & { | ||
variant?: 'default' | 'strong' | ||
size?: 'auto' | 'small' | 'medium' | 'large' | 'xl' | 'xxl' | ||
borderWidth?: 'thin' | 'default' | ||
} | ||
|
||
const strokeWidthMap = { | ||
thin: '1.2px', | ||
default: '2px' | ||
} | ||
const sizeMap = { | ||
auto: '100%', | ||
small: 24, | ||
medium: 40, | ||
large: 72, | ||
xl: 80, | ||
xxl: 120 | ||
} | ||
|
||
const rootCss: CSSObject = { | ||
height: sizeMap[size], | ||
width: sizeMap[size], | ||
overflow: 'hidden', | ||
borderRadius: 'calc(infinity * 1px)', | ||
border: `${strokeWidthMap[strokeWidth]} solid ${color.border.default}`, | ||
boxSizing: 'border-box', | ||
boxShadow: | ||
variant === 'strong' | ||
? '0px 0.5px 1.5px 0px rgba(0, 0, 0, 0.03), 0px 1.5px 5px 0px rgba(0, 0, 0, 0.08), 0px 6px 15px 0px rgba(0, 0, 0, 0.10)' | ||
: 'none', | ||
backgroundColor: color.neutral.n400, | ||
position: 'relative', | ||
zIndex: 1 | ||
} | ||
const borderWidthMap = { | ||
thin: 1.2, | ||
default: 2 | ||
} | ||
|
||
const imgCss: CSSObject = { | ||
height: sizeMap[size], | ||
width: sizeMap[size], | ||
backgroundImage: src ? `url(${src})` : undefined, | ||
backgroundColor: src ? 'unset' : color.neutral.n400, | ||
backgroundSize: 'cover', | ||
zIndex: 1, | ||
display: 'flex', | ||
alignItems: 'center', | ||
justifyContent: 'center' | ||
} | ||
export const Avatar = (props: AvatarProps) => { | ||
const { variant, size = 'auto', borderWidth = 'default', ...other } = props | ||
|
||
return ( | ||
<div css={rootCss} className={className}> | ||
<div css={imgCss}>{children}</div> | ||
</div> | ||
<Artwork | ||
borderRadius='circle' | ||
h={sizeMap[size]} | ||
w={sizeMap[size]} | ||
shadow={variant === 'strong' ? 'emphasis' : 'flat'} | ||
borderWidth={borderWidthMap[borderWidth]} | ||
css={variant === 'strong' ? { zIndex: 1 } : undefined} | ||
{...other} | ||
/> | ||
) | ||
} |
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
export { Avatar } from './Avatar' | ||
export * from './types' | ||
export type { AvatarProps } from './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
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
Oops, something went wrong.