fomantic-ui-react
Version:
Fomantic-UI React -- A React Component Library.
185 lines (155 loc) • 6.34 kB
JavaScript
/**
* fomantic-ui-react v0.0.1-alpha.10
* (c) 2022 FireLoong <fireloong@foxmail.com>
* @license MIT
*/
;
Object.defineProperty(exports, '__esModule', { value: true });
var defineProperty = require('../_chunks/dep-6ab59a61.js');
var slicedToArray = require('../_chunks/dep-640599ea.js');
var objectWithoutProperties = require('../_chunks/dep-03754121.js');
var React = require('react');
var classNames = require('classnames');
var _ = require('lodash');
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
var classNames__default = /*#__PURE__*/_interopDefaultLegacy(classNames);
var ___default = /*#__PURE__*/_interopDefaultLegacy(_);
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._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._objectWithoutProperties(_ref, _excluded);
var _useState = React.useState(true),
_useState2 = slicedToArray._slicedToArray(_useState, 2),
start = _useState2[0],
setStart = _useState2[1];
var _useState3 = React.useState(false),
_useState4 = slicedToArray._slicedToArray(_useState3, 2),
update = _useState4[0],
setUpdate = _useState4[1];
var _useState5 = React.useState(""),
_useState6 = slicedToArray._slicedToArray(_useState5, 2),
css = _useState6[0],
setCss = _useState6[1];
var _useState7 = React.useState({}),
_useState8 = slicedToArray._slicedToArray(_useState7, 2),
style = _useState8[0],
setStyle = _useState8[1];
var _useState9 = React.useState(false),
_useState10 = slicedToArray._slicedToArray(_useState9, 2),
animating = _useState10[0],
setAnimating = _useState10[1];
var handleStart = function handleStart() {
setCss(visible ? "visible" : "hidden");
};
React.useEffect(function () {
handleStart();
setStart(false);
}, []);
React.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]);
React.useEffect(function () {
if (!update) {
handleStart();
setStyle({});
}
}, [update]);
return /*#__PURE__*/React.createElement(as, _objectSpread({
className: classNames__default["default"]("transition", {
animating: animating
}, css, className),
style: _objectSpread(_objectSpread({}, style), props.style)
}, ___default["default"].omit(props, "style")), children);
};
Transition.displayName = "Transition";
exports["default"] = Transition;
//# sourceMappingURL=Transition.js.map