singleConstants.ts 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. // single
  2. const rowStyleBase = {
  3. width: '100%',
  4. height: '10px',
  5. top: '0px',
  6. left: '0px',
  7. cursor: 'row-resize',
  8. } as const;
  9. const colStyleBase = {
  10. width: '10px',
  11. height: '100%',
  12. top: '0px',
  13. left: '0px',
  14. cursor: 'col-resize',
  15. } as const;
  16. const edgeStyleBase = {
  17. width: '20px',
  18. height: '20px',
  19. position: 'absolute',
  20. } as const;
  21. export const directions = ['top', 'right', 'bottom', 'left', 'topRight', 'bottomRight', 'bottomLeft', 'topLeft'] as const;
  22. export const directionStyles = {
  23. top: {
  24. ...rowStyleBase,
  25. top: '-5px',
  26. },
  27. right: {
  28. ...colStyleBase,
  29. left: undefined,
  30. right: '-5px',
  31. },
  32. bottom: {
  33. ...rowStyleBase,
  34. top: undefined,
  35. bottom: '-5px',
  36. },
  37. left: {
  38. ...colStyleBase,
  39. left: '-5px',
  40. },
  41. topRight: {
  42. ...edgeStyleBase,
  43. right: '-10px',
  44. top: '-10px',
  45. cursor: 'ne-resize',
  46. },
  47. bottomRight: {
  48. ...edgeStyleBase,
  49. right: '-10px',
  50. bottom: '-10px',
  51. cursor: 'se-resize',
  52. },
  53. bottomLeft: {
  54. ...edgeStyleBase,
  55. left: '-10px',
  56. bottom: '-10px',
  57. cursor: 'sw-resize',
  58. },
  59. topLeft: {
  60. ...edgeStyleBase,
  61. left: '-10px',
  62. top: '-10px',
  63. cursor: 'nw-resize',
  64. },
  65. } as const;
  66. export type Direction = 'top' | 'right' | 'bottom' | 'left' | 'topRight' | 'bottomRight' | 'bottomLeft' | 'topLeft';
  67. export interface HandleClassName {
  68. top?: string;
  69. right?: string;
  70. bottom?: string;
  71. left?: string;
  72. topRight?: string;
  73. bottomRight?: string;
  74. bottomLeft?: string;
  75. topLeft?: string
  76. }
  77. export type HandlerCallback = (
  78. e: MouseEvent,
  79. direction: Direction
  80. ) => void;
  81. export interface Enable {
  82. top?: boolean;
  83. right?: boolean;
  84. bottom?: boolean;
  85. left?: boolean;
  86. topRight?: boolean;
  87. bottomRight?: boolean;
  88. bottomLeft?: boolean;
  89. topLeft?: boolean
  90. }
  91. export interface Size {
  92. width?: string | number;
  93. height?: string | number
  94. }
  95. export interface NumberSize {
  96. width: number;
  97. height: number
  98. }
  99. export interface NewSize {
  100. newHeight: number | string;
  101. newWidth: number | string
  102. }
  103. export const DEFAULT_SIZE = {
  104. width: 'auto',
  105. height: 'auto',
  106. };
  107. export type ResizeCallback = (
  108. size: Size,
  109. event: MouseEvent,
  110. direction: Direction,
  111. ) => void;
  112. export type ResizeStartCallback = (
  113. e: MouseEvent,
  114. dir: Direction,
  115. ) => void | boolean;