Skip to content

Commit

Permalink
refactor: resizer component and remove div resizer
Browse files Browse the repository at this point in the history
  • Loading branch information
hamed-musallam committed Nov 2, 2023
1 parent c7b05c9 commit efc4100
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 133 deletions.
7 changes: 3 additions & 4 deletions src/component/elements/ResizerWithScale.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -28,15 +28,14 @@ export function ResizerWithScale(props: ResizerWithScaleProps) {
}, [from, scaleX, to]);

return (
<Resizer
tag="svg"
<SVGResizer
position={position}
onEnd={onEnd}
parentElement={viewerRef}
disabled={disabled}
onMove={(p) => setPosition(p)}
>
{children}
</Resizer>
</SVGResizer>
);
}
95 changes: 0 additions & 95 deletions src/component/elements/resizer/DivResizer.tsx

This file was deleted.

32 changes: 0 additions & 32 deletions src/component/elements/resizer/Resizer.tsx

This file was deleted.

22 changes: 21 additions & 1 deletion src/component/elements/resizer/SVGResizer.tsx
Original file line number Diff line number Diff line change
@@ -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> = {
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/component/elements/resizer/useResizer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit efc4100

Please sign in to comment.