woocommerce/plugins/woocommerce-blocks/assets/js/blocks/mini-cart/mini-cart-contents/inner-blocks/utils.ts

34 lines
678 B
TypeScript
Raw Normal View History

/**
* External dependencies
*/
2023-04-28 10:29:45 +00:00
import { isObject } from '@woocommerce/types';
type Variant = 'text' | 'contained' | 'outlined';
export const getVariant = (
className = '',
defaultVariant: Variant
): Variant => {
if ( className.includes( 'is-style-outline' ) ) {
return 'outlined';
}
if ( className.includes( 'is-style-fill' ) ) {
return 'contained';
}
return defaultVariant;
};
/**
* Checks if there are any children that are blocks.
*/
export const hasChildren = ( children ): boolean => {
return children.some( ( child ) => {
if ( Array.isArray( child ) ) {
return hasChildren( child );
}
return isObject( child ) && child.key !== null;
} );
};