Skip to content

Commit

Permalink
Update UserAvatar and docs to accept arbitrary props
Browse files Browse the repository at this point in the history
  • Loading branch information
Justin Campbell committed Oct 20, 2020
1 parent 8144304 commit f3d742a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
10 changes: 5 additions & 5 deletions src/components/UserAvatar/UserAvatar.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@ import React from "react";
import PropTypes from "prop-types";
import { Avatar } from "@material-ui/core";

export default function UserAvatar({ userName }){
export default function UserAvatar({ name, ...avatarProps }){

return(
<Avatar>
{userName === "" ? null : userName.charAt(0)}
<Avatar {...avatarProps}>
{name === "" ? null : name.charAt(0)}
</Avatar>
);
};

UserAvatar.propTypes = {
/** The name of the user. */
"userName": PropTypes.string
"name": PropTypes.string
};

UserAvatar.defaultProps = {
"userName": ""
"name": ""
};
29 changes: 21 additions & 8 deletions src/components/UserAvatar/UserAvatar.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,36 @@
The UserAvatar displays a graphical representation of a person and is meant to be used in conjunction with other identifiers like names or emails.
The UserAvatar displays a graphical representation of a person.

---

The UserAvatar will the first letter of the `userName` prop.
## Default Usage
Used without any props, the UserAvatar will display a generic person icon.
```jsx
import UserAvatar from "./UserAvatar";
<UserAvatar userName="Justin Campbell" />
```

<UserAvatar />
```
```jsx static
<UserAvatar userName="Justin Campbell" />
<UserAvatar />
```

If no value, a null value, or an empty string is passed to the UserAvatar, it will fall back to a generic icon.
## With A Name
If the `name` prop is passed, the UserAvatar will display the first letter of the name.
```jsx
import UserAvatar from "./UserAvatar";
<UserAvatar />

<UserAvatar name="Jane Doe" />
```
```jsx static
<UserAvatar name="Jane Doe" />
```

## Other Props
All props other than `name` are passed to the underlying [MUI Avatar component](https://material-ui.com/api/avatar/).
```jsx
import UserAvatar from "./UserAvatar";

<UserAvatar name="Jane Doe" variant="square" />
```
```jsx static
<UserAvatar />
<UserAvatar name="Jane Doe" variant="square" />
```

0 comments on commit f3d742a

Please sign in to comment.