newWidgetBuilder.tsx 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import {Fragment, useEffect} from 'react';
  2. import {css} from '@emotion/react';
  3. import styled from '@emotion/styled';
  4. import {AnimatePresence, motion} from 'framer-motion';
  5. import useKeyPress from 'sentry/utils/useKeyPress';
  6. import WidgetBuilderSlideout from 'sentry/views/dashboards/widgetBuilder/components/widgetBuilderSlideout';
  7. import {WidgetBuilderProvider} from 'sentry/views/dashboards/widgetBuilder/contexts/widgetBuilderContext';
  8. type DevWidgetBuilderProps = {
  9. isOpen: boolean;
  10. onClose: () => void;
  11. };
  12. function WidgetBuilderV2({isOpen, onClose}: DevWidgetBuilderProps) {
  13. const escapeKeyPressed = useKeyPress('Escape');
  14. useEffect(() => {
  15. if (escapeKeyPressed) {
  16. if (isOpen) {
  17. onClose?.();
  18. }
  19. }
  20. }, [escapeKeyPressed, isOpen, onClose]);
  21. return (
  22. <Fragment>
  23. {isOpen && <Backdrop style={{opacity: 0.5, pointerEvents: 'auto'}} />}
  24. <AnimatePresence>
  25. {isOpen && (
  26. <WidgetBuilderProvider>
  27. <WidgetBuilderContainer>
  28. <WidgetBuilderSlideout isOpen={isOpen} onClose={onClose} />
  29. <SampleWidgetCard
  30. initial={{opacity: 0, x: '50%', y: 0}}
  31. animate={{opacity: 1, x: 0, y: 0}}
  32. exit={{opacity: 0, x: '50%', y: 0}}
  33. transition={{
  34. type: 'spring',
  35. stiffness: 500,
  36. damping: 50,
  37. }}
  38. >
  39. {'TEST WIDGET'}
  40. </SampleWidgetCard>
  41. </WidgetBuilderContainer>
  42. </WidgetBuilderProvider>
  43. )}
  44. </AnimatePresence>
  45. </Fragment>
  46. );
  47. }
  48. export default WidgetBuilderV2;
  49. const fullPageCss = css`
  50. position: absolute;
  51. top: 0;
  52. right: 0;
  53. bottom: 0;
  54. left: 0;
  55. `;
  56. const Backdrop = styled('div')`
  57. ${fullPageCss};
  58. z-index: ${p => p.theme.zIndex.widgetBuilderDrawer};
  59. background: ${p => p.theme.black};
  60. will-change: opacity;
  61. transition: opacity 200ms;
  62. pointer-events: none;
  63. opacity: 0;
  64. `;
  65. // TODO: Make this centered
  66. const SampleWidgetCard = styled(motion.div)`
  67. width: 400px;
  68. height: 300px;
  69. border: 2px dashed ${p => p.theme.border};
  70. border-radius: ${p => p.theme.borderRadius};
  71. background-color: ${p => p.theme.background};
  72. align-content: center;
  73. text-align: center;
  74. z-index: ${p => p.theme.zIndex.widgetBuilderDrawer};
  75. position: relative;
  76. margin-right: 2%;
  77. `;
  78. const WidgetBuilderContainer = styled('div')`
  79. ${fullPageCss}
  80. z-index: ${p => p.theme.zIndex.widgetBuilderDrawer};
  81. display: flex;
  82. align-items: center;
  83. justify-content: space-between;
  84. `;