Skip to content

Commit

Permalink
Allow overriding default validation logic of SelectToZoom
Browse files Browse the repository at this point in the history
  • Loading branch information
axelboc committed Jul 27, 2023
1 parent f609c92 commit c0da8d0
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packages/lib/src/interactions/SelectToZoom.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useVisCanvasContext } from '../vis/shared/VisCanvasProvider';
import Box from './box';
import { useZoomOnSelection } from './hooks';
import type { CommonInteractionProps, Rect, Selection } from './models';
import type { SelectionToolProps } from './SelectionTool';
import SelectionTool from './SelectionTool';
import styles from './SelectToZoom.module.css';
import SvgElement from './svg/SvgElement';
Expand All @@ -14,10 +15,11 @@ const DEFAULT_MIN_ZOOM = 20;

interface Props extends CommonInteractionProps {
minZoom?: number;
validate?: SelectionToolProps['validate'];
}

function SelectToZoom(props: Props) {
const { minZoom = DEFAULT_MIN_ZOOM, ...commonProps } = props;
const { minZoom = DEFAULT_MIN_ZOOM, validate, ...commonProps } = props;
const {
canvasSize,
canvasRatio,
Expand Down Expand Up @@ -58,7 +60,9 @@ function SelectToZoom(props: Props) {
<SelectionTool
id="SelectToZoom"
transform={computeZoomSelection}
validate={({ html }) => Box.fromPoints(...html).hasMinSize(minZoom)}
validate={
validate || (({ html }) => Box.fromPoints(...html).hasMinSize(minZoom))
}
onValidSelection={zoomOnSelection}
{...commonProps}
>
Expand Down

0 comments on commit c0da8d0

Please sign in to comment.