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

[Joy] Add AvatarGroup component #31980

Merged
merged 9 commits into from
Mar 27, 2022
Merged

Conversation

siriwatknp
Copy link
Member

@siriwatknp siriwatknp commented Mar 25, 2022

🖥 Preview


Inspired by #31958 (comment).

Get rid of internal calculation about the number of extra to show which give developers full control of the extra number logic. This approach would reduce a lot of edge cases problem because we don't use React.cloneElement anymore, developers can wrap with whatever they want. Thanks to CSS variables, we don't introduce any class selector which makes customization so easy.

// Material
<AvatarGroup max={4}>
  {items.map(() => <Avatar />}
</AvatarGroup>

// Joy
<AvatarGroup>
  {items.slice(0, 5).map(() => <Avatar />}
  <Avatar>+4</Avatar>
</AvatarGroup>

Benefits

Joy solves these existing issues:

  • [AvatarGroup] Add a prop for configuring the overlap #30789

    <AvatarGroup sx={{ flexDirection: 'row-reverse' }}>
      <Avatar>+3</Avatar>
      <Avatar src="/static/images/avatar/1.jpg" />
      <Avatar src="/static/images/avatar/2.jpg" />
      <Avatar src="/static/images/avatar/3.jpg" />
    </AvatarGroup>
  • [AvatarGroup] Clickable "ellipsis" #27677

    <AvatarGroup>
      <Avatar src="/static/images/avatar/1.jpg" />
      <Avatar src="/static/images/avatar/2.jpg" />
      <Avatar src="/static/images/avatar/3.jpg" />
      <IconButton
        color="neutral"
        onClick={() => alert('clicked')}
        sx={{
          borderRadius: '50%',
          marginInlineStart: 'var(--Avatar-marginInlineStart)',
          boxShadow: 'var(--Avatar-ring)',
        }}
      >
        <MoreVert />
      </IconButton>
    </AvatarGroup>
  • [AvatarGroup] Add the possibility to show a tooltip when using a group #31958

    <AvatarGroup variant="contained">
      <Avatar src="/static/images/avatar/1.jpg" />
      <Avatar src="/static/images/avatar/2.jpg" />
      <Avatar src="/static/images/avatar/3.jpg" />
      <Avatar
        onMouseEnter={(event) => setAnchorEl(event.currentTarget)}
        onMouseLeave={() => setAnchorEl(null)}
      >
        <Mouse />
        <PopperUnstyled
          open={Boolean(anchorEl)}
          anchorEl={anchorEl}
          disablePortal
          placement="right-start"
          style={{ zIndex: 1 }}
        >
          ...content
        </PopperUnstyled>
      </Avatar>
    </AvatarGroup>

Benchmark

Material Joy % change
Avatar 254 279 +9.84
AvatarGroup 222 131 -40.99
total 476 410 -13.87

@mui-bot
Copy link

mui-bot commented Mar 25, 2022

Details of bundle changes

@mui/joy: parsed: +1.23% , gzip: +0.97%

Generated by 🚫 dangerJS against 6e8d3f6

@siriwatknp siriwatknp added the package: joy-ui Specific to @mui/joy label Mar 25, 2022
Copy link
Contributor

@danilo-leal danilo-leal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks amazing, excellent work!

@siriwatknp siriwatknp merged commit a6875dd into mui:master Mar 27, 2022
@oliviertassinari oliviertassinari added the component: avatar This is the name of the generic UI component, not the React module! label Mar 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: avatar This is the name of the generic UI component, not the React module! package: joy-ui Specific to @mui/joy
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants