Skip to content

Commit

Permalink
Add Avatar outline variant
Browse files Browse the repository at this point in the history
  • Loading branch information
ghsteff committed Apr 24, 2024
1 parent 575dae0 commit a9ae66c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/elements/Avatar/Avatar.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ Default.args = {
rounded: false
};

export const Outline = Template.bind({});
Outline.args = {
name: 'John Doe',
size: 50,
rounded: false,
variant: 'outline'
};

export const RoundedWithImage = Template.bind({});
RoundedWithImage.args = {
src: 'https://goodcode.us/static/austin-d1a2c5249336c31662b8ee6d4e169b2b.jpg',
Expand Down
16 changes: 14 additions & 2 deletions src/elements/Avatar/Avatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ export interface AvatarProps extends React.HTMLAttributes<HTMLDivElement> {
*/
size?: number;

/**
* Style variant for the avatar.
*/
variant?: 'filled' | 'outline';

/**
* Whether the avatar is rounded.
*/
Expand Down Expand Up @@ -53,6 +58,7 @@ export const Avatar = React.forwardRef<HTMLDivElement, AvatarProps>(
src,
color,
size,
variant,
rounded,
className,
colorOptions,
Expand Down Expand Up @@ -88,7 +94,12 @@ export const Avatar = React.forwardRef<HTMLDivElement, AvatarProps>(
height: `${size}px`,
fontSize: `${fontSize}px`,
backgroundImage: src ? `url(${src})` : 'none',
backgroundColor
backgroundColor,
...(variant === 'outline' && {
backgroundColor: 'transparent',
border: `solid 1px ${backgroundColor}`,
color: backgroundColor
})
}}
ref={ref}
>
Expand All @@ -100,5 +111,6 @@ export const Avatar = React.forwardRef<HTMLDivElement, AvatarProps>(

Avatar.defaultProps = {
size: 24,
rounded: true
rounded: true,
variant: 'filled'
};

0 comments on commit a9ae66c

Please sign in to comment.