Skip to content

Commit

Permalink
Merge pull request #2506 from anuradha9712/feat-avatar-selection-stat…
Browse files Browse the repository at this point in the history
…us-presence-support

feat(avatarSelection): add status & presence support in avatar selection
  • Loading branch information
samyak3009 authored Jan 22, 2025
2 parents e15998d + 007425d commit f14dc9b
Show file tree
Hide file tree
Showing 9 changed files with 532 additions and 36 deletions.
2 changes: 1 addition & 1 deletion core/components/atoms/avatar/Avatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export const Avatar = (props: AvatarProps) => {
appearance || colors[(initials.charCodeAt(0) + (initials.charCodeAt(1) || 0)) % 8] || DefaultAppearance;

const darkAppearance = ['secondary', 'success', 'warning', 'accent1', 'accent4'];
const showPresence = presence && !disabled && shape === 'round';
const showPresence = presence && !disabled && shape === 'round' && (presence === 'active' || presence === 'away');
const showStatus = status && size === 'regular' && shape === 'round';

const AvatarClassNames = classNames(
Expand Down
2 changes: 1 addition & 1 deletion core/components/atoms/avatarGroup/AvatarGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export interface AvatarGroupProps extends BaseProps {
* disabled?: boolean;
* tooltipSuffix?: string;
* status?: React.ReactNode;
* presence?: AvatarProps['presence'];
* presence?: 'active' | 'away';
* }
* </pre>
*
Expand Down
19 changes: 18 additions & 1 deletion core/components/atoms/avatarSelection/AvatarSelection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ export interface AvatarData extends Record<string, any> {
selected?: boolean;
disabled?: boolean;
tooltipSuffix?: string;
status?: React.ReactNode;
presence?: AvatarProps['presence'];
}

export interface AvatarSelectionProps extends BaseProps {
Expand All @@ -42,9 +44,24 @@ export interface AvatarSelectionProps extends BaseProps {
* selected?: boolean;
* disabled?: boolean;
* tooltipSuffix?: string;
* status?: React.ReactNode;
* presence?: 'active' | 'away';
* }
* </pre>
*
* | Name | Description | Default |
* | --- | --- | --- |
* | `firstName` | First name of the user | - |
* | `lastName` | Last name of the user | - |
* | `appearance` | Appearance of the avatar | - |
* | `icon` | Icon to be rendered | - |
* | `image` | Image to be rendered | - |
* | `selected` | Determines if the avatar is selected | - |
* | `disabled` | Determines if the avatar is disabled | - |
* | `tooltipSuffix` | Text to be shown in the tooltip | - |
* | `status` | Status to be shown in Regular Round Avatar | - |
* | `presence` | Presence of the user | - |
*
*/
list: AvatarData[];
/**
Expand Down Expand Up @@ -259,7 +276,7 @@ AvatarSelection.defaultProps = {
tooltipPosition: 'bottom',
borderColor: 'white',
size: 'regular',
width: 176,
width: 256,
maxHeight: 256,
};

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
import * as React from 'react';
import { action } from '@/utils/action';
import { AvatarSelection, Avatar, Input } from '@/index';

export const withPresence = () => {
const list = [
{
firstName: 'John',
lastName: 'Doe',
selected: true,
},
{
firstName: 'Anuradha',
lastName: 'Aggarwal',
image: <Avatar.Image src="https://design.innovaccer.com/images/avatar2.jpeg" />,
presence: 'active',
},
{
firstName: 'Nancy',
lastName: 'Wheeler',
},
{
firstName: 'Monica',
lastName: 'Geller',
presence: 'away',
},
{
firstName: 'Arya',
lastName: 'Stark',
},
{
firstName: 'Rachel',
lastName: 'Green',
icon: <Avatar.Icon name="person" />,
},
{
firstName: 'Satyam',
lastName: 'Yadav',
selected: true,
presence: 'away',
image: <Avatar.Image src="https://design.innovaccer.com/images/avatar1.png" />,
},
{
firstName: 'Walter',
lastName: 'Wheeler',
selected: true,
},
{
firstName: 'Monica',
lastName: 'Geller',
},
{
firstName: 'Arya',
lastName: 'Stark',
presence: 'away',
},
];

const onSelectHandler = (props) => {
action('props', props)();
};

const searchComparator = (searchValue, data) => {
if (searchValue === '') {
return true;
}
return data.firstName.toLowerCase().includes(searchValue.toLowerCase());
};

return (
<AvatarSelection
list={list}
withSearch={true}
onSelect={onSelectHandler}
searchPlaceholder="Search User"
searchComparator={searchComparator}
/>
);
};

const customCode = `() => {
const list = [
{
firstName: 'John',
lastName: 'Doe',
selected: true,
},
{
firstName: 'Anuradha',
lastName: 'Aggarwal',
image: <Avatar.Image src="https://design.innovaccer.com/images/avatar2.jpeg" />,
presence: 'active',
},
{
firstName: 'Nancy',
lastName: 'Wheeler',
},
{
firstName: 'Monica',
lastName: 'Geller',
presence: 'away',
},
{
firstName: 'Arya',
lastName: 'Stark',
},
{
firstName: 'Rachel',
lastName: 'Green',
icon: <Avatar.Icon name="person" />,
},
{
firstName: 'Satyam',
lastName: 'Yadav',
selected: true,
presence: 'away',
image: <Avatar.Image src="https://design.innovaccer.com/images/avatar1.png" />,
},
{
firstName: 'Walter',
lastName: 'Wheeler',
selected: true,
},
{
firstName: 'Monica',
lastName: 'Geller',
},
{
firstName: 'Arya',
lastName: 'Stark',
presence: 'away',
},
];
const onSelectHandler = (props) => {
console.log('props', props);
};
const searchComparator = (searchValue, data) => {
if (searchValue === '') {
return true;
}
return data.firstName.toLowerCase().includes(searchValue.toLowerCase());
};
return (
<AvatarSelection
list={list}
withSearch={true}
onSelect={onSelectHandler}
searchPlaceholder="Search User"
searchComparator={searchComparator}
/>
);
}`;

export default {
title: 'Components/Avatar/AvatarSelection/With Presence',
component: AvatarSelection,
subcomponents: {
'AvatarSelection.Input': Input,
'AvatarSelection.List': AvatarSelection.List,
'AvatarSelection.Option': AvatarSelection.Option,
'AvatarSelection.EmptyState': AvatarSelection.EmptyState,
},
parameters: {
docs: {
docPage: {
customCode,
},
},
},
};
Loading

0 comments on commit f14dc9b

Please sign in to comment.