Skip to content
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
1 change: 1 addition & 0 deletions docs/pages/api/avatar-group.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ You can learn more about the difference by [reading this guide](/guides/minimizi
|:-----|:-----|:--------|:------------|
| <span class="prop-name">children</span> | <span class="prop-type">node</span> | | The avatars to stack. |
| <span class="prop-name">classes</span> | <span class="prop-type">object</span> | | Override or extend the styles applied to the component. See [CSS API](#css) below for more details. |
| <span class="prop-name">spacing</span> | <span class="prop-type">'medium'<br>&#124;&nbsp;'small'<br>&#124;&nbsp;number</span> | <span class="prop-default">'medium'</span> | Spacing between avatars. |

The `ref` is forwarded to the root element.

Expand Down
6 changes: 5 additions & 1 deletion packages/material-ui-lab/src/AvatarGroup/AvatarGroup.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@ export interface AvatarGroupProps
* The avatars to stack.
*/
children: React.ReactNode;
/**
* Spacing between avatars.
*/
spacing?: 'small' | 'medium' | number;
}

export type AvatarGroupClassKey = 'root' | 'avatar';

export default function AvatarGroup(props: AvatarGroupProps): JSX.Element | null;
export default function AvatarGroup(props: AvatarGroupProps): JSX.Element;
12 changes: 11 additions & 1 deletion packages/material-ui-lab/src/AvatarGroup/AvatarGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ import { isFragment } from 'react-is';
import clsx from 'clsx';
import { withStyles } from '@material-ui/core/styles';

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

export const styles = theme => ({
/* Styles applied to the root element. */
root: {
Expand All @@ -17,7 +22,7 @@ export const styles = theme => ({
});

const AvatarGroup = React.forwardRef(function AvatarGroup(props, ref) {
const { children: childrenProp, classes, className, ...other } = props;
const { children: childrenProp, classes, className, spacing = 'medium', ...other } = props;

const children = React.Children.toArray(childrenProp).filter(child => {
if (process.env.NODE_ENV !== 'production') {
Expand All @@ -41,6 +46,7 @@ const AvatarGroup = React.forwardRef(function AvatarGroup(props, ref) {
className: clsx(child.props.className, classes.avatar),
style: {
zIndex: children.length - index,
marginLeft: spacing && SPACINGS[spacing] !== undefined ? SPACINGS[spacing] : -spacing,
...child.props.style,
},
});
Expand All @@ -67,6 +73,10 @@ AvatarGroup.propTypes = {
* @ignore
*/
className: PropTypes.string,
/**
* Spacing between avatars.
*/
spacing: PropTypes.oneOfType([PropTypes.oneOf(['medium', 'small']), PropTypes.number]),
};

export default withStyles(styles, { name: 'MuiAvatarGroup' })(AvatarGroup);