util.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. export function getPlacementStyle(placement, top, bottom) {
  2. let style;
  3. top = typeof top === 'number' ? `${top}px` : top;
  4. bottom = typeof bottom === 'number' ? `${bottom}px` : bottom;
  5. switch (placement) {
  6. case 'top':
  7. style = {
  8. left: '50%',
  9. transform: 'translateX(-50%)',
  10. right: 'auto',
  11. top,
  12. bottom: 'auto'
  13. };
  14. break;
  15. case 'topLeft':
  16. style = {
  17. left: 0,
  18. top,
  19. bottom: 'auto'
  20. };
  21. break;
  22. case 'topRight':
  23. style = {
  24. right: 0,
  25. top,
  26. bottom: 'auto'
  27. };
  28. break;
  29. case 'bottom':
  30. style = {
  31. left: '50%',
  32. transform: 'translateX(-50%)',
  33. right: 'auto',
  34. top: 'auto',
  35. bottom
  36. };
  37. break;
  38. case 'bottomLeft':
  39. style = {
  40. left: 0,
  41. top: 'auto',
  42. bottom
  43. };
  44. break;
  45. default:
  46. style = {
  47. right: 0,
  48. top: 'auto',
  49. bottom
  50. };
  51. break;
  52. }
  53. return style;
  54. }
  55. export function getMotion(prefixCls) {
  56. return {
  57. name: `${prefixCls}-fade`
  58. };
  59. }