2020-05-28 10:02:10 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { createContext, useContext } from '@wordpress/element';
|
2020-06-05 12:18:16 +00:00
|
|
|
import classnames from 'classnames';
|
2020-05-28 10:02:10 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
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 = '',
|
|
|
|
isLoading = false,
|
2020-05-28 10:02:10 +00:00
|
|
|
children,
|
|
|
|
} ) => {
|
|
|
|
const contextValue = {
|
|
|
|
parentName,
|
2020-06-05 12:18:16 +00:00
|
|
|
parentClassName,
|
|
|
|
isLoading,
|
2020-05-28 10:02:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
2020-06-02 11:14:46 +00:00
|
|
|
<InnerBlockLayoutContext.Provider value={ contextValue }>
|
2020-06-05 12:18:16 +00:00
|
|
|
<div
|
|
|
|
className={ classnames( 'wc-block-layout', {
|
|
|
|
'wc-block-layout--is-loading': isLoading,
|
|
|
|
} ) }
|
|
|
|
>
|
|
|
|
{ children }
|
|
|
|
</div>
|
2020-06-02 11:14:46 +00:00
|
|
|
</InnerBlockLayoutContext.Provider>
|
2020-05-28 10:02:10 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2020-06-02 11:14:46 +00:00
|
|
|
InnerBlockLayoutContextProvider.propTypes = {
|
2020-05-28 10:02:10 +00:00
|
|
|
children: PropTypes.node,
|
|
|
|
parentName: PropTypes.string,
|
2020-06-05 12:18:16 +00:00
|
|
|
parentClassName: PropTypes.string,
|
2020-05-28 10:02:10 +00:00
|
|
|
};
|