Skip to content

Commit 61b5f95

Browse files
committed
Improvements nd fixes
1 parent 454a1f5 commit 61b5f95

File tree

4 files changed

+23
-9
lines changed

4 files changed

+23
-9
lines changed

site/src/components/Avatar/Avatar.stories.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Story } from "@storybook/react"
2-
import { Avatar, AvatarProps } from "./Avatar"
2+
import { Avatar, AvatarIcon, AvatarProps } from "./Avatar"
33
import PauseIcon from "@material-ui/icons/PauseOutlined"
44

55
export default {
@@ -53,3 +53,9 @@ MuiIconXL.args = {
5353
children: <PauseIcon />,
5454
size: "xl",
5555
}
56+
57+
export const AvatarIconDarken = Template.bind({})
58+
AvatarIconDarken.args = {
59+
children: <AvatarIcon src="/icon/database.svg" />,
60+
colorScheme: "darken",
61+
}

site/src/components/Avatar/Avatar.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import MuiAvatar, {
44
AvatarProps as MuiAvatarProps,
55
} from "@material-ui/core/Avatar"
66
import { makeStyles } from "@material-ui/core/styles"
7-
import { cloneElement, FC } from "react"
7+
import { FC } from "react"
88
import { combineClasses } from "util/combineClasses"
99
import { firstLetter } from "./firstLetter"
1010

@@ -40,9 +40,12 @@ export const Avatar: FC<AvatarProps> = ({
4040
)
4141
}
4242

43-
export const AvatarIcon: FC<{ children: JSX.Element }> = ({ children }) => {
43+
/**
44+
* Use it to make an img element behaves like a MaterialUI Icon component
45+
*/
46+
export const AvatarIcon: FC<{ src: string }> = ({ src }) => {
4447
const styles = useStyles()
45-
return cloneElement(children, { className: styles.avatarIcon })
48+
return <img src={src} alt="" className={styles.avatarIcon} />
4649
}
4750

4851
const useStyles = makeStyles((theme) => ({

site/src/components/Resources/ResourceAvatar.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,7 @@ export const ResourceAvatar: FC<ResourceAvatarProps> = ({ resource }) => {
3838

3939
return (
4040
<Avatar colorScheme="darken">
41-
<AvatarIcon>
42-
<img src={avatarSrc} alt="" />
43-
</AvatarIcon>
41+
<AvatarIcon src={avatarSrc} />
4442
</Avatar>
4543
)
4644
}

site/src/components/UserAvatar/UserAvatar.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,18 @@ import { FC } from "react"
44
export interface UserAvatarProps {
55
username: string
66
avatarURL?: string
7+
// It is needed to work with the AvatarGroup so it can pass the
8+
// MuiAvatarGroup-avatar className
9+
className?: string
710
}
811

9-
export const UserAvatar: FC<UserAvatarProps> = ({ username, avatarURL }) => {
12+
export const UserAvatar: FC<UserAvatarProps> = ({
13+
username,
14+
avatarURL,
15+
className,
16+
}) => {
1017
return (
11-
<Avatar title={username} src={avatarURL}>
18+
<Avatar title={username} src={avatarURL} className={className}>
1219
{username}
1320
</Avatar>
1421
)

0 commit comments

Comments
 (0)