fomantic-ui-react
Version:
Fomantic-UI React -- A React Component Library.
175 lines (149 loc) • 5.81 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 { useState, useEffect, createElement } from 'react';
import classNames from 'classnames';
import _ from 'lodash';
var _excluded = ["as", "visible", "animation", "duration", "className", "children", "onShow", "onHide", "onStart", "onComplete"];
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 Transition = function Transition(_ref) {
var _ref$as = _ref.as,
as = _ref$as === void 0 ? "div" : _ref$as,
_ref$visible = _ref.visible,
visible = _ref$visible === void 0 ? true : _ref$visible,
_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,
onShow = _ref.onShow,
onHide = _ref.onHide,
onStart = _ref.onStart,
onComplete = _ref.onComplete,
props = _objectWithoutProperties(_ref, _excluded);
var _useState = useState(true),
_useState2 = _slicedToArray(_useState, 2),
start = _useState2[0],
setStart = _useState2[1];
var _useState3 = useState(false),
_useState4 = _slicedToArray(_useState3, 2),
update = _useState4[0],
setUpdate = _useState4[1];
var _useState5 = useState(""),
_useState6 = _slicedToArray(_useState5, 2),
css = _useState6[0],
setCss = _useState6[1];
var _useState7 = useState({}),
_useState8 = _slicedToArray(_useState7, 2),
style = _useState8[0],
setStyle = _useState8[1];
var _useState9 = useState(false),
_useState10 = _slicedToArray(_useState9, 2),
animating = _useState10[0],
setAnimating = _useState10[1];
var handleStart = function handleStart() {
setCss(visible ? "visible" : "hidden");
};
useEffect(function () {
handleStart();
setStart(false);
}, []);
useEffect(function () {
var timer;
if (!start) {
setUpdate(true);
setAnimating(true);
if (typeof onStart === "function") {
onStart();
}
if (typeof duration === "number") {
if (typeof animation === "string") {
setCss("".concat(animation, " ").concat(visible ? "in" : "out"));
} else {
setCss(visible ? "".concat(animation.show, " in") : "".concat(animation.hide, " out"));
}
setStyle({
animationDuration: "".concat(duration, "ms"),
display: "block"
});
timer = setTimeout(function () {
clearTimeout(timer);
setUpdate(false);
setAnimating(false);
if (visible) {
if (typeof onShow === "function") {
onShow();
}
} else {
if (typeof onHide === "function") {
onHide();
}
}
if (typeof onComplete === "function") {
onComplete();
}
}, duration);
} else {
if (visible) {
setCss("".concat(typeof animation === "string" ? animation : animation.show, " in"));
setStyle({
animationDuration: "".concat(duration.show, "ms"),
display: "block"
});
timer = setTimeout(function () {
clearTimeout(timer);
setUpdate(false);
setAnimating(false);
if (typeof onShow === "function") {
onShow();
}
if (typeof onComplete === "function") {
onComplete();
}
}, duration.show);
} else {
setCss("".concat(typeof animation === "string" ? animation : animation.hide, " out"));
setStyle({
animationDuration: "".concat(duration.hide, "ms"),
display: "block"
});
timer = setTimeout(function () {
clearTimeout(timer);
setUpdate(false);
setAnimating(false);
if (typeof onHide === "function") {
onHide();
}
if (typeof onComplete === "function") {
onComplete();
}
}, duration.hide);
}
}
}
return function () {
if (timer) clearTimeout(timer);
};
}, [visible]);
useEffect(function () {
if (!update) {
handleStart();
setStyle({});
}
}, [update]);
return /*#__PURE__*/createElement(as, _objectSpread({
className: classNames("transition", {
animating: animating
}, css, className),
style: _objectSpread(_objectSpread({}, style), props.style)
}, _.omit(props, "style")), children);
};
Transition.displayName = "Transition";
export { Transition as default };
//# sourceMappingURL=Transition.js.map