resizePanel.tsx 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import {CSSProperties} from 'react';
  2. import BaseResizePanel from 'react-resize-panel';
  3. import styled from '@emotion/styled';
  4. type Props = {
  5. direction: 'n' | 'e' | 's' | 'w';
  6. minHeight?: number;
  7. minWidth?: number;
  8. modifierClass?: string;
  9. style?: CSSProperties;
  10. };
  11. export const CLASSNAMES = {
  12. bar: {
  13. height: 'resizeHeightBar',
  14. width: 'resizeWidthBar',
  15. },
  16. handle: {
  17. height: 'resizeHeightHandle',
  18. width: 'resizeWidthHandle',
  19. },
  20. };
  21. const ResizePanel = styled(function ResizePanelContent({
  22. direction,
  23. modifierClass = '',
  24. ...props
  25. }: Props) {
  26. const movesUpDown = ['n', 's'].includes(direction);
  27. const borderClass = movesUpDown ? CLASSNAMES.bar.height : CLASSNAMES.bar.width;
  28. const handleClass = movesUpDown ? CLASSNAMES.handle.height : CLASSNAMES.handle.width;
  29. return (
  30. <BaseResizePanel
  31. direction={direction}
  32. {...props}
  33. borderClass={`${borderClass} ${modifierClass}`}
  34. handleClass={`${handleClass} ${modifierClass}`}
  35. />
  36. );
  37. })`
  38. position: relative;
  39. `;
  40. export default ResizePanel;