fomantic-ui-react
Version:
Fomantic-UI React -- A React Component Library.
102 lines (84 loc) • 3.92 kB
JavaScript
/**
* fomantic-ui-react v0.0.1-alpha.10
* (c) 2022 FireLoong <fireloong@foxmail.com>
* @license MIT
*/
import { _ as _defineProperty, a as _objectWithoutProperties } from '../_chunks/dep-9f1126c1.js';
import { _ as _slicedToArray } from '../_chunks/dep-dc9b74a1.js';
import React, { useState, Children, useEffect, isValidElement, createElement } from 'react';
import { Transition } from './index.js';
import _ from 'lodash';
import './Transition.js';
import 'classnames';
import './style/index.js';
import './type.js';
var _excluded = ["as", "animation", "duration", "className", "children"];
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
var TransitionGroup = function TransitionGroup(_ref) {
var _ref$as = _ref.as,
as = _ref$as === void 0 ? "div" : _ref$as,
_ref$animation = _ref.animation,
animation = _ref$animation === void 0 ? "fade" : _ref$animation,
_ref$duration = _ref.duration,
duration = _ref$duration === void 0 ? 500 : _ref$duration,
className = _ref.className,
children = _ref.children,
props = _objectWithoutProperties(_ref, _excluded);
var _useState = useState(children),
_useState2 = _slicedToArray(_useState, 2),
preChildren = _useState2[0],
setPreChildren = _useState2[1];
var _useState3 = useState(Children.count(preChildren)),
_useState4 = _slicedToArray(_useState3, 2),
count = _useState4[0],
setCount = _useState4[1];
useEffect(function () {
if (count !== Children.count(children)) {
setPreChildren(children);
setCount(Children.count(children));
}
});
if (children) {
if (count <= Children.count(children)) {
children = Children.map(children, function (child) {
if ( /*#__PURE__*/isValidElement(child)) {
var visibleCurrent = true;
if (count < Children.count(children) && _.last(_.toArray(children)) === child) {
visibleCurrent = false;
}
return /* @__PURE__ */React.createElement(Transition, _objectSpread({
key: child.key,
as: child.type,
animation: animation,
duration: duration,
visible: visibleCurrent
}, child.props));
}
});
} else {
children = Children.map(preChildren, function (child) {
if ( /*#__PURE__*/isValidElement(child)) {
var visibleCurrent = true;
if (count > Children.count(children) && _.last(_.toArray(preChildren)) === child) {
visibleCurrent = false;
}
return /* @__PURE__ */React.createElement(Transition, _objectSpread({
key: child.key,
as: child.type,
animation: animation,
duration: duration,
visible: visibleCurrent
}, child.props));
}
});
}
console.log(children);
}
return /*#__PURE__*/createElement(as, _objectSpread({
className: className
}, props), children);
};
TransitionGroup.displayName = "TransitionGroup";
export { TransitionGroup as default };
//# sourceMappingURL=TransitionGroup copy.js.map