index.js 1019 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
import React from 'react';
import { Tooltip, Avatar } from 'antd';
import classNames from 'classnames';

import styles from './index.less';

const AvatarList = ({ children, size, ...other }) => {
  const childrenWithProps = React.Children.map(children, child =>
    React.cloneElement(child, {
      size,
    })
  );

  return (
    <div {...other} className={styles.avatarList}>
      <ul> {childrenWithProps} </ul>
    </div>
  );
};

jim's avatar
jim committed
21
const Item = ({ src, size, tips, onClick = () => {} }) => {
22 23 24
  const cls = classNames(styles.avatarItem, {
    [styles.avatarItemLarge]: size === 'large',
    [styles.avatarItemSmall]: size === 'small',
niko's avatar
niko committed
25
    [styles.avatarItemMini]: size === 'mini',
26 27 28
  });

  return (
jim's avatar
jim committed
29 30 31 32 33 34 35 36
    <li className={cls} onClick={onClick}>
      {tips ? (
        <Tooltip title={tips}>
          <Avatar src={src} size={size} style={{ cursor: 'pointer' }} />
        </Tooltip>
      ) : (
        <Avatar src={src} size={size} />
      )}
37 38 39 40 41 42 43
    </li>
  );
};

AvatarList.Item = Item;

export default AvatarList;