2019-02-21 19:00:47 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { __ } from '@wordpress/i18n';
|
|
|
|
import { Fragment } from '@wordpress/element';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { ToggleControl } from '@wordpress/components';
|
|
|
|
|
|
|
|
/**
|
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
|
|
|
*
|
|
|
|
* @param {Object} props Incoming props for the component.
|
|
|
|
* @param {function(any):any} props.onChange
|
|
|
|
* @param {Object} props.settings
|
2019-02-21 19:00:47 +00:00
|
|
|
*/
|
|
|
|
const GridContentControl = ( { onChange, settings } ) => {
|
2019-03-06 18:50:32 +00:00
|
|
|
const { button, price, rating, title } = settings;
|
2019-02-21 19:00:47 +00:00
|
|
|
return (
|
|
|
|
<Fragment>
|
|
|
|
<ToggleControl
|
|
|
|
label={ __( 'Product title', 'woo-gutenberg-products-block' ) }
|
|
|
|
help={
|
2019-09-05 15:09:31 +00:00
|
|
|
title
|
2019-09-09 10:52:48 +00:00
|
|
|
? __(
|
|
|
|
'Product title is visible.',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
)
|
|
|
|
: __(
|
|
|
|
'Product title is hidden.',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
)
|
2019-02-21 19:00:47 +00:00
|
|
|
}
|
|
|
|
checked={ title }
|
|
|
|
onChange={ () => onChange( { ...settings, title: ! title } ) }
|
|
|
|
/>
|
|
|
|
<ToggleControl
|
|
|
|
label={ __( 'Product price', 'woo-gutenberg-products-block' ) }
|
|
|
|
help={
|
2019-09-05 15:09:31 +00:00
|
|
|
price
|
2019-09-09 10:52:48 +00:00
|
|
|
? __(
|
|
|
|
'Product price is visible.',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
)
|
|
|
|
: __(
|
|
|
|
'Product price is hidden.',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
)
|
2019-02-21 19:00:47 +00:00
|
|
|
}
|
|
|
|
checked={ price }
|
|
|
|
onChange={ () => onChange( { ...settings, price: ! price } ) }
|
|
|
|
/>
|
2019-03-06 18:50:32 +00:00
|
|
|
<ToggleControl
|
|
|
|
label={ __( 'Product rating', 'woo-gutenberg-products-block' ) }
|
|
|
|
help={
|
2019-09-05 15:09:31 +00:00
|
|
|
rating
|
2019-09-09 10:52:48 +00:00
|
|
|
? __(
|
|
|
|
'Product rating is visible.',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
)
|
|
|
|
: __(
|
|
|
|
'Product rating is hidden.',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
)
|
2019-03-06 18:50:32 +00:00
|
|
|
}
|
|
|
|
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
|
|
|
help={
|
2019-09-05 15:09:31 +00:00
|
|
|
button
|
|
|
|
? __(
|
|
|
|
'Add to Cart button is visible.',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
)
|
|
|
|
: __(
|
|
|
|
'Add to Cart button is hidden.',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
)
|
2019-02-21 19:00:47 +00:00
|
|
|
}
|
|
|
|
checked={ button }
|
|
|
|
onChange={ () => onChange( { ...settings, button: ! button } ) }
|
|
|
|
/>
|
|
|
|
</Fragment>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
GridContentControl.propTypes = {
|
|
|
|
/**
|
|
|
|
* The current title visibility.
|
|
|
|
*/
|
|
|
|
settings: PropTypes.shape( {
|
|
|
|
button: PropTypes.bool.isRequired,
|
|
|
|
price: PropTypes.bool.isRequired,
|
2019-07-09 10:50:09 +00:00
|
|
|
rating: PropTypes.bool.isRequired,
|
2019-02-21 19:00:47 +00:00
|
|
|
title: PropTypes.bool.isRequired,
|
|
|
|
} ).isRequired,
|
|
|
|
/**
|
|
|
|
* Callback to update the layout settings.
|
|
|
|
*/
|
|
|
|
onChange: PropTypes.func.isRequired,
|
|
|
|
};
|
|
|
|
|
|
|
|
export default GridContentControl;
|