How to use the @wordpress/compose.createHigherOrderComponent function in @wordpress/compose

To help you get started, we’ve selected a few @wordpress/compose examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github WordPress / gutenberg / packages / block-editor / src / hooks / align.js View on Github external
),
				,
			];
		}
	),
	'withToolbarControls'
);

/**
 * Override the default block element to add alignment wrapper props.
 *
 * @param  {Function} BlockListBlock Original component
 * @return {Function}                Wrapped component
 */
export const withDataAlign = createHigherOrderComponent( ( BlockListBlock ) => ( props ) => {
	const { name, attributes } = props;
	const { align } = attributes;
	const hasWideEnabled = useSelect( ( select ) => (
		!! select( 'core/block-editor' ).getSettings().alignWide
	) );

	// If an alignment is not assigned, there's no need to go through the
	// effort to validate or assign its value.
	if ( align === undefined ) {
		return ;
	}

	const validAlignments = getValidAlignments(
		getBlockSupport( name, 'align' ),
		hasBlockSupport( name, 'alignWide', true ),
		hasWideEnabled
github ampproject / amp-wp / assets / src / components / with-initial-positioning.js View on Github external
import { createBlock } from '@wordpress/blocks';

/**
 * External dependencies
 */
import { every } from 'lodash';

/**
 * Internal dependencies
 */
import { ALLOWED_CHILD_BLOCKS } from '../constants';
import { withParentBlock } from './';

const positionTopLimit = 75;

export default createHigherOrderComponent(
	( BlockEdit ) => {
		return withParentBlock( ( props ) => {
			const { attributes, name, parentBlock } = props;

			if ( -1 === ALLOWED_CHILD_BLOCKS.indexOf( name ) || ! parentBlock || 'amp/amp-story-page' !== parentBlock.name ) {
				return ;
			}

			// If the positions are already set or the block is not selected, just return original.
			if (
				! props.isSelected ||
				0 !== attributes.positionTop ||
				0 !== attributes.positionLeft ||
				! parentBlock.innerBlocks.length
			) {
				return ;
github gambitph / Stackable / src / higher-order / with-content-align-reseter / index.js View on Github external
const withContentAlignReseter = ( attributeNamesToReset = [] ) => createHigherOrderComponent(
	WrappedComponent => class extends Component {
		static defaultProps = {
			attributes: {},
			blockName: '',
		}

		componentDidMount() {
			const { blockName } = this.props

			// Go through each screen then reset attibutes if needed.
			addFilter( `stackable.${ blockName }.setAttributes`, `stackable/${ blockName }/contentAlign`, attributes => {
				const screens = [ '', 'Tablet', 'Mobile' ]
				const resetAlignments = applyFilters( 'stackable.with-content-align-reseter.attributeNamesToReset', attributeNamesToReset, blockName )

				screens.forEach( screen => {
					if ( typeof attributes[ getAttrName( '%sContentAlign', screen ) ] !== 'undefined' ) {
github godaddy-wordpress / coblocks / src / extensions / colors / inspector.js View on Github external
const allowedBlocks = [ 'core/list', 'core/quote' ];
	// Use Lodash's assign to gracefully handle if attributes are undefined
	if ( allowedBlocks.includes( settings.name ) ) {
		settings.attributes = Object.assign( settings.attributes, ColorSettingsAttributes );
	}

	return settings;
}

/**
 * Override the default edit UI to include a new block inspector control
 *
 * @param {function|Component} BlockEdit Original component.
 * @return {string} Wrapped component.
 */
const withInspectorControl = createHigherOrderComponent( ( BlockEdit ) => {
	return ( props ) => {
		const allowedBlocks = [ 'core/list', 'core/quote' ];
		return (
			
				
				{ props.isSelected && allowedBlocks.includes( props.name ) &&  }
			
		);
	};
}, 'withInspectorControl' );

addFilter(
	'blocks.registerBlockType',
	'coblocks/colors/attributes',
	addAttributes
);
github WordPress / gutenberg / packages / block-editor / src / hooks / align.js View on Github external
type: 'string',
			},
		} );
	}

	return settings;
}

/**
 * Override the default edit UI to include new toolbar controls for block
 * alignment, if block defines support.
 *
 * @param  {Function} BlockEdit Original component
 * @return {Function}           Wrapped component
 */
export const withToolbarControls = createHigherOrderComponent(
	( BlockEdit ) => (
		( props ) => {
			const { name: blockName } = props;
			// Compute valid alignments without taking into account,
			// if the theme supports wide alignments or not.
			// BlockAlignmentToolbar takes into account the theme support.
			const validAlignments = getValidAlignments(
				getBlockSupport( blockName, 'align' ),
				hasBlockSupport( blockName, 'alignWide', true ),
			);

			const updateAlignment = ( nextAlign ) => {
				if ( ! nextAlign ) {
					const blockType = getBlockType( props.name );
					const blockDefaultAlign = get( blockType, [ 'attributes', 'align', 'default' ] );
					if ( blockDefaultAlign ) {
github eventespresso / event-espresso-core / assets / src / editor / events / hocs / with-editor-date-ticket-entities.js View on Github external
* External imports
 */
import { withSelect } from '@wordpress/data';
import { createHigherOrderComponent } from '@wordpress/compose';
import { isModelEntityOfModel } from '@eventespresso/validators';

const DEFAULT_OBJECT = {
	ticketEntities: [],
};

/**
 * A Hoc exposing ticket entities related to the provided DateTimeEntity.
 *
 * @return {function} A higher order component.
 */
const withEditorDateTicketEntities = createHigherOrderComponent(
	withSelect(
		( select, { dateEntity } ) => {
			const { getRelatedEntities } = select( 'eventespresso/core' );
			if ( isModelEntityOfModel( dateEntity, 'datetime' ) ) {
				const ticketEntities = getRelatedEntities(
					dateEntity,
					'ticket'
				);
				return { ticketEntities };
			}
			return DEFAULT_OBJECT;
		}
	),
	'withEditorDateTicketEntities'
);
github WordPress / gutenberg / packages / viewport / src / if-viewport-matches.js View on Github external
const ifViewportMatches = ( query ) => createHigherOrderComponent(
	compose( [
		withViewportMatch( {
			isViewportMatch: query,
		} ),
		ifCondition( ( props ) => props.isViewportMatch ),
	] ),
	'ifViewportMatches'
);
github WordPress / gutenberg / packages / block-editor / src / components / block-edit / context.js View on Github external
{ ...mapContextToProps( context, props ) }
				/>
			) }
		
	);
}, 'withBlockEditContext' );

/**
 * A Higher Order Component used to render conditionally the wrapped
 * component only when the BlockEdit has selected state set.
 *
 * @param {Component} OriginalComponent Component to wrap.
 *
 * @return {Component} Component which renders only when the BlockEdit is selected.
 */
export const ifBlockEditSelected = createHigherOrderComponent( ( OriginalComponent ) => {
	return ( props ) => (
		
			{ ( { isSelected } ) => isSelected && (
				
			) }
		
	);
}, 'ifBlockEditSelected' );
github eventespresso / event-espresso-core / assets / src / higher-order-components / pagination / index.js View on Github external
export default ( paginationConfig = {} ) => createHigherOrderComponent(
	compose( [
		withInstanceId,
		( EntityList ) => ( props ) => {
			return ;
		},
	] ),
	'withEntityPagination'
);
github gambitph / Stackable / src / higher-order / with-tabbed-inspector / index.js View on Github external
const withTabbedInspector = ( tabs = null ) => createHigherOrderComponent(
	WrappedComponent => class extends Component {
		static defaultProps = {
			attributes: {},
			blockName: '',
		}

		render() {
			const { blockName } = this.props
			const blockStyleControls = applyFilters( `stackable.${ blockName }.edit.inspector.style.block`, null, this.props )

			return (
				
					{ applyFilters( `stackable.${ blockName }.edit.inspector.before`, null, this.props ) }