2019-02-21 19:00:47 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { __ } from '@wordpress/i18n';
|
|
|
|
import { ToggleControl } from '@wordpress/components';
|
|
|
|
|
2023-06-07 11:22:50 +00:00
|
|
|
interface GridContentControlProps {
|
|
|
|
onChange: ( settings: GridContentSettings ) => void;
|
|
|
|
settings: GridContentSettings;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface GridContentSettings {
|
|
|
|
image: boolean;
|
|
|
|
button: boolean;
|
|
|
|
price: boolean;
|
|
|
|
rating: boolean;
|
|
|
|
title: boolean;
|
|
|
|
}
|
2019-02-21 19:00:47 +00:00
|
|
|
/**
|
2019-05-09 14:45:09 +00:00
|
|
|
* A combination of toggle controls for content visibility in product grids.
|
2020-09-20 23:54:08 +00:00
|
|
|
*
|
2022-04-08 13:47:19 +00:00
|
|
|
* @param {Object} props Incoming props for the component.
|
2020-09-20 23:54:08 +00:00
|
|
|
* @param {function(any):any} props.onChange
|
2022-04-08 13:47:19 +00:00
|
|
|
* @param {Object} props.settings
|
2019-02-21 19:00:47 +00:00
|
|
|
*/
|
2023-06-07 11:22:50 +00:00
|
|
|
const GridContentControl = ( {
|
|
|
|
onChange,
|
|
|
|
settings,
|
|
|
|
}: GridContentControlProps ) => {
|
2022-05-09 10:04:33 +00:00
|
|
|
const { image, button, price, rating, title } = settings;
|
2022-06-20 12:13:56 +00:00
|
|
|
// If `image` is undefined, that might be because it's a block that was
|
|
|
|
// created before the `image` attribute existed, so we default to true.
|
|
|
|
const imageIsVisible = image !== false;
|
2019-02-21 19:00:47 +00:00
|
|
|
return (
|
2020-12-14 11:54:34 +00:00
|
|
|
<>
|
2022-05-09 10:04:33 +00:00
|
|
|
<ToggleControl
|
2023-12-12 22:12:36 +00:00
|
|
|
label={ __( 'Product image', 'woocommerce' ) }
|
2022-06-20 12:13:56 +00:00
|
|
|
checked={ imageIsVisible }
|
|
|
|
onChange={ () =>
|
|
|
|
onChange( { ...settings, image: ! imageIsVisible } )
|
|
|
|
}
|
2022-05-09 10:04:33 +00:00
|
|
|
/>
|
2019-02-21 19:00:47 +00:00
|
|
|
<ToggleControl
|
2023-12-12 22:12:36 +00:00
|
|
|
label={ __( 'Product title', 'woocommerce' ) }
|
2019-02-21 19:00:47 +00:00
|
|
|
checked={ title }
|
|
|
|
onChange={ () => onChange( { ...settings, title: ! title } ) }
|
|
|
|
/>
|
|
|
|
<ToggleControl
|
2023-12-12 22:12:36 +00:00
|
|
|
label={ __( 'Product price', 'woocommerce' ) }
|
2019-02-21 19:00:47 +00:00
|
|
|
checked={ price }
|
|
|
|
onChange={ () => onChange( { ...settings, price: ! price } ) }
|
|
|
|
/>
|
2019-03-06 18:50:32 +00:00
|
|
|
<ToggleControl
|
2023-12-12 22:12:36 +00:00
|
|
|
label={ __( 'Product rating', 'woocommerce' ) }
|
2019-03-06 18:50:32 +00:00
|
|
|
checked={ rating }
|
|
|
|
onChange={ () => onChange( { ...settings, rating: ! rating } ) }
|
|
|
|
/>
|
2019-02-21 19:00:47 +00:00
|
|
|
<ToggleControl
|
2023-12-12 23:05:20 +00:00
|
|
|
label={ __( 'Add to Cart button', 'woocommerce' ) }
|
2019-02-21 19:00:47 +00:00
|
|
|
checked={ button }
|
|
|
|
onChange={ () => onChange( { ...settings, button: ! button } ) }
|
|
|
|
/>
|
2020-12-14 11:54:34 +00:00
|
|
|
</>
|
2019-02-21 19:00:47 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default GridContentControl;
|