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
|
|
|
|
label={ __( 'Product image', 'woo-gutenberg-products-block' ) }
|
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
|
|
|
|
label={ __( 'Product title', 'woo-gutenberg-products-block' ) }
|
|
|
|
checked={ title }
|
|
|
|
onChange={ () => onChange( { ...settings, title: ! title } ) }
|
|
|
|
/>
|
|
|
|
<ToggleControl
|
|
|
|
label={ __( 'Product price', 'woo-gutenberg-products-block' ) }
|
|
|
|
checked={ price }
|
|
|
|
onChange={ () => onChange( { ...settings, price: ! price } ) }
|
|
|
|
/>
|
2019-03-06 18:50:32 +00:00
|
|
|
<ToggleControl
|
|
|
|
label={ __( 'Product rating', 'woo-gutenberg-products-block' ) }
|
|
|
|
checked={ rating }
|
|
|
|
onChange={ () => onChange( { ...settings, rating: ! rating } ) }
|
|
|
|
/>
|
2019-02-21 19:00:47 +00:00
|
|
|
<ToggleControl
|
2019-09-09 10:52:48 +00:00
|
|
|
label={ __(
|
|
|
|
'Add to Cart button',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
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;
|