2023-04-14 07:21:21 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2023-04-28 10:29:45 +00:00
|
|
|
import { isObject } from '@woocommerce/types';
|
2023-04-14 07:21:21 +00:00
|
|
|
|
2023-03-24 09:14:06 +00:00
|
|
|
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;
|
|
|
|
};
|
2023-04-14 07:21:21 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
} );
|
|
|
|
};
|