2022-08-11 00:04:12 +00:00
/* eslint-disable @wordpress/no-unsafe-wp-apis */
/ * *
* External dependencies
* /
import { __experimentalGetSpacingClassesAndStyles } from '@wordpress/block-editor' ;
import { isObject } from '@woocommerce/types' ;
import { parseStyle } from '@woocommerce/base-utils' ;
type WithStyle = {
style : Record < string , unknown > ;
} ;
2023-01-11 17:12:06 +00:00
// @todo The @wordpress/block-editor dependency should never be used on the frontend of the store due to excessive side and its dependency on @wordpress/components
// @see https://github.com/woocommerce/woocommerce-blocks/issues/8071
2022-08-11 00:04:12 +00:00
export const useSpacingProps = ( attributes : unknown ) : WithStyle = > {
2023-02-27 13:38:45 +00:00
if ( typeof __experimentalGetSpacingClassesAndStyles !== 'function' ) {
2022-08-11 00:04:12 +00:00
return {
style : { } ,
} ;
}
2023-02-27 13:38:45 +00:00
2022-08-11 00:04:12 +00:00
const attributesObject = isObject ( attributes ) ? attributes : { } ;
const style = parseStyle ( attributesObject . style ) ;
return __experimentalGetSpacingClassesAndStyles ( {
. . . attributesObject ,
style ,
} ) ;
} ;