ExploreDrawer.tsx 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. // Libraries
  2. import { css, cx, keyframes } from '@emotion/css';
  3. import { Resizable, ResizeCallback } from 're-resizable';
  4. import React from 'react';
  5. // Services & Utils
  6. import { GrafanaTheme2 } from '@grafana/data';
  7. import { stylesFactory, useTheme2 } from '@grafana/ui';
  8. // Types
  9. const drawerSlide = (theme: GrafanaTheme2) => keyframes`
  10. 0% {
  11. transform: translateY(${theme.components.horizontalDrawer.defaultHeight}px);
  12. }
  13. 100% {
  14. transform: translateY(0px);
  15. }
  16. `;
  17. const getStyles = stylesFactory((theme: GrafanaTheme2) => {
  18. return {
  19. container: css`
  20. position: fixed !important;
  21. bottom: 0;
  22. background: ${theme.colors.background.primary};
  23. border-top: 1px solid ${theme.colors.border.weak};
  24. margin: ${theme.spacing(0, -2, 0, -2)};
  25. box-shadow: ${theme.shadows.z3};
  26. z-index: ${theme.zIndex.sidemenu};
  27. `,
  28. drawerActive: css`
  29. opacity: 1;
  30. animation: 0.5s ease-out ${drawerSlide(theme)};
  31. `,
  32. rzHandle: css`
  33. background: ${theme.colors.secondary.main};
  34. transition: 0.3s background ease-in-out;
  35. position: relative;
  36. width: 200px !important;
  37. height: 7px !important;
  38. left: calc(50% - 100px) !important;
  39. top: -4px !important;
  40. cursor: grab;
  41. border-radius: 4px;
  42. &:hover {
  43. background: ${theme.colors.secondary.shade};
  44. }
  45. `,
  46. };
  47. });
  48. export interface Props {
  49. width: number;
  50. children: React.ReactNode;
  51. onResize?: ResizeCallback;
  52. }
  53. export function ExploreDrawer(props: Props) {
  54. const { width, children, onResize } = props;
  55. const theme = useTheme2();
  56. const styles = getStyles(theme);
  57. const drawerWidth = `${width + 31.5}px`;
  58. return (
  59. <Resizable
  60. className={cx(styles.container, styles.drawerActive)}
  61. defaultSize={{ width: drawerWidth, height: `${theme.components.horizontalDrawer.defaultHeight}px` }}
  62. handleClasses={{ top: styles.rzHandle }}
  63. enable={{
  64. top: true,
  65. right: false,
  66. bottom: false,
  67. left: false,
  68. topRight: false,
  69. bottomRight: false,
  70. bottomLeft: false,
  71. topLeft: false,
  72. }}
  73. maxHeight="100vh"
  74. maxWidth={drawerWidth}
  75. minWidth={drawerWidth}
  76. onResize={onResize}
  77. >
  78. {children}
  79. </Resizable>
  80. );
  81. }