@kubit-ui-web/react-components
Version:
Kubit React Components is a customizable, accessible library of React web components, designed to enhance your application's user experience
113 lines • 5.11 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.CssAnimation = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = __importStar(require("react"));
const react_transition_group_1 = require("react-transition-group");
const string_utility_1 = require("../../utils/stringUtility/string.utility");
const cssAnimation_styled_1 = require("./cssAnimation.styled");
const cssAnimation_1 = require("./types/cssAnimation");
const CssAnimationComponent = ({ children, variant, options, exec = cssAnimation_1.CssAnimationExecuteOption.HIDDEN, dataTestId = 'css-animation', }, ref) => {
const nodeRef = (0, react_1.useRef)();
const [execute, setExecute] = (0, react_1.useState)(cssAnimation_1.CssAnimationExecuteOption.HIDDEN);
// deprecated - Remove the condition when `enterDuration` and `duration` are type string
const enterDuration = () => {
if (options?.enterDuration) {
if (typeof options?.enterDuration === 'string') {
return (0, string_utility_1.convertDurationToNumber)(options?.enterDuration);
}
return options.enterDuration * 1000;
}
else if (options?.duration) {
if (typeof options?.duration === 'string') {
return (0, string_utility_1.convertDurationToNumber)(options?.duration);
}
return options.duration * 1000;
}
return 0;
};
// deprecated - Remove the condition when `exitDuration` and `duration` are type string
const exitDuration = () => {
if (options?.exitDuration) {
if (typeof options?.exitDuration === 'string') {
return (0, string_utility_1.convertDurationToNumber)(options?.exitDuration);
}
return options.exitDuration * 1000;
}
else if (options?.duration) {
if (typeof options?.duration === 'string') {
return (0, string_utility_1.convertDurationToNumber)(options?.duration);
}
return options.duration * 1000;
}
return 0;
};
const setNodeRef = react_1.default.useCallback(node => {
nodeRef.current = node;
if (ref) {
if (typeof ref === 'function') {
ref(node);
}
else {
ref.current = node;
}
}
}, []);
(0, react_1.useEffect)(() => {
if (exec)
setExecute(exec);
}, [exec]);
return ((0, jsx_runtime_1.jsx)(react_transition_group_1.CSSTransition, { unmountOnExit: true, classNames: `${variant.type}`, in: execute === cssAnimation_1.CssAnimationExecuteOption.START ? true : false, nodeRef: nodeRef, timeout: {
enter: enterDuration(),
exit: exitDuration(),
}, children: (0, jsx_runtime_1.jsx)(cssAnimation_styled_1.CssAnimationContainer, { "data-testid": dataTestId, exec: exec, options: options, variant: variant, children: (exec === cssAnimation_1.CssAnimationExecuteOption.START || exec === cssAnimation_1.CssAnimationExecuteOption.END) &&
react_1.Children.map(children, child => (0, react_1.isValidElement)(child) &&
(0, react_1.cloneElement)(child, {
ref: setNodeRef,
})) }) }));
};
/**
* @deprecated This component has been deprecated and will be removed in the next MAJOR release.
*
* CssAnimation component is a wrapper component that can be used to wrap other components.
*
* @param {React.PropsWithChildren<ICssAnimation>} props
* @returns {JSX.Element}
* @constructor
*
*/
exports.CssAnimation = react_1.default.forwardRef(CssAnimationComponent);
//# sourceMappingURL=cssAnimation.js.map