2020-05-28 10:02:10 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { createContext, useContext } from '@wordpress/element';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This context is a configuration object used for connecting
|
|
|
|
* all children blocks in a given tree contained in the context with information
|
|
|
|
* about the parent block. Typically this is used for extensibility features.
|
|
|
|
*
|
2020-06-02 11:14:46 +00:00
|
|
|
* @member {Object} InnerBlockLayoutContext A react context object
|
2020-05-28 10:02:10 +00:00
|
|
|
*/
|
2020-06-02 11:14:46 +00:00
|
|
|
const InnerBlockLayoutContext = createContext( {
|
2020-05-28 10:02:10 +00:00
|
|
|
parentName: '',
|
2020-06-05 12:18:16 +00:00
|
|
|
parentClassName: '',
|
|
|
|
isLoading: false,
|
2020-05-28 10:02:10 +00:00
|
|
|
} );
|
|
|
|
|
2020-06-02 11:14:46 +00:00
|
|
|
export const useInnerBlockLayoutContext = () =>
|
|
|
|
useContext( InnerBlockLayoutContext );
|
2020-05-28 10:02:10 +00:00
|
|
|
|
2023-06-14 13:36:39 +00:00
|
|
|
interface InnerBlockLayoutContextProviderProps {
|
|
|
|
parentName?: string;
|
|
|
|
parentClassName?: string;
|
|
|
|
isLoading?: boolean;
|
|
|
|
children: React.ReactNode;
|
|
|
|
}
|
|
|
|
|
2020-06-02 11:14:46 +00:00
|
|
|
export const InnerBlockLayoutContextProvider = ( {
|
2020-05-28 10:02:10 +00:00
|
|
|
parentName = '',
|
2020-06-05 12:18:16 +00:00
|
|
|
parentClassName = '',
|
2023-06-14 13:36:39 +00:00
|
|
|
isLoading = false,
|
2020-05-28 10:02:10 +00:00
|
|
|
children,
|
2023-06-14 13:36:39 +00:00
|
|
|
}: InnerBlockLayoutContextProviderProps ) => {
|
2020-05-28 10:02:10 +00:00
|
|
|
const contextValue = {
|
|
|
|
parentName,
|
2020-06-05 12:18:16 +00:00
|
|
|
parentClassName,
|
2023-06-14 13:36:39 +00:00
|
|
|
isLoading,
|
2020-05-28 10:02:10 +00:00
|
|
|
};
|
|
|
|
return (
|
2020-06-02 11:14:46 +00:00
|
|
|
<InnerBlockLayoutContext.Provider value={ contextValue }>
|
2020-07-22 12:20:54 +00:00
|
|
|
{ children }
|
2020-06-02 11:14:46 +00:00
|
|
|
</InnerBlockLayoutContext.Provider>
|
2020-05-28 10:02:10 +00:00
|
|
|
);
|
|
|
|
};
|