-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1433 from narmi/avatar
feat(Avatar): Implement Avatar Component
- Loading branch information
Showing
6 changed files
with
120 additions
and
1 deletion.
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 @@ | ||
.nds-avatar { | ||
color: white; | ||
border-radius: 50%; | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
position: relative; | ||
text-transform: uppercase; | ||
} | ||
|
||
.nds-avatar--xs { | ||
height: rem(24px); | ||
width: rem(24px); | ||
font-size: var(--font-size-s); | ||
} | ||
|
||
.nds-avatar--s { | ||
height: rem(32px); | ||
width: rem(32px); | ||
} | ||
|
||
.nds-avatar--m { | ||
height: rem(40px); | ||
width: rem(40px); | ||
font-size: var(--font-size-l); | ||
} |
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,41 @@ | ||
import React from "react"; | ||
import Avatar from "./"; | ||
import Row from "../Row"; | ||
|
||
export const Overview = () => { | ||
return <Avatar initials="CP" label="Christian Paz" />; | ||
}; | ||
|
||
export const WithImage = () => { | ||
return ( | ||
<Avatar | ||
imgurl="https://media.licdn.com/dms/image/v2/D4E0BAQHnVTkZjhvlQg/company-logo_200_200/company-logo_200_200/0/1680295112021?e=2147483647&v=beta&t=-4A2TRSHuDiBT_anhoqTULvjXfzVh7_vZApmdXUVzsc" | ||
label="Narmi linked in logo" | ||
/> | ||
); | ||
}; | ||
|
||
export const WithLink = () => { | ||
return <Avatar initials="NM" label="Narmi" linkurl="https://narmi.com" />; | ||
}; | ||
|
||
export const Sizes = () => { | ||
return ( | ||
<Row> | ||
<Row.Item> | ||
<Avatar initials="xs" label="extra small" size="xs" /> | ||
</Row.Item> | ||
<Row.Item> | ||
<Avatar initials="s" label="small" size="s" /> | ||
</Row.Item> | ||
<Row.Item> | ||
<Avatar initials="m" label="medium" size="m" /> | ||
</Row.Item> | ||
</Row> | ||
); | ||
}; | ||
|
||
export default { | ||
title: "Components/Avatar", | ||
component: 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,47 @@ | ||
import React from "react"; | ||
import cc from "classcat"; | ||
import AsElement from "../util/AsElement"; | ||
|
||
export interface AvatarProps { | ||
/** aria-label for accessibility */ | ||
label: string; | ||
/** Fixed height and width of the avatar. Default: "s". */ | ||
size?: "xs" | "s" | "m"; | ||
/** String to display in the avatar. If imgurl is provided, this will be ignored. */ | ||
initials?: string; | ||
/** Optional: URL of the image to display in the avatar. If provided, initials will be ignored. */ | ||
imgurl?: string; | ||
/** Optional: URL to navigate to when the avatar is clicked */ | ||
linkurl?: string; | ||
} | ||
|
||
const Avatar = ({ | ||
label, | ||
size = "s", | ||
initials, | ||
imgurl, | ||
linkurl, | ||
}: AvatarProps) => { | ||
const backgroundImage = imgurl | ||
? { backgroundImage: `url(${imgurl})`, backgroundSize: "cover" } | ||
: {}; | ||
|
||
return ( | ||
<AsElement | ||
elementType={linkurl ? "a" : "div"} | ||
href={linkurl} | ||
className={cc([ | ||
"nds-avatar", | ||
`nds-avatar--${size}`, | ||
"alignChild--center--center", | ||
"bgColor--theme--primary", | ||
])} | ||
style={backgroundImage} | ||
aria-label={label} | ||
> | ||
{initials} | ||
</AsElement> | ||
); | ||
}; | ||
|
||
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
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