slideOverPanel.tsx 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import {ForwardedRef, forwardRef, useEffect} from 'react';
  2. import isPropValid from '@emotion/is-prop-valid';
  3. import styled from '@emotion/styled';
  4. import {motion} from 'framer-motion';
  5. import {trackAnalytics} from 'sentry/utils/analytics';
  6. import {useLocation} from 'sentry/utils/useLocation';
  7. import useOrganization from 'sentry/utils/useOrganization';
  8. const PANEL_WIDTH = '50vw';
  9. type SlideOverPanelProps = {
  10. children: React.ReactNode;
  11. collapsed: boolean;
  12. };
  13. export default forwardRef(SlideOverPanel);
  14. function SlideOverPanel(
  15. {collapsed, children}: SlideOverPanelProps,
  16. ref: ForwardedRef<HTMLDivElement>
  17. ) {
  18. const {query} = useLocation();
  19. const organization = useOrganization();
  20. useEffect(() => {
  21. if (!collapsed) {
  22. trackAnalytics('starfish.panel.open', {organization});
  23. }
  24. }, [query, collapsed, organization]);
  25. return (
  26. <_SlideOverPanel
  27. ref={ref}
  28. collapsed={collapsed}
  29. initial={{opacity: 0, x: PANEL_WIDTH}}
  30. animate={!collapsed ? {opacity: 1, x: 0} : {opacity: 0, x: PANEL_WIDTH}}
  31. transition={{
  32. type: 'spring',
  33. stiffness: 500,
  34. damping: 50,
  35. }}
  36. >
  37. {children}
  38. </_SlideOverPanel>
  39. );
  40. }
  41. const _SlideOverPanel = styled(motion.div, {
  42. shouldForwardProp: prop =>
  43. ['animate', 'transition', 'initial'].includes(prop) ||
  44. (prop !== 'collapsed' && isPropValid(prop)),
  45. })<{
  46. collapsed: boolean;
  47. }>`
  48. width: ${PANEL_WIDTH};
  49. position: fixed;
  50. top: 0;
  51. bottom: 0;
  52. right: 0;
  53. background: ${p => p.theme.background};
  54. color: ${p => p.theme.textColor};
  55. border-left: 1px solid ${p => p.theme.border};
  56. text-align: left;
  57. z-index: ${p => p.theme.zIndex.sidebar - 1};
  58. ${p =>
  59. p.collapsed
  60. ? 'overflow: hidden;'
  61. : `overflow-x: hidden;
  62. overflow-y: scroll;`}
  63. `;