Skip to content

Commit

Permalink
introductionTime parameter for NodeContent to visualize the node was …
Browse files Browse the repository at this point in the history
…added or updated
  • Loading branch information
haschek committed Aug 10, 2023
1 parent 89cec5d commit 73ca297
Show file tree
Hide file tree
Showing 3 changed files with 169 additions and 112 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p

- linting the code automatically via git hook on commit action
- `<HandleTools />`: can be used as single handle content to add an context menu to handles
- `<NodeContent />`
- `introductionTime` parameter could be used to visualize the node was added or updated
- `<SuggestField />`
- will replace `<AutoCompleteField />`
- match dropdown to element width when `fill=true`
Expand Down
32 changes: 30 additions & 2 deletions src/extensions/react-flow/nodes/NodeContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,10 @@ export interface NodeContentProps<NODE_DATA, NODE_CONTENT_PROPS = any>
* The node is displayed with some animated shadow for highlighting purposes.
*/
animated?: boolean;
/**
* Time in ms used for a short animation of the node to visualize it was added or updated.
*/
introductionTime?: number;

/** Additional data stored in the node. */
businessData?: NODE_DATA;
Expand Down Expand Up @@ -324,6 +328,7 @@ export function NodeContent<CONTENT_PROPS = any>({
style = {},
showUnconnectableHandles = false,
animated = false,
introductionTime = 0,
onNodeResize,
nodeDimensions,
// forwarded props
Expand Down Expand Up @@ -386,14 +391,26 @@ export function NodeContent<CONTENT_PROPS = any>({
}
}, [nodeContentRef, onNodeResize, minimalShape, nodeDimensions]);

//update node dimensions when resized
// update node dimensions when resized
React.useEffect(() => {
if (nodeDimensions) {
setWidth(nodeDimensions.width);
setHeight(nodeDimensions.height);
}
}, [nodeDimensions]);

// remove introduction class
React.useEffect(() => {
if (nodeContentRef && introductionTime) {
setTimeout(() => {
nodeContentRef.current.className = nodeContentRef.current.className.replace(
`${eccgui}-graphviz__node--introduction`,
""
);
}, introductionTime);
}
}, [nodeContentRef, introductionTime]);

if (handles.length > 0) {
handles.forEach((handle) => {
if (handle.position) {
Expand Down Expand Up @@ -430,12 +447,22 @@ export function NodeContent<CONTENT_PROPS = any>({

const resizableStyles =
!!onNodeResize === true && minimalShape === "none" && width + height > 0 ? { width, height } : {};

const introductionStyles = introductionTime
? ({ "--node-introduction-time": `${introductionTime}ms` } as React.CSSProperties)
: {};
const nodeContent = (
<>
<section
ref={nodeContentRef}
{...otherProps}
style={{ ...style, ...highlightCustomPropertySettings, ...styleExpandDimensions, ...resizableStyles }}
style={{
...style,
...highlightCustomPropertySettings,
...styleExpandDimensions,
...resizableStyles,
...introductionStyles,
}}
className={
`${eccgui}-graphviz__node` +
` ${eccgui}-graphviz__node--${size}` +
Expand All @@ -452,6 +479,7 @@ export function NodeContent<CONTENT_PROPS = any>({
? " " + gethighlightedStateClasses(highlightedState, `${eccgui}-graphviz__node`)
: "") +
(animated ? ` ${eccgui}-graphviz__node--animated` : "") +
(introductionTime ? ` ${eccgui}-graphviz__node--introduction` : "") +
(showUnconnectableHandles === false ? ` ${eccgui}-graphviz__node--hidehandles` : "") +
(letPassWheelEvents === false ? ` nowheel` : "")
}
Expand Down
Loading

0 comments on commit 73ca297

Please sign in to comment.