Skip to content

Commit

Permalink
feat(avatars): split avatars click handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
Selnapenek committed Jan 25, 2021
1 parent 0f112c4 commit d26174e
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/components/Avatars/Avatars.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ type AvatarsProps = {
lastName: string,
avatarUrl: string,
}>,
onClick: Function,
onAvatarsClick?: Function,
onCounterClick?: Function,
onPlusClick?: Function,
};

const tooltipClassName = css`
Expand All @@ -30,13 +32,21 @@ const avatarClassName = css`
cursor: pointer;
`;

const Avatars = ({ users, size, onClick, ...rest }: AvatarsProps) => {
const Avatars = ({
users,
size,
onAvatarsClick,
onCounterClick,
onPlusClick,
...rest
}: AvatarsProps) => {
return (
<AvatarsTag { ...rest } tagName="div" onClick={ onClick }>
<AvatarsTag { ...rest } tagName="div">
{ React.Children.toArray(
users.slice(0, 4).map(({ firstName, lastName, avatarUrl }, index) => (
<Tooltip css={ css(tooltipClassName) } message={ `${firstName} ${lastName}` }>
<Avatar
onClick={ onAvatarsClick }
css={ css(avatarClassName) }
style={{ zIndex: Math.abs(index - 7) }}
firstName={ firstName }
Expand All @@ -49,9 +59,9 @@ const Avatars = ({ users, size, onClick, ...rest }: AvatarsProps) => {
) }

<If condition={ users.length > 4 }>
<AvatarsCounterTag size={ size }>+ { users.length - 4 }</AvatarsCounterTag>
<AvatarsCounterTag onClick={ onCounterClick } size={ size }>+ { users.length - 4 }</AvatarsCounterTag>
</If>
<AvatarsHandleTag size={ size }>
<AvatarsHandleTag onClick={ onPlusClick } size={ size }>
<Icon name="Plus" size="xs" color="PRIMARY" />
</AvatarsHandleTag>
</AvatarsTag>
Expand Down

0 comments on commit d26174e

Please sign in to comment.