Skip to content

Commit

Permalink
Allow overriding Pan interaction ID
Browse files Browse the repository at this point in the history
  • Loading branch information
axelboc committed Jul 12, 2022
1 parent a613d45 commit d0eeb8a
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
26 changes: 26 additions & 0 deletions apps/storybook/src/Pan.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,43 @@ Disabled.args = {
disabled: true,
};

export const TwoComponents: Story<PanProps> = (args) => {
return (
<VisCanvas
title="Pan with middle button, or with <modifierKey> + left button"
abscissaConfig={{ visDomain: [-10, 0], showGrid: true }}
ordinateConfig={{ visDomain: [50, 100], showGrid: true }}
>
<Pan id="PanMiddle" button={MouseButton.Middle} />
<Pan
id="PanLeft"
button={MouseButton.Left}
modifierKey={args.modifierKey}
/>
<Zoom />
<ResetZoomButton />
</VisCanvas>
);
};
TwoComponents.args = { modifierKey: ['Control'] };
TwoComponents.argTypes = {
button: { control: false },
disabled: { control: false },
};

export default {
title: 'Building Blocks/Interactions/Pan',
component: Pan,
parameters: { layout: 'fullscreen' },
decorators: [FillHeight],
args: {
id: undefined,
button: [MouseButton.Left],
modifierKey: [],
disabled: false,
},
argTypes: {
id: { control: false },
button: {
control: {
type: 'inline-check',
Expand Down
2 changes: 1 addition & 1 deletion packages/lib/src/interactions/AxialSelectToZoom.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ function AxialSelectToZoom(props: Props) {

return (
<SelectionTool
onSelectionEnd={onSelectionEnd}
id={`${axis.toUpperCase()}SelectToZoom`}
modifierKey={modifierKey}
disabled={disabled}
onSelectionEnd={onSelectionEnd}
>
{(selection) => (
<SelectionRect
Expand Down
10 changes: 8 additions & 2 deletions packages/lib/src/interactions/Pan.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,20 @@ import type { CanvasEvent, CommonInteractionProps } from './models';
import { getModifierKeyArray } from './utils';

interface Props extends CommonInteractionProps {
id?: string;
button?: MouseButton | MouseButton[];
}

function Pan(props: Props) {
const { button = MouseButton.Left, modifierKey, disabled } = props;
const {
id = 'Pan',
button = MouseButton.Left,
modifierKey,
disabled,
} = props;

const modifierKeys = getModifierKeyArray(modifierKey);
const shouldInteract = useInteraction('Pan', {
const shouldInteract = useInteraction(id, {
button,
modifierKeys,
disabled,
Expand Down

0 comments on commit d0eeb8a

Please sign in to comment.