Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(avatar): add status indicator support in avatar #2442

Draft
wants to merge 4 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 34 additions & 9 deletions core/components/atoms/avatar/Avatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import AvatarImage from './avatarImage';
import AvatarProvider from './AvatarProvider';

type TPresence = 'active' | 'away';

export interface AvatarProps extends BaseProps {
/**
* Color of the `Avatar`
Expand Down Expand Up @@ -57,6 +59,10 @@
* Defines tabIndex of the `Avatar`
*/
tabIndex?: number;
/**
* Show presence indicator for the `Avatar`
*/
presence?: TPresence;
}

const initialsLength = 2;
Expand All @@ -77,6 +83,7 @@
disabled,
tooltipSuffix,
tabIndex,
presence,
role = 'presentation',
} = props;

Expand Down Expand Up @@ -127,6 +134,18 @@
['Avatar-content']: darkAppearance.includes(AvatarAppearance),
});

const presenceClassNames = classNames({
['Avatar-presence']: presence,
['d-none']: shape !== 'round' || disabled,
['Avatar-presence--active']: presence === 'active',
['Avatar-presence--away']: presence === 'away',
});

const statusHintClassName = classNames({
['Avatar-statusHint']: true,
['d-none']: shape !== 'round' || size !== 'regular',
});

const sharedProp = {
size,
firstName,
Expand Down Expand Up @@ -180,17 +199,23 @@
);
};

const renderTooltip = () => {
if (withTooltip && initials) {
return (
<Tooltip tooltip={getTooltipName()} position={tooltipPosition} triggerClass={'flex-grow-0'}>
const renderTooltip = () => (
<span className="position-relative d-inline-flex">
{withTooltip && initials ? (
<Tooltip tooltip={getTooltipName()} position={tooltipPosition} triggerClass="flex-grow-0">
{renderAvatar()}
</Tooltip>
);
}

return renderAvatar();
};
) : (
renderAvatar()
)}
{presence && <span className={presenceClassNames} />}
<span className={statusHintClassName}>
<Tooltip tooltip='verified'>

Check failure on line 213 in core/components/atoms/avatar/Avatar.tsx

View workflow job for this annotation

GitHub Actions / lint, test and build

Replace `'verified'` with `"verified"`
<Icon name="done" size={12} appearance="white" type="rounded" className='bg-warning' />

Check failure on line 214 in core/components/atoms/avatar/Avatar.tsx

View workflow job for this annotation

GitHub Actions / lint, test and build

Replace `'bg-warning'` with `"bg-warning"`
</Tooltip>
</span>
</span>
);

return renderTooltip();
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import * as React from 'react';
import { Avatar, Row, Column, Text } from '@/index';

// CSF format story
export const presence = () => {
const weight = 'strong';

return (
<Row className="w-50">
<Column>
<Text weight={weight}>Active</Text>
<br />
<br />
<Avatar firstName="John" lastName="Doe" presence="active" />
</Column>
<Column>
<Text weight={weight}>Away</Text>
<br />
<br />
<Avatar firstName="John" lastName="Doe" presence="away" />
</Column>
</Row>
);
};

export default {
title: 'Components/Avatar/Avatar/Variants/Presence',
component: Avatar,
parameters: {
docs: {
docPage: {
title: 'Avatar',
},
},
},
};
32 changes: 32 additions & 0 deletions css/src/components/avatar.css
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,35 @@
opacity: var(--opacity-20);
mix-blend-mode: multiply;
}

.Avatar-presence {
position: absolute;
border-radius: 50%;
width: var(--spacing);
height: var(--spacing);
box-shadow: 0 0 0 var(--spacing-s) var(--white);
right: 0;
bottom: 0;
}

.Avatar-presence--active {
background: var(--success);
}

.Avatar-presence--away {
background: var(--secondary-dark);
}

.Avatar-statusHint {
top: -2px;
right: -2px;
width: 12px;
height: 12px;
border-radius: 50%;
box-shadow: 0 0 0 2px red;
display: flex;
align-items: center;
justify-content: center;
background: green;
position: absolute;
}
Loading