|
|
@@ -4,12 +4,34 @@ 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,
|
|
|
- })
|
|
|
- );
|
|
|
+const avatarSizeToClassName = size =>
|
|
|
+ classNames(styles.avatarItem, {
|
|
|
+ [styles.avatarItemLarge]: size === 'large',
|
|
|
+ [styles.avatarItemSmall]: size === 'small',
|
|
|
+ [styles.avatarItemMini]: size === 'mini',
|
|
|
+ });
|
|
|
+
|
|
|
+const AvatarList = ({ children, size, maxLength, excessItemsStyle, ...other }) => {
|
|
|
+ const numOfChildren = React.Children.count(children);
|
|
|
+ const numToShow = maxLength >= numOfChildren ? numOfChildren : maxLength;
|
|
|
+
|
|
|
+ const childrenWithProps = React.Children.toArray(children)
|
|
|
+ .slice(0, numToShow)
|
|
|
+ .map(child =>
|
|
|
+ React.cloneElement(child, {
|
|
|
+ size,
|
|
|
+ })
|
|
|
+ );
|
|
|
+
|
|
|
+ if (numToShow < numOfChildren) {
|
|
|
+ const cls = avatarSizeToClassName(size);
|
|
|
+
|
|
|
+ childrenWithProps.push(
|
|
|
+ <li key="exceed" className={cls}>
|
|
|
+ <Avatar size={size} style={excessItemsStyle}>{`+${numOfChildren - maxLength}`}</Avatar>
|
|
|
+ </li>
|
|
|
+ );
|
|
|
+ }
|
|
|
|
|
|
return (
|
|
|
<div {...other} className={styles.avatarList}>
|
|
|
@@ -19,11 +41,7 @@ const AvatarList = ({ children, size, ...other }) => {
|
|
|
};
|
|
|
|
|
|
const Item = ({ src, size, tips, onClick = () => {} }) => {
|
|
|
- const cls = classNames(styles.avatarItem, {
|
|
|
- [styles.avatarItemLarge]: size === 'large',
|
|
|
- [styles.avatarItemSmall]: size === 'small',
|
|
|
- [styles.avatarItemMini]: size === 'mini',
|
|
|
- });
|
|
|
+ const cls = avatarSizeToClassName(size);
|
|
|
|
|
|
return (
|
|
|
<li className={cls} onClick={onClick}>
|