-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[AvatarGroup] Introduce new component
- Loading branch information
1 parent
c98b9c4
commit 69e8ced
Showing
25 changed files
with
271 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import React from 'react'; | ||
import MarkdownDocs from 'docs/src/modules/components/MarkdownDocs'; | ||
import markdown from './avatar-group.md'; | ||
|
||
export default function Page() { | ||
return <MarkdownDocs markdown={markdown} />; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
--- | ||
filename: /packages/material-ui/src/AvatarGroup/AvatarGroup.js | ||
--- | ||
|
||
<!--- This documentation is automatically generated, do not try to edit it. --> | ||
|
||
# AvatarGroup API | ||
|
||
<p class="description">The API documentation of the AvatarGroup React component. Learn more about the props and the CSS customization points.</p> | ||
|
||
## Import | ||
|
||
```js | ||
import AvatarGroup from '@material-ui/core/AvatarGroup'; | ||
// or | ||
import { AvatarGroup } from '@material-ui/core'; | ||
``` | ||
|
||
You can learn more about the difference by [reading this guide](/guides/minimizing-bundle-size/). | ||
|
||
|
||
|
||
## Props | ||
|
||
| Name | Type | Default | Description | | ||
|:-----|:-----|:--------|:------------| | ||
| <span class="prop-name">children</span> | <span class="prop-type">node</span> | | Used to render icon or text elements inside the AvatarGroup if `src` is not set. This can be an element, or just a string. | | ||
| <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. | | ||
|
||
The `ref` is forwarded to the root element. | ||
|
||
Any other props supplied will be provided to the root element (native element). | ||
|
||
## CSS | ||
|
||
- Style sheet name: `MuiAvatarGroup`. | ||
- Style sheet details: | ||
|
||
| Rule name | Global class | Description | | ||
|:-----|:-------------|:------------| | ||
| <span class="prop-name">root</span> | <span class="prop-name">.MuiAvatarGroup-root</span> | Styles applied to the root element. | ||
| <span class="prop-name">avatar</span> | <span class="prop-name">.MuiAvatarGroup-avatar</span> | Styles applied to the avatar elements. | ||
|
||
You can override the style of the component thanks to one of these customization points: | ||
|
||
- With a rule name of the [`classes` object prop](/customization/components/#overriding-styles-with-classes). | ||
- With a [global class name](/customization/components/#overriding-styles-with-global-class-names). | ||
- With a theme and an [`overrides` property](/customization/globals/#css). | ||
|
||
If that's not sufficient, you can check the [implementation of the component](https://github.com/mui-org/material-ui/blob/master/packages/material-ui/src/AvatarGroup/AvatarGroup.js) for more detail. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import React from 'react'; | ||
import Badge from '@material-ui/core/Badge'; | ||
import Avatar from '@material-ui/core/Avatar'; | ||
|
||
export default function BadgeAvatars() { | ||
return ( | ||
<Badge | ||
overlap="circle" | ||
anchorOrigin={{ vertical: 'bottom', horizontal: 'right' }} | ||
badgeContent={1} | ||
color="error" | ||
> | ||
<Avatar alt="Remy Sharp" src="/static/images/avatar/1.jpg" /> | ||
</Badge> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import React from 'react'; | ||
import Badge from '@material-ui/core/Badge'; | ||
import Avatar from '@material-ui/core/Avatar'; | ||
|
||
export default function BadgeAvatars() { | ||
return ( | ||
<Badge | ||
overlap="circle" | ||
anchorOrigin={{ vertical: 'bottom', horizontal: 'right' }} | ||
badgeContent={1} | ||
color="error" | ||
> | ||
<Avatar alt="Remy Sharp" src="/static/images/avatar/1.jpg" /> | ||
</Badge> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import React from 'react'; | ||
import Avatar from '@material-ui/core/Avatar'; | ||
import AvatarGroup from '@material-ui/core/AvatarGroup'; | ||
import Tooltip from '@material-ui/core/Tooltip'; | ||
|
||
export default function GroupAvatars() { | ||
return ( | ||
<AvatarGroup> | ||
<Avatar alt="Remy Sharp" src="/static/images/avatar/1.jpg" /> | ||
<Avatar alt="Travis Howard" src="/static/images/avatar/2.jpg" /> | ||
<Avatar alt="Cindy Baker" src="/static/images/avatar/3.jpg" /> | ||
<Tooltip title="Foo • Bar • Baz"> | ||
<Avatar>+3</Avatar> | ||
</Tooltip> | ||
</AvatarGroup> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import React from 'react'; | ||
import Avatar from '@material-ui/core/Avatar'; | ||
import AvatarGroup from '@material-ui/core/AvatarGroup'; | ||
import Tooltip from '@material-ui/core/Tooltip'; | ||
|
||
export default function GroupAvatars() { | ||
return ( | ||
<AvatarGroup> | ||
<Avatar alt="Remy Sharp" src="/static/images/avatar/1.jpg" /> | ||
<Avatar alt="Travis Howard" src="/static/images/avatar/2.jpg" /> | ||
<Avatar alt="Cindy Baker" src="/static/images/avatar/3.jpg" /> | ||
<Tooltip title="Foo • Bar • Baz"> | ||
<Avatar>+3</Avatar> | ||
</Tooltip> | ||
</AvatarGroup> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import * as React from 'react'; | ||
import { StandardProps, PropTypes } from '..'; | ||
|
||
export interface AvatarGroupProps | ||
extends StandardProps<React.HTMLAttributes<HTMLDivElement>, AvatarGroupClassKey> { | ||
/** | ||
* The badge will be added relative to this node. | ||
*/ | ||
children: React.ReactNode; | ||
} | ||
|
||
export type AvatarGroupClassKey = 'root' | 'avatar'; | ||
|
||
export default function AvatarGroup(props: AvatarGroupProps): JSX.Element | null; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { isFragment } from 'react-is'; | ||
import clsx from 'clsx'; | ||
import withStyles from '../styles/withStyles'; | ||
|
||
export const styles = theme => ({ | ||
/* Styles applied to the root element. */ | ||
root: { | ||
display: 'flex', | ||
}, | ||
/* 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 = React.Children.toArray(childrenProp).filter(child => { | ||
if (process.env.NODE_ENV !== 'production') { | ||
if (isFragment(child)) { | ||
console.error( | ||
[ | ||
"Material-UI: the Breadcrumbs component doesn't accept a Fragment as a child.", | ||
'Consider providing an array instead.', | ||
].join('\n'), | ||
); | ||
} | ||
} | ||
|
||
return React.isValidElement(child); | ||
}); | ||
|
||
return ( | ||
<div className={clsx(classes.root, className)} ref={ref} {...other}> | ||
{children.map((child, index) => { | ||
return React.cloneElement(child, { | ||
className: clsx(child.props.className, classes.avatar), | ||
style: { | ||
zIndex: children.length - index, | ||
...child.props.style, | ||
}, | ||
}); | ||
})} | ||
</div> | ||
); | ||
}); | ||
|
||
AvatarGroup.propTypes = { | ||
// ----------------------------- Warning -------------------------------- | ||
// | These PropTypes are generated from the TypeScript type definitions | | ||
// | To update them edit the d.ts file and run "yarn proptypes" | | ||
// ---------------------------------------------------------------------- | ||
/** | ||
* The badge will be added relative to this node. | ||
*/ | ||
children: PropTypes.node, | ||
/** | ||
* Override or extend the styles applied to the component. | ||
* See [CSS API](#css) below for more details. | ||
*/ | ||
classes: PropTypes.object, | ||
/** | ||
* @ignore | ||
*/ | ||
className: PropTypes.string, | ||
}; | ||
|
||
export default withStyles(styles, { name: 'MuiAvatarGroup' })(AvatarGroup); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import React from 'react'; | ||
import { createMount, getClasses } from '@material-ui/core/test-utils'; | ||
import describeConformance from '../test-utils/describeConformance'; | ||
import AvatarGroup from './AvatarGroup'; | ||
|
||
describe('<AvatarGroup />', () => { | ||
let mount; | ||
let classes; | ||
|
||
before(() => { | ||
mount = createMount({ strict: true }); | ||
classes = getClasses(<AvatarGroup />); | ||
}); | ||
|
||
after(() => { | ||
mount.cleanUp(); | ||
}); | ||
|
||
describeConformance(<AvatarGroup />, () => ({ | ||
classes, | ||
inheritComponent: 'div', | ||
mount, | ||
refInstanceof: window.HTMLDivElement, | ||
skip: ['componentProp'], | ||
})); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { default } from './AvatarGroup'; | ||
export * from './AvatarGroup'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from './AvatarGroup'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.