@itwin/itwinui-react
Version:
A react component library for iTwinUI
79 lines (78 loc) • 2.19 kB
JavaScript
;
Object.defineProperty(exports, '__esModule', {
value: true,
});
Object.defineProperty(exports, 'AvatarGroup', {
enumerable: true,
get: function () {
return AvatarGroup;
},
});
const _interop_require_default = require('@swc/helpers/_/_interop_require_default');
const _interop_require_wildcard = require('@swc/helpers/_/_interop_require_wildcard');
const _react = /*#__PURE__*/ _interop_require_wildcard._(require('react'));
const _classnames = /*#__PURE__*/ _interop_require_default._(
require('classnames'),
);
const _index = require('../../utils/index.js');
const AvatarGroup = _react.forwardRef((props, ref) => {
let maxLength = 99;
let {
children,
animated = false,
stacked = true,
maxIcons = 5,
iconSize = 'small',
countIconProps,
className,
...rest
} = props;
let childrenArray = _react.Children.toArray(children);
let childrenLength = childrenArray.length;
let getAvatarList = (count) =>
childrenArray.slice(0, count).map((child) =>
_react.cloneElement(child, {
status: void 0,
size: iconSize,
}),
);
return _react.createElement(
_index.Box,
{
className: (0, _classnames.default)(
'iui-avatar-list',
{
'iui-animated': animated,
'iui-stacked': stacked,
},
className,
),
ref: ref,
...rest,
},
childrenArray.length <= maxIcons + 1 && getAvatarList(maxIcons + 1),
childrenArray.length > maxIcons + 1 &&
_react.createElement(
_react.Fragment,
null,
getAvatarList(maxIcons),
_react.createElement(
_index.Box,
{
...countIconProps,
className: (0, _classnames.default)(
'iui-avatar',
'iui-avatar-count',
countIconProps?.className,
),
'data-iui-size': 'medium' !== iconSize ? iconSize : void 0,
},
childrenLength <= maxLength
? `${childrenLength - maxIcons}`
: `${maxLength}+`,
),
),
);
});
if ('development' === process.env.NODE_ENV)
AvatarGroup.displayName = 'AvatarGroup';