@nutui/nutui-react-taro
Version:
京东风格的轻量级移动端 React 组件库,支持一套代码生成 H5 和小程序
44 lines (43 loc) • 1.84 kB
JavaScript
import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
import React, { useRef } from "react";
import classNames from "classnames";
import { View } from "@tarojs/components";
import { AvatarContext } from "./context";
import { ComponentDefaults } from "../../utils/typings";
var defaultProps = _object_spread_props(_object_spread({}, ComponentDefaults), {
maxContent: '',
max: '',
maxBackground: '#eee',
maxColor: '#666',
gap: '-8',
level: 'left'
});
var classPrefix = "nut-avatar-group";
export var AvatarGroup = function(props) {
var propAvatarGroup = _object_spread({}, defaultProps, props);
var className = propAvatarGroup.className, style = propAvatarGroup.style, children = propAvatarGroup.children;
var avatarGroupRef = useRef(null);
var cls = classNames(classPrefix, className);
var parentAvatar = {
propAvatarGroup: _object_spread({
avatarCount: React.Children.count(children) || 0
}, propAvatarGroup),
avatarGroupRef: avatarGroupRef
};
return /*#__PURE__*/ React.createElement(AvatarContext.Provider, {
value: parentAvatar
}, /*#__PURE__*/ React.createElement(View, {
className: cls,
style: style,
ref: avatarGroupRef
}, React.Children.map(children, function(child, index) {
var _child_type;
// @ts-ignore
return (child === null || child === void 0 ? void 0 : (_child_type = child.type) === null || _child_type === void 0 ? void 0 : _child_type.displayName) === 'NutAvatar' ? /*#__PURE__*/ React.cloneElement(child, {
avatarIndex: index + 1,
className: 'nut-avatar-group-avatar'
}) : child;
})));
};
AvatarGroup.displayName = 'NutAvatarGroup';