How to use the @wordpress/element.Children.count function in @wordpress/element

To help you get started, we’ve selected a few @wordpress/element 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 / components / src / responsive-wrapper / index.js View on Github external
function ResponsiveWrapper( { naturalWidth, naturalHeight, children } ) {
	if ( Children.count( children ) !== 1 ) {
		return null;
	}
	const imageStyle = {
		paddingBottom: ( naturalHeight / naturalWidth * 100 ) + '%',
	};
	return (
		<div>
			<div style="{">
			{ cloneElement( children, {
				className: classnames( 'components-responsive-wrapper__content', children.props.className ),
			} ) }
		</div>
	);
}
</div>
github WordPress / gutenberg / packages / block-library / src / gallery / tiles.native.js View on Github external
function Tiles( props ) {
	const {
		columns,
		children,
		spacing = 10,
		style,
	} = props;

	const { compose } = StyleSheet;

	const tileCount = Children.count( children );
	const lastTile = tileCount - 1;
	const lastRow = Math.floor( lastTile / columns );

	const wrappedChildren = Children.map( children, ( child, index ) => {
		/** Since we don't have `calc()`, we must calculate our spacings here in
		 * order to preserve even spacing between tiles and equal width for tiles
		 * in a given row.
		 *
		 * In order to ensure equal sizing of tile contents, we distribute the
		 * spacing such that each tile has an equal "share" of the fixed spacing. To
		 * keep the tiles properly aligned within their rows, we calculate the left
		 * and right paddings based on the tile's relative position within the row.
		 *
		 * Note: we use padding instead of margins so that the fixed spacing is
		 * included within the relative spacing (i.e. width percentage), and
		 * wrapping behavior is preserved.
github WordPress / gutenberg / packages / block-editor / src / components / warning / index.js View on Github external
function Warning( { className, actions, children, secondaryActions } ) {
	return (
		<div>
			<div>
				<p>{ children }</p>

				{ Children.count( actions ) &gt; 0 &amp;&amp; (
					<div>
						{ Children.map( actions, ( action, i ) =&gt; (
							<span>
								{ action }
							</span>
						) ) }
					</div>
				) }
			</div>

			{ secondaryActions &amp;&amp; (
				 (
						</div>
github WordPress / gutenberg / packages / components / src / tooltip / index.js View on Github external
emitToChild( eventName, event ) {
		const { children } = this.props;
		if ( Children.count( children ) !== 1 ) {
			return;
		}

		const child = Children.only( children );
		if ( typeof child.props[ eventName ] === 'function' ) {
			child.props[ eventName ]( event );
		}
	}
github eventespresso / event-espresso-core / assets / ZZZ / components / ui / responsive-table / utils.js View on Github external
export const getChildren = ( props ) => {
	return props.hasOwnProperty( 'children' ) &&
	Children.count( props.children ) ?
		Children.toArray( props.children ) :
		[];
};
github WordPress / gutenberg / editor / components / warning / index.js View on Github external
function Warning( { actions, children } ) {
	return (
		<div>
			<div>
				<p>{ children }</p>

				{ Children.count( actions ) &gt; 0 &amp;&amp; (
					<div>
						{ Children.map( actions, ( action, i ) =&gt; (
							<span>
								{ action }
							</span>
						) ) }
					</div>
				) }
			</div>
		</div>
	);
}
github WordPress / gutenberg / packages / components / src / menu-group / index.js View on Github external
export function MenuGroup( {
	children,
	className = '',
	label,
} ) {
	const instanceId = useInstanceId( MenuGroup );

	if ( ! Children.count( children ) ) {
		return null;
	}

	const labelId = `components-menu-group-label-${ instanceId }`;
	const classNames = classnames(
		className,
		'components-menu-group'
	);

	return (
		<div>
			{ label &amp;&amp;
				</div>
github WordPress / gutenberg / packages / components / src / mobile / html-element / index.native.js View on Github external
injectContextIntoChildren( cssPath, children ) {
		const siblingCount = Children.count( children );
		return Children.map( children, ( child, siblingPosition ) => {
			return cloneElement( child, { siblingCount, siblingPosition, ancestorPath: cssPath } );
		} );
	}