-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Using our own
createContext()
+ QoL changes (#1687)
Co-authored-by: Ole Martin Handeland <git@olemartin.org>
- Loading branch information
1 parent
75a6559
commit bf1edfa
Showing
12 changed files
with
95 additions
and
79 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
31 changes: 12 additions & 19 deletions
31
src/features/devtools/components/NodeInspector/NodeInspectorContext.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 |
---|---|---|
@@ -1,23 +1,16 @@ | ||
import { createContext, useContext } from 'react'; | ||
|
||
import { createContext } from 'src/core/contexts/context'; | ||
import type { LayoutNode } from 'src/utils/layout/LayoutNode'; | ||
|
||
export type NodeInspectorContextValue = | ||
| { | ||
selectedNodeId: string | undefined; | ||
selectNode: (id: string) => void; | ||
node: LayoutNode | undefined; | ||
} | ||
| undefined; | ||
|
||
const NodeInspectorContext = createContext<NodeInspectorContextValue>(undefined); | ||
interface NodeInspectorContextValue { | ||
selectedNodeId: string | undefined; | ||
selectNode: (id: string) => void; | ||
node: LayoutNode | undefined; | ||
} | ||
|
||
export const useNodeInspectorContext = () => { | ||
const context = useContext(NodeInspectorContext); | ||
if (!context) { | ||
throw new Error('useNodeInspectorContext must be used within a NodeInspectorContextProvider'); | ||
} | ||
return context; | ||
}; | ||
const { Provider, useCtx } = createContext<NodeInspectorContextValue>({ | ||
name: 'NodeInspectorContext', | ||
required: true, | ||
}); | ||
|
||
export const NodeInspectorContextProvider = NodeInspectorContext.Provider; | ||
export const useNodeInspectorContext = () => useCtx(); | ||
export const NodeInspectorContextProvider = Provider; |
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,19 @@ | ||
import { createContext } from 'src/core/contexts/context'; | ||
import type { IGrid } from 'src/layout/common.generated'; | ||
import type { LayoutNode } from 'src/utils/layout/LayoutNode'; | ||
|
||
export interface IFormComponentContext { | ||
id: string; | ||
baseComponentId: string | undefined; | ||
node: LayoutNode; | ||
grid?: IGrid; | ||
} | ||
|
||
const { Provider, useCtx } = createContext<IFormComponentContext | undefined>({ | ||
name: 'FormComponent', | ||
required: false, | ||
default: undefined, | ||
}); | ||
|
||
export const useFormComponentCtx = () => useCtx(); | ||
export const FormComponentContextProvider = Provider; |
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