Dashboard sipadu mbip
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

CSSTransition.js 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  1. "use strict";
  2. exports.__esModule = true;
  3. exports.default = void 0;
  4. var _propTypes = _interopRequireDefault(require("prop-types"));
  5. var _addClass2 = _interopRequireDefault(require("dom-helpers/addClass"));
  6. var _removeClass = _interopRequireDefault(require("dom-helpers/removeClass"));
  7. var _react = _interopRequireDefault(require("react"));
  8. var _Transition = _interopRequireDefault(require("./Transition"));
  9. var _PropTypes = require("./utils/PropTypes");
  10. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  11. function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
  12. function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
  13. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
  14. var _addClass = function addClass(node, classes) {
  15. return node && classes && classes.split(' ').forEach(function (c) {
  16. return (0, _addClass2.default)(node, c);
  17. });
  18. };
  19. var removeClass = function removeClass(node, classes) {
  20. return node && classes && classes.split(' ').forEach(function (c) {
  21. return (0, _removeClass.default)(node, c);
  22. });
  23. };
  24. /**
  25. * A transition component inspired by the excellent
  26. * [ng-animate](http://www.nganimate.org/) library, you should use it if you're
  27. * using CSS transitions or animations. It's built upon the
  28. * [`Transition`](https://reactcommunity.org/react-transition-group/transition)
  29. * component, so it inherits all of its props.
  30. *
  31. * `CSSTransition` applies a pair of class names during the `appear`, `enter`,
  32. * and `exit` states of the transition. The first class is applied and then a
  33. * second `*-active` class in order to activate the CSS transition. After the
  34. * transition, matching `*-done` class names are applied to persist the
  35. * transition state.
  36. *
  37. * ```jsx
  38. * function App() {
  39. * const [inProp, setInProp] = useState(false);
  40. * return (
  41. * <div>
  42. * <CSSTransition in={inProp} timeout={200} classNames="my-node">
  43. * <div>
  44. * {"I'll receive my-node-* classes"}
  45. * </div>
  46. * </CSSTransition>
  47. * <button type="button" onClick={() => setInProp(true)}>
  48. * Click to Enter
  49. * </button>
  50. * </div>
  51. * );
  52. * }
  53. * ```
  54. *
  55. * When the `in` prop is set to `true`, the child component will first receive
  56. * the class `example-enter`, then the `example-enter-active` will be added in
  57. * the next tick. `CSSTransition` [forces a
  58. * reflow](https://github.com/reactjs/react-transition-group/blob/5007303e729a74be66a21c3e2205e4916821524b/src/CSSTransition.js#L208-L215)
  59. * between before adding the `example-enter-active`. This is an important trick
  60. * because it allows us to transition between `example-enter` and
  61. * `example-enter-active` even though they were added immediately one after
  62. * another. Most notably, this is what makes it possible for us to animate
  63. * _appearance_.
  64. *
  65. * ```css
  66. * .my-node-enter {
  67. * opacity: 0;
  68. * }
  69. * .my-node-enter-active {
  70. * opacity: 1;
  71. * transition: opacity 200ms;
  72. * }
  73. * .my-node-exit {
  74. * opacity: 1;
  75. * }
  76. * .my-node-exit-active {
  77. * opacity: 0;
  78. * transition: opacity 200ms;
  79. * }
  80. * ```
  81. *
  82. * `*-active` classes represent which styles you want to animate **to**.
  83. *
  84. * **Note**: If you're using the
  85. * [`appear`](http://reactcommunity.org/react-transition-group/transition#Transition-prop-appear)
  86. * prop, make sure to define styles for `.appear-*` classes as well.
  87. */
  88. var CSSTransition =
  89. /*#__PURE__*/
  90. function (_React$Component) {
  91. _inheritsLoose(CSSTransition, _React$Component);
  92. function CSSTransition() {
  93. var _this;
  94. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  95. args[_key] = arguments[_key];
  96. }
  97. _this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;
  98. _this.appliedClasses = {
  99. appear: {},
  100. enter: {},
  101. exit: {}
  102. };
  103. _this.onEnter = function (node, appearing) {
  104. _this.removeClasses(node, 'exit');
  105. _this.addClass(node, appearing ? 'appear' : 'enter', 'base');
  106. if (_this.props.onEnter) {
  107. _this.props.onEnter(node, appearing);
  108. }
  109. };
  110. _this.onEntering = function (node, appearing) {
  111. var type = appearing ? 'appear' : 'enter';
  112. _this.addClass(node, type, 'active');
  113. if (_this.props.onEntering) {
  114. _this.props.onEntering(node, appearing);
  115. }
  116. };
  117. _this.onEntered = function (node, appearing) {
  118. var type = appearing ? 'appear' : 'enter';
  119. _this.removeClasses(node, type);
  120. _this.addClass(node, type, 'done');
  121. if (_this.props.onEntered) {
  122. _this.props.onEntered(node, appearing);
  123. }
  124. };
  125. _this.onExit = function (node) {
  126. _this.removeClasses(node, 'appear');
  127. _this.removeClasses(node, 'enter');
  128. _this.addClass(node, 'exit', 'base');
  129. if (_this.props.onExit) {
  130. _this.props.onExit(node);
  131. }
  132. };
  133. _this.onExiting = function (node) {
  134. _this.addClass(node, 'exit', 'active');
  135. if (_this.props.onExiting) {
  136. _this.props.onExiting(node);
  137. }
  138. };
  139. _this.onExited = function (node) {
  140. _this.removeClasses(node, 'exit');
  141. _this.addClass(node, 'exit', 'done');
  142. if (_this.props.onExited) {
  143. _this.props.onExited(node);
  144. }
  145. };
  146. _this.getClassNames = function (type) {
  147. var classNames = _this.props.classNames;
  148. var isStringClassNames = typeof classNames === 'string';
  149. var prefix = isStringClassNames && classNames ? classNames + "-" : '';
  150. var baseClassName = isStringClassNames ? "" + prefix + type : classNames[type];
  151. var activeClassName = isStringClassNames ? baseClassName + "-active" : classNames[type + "Active"];
  152. var doneClassName = isStringClassNames ? baseClassName + "-done" : classNames[type + "Done"];
  153. return {
  154. baseClassName: baseClassName,
  155. activeClassName: activeClassName,
  156. doneClassName: doneClassName
  157. };
  158. };
  159. return _this;
  160. }
  161. var _proto = CSSTransition.prototype;
  162. _proto.addClass = function addClass(node, type, phase) {
  163. var className = this.getClassNames(type)[phase + "ClassName"];
  164. if (type === 'appear' && phase === 'done') {
  165. className += " " + this.getClassNames('enter').doneClassName;
  166. } // This is for to force a repaint,
  167. // which is necessary in order to transition styles when adding a class name.
  168. if (phase === 'active') {
  169. /* eslint-disable no-unused-expressions */
  170. node && node.scrollTop;
  171. }
  172. this.appliedClasses[type][phase] = className;
  173. _addClass(node, className);
  174. };
  175. _proto.removeClasses = function removeClasses(node, type) {
  176. var _this$appliedClasses$ = this.appliedClasses[type],
  177. baseClassName = _this$appliedClasses$.base,
  178. activeClassName = _this$appliedClasses$.active,
  179. doneClassName = _this$appliedClasses$.done;
  180. this.appliedClasses[type] = {};
  181. if (baseClassName) {
  182. removeClass(node, baseClassName);
  183. }
  184. if (activeClassName) {
  185. removeClass(node, activeClassName);
  186. }
  187. if (doneClassName) {
  188. removeClass(node, doneClassName);
  189. }
  190. };
  191. _proto.render = function render() {
  192. var _this$props = this.props,
  193. _ = _this$props.classNames,
  194. props = _objectWithoutPropertiesLoose(_this$props, ["classNames"]);
  195. return _react.default.createElement(_Transition.default, _extends({}, props, {
  196. onEnter: this.onEnter,
  197. onEntered: this.onEntered,
  198. onEntering: this.onEntering,
  199. onExit: this.onExit,
  200. onExiting: this.onExiting,
  201. onExited: this.onExited
  202. }));
  203. };
  204. return CSSTransition;
  205. }(_react.default.Component);
  206. CSSTransition.defaultProps = {
  207. classNames: ''
  208. };
  209. CSSTransition.propTypes = process.env.NODE_ENV !== "production" ? _extends({}, _Transition.default.propTypes, {
  210. /**
  211. * The animation classNames applied to the component as it appears, enters,
  212. * exits or has finished the transition. A single name can be provided and it
  213. * will be suffixed for each stage: e.g.
  214. *
  215. * `classNames="fade"` applies `fade-appear`, `fade-appear-active`,
  216. * `fade-appear-done`, `fade-enter`, `fade-enter-active`, `fade-enter-done`,
  217. * `fade-exit`, `fade-exit-active`, and `fade-exit-done`.
  218. *
  219. * **Note**: `fade-appear-done` and `fade-enter-done` will _both_ be applied.
  220. * This allows you to define different behavior for when appearing is done and
  221. * when regular entering is done, using selectors like
  222. * `.fade-enter-done:not(.fade-appear-done)`. For example, you could apply an
  223. * epic entrance animation when element first appears in the DOM using
  224. * [Animate.css](https://daneden.github.io/animate.css/). Otherwise you can
  225. * simply use `fade-enter-done` for defining both cases.
  226. *
  227. * Each individual classNames can also be specified independently like:
  228. *
  229. * ```js
  230. * classNames={{
  231. * appear: 'my-appear',
  232. * appearActive: 'my-active-appear',
  233. * appearDone: 'my-done-appear',
  234. * enter: 'my-enter',
  235. * enterActive: 'my-active-enter',
  236. * enterDone: 'my-done-enter',
  237. * exit: 'my-exit',
  238. * exitActive: 'my-active-exit',
  239. * exitDone: 'my-done-exit',
  240. * }}
  241. * ```
  242. *
  243. * If you want to set these classes using CSS Modules:
  244. *
  245. * ```js
  246. * import styles from './styles.css';
  247. * ```
  248. *
  249. * you might want to use camelCase in your CSS file, that way could simply
  250. * spread them instead of listing them one by one:
  251. *
  252. * ```js
  253. * classNames={{ ...styles }}
  254. * ```
  255. *
  256. * @type {string | {
  257. * appear?: string,
  258. * appearActive?: string,
  259. * appearDone?: string,
  260. * enter?: string,
  261. * enterActive?: string,
  262. * enterDone?: string,
  263. * exit?: string,
  264. * exitActive?: string,
  265. * exitDone?: string,
  266. * }}
  267. */
  268. classNames: _PropTypes.classNamesShape,
  269. /**
  270. * A `<Transition>` callback fired immediately after the 'enter' or 'appear' class is
  271. * applied.
  272. *
  273. * @type Function(node: HtmlElement, isAppearing: bool)
  274. */
  275. onEnter: _propTypes.default.func,
  276. /**
  277. * A `<Transition>` callback fired immediately after the 'enter-active' or
  278. * 'appear-active' class is applied.
  279. *
  280. * @type Function(node: HtmlElement, isAppearing: bool)
  281. */
  282. onEntering: _propTypes.default.func,
  283. /**
  284. * A `<Transition>` callback fired immediately after the 'enter' or
  285. * 'appear' classes are **removed** and the `done` class is added to the DOM node.
  286. *
  287. * @type Function(node: HtmlElement, isAppearing: bool)
  288. */
  289. onEntered: _propTypes.default.func,
  290. /**
  291. * A `<Transition>` callback fired immediately after the 'exit' class is
  292. * applied.
  293. *
  294. * @type Function(node: HtmlElement)
  295. */
  296. onExit: _propTypes.default.func,
  297. /**
  298. * A `<Transition>` callback fired immediately after the 'exit-active' is applied.
  299. *
  300. * @type Function(node: HtmlElement)
  301. */
  302. onExiting: _propTypes.default.func,
  303. /**
  304. * A `<Transition>` callback fired immediately after the 'exit' classes
  305. * are **removed** and the `exit-done` class is added to the DOM node.
  306. *
  307. * @type Function(node: HtmlElement)
  308. */
  309. onExited: _propTypes.default.func
  310. }) : {};
  311. var _default = CSSTransition;
  312. exports.default = _default;
  313. module.exports = exports["default"];