-
-
Notifications
You must be signed in to change notification settings - Fork 658
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
--------- Co-authored-by: Thomas Heartman <thomas@getunleash.io>
- Loading branch information
1 parent
3978c69
commit b6865a5
Showing
24 changed files
with
428 additions
and
265 deletions.
There are no files selected for viewing
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
128 changes: 128 additions & 0 deletions
128
.../src/component/admin/groups/GroupsList/GroupCard/GroupCardAvatars/NewGroupCardAvatars.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
import { styled } from '@mui/material'; | ||
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender'; | ||
import type { IGroupUser } from 'interfaces/group'; | ||
import type React from 'react'; | ||
import { type ReactNode, useMemo, useState } from 'react'; | ||
import { GroupPopover } from './GroupPopover/GroupPopover'; | ||
import { UserAvatar } from 'component/common/UserAvatar/UserAvatar'; | ||
import { objectId } from 'utils/objectId'; | ||
|
||
const StyledContainer = styled('div')(() => ({ | ||
display: 'flex', | ||
flexDirection: 'column', | ||
})); | ||
|
||
const StyledAvatars = styled('div')(({ theme }) => ({ | ||
display: 'inline-flex', | ||
alignItems: 'center', | ||
flexWrap: 'wrap', | ||
marginLeft: theme.spacing(1), | ||
})); | ||
|
||
const StyledAvatar = styled(UserAvatar)(({ theme }) => ({ | ||
outline: `${theme.spacing(0.25)} solid ${theme.palette.background.paper}`, | ||
marginLeft: theme.spacing(-1), | ||
'&:hover': { | ||
outlineColor: theme.palette.primary.main, | ||
}, | ||
})); | ||
|
||
const StyledUsername = styled('div')(({ theme }) => ({ | ||
fontSize: theme.typography.body2.fontSize, | ||
color: theme.palette.text.primary, | ||
marginLeft: theme.spacing(1), | ||
})); | ||
|
||
const StyledHeader = styled('h3')(({ theme }) => ({ | ||
margin: theme.spacing(0, 0, 1), | ||
fontSize: theme.typography.caption.fontSize, | ||
color: theme.palette.text.primary, | ||
fontWeight: theme.typography.fontWeightRegular, | ||
})); | ||
|
||
interface IGroupCardAvatarsProps { | ||
users: { | ||
name: string; | ||
description?: string; | ||
imageUrl?: string; | ||
}[]; | ||
header?: ReactNode; | ||
} | ||
|
||
export const GroupCardAvatars = ({ | ||
users = [], | ||
header = null, | ||
}: IGroupCardAvatarsProps) => { | ||
const shownUsers = useMemo( | ||
() => | ||
users | ||
.sort((a, b) => { | ||
if ( | ||
Object.hasOwn(a, 'joinedAt') && | ||
Object.hasOwn(b, 'joinedAt') | ||
) { | ||
return ( | ||
(b as IGroupUser)?.joinedAt!.getTime() - | ||
(a as IGroupUser)?.joinedAt!.getTime() | ||
); | ||
} | ||
return 0; | ||
}) | ||
.slice(0, 9), | ||
[users], | ||
); | ||
|
||
const [anchorEl, setAnchorEl] = useState<HTMLElement | null>(null); | ||
const [popupUser, setPopupUser] = useState<{ | ||
name: string; | ||
description?: string; | ||
imageUrl?: string; | ||
}>(); | ||
|
||
const onPopoverOpen = (event: React.MouseEvent<HTMLElement>) => { | ||
setAnchorEl(event.currentTarget); | ||
}; | ||
|
||
const onPopoverClose = () => { | ||
setAnchorEl(null); | ||
}; | ||
|
||
const avatarOpen = Boolean(anchorEl); | ||
|
||
return ( | ||
<StyledContainer> | ||
<ConditionallyRender | ||
condition={typeof header === 'string'} | ||
show={<StyledHeader>{header}</StyledHeader>} | ||
elseShow={header} | ||
/> | ||
<StyledAvatars> | ||
{shownUsers.map((user) => ( | ||
<StyledAvatar | ||
key={objectId(user)} | ||
user={{ ...user, id: objectId(user) }} | ||
onMouseEnter={(event) => { | ||
onPopoverOpen(event); | ||
setPopupUser(user); | ||
}} | ||
onMouseLeave={onPopoverClose} | ||
/> | ||
))} | ||
<ConditionallyRender | ||
condition={users.length > 9} | ||
show={ | ||
<StyledAvatar> | ||
+{users.length - shownUsers.length} | ||
</StyledAvatar> | ||
} | ||
/> | ||
<GroupPopover | ||
open={avatarOpen} | ||
user={popupUser} | ||
anchorEl={anchorEl} | ||
onPopoverClose={onPopoverClose} | ||
/> | ||
</StyledAvatars> | ||
</StyledContainer> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.