1 | 'use client';
|
2 |
|
3 | import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
4 | import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
5 | import _extends from "@babel/runtime/helpers/esm/extends";
|
6 | import * as React from 'react';
|
7 | import PropTypes from 'prop-types';
|
8 | import { isFragment } from 'react-is';
|
9 | import clsx from 'clsx';
|
10 | import chainPropTypes from '@mui/utils/chainPropTypes';
|
11 | import composeClasses from '@mui/utils/composeClasses';
|
12 | import styled from '../styles/styled';
|
13 | import { useDefaultProps } from '../DefaultPropsProvider';
|
14 | import Avatar, { avatarClasses } from '../Avatar';
|
15 | import avatarGroupClasses, { getAvatarGroupUtilityClass } from './avatarGroupClasses';
|
16 | import { jsx as _jsx } from "react/jsx-runtime";
|
17 | import { jsxs as _jsxs } from "react/jsx-runtime";
|
18 | var SPACINGS = {
|
19 | small: -16,
|
20 | medium: null
|
21 | };
|
22 | var useUtilityClasses = function useUtilityClasses(ownerState) {
|
23 | var classes = ownerState.classes;
|
24 | var slots = {
|
25 | root: ['root'],
|
26 | avatar: ['avatar']
|
27 | };
|
28 | return composeClasses(slots, getAvatarGroupUtilityClass, classes);
|
29 | };
|
30 | var AvatarGroupRoot = styled('div', {
|
31 | name: 'MuiAvatarGroup',
|
32 | slot: 'Root',
|
33 | overridesResolver: function overridesResolver(props, styles) {
|
34 | return _extends(_defineProperty({}, "& .".concat(avatarGroupClasses.avatar), styles.avatar), styles.root);
|
35 | }
|
36 | })(function (_ref) {
|
37 | var theme = _ref.theme,
|
38 | ownerState = _ref.ownerState;
|
39 | var marginValue = ownerState.spacing && SPACINGS[ownerState.spacing] !== undefined ? SPACINGS[ownerState.spacing] : -ownerState.spacing;
|
40 | return _defineProperty(_defineProperty(_defineProperty({}, "& .".concat(avatarClasses.root), {
|
41 | border: "2px solid ".concat((theme.vars || theme).palette.background.default),
|
42 | boxSizing: 'content-box',
|
43 | marginLeft: marginValue != null ? marginValue : -8,
|
44 | '&:last-child': {
|
45 | marginLeft: 0
|
46 | }
|
47 | }), "display", 'flex'), "flexDirection", 'row-reverse');
|
48 | });
|
49 | var AvatarGroup = React.forwardRef(function AvatarGroup(inProps, ref) {
|
50 | var _slotProps$additional;
|
51 | var props = useDefaultProps({
|
52 | props: inProps,
|
53 | name: 'MuiAvatarGroup'
|
54 | });
|
55 | var childrenProp = props.children,
|
56 | className = props.className,
|
57 | _props$component = props.component,
|
58 | component = _props$component === void 0 ? 'div' : _props$component,
|
59 | _props$componentsProp = props.componentsProps,
|
60 | componentsProps = _props$componentsProp === void 0 ? {} : _props$componentsProp,
|
61 | _props$max = props.max,
|
62 | max = _props$max === void 0 ? 5 : _props$max,
|
63 | renderSurplus = props.renderSurplus,
|
64 | _props$slotProps = props.slotProps,
|
65 | slotProps = _props$slotProps === void 0 ? {} : _props$slotProps,
|
66 | _props$spacing = props.spacing,
|
67 | spacing = _props$spacing === void 0 ? 'medium' : _props$spacing,
|
68 | total = props.total,
|
69 | _props$variant = props.variant,
|
70 | variant = _props$variant === void 0 ? 'circular' : _props$variant,
|
71 | other = _objectWithoutProperties(props, ["children", "className", "component", "componentsProps", "max", "renderSurplus", "slotProps", "spacing", "total", "variant"]);
|
72 | var clampedMax = max < 2 ? 2 : max;
|
73 | var ownerState = _extends({}, props, {
|
74 | max: max,
|
75 | spacing: spacing,
|
76 | component: component,
|
77 | variant: variant
|
78 | });
|
79 | var classes = useUtilityClasses(ownerState);
|
80 | var children = React.Children.toArray(childrenProp).filter(function (child) {
|
81 | if (process.env.NODE_ENV !== 'production') {
|
82 | if (isFragment(child)) {
|
83 | console.error(["MUI: The AvatarGroup component doesn't accept a Fragment as a child.", 'Consider providing an array instead.'].join('\n'));
|
84 | }
|
85 | }
|
86 | return React.isValidElement(child);
|
87 | });
|
88 | var totalAvatars = total || children.length;
|
89 | if (totalAvatars === clampedMax) {
|
90 | clampedMax += 1;
|
91 | }
|
92 | clampedMax = Math.min(totalAvatars + 1, clampedMax);
|
93 | var maxAvatars = Math.min(children.length, clampedMax - 1);
|
94 | var extraAvatars = Math.max(totalAvatars - clampedMax, totalAvatars - maxAvatars, 0);
|
95 | var extraAvatarsElement = renderSurplus ? renderSurplus(extraAvatars) : "+".concat(extraAvatars);
|
96 | var additionalAvatarSlotProps = (_slotProps$additional = slotProps.additionalAvatar) != null ? _slotProps$additional : componentsProps.additionalAvatar;
|
97 | return _jsxs(AvatarGroupRoot, _extends({
|
98 | as: component,
|
99 | ownerState: ownerState,
|
100 | className: clsx(classes.root, className),
|
101 | ref: ref
|
102 | }, other, {
|
103 | children: [extraAvatars ? _jsx(Avatar, _extends({
|
104 | variant: variant
|
105 | }, additionalAvatarSlotProps, {
|
106 | className: clsx(classes.avatar, additionalAvatarSlotProps == null ? void 0 : additionalAvatarSlotProps.className),
|
107 | children: extraAvatarsElement
|
108 | })) : null, children.slice(0, maxAvatars).reverse().map(function (child) {
|
109 | return React.cloneElement(child, {
|
110 | className: clsx(child.props.className, classes.avatar),
|
111 | variant: child.props.variant || variant
|
112 | });
|
113 | })]
|
114 | }));
|
115 | });
|
116 | process.env.NODE_ENV !== "production" ? AvatarGroup.propTypes = {
|
117 |
|
118 |
|
119 |
|
120 |
|
121 | |
122 |
|
123 |
|
124 | children: PropTypes.node,
|
125 | |
126 |
|
127 |
|
128 | classes: PropTypes.object,
|
129 | |
130 |
|
131 |
|
132 | className: PropTypes.string,
|
133 | |
134 |
|
135 |
|
136 |
|
137 | component: PropTypes.elementType,
|
138 | |
139 |
|
140 |
|
141 |
|
142 |
|
143 |
|
144 |
|
145 |
|
146 |
|
147 | componentsProps: PropTypes.shape({
|
148 | additionalAvatar: PropTypes.object
|
149 | }),
|
150 | |
151 |
|
152 |
|
153 |
|
154 | max: chainPropTypes(PropTypes.number, function (props) {
|
155 | if (props.max < 2) {
|
156 | return new Error(['MUI: The prop `max` should be equal to 2 or above.', 'A value below is clamped to 2.'].join('\n'));
|
157 | }
|
158 | return null;
|
159 | }),
|
160 | |
161 |
|
162 |
|
163 |
|
164 |
|
165 | renderSurplus: PropTypes.func,
|
166 | |
167 |
|
168 |
|
169 |
|
170 |
|
171 |
|
172 |
|
173 |
|
174 | slotProps: PropTypes.shape({
|
175 | additionalAvatar: PropTypes.object
|
176 | }),
|
177 | |
178 |
|
179 |
|
180 |
|
181 | spacing: PropTypes.oneOfType([PropTypes.oneOf(['medium', 'small']), PropTypes.number]),
|
182 | |
183 |
|
184 |
|
185 | sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
|
186 | |
187 |
|
188 |
|
189 |
|
190 | total: PropTypes.number,
|
191 | |
192 |
|
193 |
|
194 |
|
195 | variant: PropTypes .oneOfType([PropTypes.oneOf(['circular', 'rounded', 'square']), PropTypes.string])
|
196 | } : void 0;
|
197 | export default AvatarGroup; |
\ | No newline at end of file |