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

[material-ui][AvatarGroup] Convert to support CSS extraction #41485

Merged
merged 7 commits into from
Mar 20, 2024
Merged
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
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',
zanivan marked this conversation as resolved.
Show resolved Hide resolved
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
Loading