diff --git a/components/drag-handle/index.js b/components/drag-handle/index.tsx similarity index 79% rename from components/drag-handle/index.js rename to components/drag-handle/index.tsx index 1ebef8ca..cba84aef 100644 --- a/components/drag-handle/index.js +++ b/components/drag-handle/index.tsx @@ -1,10 +1,13 @@ +import type { SVGProps } from 'react'; + /** * Renders an SVG drag handle. * * @param {object} props The prop object. * @returns {*} React JSX */ -export const DragHandle = (props) => ( + +export const DragHandle: React.FC> = (props) => ( { - const hasAdminPermissions = useSelect( +export const IsAdmin: React.FC = ({ + fallback = null, + children, +}) => { + const hasAdminPermissions: boolean = useSelect( (select) => select('core').canUser('read', 'users?roles=1'), [], ); diff --git a/hooks/use-is-plugin-active/index.js b/hooks/use-is-plugin-active/index.js deleted file mode 100644 index 4f44ebe1..00000000 --- a/hooks/use-is-plugin-active/index.js +++ /dev/null @@ -1,20 +0,0 @@ -import { useSelect } from '@wordpress/data'; -import { store as coreStore } from '@wordpress/core-data'; - -const ACTIVE_STATUSES = ['active', 'network-active']; - -export const useIsPluginActive = (pluginName) => { - return useSelect( - (select) => { - const plugin = select(coreStore).getPlugin(pluginName); - const hasResolvedPlugins = select(coreStore).hasFinishedResolution('getPlugin', [ - pluginName, - ]); - - const isPluginActive = ACTIVE_STATUSES.includes(plugin?.status); - - return [isPluginActive, hasResolvedPlugins]; - }, - [pluginName], - ); -}; diff --git a/hooks/use-is-plugin-active/index.ts b/hooks/use-is-plugin-active/index.ts new file mode 100644 index 00000000..715d4b9d --- /dev/null +++ b/hooks/use-is-plugin-active/index.ts @@ -0,0 +1,29 @@ +import { useSelect } from '@wordpress/data'; +import { store as coreStore } from '@wordpress/core-data'; +import type { Plugin } from '@wordpress/core-data'; + +const ACTIVE_STATUSES = ['active', 'network-active'] as const; + +/** + * Custom hook to check if a plugin is active and whether its resolution has finished. + * + * @param pluginName The name of the plugin to check. + * @returns A tuple containing two boolean values: the first indicating whether the plugin is active, + * and the second indicating whether the resolution for the plugin has finished. + */ +export const useIsPluginActive = (pluginName: string) => { + return useSelect( + (select) => { + const storeSelectors = select(coreStore); + const plugin: Plugin = (storeSelectors as any).getPlugin(pluginName); + const hasResolvedPlugins: boolean = (storeSelectors as any).hasFinishedResolution('getPlugin', [ + pluginName, + ]); + + const isPluginActive: boolean = ACTIVE_STATUSES.includes(plugin?.status); + + return [isPluginActive, hasResolvedPlugins]; + }, + [pluginName], + ) as [boolean, boolean]; +}; diff --git a/hooks/use-media/readme.md b/hooks/use-media/readme.md index 786a7096..478c1afe 100644 --- a/hooks/use-media/readme.md +++ b/hooks/use-media/readme.md @@ -18,7 +18,7 @@ function BlockEdit(props) { } return ( - {image.alt} + { ); } ```