collapse-transition.js 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. 'use strict';
  2. exports.__esModule = true;
  3. var _dom = require('element-ui/lib/utils/dom');
  4. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  5. var Transition = function () {
  6. function Transition() {
  7. _classCallCheck(this, Transition);
  8. }
  9. Transition.prototype.beforeEnter = function beforeEnter(el) {
  10. (0, _dom.addClass)(el, 'collapse-transition');
  11. if (!el.dataset) el.dataset = {};
  12. el.dataset.oldPaddingTop = el.style.paddingTop;
  13. el.dataset.oldPaddingBottom = el.style.paddingBottom;
  14. el.style.height = '0';
  15. el.style.paddingTop = 0;
  16. el.style.paddingBottom = 0;
  17. };
  18. Transition.prototype.enter = function enter(el) {
  19. el.dataset.oldOverflow = el.style.overflow;
  20. if (el.scrollHeight !== 0) {
  21. el.style.height = el.scrollHeight + 'px';
  22. el.style.paddingTop = el.dataset.oldPaddingTop;
  23. el.style.paddingBottom = el.dataset.oldPaddingBottom;
  24. } else {
  25. el.style.height = '';
  26. el.style.paddingTop = el.dataset.oldPaddingTop;
  27. el.style.paddingBottom = el.dataset.oldPaddingBottom;
  28. }
  29. el.style.overflow = 'hidden';
  30. };
  31. Transition.prototype.afterEnter = function afterEnter(el) {
  32. // for safari: remove class then reset height is necessary
  33. (0, _dom.removeClass)(el, 'collapse-transition');
  34. el.style.height = '';
  35. el.style.overflow = el.dataset.oldOverflow;
  36. };
  37. Transition.prototype.beforeLeave = function beforeLeave(el) {
  38. if (!el.dataset) el.dataset = {};
  39. el.dataset.oldPaddingTop = el.style.paddingTop;
  40. el.dataset.oldPaddingBottom = el.style.paddingBottom;
  41. el.dataset.oldOverflow = el.style.overflow;
  42. el.style.height = el.scrollHeight + 'px';
  43. el.style.overflow = 'hidden';
  44. };
  45. Transition.prototype.leave = function leave(el) {
  46. if (el.scrollHeight !== 0) {
  47. // for safari: add class after set height, or it will jump to zero height suddenly, weired
  48. (0, _dom.addClass)(el, 'collapse-transition');
  49. el.style.height = 0;
  50. el.style.paddingTop = 0;
  51. el.style.paddingBottom = 0;
  52. }
  53. };
  54. Transition.prototype.afterLeave = function afterLeave(el) {
  55. (0, _dom.removeClass)(el, 'collapse-transition');
  56. el.style.height = '';
  57. el.style.overflow = el.dataset.oldOverflow;
  58. el.style.paddingTop = el.dataset.oldPaddingTop;
  59. el.style.paddingBottom = el.dataset.oldPaddingBottom;
  60. };
  61. return Transition;
  62. }();
  63. exports.default = {
  64. name: 'ElCollapseTransition',
  65. functional: true,
  66. render: function render(h, _ref) {
  67. var children = _ref.children;
  68. var data = {
  69. on: new Transition()
  70. };
  71. return h('transition', data, children);
  72. }
  73. };