Server IP : 172.67.158.161 / Your IP : 18.227.105.189 Web Server : LiteSpeed System : Linux business53.web-hosting.com 4.18.0-553.lve.el8.x86_64 #1 SMP Mon May 27 15:27:34 UTC 2024 x86_64 User : giankuin ( 1871) PHP Version : 7.4.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home/giankuin/www/wp-content/plugins/woocommerce/packages/woocommerce-blocks/assets/js/blocks/featured-category/ |
Upload File : |
/** * External dependencies */ import { isObject } from 'lodash'; /** * Get the src from a category object, unless null (no image). * * @param {Object|null} category A product category object from the API. * @return {string} The src of the category image. */ function getCategoryImageSrc( category ) { if ( category && isObject( category.image ) ) { return category.image.src; } return ''; } /** * Get the attachment ID from a category object, unless null (no image). * * @param {Object|null} category A product category object from the API. * @return {number} The id of the category image. */ function getCategoryImageId( category ) { if ( category && isObject( category.image ) ) { return category.image.id; } return 0; } /** * Generate a style object given either a product category image from the API or URL to an image. * * @param {string} url An image URL. * @return {Object} A style object with a backgroundImage set (if a valid image is provided). */ function getBackgroundImageStyles( url ) { if ( url ) { return { backgroundImage: `url(${ url })` }; } return {}; } /** * Convert the selected ratio to the correct background class. * * @param {number} ratio Selected opacity from 0 to 100. * @return {string} The class name, if applicable (not used for ratio 0 or 50). */ function dimRatioToClass( ratio ) { return ratio === 0 || ratio === 50 ? null : `has-background-dim-${ 10 * Math.round( ratio / 10 ) }`; } export { getCategoryImageSrc, getCategoryImageId, getBackgroundImageStyles, dimRatioToClass, };