UNPKG

@afzalimdad9/react-alert

Version:
48 lines 1.82 kB
var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; import React, { useRef } from 'react'; import { Transition as AlertTransition } from 'react-transition-group'; import { transitions } from './options'; const duration = 250; const defaultStyle = { [transitions.FADE]: { transition: `opacity ${duration}ms ease`, opacity: 0 }, [transitions.SCALE]: { transform: 'scale(1)', transition: `all ${duration}ms ease-in-out` } }; const transitionStyles = { [transitions.FADE]: { entering: { opacity: 0 }, entered: { opacity: 1 }, exiting: {}, exited: {}, unmounted: {}, }, [transitions.SCALE]: { entering: { transform: 'scale(0)' }, entered: { transform: 'scale(1)' }, exiting: { transform: 'scale(0)' }, exited: { transform: 'scale(1)' }, unmounted: {}, } }; const Transition = (_a) => { var { children, type } = _a, props = __rest(_a, ["children", "type"]); const ref = useRef(null); return (React.createElement(AlertTransition, Object.assign({ nodeRef: ref }, props, { timeout: duration }), (state) => (React.createElement("div", { ref: ref, style: Object.assign(Object.assign({}, defaultStyle[type]), (transitionStyles[type][state] || {})) }, children)))); }; export default Transition; //# sourceMappingURL=Transition.js.map