-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathavatar-group.tsx
More file actions
executable file
·35 lines (31 loc) · 1.3 KB
/
Copy pathavatar-group.tsx
File metadata and controls
executable file
·35 lines (31 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import React, { useContext } from 'react';
import classNames from 'classnames';
import { AVATAR_MARK, hasMarker } from '../_utils/component-markers';
import { ConfigContext } from '../config-provider/config-context';
import { getPrefixCls } from '../_utils/general';
import { AvatarProps, AvatarGroupProps } from './types';
const AvatarGroup = (props: AvatarGroupProps): JSX.Element => {
const { gap = -15, className, style, children, prefixCls: customisedCls, ...otherProps } = props;
const configContext = useContext(ConfigContext);
const prefixCls = getPrefixCls('avatar-group', configContext.prefixCls, customisedCls);
const cls = classNames(prefixCls, className);
return (
<span {...otherProps} className={cls} style={style}>
{React.Children.map(children, (child, idx) => {
const childElement = child as React.FunctionComponentElement<AvatarProps>;
if (hasMarker(childElement.type, AVATAR_MARK)) {
const childProps: Partial<AvatarProps> = {
style: {
...childElement.props.style,
marginLeft: idx === 0 ? 0 : gap,
},
};
return React.cloneElement(childElement, childProps);
}
return child;
})}
</span>
);
};
AvatarGroup.displayName = 'AvatarGroup';
export default AvatarGroup;