Skip to content

Commit

Permalink
[material-ui][AvatarGroup] Convert to support CSS extraction (#41485)
Browse files Browse the repository at this point in the history
  • Loading branch information
zanivan authored Mar 20, 2024
1 parent d37dd5c commit f6a89c1
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 26 deletions.
10 changes: 5 additions & 5 deletions apps/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 28 additions & 21 deletions packages/mui-material/src/AvatarGroup/AvatarGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@ import { isFragment } from 'react-is';
import clsx from 'clsx';
import chainPropTypes from '@mui/utils/chainPropTypes';
import composeClasses from '@mui/utils/composeClasses';
import styled from '../styles/styled';
import useThemeProps from '../styles/useThemeProps';
import { styled, createUseThemeProps } from '../zero-styled';
import Avatar, { avatarClasses } from '../Avatar';
import avatarGroupClasses, { getAvatarGroupUtilityClass } from './avatarGroupClasses';

const SPACINGS = {
small: -16,
medium: null,
medium: -8,
};

const useThemeProps = createUseThemeProps('MuiAlert');

const useUtilityClasses = (ownerState) => {
const { classes } = ownerState;

Expand All @@ -33,25 +34,18 @@ const AvatarGroupRoot = styled('div', {
[`& .${avatarGroupClasses.avatar}`]: styles.avatar,
...styles.root,
}),
})(({ theme, ownerState }) => {
const marginValue =
ownerState.spacing && SPACINGS[ownerState.spacing] !== undefined
? SPACINGS[ownerState.spacing]
: -ownerState.spacing;

return {
[`& .${avatarClasses.root}`]: {
border: `2px solid ${(theme.vars || theme).palette.background.default}`,
boxSizing: 'content-box',
marginLeft: marginValue ?? -8,
'&:last-child': {
marginLeft: 0,
},
})(({ theme }) => ({
display: 'flex',
flexDirection: 'row-reverse',
[`& .${avatarClasses.root}`]: {
border: `2px solid ${(theme.vars || theme).palette.background.default}`,
boxSizing: 'content-box',
marginLeft: 'var(--AvatarGroup-spacing, -8px)',
'&:last-child': {
marginLeft: 0,
},
display: 'flex',
flexDirection: 'row-reverse',
};
});
},
}));

const AvatarGroup = React.forwardRef(function AvatarGroup(inProps, ref) {
const props = useThemeProps({
Expand Down Expand Up @@ -113,6 +107,11 @@ const AvatarGroup = React.forwardRef(function AvatarGroup(inProps, ref) {

const additionalAvatarSlotProps = slotProps.additionalAvatar ?? componentsProps.additionalAvatar;

const marginValue =
ownerState.spacing && SPACINGS[ownerState.spacing] !== undefined
? SPACINGS[ownerState.spacing]
: -ownerState.spacing || -8;

return (
<AvatarGroupRoot
as={component}
Expand All @@ -126,6 +125,10 @@ const AvatarGroup = React.forwardRef(function AvatarGroup(inProps, ref) {
variant={variant}
{...additionalAvatarSlotProps}
className={clsx(classes.avatar, additionalAvatarSlotProps?.className)}
style={{
'--AvatarRoot-spacing': marginValue ? `${marginValue}px` : undefined,
...other.style,
}}
>
{extraAvatarsElement}
</Avatar>
Expand Down Expand Up @@ -215,6 +218,10 @@ AvatarGroup.propTypes /* remove-proptypes */ = {
* @default 'medium'
*/
spacing: PropTypes.oneOfType([PropTypes.oneOf(['medium', 'small']), PropTypes.number]),
/**
* @ignore
*/
style: PropTypes.object,
/**
* The system prop that allows defining system overrides as well as additional CSS styles.
*/
Expand Down

0 comments on commit f6a89c1

Please sign in to comment.