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

[AvatarGroup] Add spacing prop #19761

Merged
merged 8 commits into from
Feb 19, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 2 additions & 0 deletions docs/pages/api/avatar-group.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ 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">'small'<br>&#124;&nbsp;'medium'<br>&#124;&nbsp;'large</span> | | Defines the spacing between `avatar` as `'large': -4px`, `'medium': -8px`, and `'small': -16px`. |


The `ref` is forwarded to the root element.

Expand Down
4 changes: 4 additions & 0 deletions packages/material-ui-lab/src/AvatarGroup/AvatarGroup.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ export interface AvatarGroupProps
* The avatars to stack.
*/
children: React.ReactNode;
/**
* Spacing between avatars
oliviertassinari marked this conversation as resolved.
Show resolved Hide resolved
*/
spacing?: 'small' | 'medium' | 'large';
oliviertassinari marked this conversation as resolved.
Show resolved Hide resolved
}

export type AvatarGroupClassKey = 'root' | 'avatar';
Expand Down
11 changes: 8 additions & 3 deletions packages/material-ui-lab/src/AvatarGroup/AvatarGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { isFragment } from 'react-is';
import clsx from 'clsx';
import { withStyles } from '@material-ui/core/styles';

const SPACINGS = {'large': -4, 'medium': -8, 'small': -16};

export const styles = theme => ({
/* Styles applied to the root element. */
root: {
Expand All @@ -12,13 +14,11 @@ export const styles = theme => ({
/* Styles applied to the avatar elements. */
avatar: {
border: `2px solid ${theme.palette.background.default}`,
marginLeft: -8,
},
});

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

const { children: childrenProp, classes, className, spacing, ...other } = props;
const children = React.Children.toArray(childrenProp).filter(child => {
if (process.env.NODE_ENV !== 'production') {
if (isFragment(child)) {
Expand All @@ -41,6 +41,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] ? SPACINGS[spacing] : -8,
oliviertassinari marked this conversation as resolved.
Show resolved Hide resolved
...child.props.style,
},
});
Expand All @@ -63,6 +64,10 @@ AvatarGroup.propTypes = {
* See [CSS API](#css) below for more details.
*/
classes: PropTypes.object,
/**
* Defines the space between the type `avatar` component.
*/
spacing: PropTypes.oneOf(SPACINGS),
/**
* @ignore
*/
Expand Down