motion.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import { defaultPrefixCls } from '../config-provider';
  2. // ================== Collapse Motion ==================
  3. const getCollapsedHeight = () => ({
  4. height: 0,
  5. opacity: 0
  6. });
  7. const getRealHeight = node => {
  8. const {
  9. scrollHeight
  10. } = node;
  11. return {
  12. height: scrollHeight,
  13. opacity: 1
  14. };
  15. };
  16. const getCurrentHeight = node => ({
  17. height: node ? node.offsetHeight : 0
  18. });
  19. const skipOpacityTransition = (_, event) => (event === null || event === void 0 ? void 0 : event.deadline) === true || event.propertyName === 'height';
  20. const initCollapseMotion = (rootCls = defaultPrefixCls) => ({
  21. motionName: `${rootCls}-motion-collapse`,
  22. onAppearStart: getCollapsedHeight,
  23. onEnterStart: getCollapsedHeight,
  24. onAppearActive: getRealHeight,
  25. onEnterActive: getRealHeight,
  26. onLeaveStart: getCurrentHeight,
  27. onLeaveActive: getCollapsedHeight,
  28. onAppearEnd: skipOpacityTransition,
  29. onEnterEnd: skipOpacityTransition,
  30. onLeaveEnd: skipOpacityTransition,
  31. motionDeadline: 500
  32. });
  33. const _SelectPlacements = ['bottomLeft', 'bottomRight', 'topLeft', 'topRight'];
  34. const getTransitionName = (rootPrefixCls, motion, transitionName) => {
  35. if (transitionName !== undefined) {
  36. return transitionName;
  37. }
  38. return `${rootPrefixCls}-${motion}`;
  39. };
  40. export { getTransitionName };
  41. export default initCollapseMotion;