UNPKG

4.45 kBJavaScriptView Raw
1"use strict";
2
3var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
4
5var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
6
7Object.defineProperty(exports, "__esModule", {
8 value: true
9});
10exports.default = exports.styles = void 0;
11
12var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
13
14var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
15
16var React = _interopRequireWildcard(require("react"));
17
18var _propTypes = _interopRequireDefault(require("prop-types"));
19
20var _reactIs = require("react-is");
21
22var _clsx = _interopRequireDefault(require("clsx"));
23
24var _styles = require("@material-ui/core/styles");
25
26var _Avatar = _interopRequireDefault(require("@material-ui/core/Avatar"));
27
28var _utils = require("@material-ui/utils");
29
30var SPACINGS = {
31 small: -16,
32 medium: null
33};
34
35var styles = function styles(theme) {
36 return {
37 /* Styles applied to the root element. */
38 root: {
39 display: 'flex'
40 },
41
42 /* Styles applied to the avatar elements. */
43 avatar: {
44 border: "2px solid ".concat(theme.palette.background.default),
45 marginLeft: -8,
46 '&:first-child': {
47 marginLeft: 0
48 }
49 }
50 };
51};
52
53exports.styles = styles;
54var AvatarGroup = /*#__PURE__*/React.forwardRef(function AvatarGroup(props, ref) {
55 var childrenProp = props.children,
56 classes = props.classes,
57 className = props.className,
58 _props$max = props.max,
59 max = _props$max === void 0 ? 5 : _props$max,
60 _props$spacing = props.spacing,
61 spacing = _props$spacing === void 0 ? 'medium' : _props$spacing,
62 other = (0, _objectWithoutProperties2.default)(props, ["children", "classes", "className", "max", "spacing"]);
63 var clampedMax = max < 2 ? 2 : max;
64 var children = React.Children.toArray(childrenProp).filter(function (child) {
65 if (process.env.NODE_ENV !== 'production') {
66 if ((0, _reactIs.isFragment)(child)) {
67 console.error(["Material-UI: The AvatarGroup component doesn't accept a Fragment as a child.", 'Consider providing an array instead.'].join('\n'));
68 }
69 }
70
71 return /*#__PURE__*/React.isValidElement(child);
72 });
73 var extraAvatars = children.length > clampedMax ? children.length - clampedMax + 1 : 0;
74 var marginLeft = spacing && SPACINGS[spacing] !== undefined ? SPACINGS[spacing] : -spacing;
75 return /*#__PURE__*/React.createElement("div", (0, _extends2.default)({
76 className: (0, _clsx.default)(classes.root, className),
77 ref: ref
78 }, other), children.slice(0, children.length - extraAvatars).map(function (child, index) {
79 return /*#__PURE__*/React.cloneElement(child, {
80 className: (0, _clsx.default)(child.props.className, classes.avatar),
81 style: (0, _extends2.default)({
82 zIndex: children.length - index,
83 marginLeft: index === 0 ? undefined : marginLeft
84 }, child.props.style)
85 });
86 }), extraAvatars ? /*#__PURE__*/React.createElement(_Avatar.default, {
87 className: classes.avatar,
88 style: {
89 zIndex: 0,
90 marginLeft: marginLeft
91 }
92 }, "+", extraAvatars) : null);
93});
94process.env.NODE_ENV !== "production" ? AvatarGroup.propTypes = {
95 // ----------------------------- Warning --------------------------------
96 // | These PropTypes are generated from the TypeScript type definitions |
97 // | To update them edit the d.ts file and run "yarn proptypes" |
98 // ----------------------------------------------------------------------
99
100 /**
101 * The avatars to stack.
102 */
103 children: _propTypes.default.node,
104
105 /**
106 * Override or extend the styles applied to the component.
107 * See [CSS API](#css) below for more details.
108 */
109 classes: _propTypes.default.object,
110
111 /**
112 * @ignore
113 */
114 className: _propTypes.default.string,
115
116 /**
117 * Max avatars to show before +x.
118 */
119 max: (0, _utils.chainPropTypes)(_propTypes.default.number, function (props) {
120 if (props.max < 2) {
121 throw new Error(['Material-UI: The prop `max` should be equal to 2 or above.', 'A value below is clamped to 2.'].join('\n'));
122 }
123 }),
124
125 /**
126 * Spacing between avatars.
127 */
128 spacing: _propTypes.default.oneOfType([_propTypes.default.oneOf(['medium', 'small']), _propTypes.default.number])
129} : void 0;
130
131var _default = (0, _styles.withStyles)(styles, {
132 name: 'MuiAvatarGroup'
133})(AvatarGroup);
134
135exports.default = _default;
\No newline at end of file