-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allowing specifying the content of ReacNodeViewContent via a Re…
…act Context
- Loading branch information
1 parent
58e91c4
commit 64dae06
Showing
2 changed files
with
24 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,23 @@ | ||
import { createContext, useContext } from 'react' | ||
import { createContext, ReactNode, useContext } from 'react' | ||
|
||
export interface ReactNodeViewContextProps { | ||
onDragStart: (event: DragEvent) => void, | ||
nodeViewContentRef: (element: HTMLElement | null) => void, | ||
/** | ||
* This allows you to add children into the NodeViewContent component. | ||
* This is useful when statically rendering the content of a node view. | ||
*/ | ||
nodeViewContentChildren: ReactNode, | ||
} | ||
|
||
export const ReactNodeViewContext = createContext<Partial<ReactNodeViewContextProps>>({ | ||
onDragStart: undefined, | ||
export const ReactNodeViewContext = createContext<ReactNodeViewContextProps>({ | ||
onDragStart: () => { | ||
// no-op | ||
}, | ||
nodeViewContentChildren: undefined, | ||
nodeViewContentRef: () => { | ||
// no-op | ||
}, | ||
}) | ||
|
||
export const useReactNodeView = () => useContext(ReactNodeViewContext) |