Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p

## [Unreleased]

### Added

- `<Switch />`
- `noDrag` parameter: Add the `nodrag` class to the Switch element. Default: `true`

### Deprecated

- `preventReactFlowActionsClasses`: use `ClassNames.ReactFlow.preventAllActions`

## [26.1.0] - 2026-08-20

### Added
Expand Down
3 changes: 0 additions & 3 deletions src/cmem/react-flow/ReactFlow/ReactFlow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,3 @@ const ReactFlowExtendedPlain = <T extends ReactFlowExtendedProps>(
export const ReactFlowExtended = React.forwardRef(ReactFlowExtendedPlain) as <T extends ReactFlowExtendedProps>(
p: T & { ref?: Ref<HTMLDivElement> },
) => ReactElement;

/** Classes that when set for an element, prevent that they trigger react-flow dragging, wheel and panning actions. */
export const preventReactFlowActionsClasses = "nodrag nopan nowheel";
17 changes: 17 additions & 0 deletions src/cmem/react-flow/ReactFlow/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
Classes that when set for an element, prevent that they trigger react-flow dragging, wheel and panning actions.

This module must stay free of imports, so that basic components can use these class names without pulling the
react-flow packages into their dependency chain.
*/
export const preventReactFlowDragClass = "nodrag";
export const preventReactFlowPanClass = "nopan";
export const preventReactFlowWheelClass = "nowheel";
export const preventReactFlowActionsClasses = `${preventReactFlowDragClass} ${preventReactFlowPanClass} ${preventReactFlowWheelClass}`;

export const helperClasses = {
preventDrag: preventReactFlowDragClass,
preventPan: preventReactFlowPanClass,
preventWheel: preventReactFlowWheelClass,
preventAllActions: preventReactFlowActionsClasses,
};
3 changes: 2 additions & 1 deletion src/components/AutocompleteField/AutoCompleteField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
} from "@blueprintjs/core";
import { Suggest as BlueprintSuggest } from "@blueprintjs/select";

import { preventReactFlowDragClass } from "../../cmem/react-flow/ReactFlow/constants";
import { CLASSPREFIX as eccgui } from "../../configuration/constants";
import {
ContextOverlayProps,
Expand Down Expand Up @@ -485,7 +486,7 @@ export function SuggestField<T, UPDATE_VALUE>(props: SuggestFieldProps<T, UPDATE
query={query}
// This leads to odd compile errors without "as any"
popoverProps={updatedContextOverlayProps as any}
popoverContentProps={{ className: "nodrag" }}
popoverContentProps={{ className: preventReactFlowDragClass }}
selectedItem={selectedItem}
fill={fill}
{...createNewItemProps}
Expand Down
2 changes: 1 addition & 1 deletion src/components/Dialog/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
Overlay2Props as BlueprintOverlayProps,
} from "@blueprintjs/core";

import { preventReactFlowActionsClasses } from "../../cmem";
import { preventReactFlowActionsClasses } from "../../cmem/react-flow/ReactFlow/constants";
import { utils } from "../../common";
import { CLASSPREFIX as eccgui } from "../../configuration/constants";
import { TestableComponent } from "../interfaces";
Expand Down
11 changes: 11 additions & 0 deletions src/components/Switch/Stories/Switch.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,14 @@ WithStateLabel.args = {
innerLabel: "Off",
innerLabelChecked: "On",
};

/**
* By default the `nodrag` class is set, so the switch cannot be used to drag a surrounding element,
* e.g. a React Flow node. Set `noDrag` to `false` to remove the class and allow the drag interaction.
*/
export const WithoutNoDragClass = Template.bind({});
WithoutNoDragClass.args = {
...Default.args,
label: "Switch label, drag interaction not prevented",
noDrag: false,
};
10 changes: 8 additions & 2 deletions src/components/Switch/Switch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
SwitchProps as BlueprintSwitchProps,
} from "@blueprintjs/core";

import { preventReactFlowDragClass } from "../../cmem/react-flow/ReactFlow/constants";
import { CLASSPREFIX as eccgui } from "../../configuration/constants";
import { Label } from "../Label/Label";

Expand All @@ -17,18 +18,23 @@ export interface SwitchProps extends Omit<BlueprintSwitchProps, "onChange"> {
* class names
*/
className?: string;

/** Adds the 'nodrag' class to the element, preventing dragging via the Switch element. Default: true */
noDrag?: boolean;
}

export const Switch = ({ onChange, className, label, ...otherProps }: SwitchProps) => {
export const Switch = ({ onChange, className, label, noDrag = true, ...otherProps }: SwitchProps) => {
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
if (onChange) {
onChange(!!e.target?.checked);
}
};

const noDragClass = noDrag ? `${preventReactFlowDragClass} ` : "";

return (
<BlueprintSwitch
className={`${eccgui}-switch ${className ?? ""} ${
className={`${eccgui}-switch ${noDragClass}${className ?? ""} ${
label && !otherProps.labelElement ? BlueprintClasses.INLINE : ""
}`}
labelElement={
Expand Down
7 changes: 4 additions & 3 deletions src/extensions/react-flow/nodes/NodeContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ import { useStore as getStoreStateFlowV12 } from "@xyflow/react";
import Color from "color";
import { NumberSize, Resizable, ResizableProps, ResizeCallback } from "re-resizable";

import { preventReactFlowDragClass } from "../../../cmem/react-flow/ReactFlow/constants";
import { intentClassName, IntentTypes } from "../../../common/Intent";
import { Depiction, DepictionProps } from "../../../components";
import { ValidIconName } from "../../../components/Icon/canonicalIconNames";
import Icon from "../../../components/Icon/Icon";
import OverflowText from "../../../components/Typography/OverflowText";
import { CLASSPREFIX as eccgui } from "../../../configuration/constants";
import { HandleDefault, HandleDefaultProps } from "../handles/HandleDefault";
import { ReacFlowVersionSupportProps, ReactFlowVersions, useReactFlowVersion } from "../versionsupport";

import { HandleDefault, HandleDefaultProps } from "../handles/HandleDefault";
import { NodeContentExtensionProps } from "./NodeContentExtension";
import { NodeDefaultProps } from "./NodeDefault";
import { NodeHighlightColor } from "./sharedTypes";
Expand Down Expand Up @@ -649,7 +650,7 @@ export function NodeContent<CONTENT_PROPS = React.HTMLAttributes<HTMLElement>>({
)}
</div>
{(menuButtons || (showExecutionButtons && executionButtons)) && (
<div className={`${eccgui}-graphviz__node__header-menu nodrag`}>
<div className={`${eccgui}-graphviz__node__header-menu ${preventReactFlowDragClass}`}>
{showExecutionButtons && typeof executionButtons === "function"
? executionButtons(adjustedContentProps, setAdjustedContentProps)
: null}
Expand Down Expand Up @@ -782,7 +783,7 @@ export function NodeContent<CONTENT_PROPS = React.HTMLAttributes<HTMLElement>>({
(resizeDirections!.right ? ` ${eccgui}-graphviz__node__resizer--right` : "") +
(resizeDirections!.bottom ? ` ${eccgui}-graphviz__node__resizer--bottom` : "")
}
handleWrapperClass={`${eccgui}-graphviz__node__resizer--cursorhandles` + " nodrag"}
handleWrapperClass={`${eccgui}-graphviz__node__resizer--cursorhandles ${preventReactFlowDragClass}`}
size={resizableSize}
maxHeight={resizeMaxDimensions?.height ?? undefined}
maxWidth={resizeMaxDimensions?.width ?? undefined}
Expand Down
7 changes: 6 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Classes as BlueprintClasses } from "@blueprintjs/core";

import {helperClasses as reactFlowHelperClasses } from "./cmem/react-flow/ReactFlow/constants";
import { ClassNames as IntentClassNames } from "./common/Intent";
import * as Skeleton from "./components/Skeleton/classnames";
import * as TypographyClassNames from "./components/Typography/classnames";
Expand All @@ -9,12 +10,16 @@ const ClassNames = {
Intent: IntentClassNames,
Skeleton,
Typography: TypographyClassNames,
ReactFlow: reactFlowHelperClasses,
};

/** @deprecated (v27) use `ClassNames.ReactFlow.preventAllActions` */
const preventReactFlowActionsClasses = reactFlowHelperClasses.preventAllActions;

export * from "./configuration/constants";
export * from "./common";
export * from "./components";
export * from "./extensions";
export * from "./cmem";

export { ClassNames };
export { ClassNames, preventReactFlowActionsClasses };
Loading