-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
💄 ♻️ redesign nodes and add toolbar to drag'n'drop new nodes
- Loading branch information
Showing
11 changed files
with
257 additions
and
78 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,21 @@ | ||
import React, { createContext, useContext, useState } from 'react' | ||
|
||
type DnDContextType = ReturnType<typeof useState<string | undefined>> | ||
|
||
const DnDContext = createContext<DnDContextType>(['', () => {}]) | ||
|
||
export const useDnD = () => { | ||
return useContext(DnDContext) | ||
} | ||
|
||
export const DnDProvider: React.FC<{children: React.ReactNode}> = ({ children }) => { | ||
const [type, setType] = useState<string | undefined>('') | ||
|
||
return ( | ||
<DnDContext.Provider value={[type, setType]}> | ||
{children} | ||
</DnDContext.Provider> | ||
) | ||
} | ||
|
||
export default DnDContext |
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import React from 'react' | ||
import { Panel } from '@xyflow/react' | ||
import { useDnD } from '../dnd/context' | ||
|
||
const NodeSelector: React.FC = () => { | ||
const [_, setType] = useDnD() | ||
|
||
const onDragStart = (event: React.DragEvent<HTMLButtonElement>, nodeType: string) => { | ||
setType(nodeType) | ||
event.dataTransfer!.effectAllowed = 'move' | ||
} | ||
|
||
return ( | ||
<Panel position="bottom-center"> | ||
<div className="flex flex-row items-center gap-2 white z-depth-2 p-1"> | ||
<button | ||
className="btn-small tooltipped blue" | ||
data-position="top" | ||
data-tooltip="Transform Node" | ||
draggable | ||
onDragStart={(event) => onDragStart(event, 'transform')} | ||
> | ||
<i className="material-icons">filter_alt</i> | ||
</button> | ||
<button | ||
className="btn-small tooltipped red" | ||
data-position="top" | ||
data-tooltip="Switch Node" | ||
draggable | ||
onDragStart={(event) => onDragStart(event, 'switch')} | ||
> | ||
<i className="material-icons">device_hub</i> | ||
</button> | ||
<button | ||
className="btn-small tooltipped purple" | ||
data-position="top" | ||
data-tooltip="Router Node" | ||
draggable | ||
onDragStart={(event) => onDragStart(event, 'router')} | ||
> | ||
<i className="material-icons">storage</i> | ||
</button> | ||
</div> | ||
</Panel> | ||
) | ||
} | ||
|
||
export default NodeSelector |
2 changes: 1 addition & 1 deletion
2
web/components/floweditor/src/context.ts → web/components/floweditor/src/flow/hooks.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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import React from 'react' | ||
import { Handle, Position, NodeProps } from '@xyflow/react' | ||
|
||
|
||
const SourceNode: React.FC<NodeProps> = ({}) => { | ||
return ( | ||
<> | ||
<div | ||
className=" | ||
flex flex-row items-stretch | ||
z-depth-1 p-0 gap-2 | ||
white black-text | ||
hoverable | ||
" | ||
style={{ | ||
border: '4px solid #EF6C00', | ||
}} | ||
> | ||
<div className="orange white-text px-3 py-1 flex flex-row items-center"> | ||
<i className="material-icons small">input</i> | ||
</div> | ||
<div className="px-3 py-1 flex flex-row items-center"> | ||
<span className="font-semibold">Log Source</span> | ||
</div> | ||
</div> | ||
<Handle | ||
type="source" | ||
position={Position.Right} | ||
style={{ | ||
width: '12px', | ||
height: '12px', | ||
}} | ||
/> | ||
</> | ||
) | ||
} | ||
|
||
export default SourceNode |
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
Oops, something went wrong.