UNPKG

@itwin/itwinui-react

Version:

A react component library for iTwinUI

65 lines (64 loc) 1.65 kB
import * as React from 'react'; import cx from 'classnames'; import { Box } from '../../utils/index.js'; export 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( Box, { className: cx( '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( Box, { ...countIconProps, className: cx( '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';