Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[3435] Extract diagram style from useDropNode
Bug: #3435 Signed-off-by: Michaël Charfadi <michael.charfadi@obeosoft.com>
- Loading branch information
Showing
9 changed files
with
156 additions
and
147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
...iagrams/frontend/sirius-components-diagrams/src/renderer/dropNode/useDropDiagramStyle.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 Obeo. | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Obeo - initial API and implementation | ||
*******************************************************************************/ | ||
|
||
import { useTheme } from '@material-ui/core/styles'; | ||
import { useContext } from 'react'; | ||
import { useReactFlow } from 'reactflow'; | ||
import { EdgeData, NodeData } from '../DiagramRenderer.types'; | ||
import { DropNodeContext } from './DropNodeContext'; | ||
import { DropNodeContextValue } from './DropNodeContext.types'; | ||
import { useDropDiagramStyleValue } from './useDropDiagramStyle.types'; | ||
|
||
export const useDropDiagramStyle = (): useDropDiagramStyleValue => { | ||
const { droppableOnDiagram } = useContext<DropNodeContextValue>(DropNodeContext); | ||
const { getNodes } = useReactFlow<NodeData, EdgeData>(); | ||
const theme = useTheme(); | ||
|
||
const targetNode = getNodes().find((node) => node.data.isDropNodeTarget); | ||
const draggedNode = getNodes().find((node) => node.dragging); | ||
|
||
const diagramTargeted: boolean = !targetNode && !!draggedNode?.parentNode; | ||
const diagramForbidden: boolean = diagramTargeted && !!draggedNode?.id !== null && !droppableOnDiagram; | ||
const backgroundColor = diagramForbidden ? theme.palette.action.disabledBackground : theme.palette.background.default; | ||
|
||
return { | ||
backgroundColor, | ||
smallGridColor: diagramForbidden ? backgroundColor : '#f1f1f1', | ||
largeGridColor: diagramForbidden ? backgroundColor : '#cccccc', | ||
}; | ||
}; |
18 changes: 18 additions & 0 deletions
18
...ms/frontend/sirius-components-diagrams/src/renderer/dropNode/useDropDiagramStyle.types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 Obeo. | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Obeo - initial API and implementation | ||
*******************************************************************************/ | ||
|
||
export interface useDropDiagramStyleValue { | ||
backgroundColor: string; | ||
smallGridColor: string; | ||
largeGridColor: string; | ||
} |
Oops, something went wrong.