123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- import {ForwardedRef, forwardRef, useEffect} from 'react';
- import isPropValid from '@emotion/is-prop-valid';
- import styled from '@emotion/styled';
- import {motion} from 'framer-motion';
- import {trackAnalytics} from 'sentry/utils/analytics';
- import {useLocation} from 'sentry/utils/useLocation';
- import useOrganization from 'sentry/utils/useOrganization';
- const PANEL_WIDTH = '50vw';
- type SlideOverPanelProps = {
- children: React.ReactNode;
- collapsed: boolean;
- };
- export default forwardRef(SlideOverPanel);
- function SlideOverPanel(
- {collapsed, children}: SlideOverPanelProps,
- ref: ForwardedRef<HTMLDivElement>
- ) {
- const {query} = useLocation();
- const organization = useOrganization();
- useEffect(() => {
- if (!collapsed) {
- trackAnalytics('starfish.panel.open', {organization});
- }
- }, [query, collapsed, organization]);
- return (
- <_SlideOverPanel
- ref={ref}
- collapsed={collapsed}
- initial={{opacity: 0, x: PANEL_WIDTH}}
- animate={!collapsed ? {opacity: 1, x: 0} : {opacity: 0, x: PANEL_WIDTH}}
- transition={{
- type: 'spring',
- stiffness: 500,
- damping: 50,
- }}
- >
- {children}
- </_SlideOverPanel>
- );
- }
- const _SlideOverPanel = styled(motion.div, {
- shouldForwardProp: prop =>
- ['animate', 'transition', 'initial'].includes(prop) ||
- (prop !== 'collapsed' && isPropValid(prop)),
- })<{
- collapsed: boolean;
- }>`
- width: ${PANEL_WIDTH};
- position: fixed;
- top: 0;
- bottom: 0;
- right: 0;
- background: ${p => p.theme.background};
- color: ${p => p.theme.textColor};
- border-left: 1px solid ${p => p.theme.border};
- text-align: left;
- z-index: ${p => p.theme.zIndex.sidebar - 1};
- ${p =>
- p.collapsed
- ? 'overflow: hidden;'
- : `overflow-x: hidden;
- overflow-y: scroll;`}
- `;
|