import React from 'react'; import { Tooltip, Avatar } from 'antd'; import classNames from 'classnames'; import styles from './index.less'; export declare type SizeType = number | 'small' | 'default' | 'large'; export interface AvatarItemProps { tips: React.ReactNode; src: string; size?: SizeType; style?: React.CSSProperties; onClick?: () => void; } export interface AvatarListProps { Item?: React.ReactElement; size?: SizeType; maxLength?: number; excessItemsStyle?: React.CSSProperties; style?: React.CSSProperties; children: React.ReactElement | Array>; } const avatarSizeToClassName = (size?: SizeType) => classNames(styles.avatarItem, { [styles.avatarItemLarge]: size === 'large', [styles.avatarItemSmall]: size === 'small', [styles.avatarItemMini]: size === 'mini', }); const Item: React.SFC = ({ src, size, tips, onClick = () => {} }) => { const cls = avatarSizeToClassName(size); return (
  • {tips ? ( ) : ( )}
  • ); }; const AvatarList: React.SFC & { Item: typeof Item } = ({ children, size, maxLength = 5, excessItemsStyle, ...other }) => { const numOfChildren = React.Children.count(children); const numToShow = maxLength >= numOfChildren ? numOfChildren : maxLength; const childrenArray = React.Children.toArray(children) as Array< React.ReactElement >; const childrenWithProps = childrenArray.slice(0, numToShow).map(child => React.cloneElement(child, { size, }) ); if (numToShow < numOfChildren) { const cls = avatarSizeToClassName(size); childrenWithProps.push(
  • {`+${numOfChildren - maxLength}`}
  • ); } return (
      {childrenWithProps}
    ); }; AvatarList.Item = Item; export default AvatarList;