Skip to content

Commit

Permalink
Merge pull request #64 from tulup-conner/feature/avatar-alt-text
Browse files Browse the repository at this point in the history
feat(component): Add `alt` attribute to `Avatar`s
  • Loading branch information
bacali95 authored Apr 26, 2022
2 parents 8d7cbd8 + b619076 commit d056bec
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/components/Avatar/Avatar.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ const Template: Story<AvatarProps> = (args) => <Avatar {...args} />;
export const DefaultAvatar = Template.bind({});
DefaultAvatar.storyName = 'Default';
DefaultAvatar.args = {
alt: 'Your avatar',
img: 'https://flowbite.com/docs/images/people/profile-picture-5.jpg',
};
4 changes: 3 additions & 1 deletion src/components/Avatar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { AvatarGroup } from './AvatarGroup';
import { AvatarGroupCounter } from './AvatarGroupCounter';

export type AvatarProps = PropsWithChildren<{
alt?: string;
size?: 'xs' | 'sm' | 'md' | 'lg' | 'xl';
rounded?: boolean;
bordered?: boolean;
Expand Down Expand Up @@ -36,6 +37,7 @@ const statusPositionClasses: Record<AvatarProps['statusPosition'] & string, stri
};

const AvatarComponent: FC<AvatarProps> = ({
alt = '',
img,
status,
children,
Expand All @@ -57,7 +59,7 @@ const AvatarComponent: FC<AvatarProps> = ({
'p-1': bordered,
})}
src={img}
alt="Rounded avatar"
alt={alt}
/>
) : (
<div
Expand Down
10 changes: 10 additions & 0 deletions src/pages/AvatarPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,16 @@ const AvatarPage: FC = () => {
</div>
),
},
{
title: 'Alternative text',
code: (
<Avatar
alt="Default avatar with alt text"
img="https://flowbite.com/docs/images/people/profile-picture-5.jpg"
rounded
/>
),
},
];

return <DemoPage examples={examples} />;
Expand Down

0 comments on commit d056bec

Please sign in to comment.