Skip to content

Commit

Permalink
refactor: resizer component (#1568)
Browse files Browse the repository at this point in the history
* chore: downgrade react-d3-utils

* Revert "chore: downgrade react-d3-utils"

This reverts commit e64a26d.

* refactor: use inline style

* refactor: remove memoization
  • Loading branch information
hamed-musallam authored Jun 3, 2022
1 parent e01e263 commit d2449e3
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 30 deletions.
41 changes: 22 additions & 19 deletions src/component/elements/resizer/SVGResizer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,32 @@ import { CSSProperties, MouseEventHandler } from 'react';
import { ResizerProps } from './Resizer';
import useResizer from './useResizer';

const anchorStyle: CSSProperties = {
width: '2px',
height: '100%',
pointerEvents: 'none',
fill: 'transparent',
const style: Record<'anchor' | 'innerContainer', CSSProperties> = {
anchor: {
width: '2px',
height: '100%',
pointerEvents: 'none',
fill: 'transparent',
},
innerContainer: {
position: 'absolute',
height: '100%',
fill: 'transparent',
width: '10px',
cursor: 'e-resize',
userSelect: 'none',
zIndex: 99999999,
},
};

const styles = {
container: (position: number) => css`
transform: translateX(${position}px);
container: css`
&:hover {
rect:last-child {
fill: red !important;
}
}
`,
innerContainer: css`
position: absolute;
height: 100%;
fill: transparent;
width: 10px;
cursor: e-resize;
user-select: none;
z-index: 99999999;
`,
};

export default function SVGResizer(props: ResizerProps) {
Expand Down Expand Up @@ -60,11 +62,12 @@ function SVGResizerHandle(props: {
return (
<g
onMouseDown={props.onMouseDown}
css={styles.container(props.position)}
css={styles.container}
style={{ transform: `translateX(${props.position}px)` }}
data-no-export="true"
>
<rect x="-5px" css={styles.innerContainer} />
<rect x="-2.5px" style={anchorStyle} />
<rect x="-5px" style={style.innerContainer} />
<rect x="-2.5px" style={style.anchor} />
</g>
);
}
19 changes: 8 additions & 11 deletions src/component/elements/resizer/useResizer.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect, useMemo, useRef } from 'react';
import { useEffect, useRef } from 'react';

import useDraggable, { Draggable } from '../draggble/useDraggable';

Expand Down Expand Up @@ -87,14 +87,11 @@ export default function useResizer(props: ResizerProps): UseResizer {
triggerEvent.current(position, action);
}, [right.position]);

return useMemo(
() => ({
left,
right,
prevPosition: prevPosition.current,
currentPosition: currentPosition.current,
isActive: activeRef.current,
}),
[left, right],
);
return {
left,
right,
prevPosition: prevPosition.current,
currentPosition: currentPosition.current,
isActive: activeRef.current,
};
}

0 comments on commit d2449e3

Please sign in to comment.