-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TreeView] Add utility function to check if an optional plugin is pre…
…sent (#13788)
- Loading branch information
1 parent
b523fd5
commit d3fad51
Showing
7 changed files
with
48 additions
and
1 deletion.
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
2 changes: 2 additions & 0 deletions
2
packages/x-tree-view/src/internals/corePlugins/useTreeViewOptionalPlugins/index.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,2 @@ | ||
export { useTreeViewOptionalPlugins } from './useTreeViewOptionalPlugins'; | ||
export type { UseTreeViewOptionalPluginsSignature } from './useTreeViewOptionalPlugins.types'; |
17 changes: 17 additions & 0 deletions
17
...e-view/src/internals/corePlugins/useTreeViewOptionalPlugins/useTreeViewOptionalPlugins.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,17 @@ | ||
import { TreeViewPlugin } from '../../models'; | ||
import { UseTreeViewOptionalPluginsSignature } from './useTreeViewOptionalPlugins.types'; | ||
|
||
export const useTreeViewOptionalPlugins: TreeViewPlugin<UseTreeViewOptionalPluginsSignature> = ({ | ||
plugins, | ||
}) => { | ||
const pluginSet = new Set(plugins); | ||
const getAvailablePlugins = () => pluginSet; | ||
|
||
return { | ||
instance: { | ||
getAvailablePlugins, | ||
}, | ||
}; | ||
}; | ||
|
||
useTreeViewOptionalPlugins.params = {}; |
9 changes: 9 additions & 0 deletions
9
.../src/internals/corePlugins/useTreeViewOptionalPlugins/useTreeViewOptionalPlugins.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,9 @@ | ||
import { TreeViewPlugin, TreeViewAnyPluginSignature, TreeViewPluginSignature } from '../../models'; | ||
|
||
interface UseTreeViewOptionalPluginsInstance { | ||
getAvailablePlugins: () => Set<TreeViewPlugin<TreeViewAnyPluginSignature>>; | ||
} | ||
|
||
export type UseTreeViewOptionalPluginsSignature = TreeViewPluginSignature<{ | ||
instance: UseTreeViewOptionalPluginsInstance; | ||
}>; |
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,12 @@ | ||
import { TreeViewAnyPluginSignature, TreeViewInstance, TreeViewPlugin } from '../models'; | ||
|
||
export const hasPlugin = < | ||
TSignature extends TreeViewAnyPluginSignature, | ||
TInstance extends TreeViewInstance<[], [TSignature]>, | ||
>( | ||
instance: TInstance, | ||
plugin: TreeViewPlugin<TSignature>, | ||
): instance is Omit<TInstance, keyof TSignature['instance']> & TSignature['instance'] => { | ||
const plugins = instance.getAvailablePlugins(); | ||
return plugins.has(plugin as any); | ||
}; |