diff --git a/src/component/elements/ResizerWithScale.tsx b/src/component/elements/ResizerWithScale.tsx index ba89dcf8ef..e183088774 100644 --- a/src/component/elements/ResizerWithScale.tsx +++ b/src/component/elements/ResizerWithScale.tsx @@ -3,7 +3,7 @@ import { useEffect, useState } from 'react'; import { useScaleX } from '../1d/utilities/scale'; import { useGlobal } from '../context/GlobalContext'; -import Resizer, { ResizerProps } from './resizer/Resizer'; +import SVGResizer, { ResizerProps } from './resizer/SVGResizer'; interface ResizerWithScaleProps { disabled: boolean; @@ -28,8 +28,7 @@ export function ResizerWithScale(props: ResizerWithScaleProps) { }, [from, scaleX, to]); return ( - setPosition(p)} > {children} - + ); } diff --git a/src/component/elements/resizer/DivResizer.tsx b/src/component/elements/resizer/DivResizer.tsx deleted file mode 100644 index 6429b1531a..0000000000 --- a/src/component/elements/resizer/DivResizer.tsx +++ /dev/null @@ -1,95 +0,0 @@ -/** @jsxImportSource @emotion/react */ -import { css } from '@emotion/react'; -import { CSSProperties } from 'react'; - -import { Draggable } from '../draggable/useDraggable'; - -import { ResizerProps, Position } from './Resizer'; -import useResizer from './useResizer'; - -const anchorStyle: CSSProperties = { - marginLeft: '5px', - width: '2px', - height: '100%', - pointerEvents: 'none', - position: 'relative', -}; -const styles = { - container: (position: number) => css` - position: absolute; - height: 100%; - width: 10px; - left: -5px; - cursor: e-resize; - transform: translateX(${position}px); - user-select: none; - z-index: 99999999; - - &:hover { - div { - background-color: red; - } - } - `, - - content: (left: Draggable, right: Draggable, prevPosition: Position) => { - const width = prevPosition.x2 - prevPosition.x1; - - const baseCss = css` - position: absolute; - width: ${width}px; - overflow: hidden; - `; - if (right.position.action === 'move' || left.position.action === 'move') { - const scale = (right.position.value.x - left.position.value.x) / width; - return [ - baseCss, - css` - transform: translateX(${left.position.value.x}px) scaleX(${scale}); - transform-origin: left center; - `, - ]; - } else { - return css([ - baseCss, - css` - transform: translateX(${left.position.value.x}px); - `, - ]); - } - }, -}; - -export default function DivResizer(props: ResizerProps) { - const { children, disabled } = props; - const { left, right, prevPosition, currentPosition, isActive } = - useResizer(props); - - return ( - <> - {!disabled && ( -
-
-
- )} -
- {typeof children === 'function' - ? children?.(currentPosition, isActive) - : children} -
- {!disabled && ( -
-
-
- )} - - ); -} diff --git a/src/component/elements/resizer/Resizer.tsx b/src/component/elements/resizer/Resizer.tsx deleted file mode 100644 index bd22c20442..0000000000 --- a/src/component/elements/resizer/Resizer.tsx +++ /dev/null @@ -1,32 +0,0 @@ -import DivResizer from './DivResizer'; -import SVGResizer from './SVGResizer'; - -export interface Position { - x1: number; - x2: number; -} - -type ChildType = React.ReactElement[] | React.ReactElement | boolean | null; - -export interface ResizerProps { - children?: ChildType | ((position: Position, isActive: boolean) => ChildType); - position: Position; - onStart?: PositionChangeHandler; - onMove?: PositionChangeHandler; - onEnd?: PositionChangeHandler; - tag?: 'div' | 'svg'; - parentElement?: HTMLElement | null; - dragHandleClassName?: string; - disabled?: boolean; -} - -type PositionChangeHandler = (data: Position) => void; - -export default function Resizer(props: ResizerProps) { - const { tag = 'div', ...resProps } = props; - if (tag === 'div') { - return ; - } else { - return ; - } -} diff --git a/src/component/elements/resizer/SVGResizer.tsx b/src/component/elements/resizer/SVGResizer.tsx index 6e57ba4a26..49e09600b4 100644 --- a/src/component/elements/resizer/SVGResizer.tsx +++ b/src/component/elements/resizer/SVGResizer.tsx @@ -1,8 +1,8 @@ +/* eslint-disable react/no-unused-prop-types */ /** @jsxImportSource @emotion/react */ import { css } from '@emotion/react'; import { CSSProperties } from 'react'; -import { ResizerProps } from './Resizer'; import useResizer from './useResizer'; const style: Record<'anchor' | 'innerContainer', CSSProperties> = { @@ -33,6 +33,26 @@ const styles = { `, }; +export interface Position { + x1: number; + x2: number; +} + +type ChildType = React.ReactElement[] | React.ReactElement | boolean | null; + +export interface ResizerProps { + children?: ChildType | ((position: Position, isActive: boolean) => ChildType); + position: Position; + onStart?: PositionChangeHandler; + onMove?: PositionChangeHandler; + onEnd?: PositionChangeHandler; + parentElement?: HTMLElement | null; + dragHandleClassName?: string; + disabled?: boolean; +} + +type PositionChangeHandler = (data: Position) => void; + export default function SVGResizer(props: ResizerProps) { const { children, disabled, position } = props; const { left, right, isActive } = useResizer(props); diff --git a/src/component/elements/resizer/useResizer.tsx b/src/component/elements/resizer/useResizer.tsx index 4ecdacdd53..38b5d884aa 100644 --- a/src/component/elements/resizer/useResizer.tsx +++ b/src/component/elements/resizer/useResizer.tsx @@ -2,7 +2,7 @@ import { useRef } from 'react'; import useDraggable, { Draggable } from '../draggable/useDraggable'; -import { ResizerProps, Position } from './Resizer'; +import { ResizerProps, Position } from './SVGResizer'; interface UseResizer { right: Draggable;