@alifd/meet-react
Version:
Fusion Mobile React UI System Component
46 lines • 2.5 kB
JavaScript
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
import React, { createElement, Children, isValidElement, cloneElement } from "react";
import classNames from 'classnames';
import { Text } from "@alifd/meet-react-component-one";
import Icon from '../icon';
import { isBoolean, isNil, isNumber, isString } from '../utils';
var CreateChildren = function CreateChildren(children, classes, prefix, size) {
var count = Children.count(children);
return Children.map(children, function (child, index) {
if (isNil(child) || isBoolean(child)) {
return null;
}
var key = child.key || "mt-tag-".concat(index);
if (isNumber(child) || isString(child)) {
return /*#__PURE__*/React.createElement(Text, {
key: key,
className: classes.textCls
}, child);
}
if (!isValidElement(child)) {
return child;
}
switch (true) {
case child.type === Text:
return cloneElement(child, {
key: key,
className: classes.textCls,
style: child.props.style || {}
});
case child.type === Icon:
return cloneElement(child, {
key: key,
className: classNames(classes.iconCls, _defineProperty(_defineProperty({}, "".concat(prefix, "tag-icon--").concat(size, "-first"), index === 0), "".concat(prefix, "tag-icon--").concat(size, "-last"), index === count - 1)),
style: child.props.style || {}
});
default:
return cloneElement(child, {
key: key
});
}
});
};
export default CreateChildren;