Skip to content

Commit

Permalink
feat: improve avatar ts-docs
Browse files Browse the repository at this point in the history
  • Loading branch information
MrMaz committed Jul 15, 2024
1 parent 276ec58 commit 5965e5d
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 9 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,6 @@ dist
.idea

# generated docs
./docs
/docs
*storybook.log
storybook-static
/storybook-static
36 changes: 32 additions & 4 deletions packages/react-material-ui/src/components/Avatar/Avatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,46 @@ import Box from '@mui/material/Box';
import { Image } from './Styles';
import Text from '../Text';

type Props = {
/**
* Avatar component props.
*/
export type AvatarProps = {
/** Path or URL to image file */
src?: string;
/** Alternate attribute text */
alt?: string;
/** Size in pixels */
size?: number;
/** Optional and/or fallback initials to display with the avatar */
initials?: string;
/** Custom `onClick` handler */
onClick?: () => void;
/** Background color name or code */
backgroundColor?: string;
};

export const Avatar = (props: Props) => {
/**
* The Avatar component is a UI element used to display a user's
* profile picture or initials. It supports various features such as image
* source handling, fallbacks (e.g., initials or default image),
* and customization options for styling and sizes.
*
* @see [Storybook - Avatar](https://storybook.rockets.tools/?path=/docs/avatar)
*
* @example
* ```tsx
* <Avatar
* src="https://example.com/nonexistent.jpg"
* alt="Annabel B"
* initials="AB"
* size={40}
* backgroundColor="#789abc"
* />
* ```
*
* @param props - Avatar component props
*/
export const Avatar = (props: AvatarProps) => {
const { src, alt, size = 30, initials, backgroundColor, onClick } = props;
const [failed, setFailed] = useState(!src);

Expand Down Expand Up @@ -57,5 +87,3 @@ export const Avatar = (props: Props) => {
</Box>
);
};

export default Avatar;
2 changes: 1 addition & 1 deletion packages/react-material-ui/src/components/Avatar/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { default } from './Avatar';
export { Avatar, AvatarProps } from './Avatar';
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useState, ReactNode } from 'react';
import Box from '@mui/material/Box';
import Text from '../Text';
import Avatar from '../Avatar';
import { Avatar } from '../Avatar';
import { TextProps } from 'interfaces';
import ExpandMore from '@mui/icons-material/ExpandMore';
import Button from '@mui/material/Button';
Expand Down
2 changes: 1 addition & 1 deletion packages/react-material-ui/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export { default as Avatar } from './components/Avatar';
export { Avatar, AvatarProps } from './components/Avatar';
export { default as Checkbox } from './components/Checkbox';

import AppBar from './components/AppBar';
Expand Down

0 comments on commit 5965e5d

Please sign in to comment.