);
}
}
/**
* A list of all available ways to display products.
*/
class ProductsBlockSettingsEditorDisplayOptions extends React.Component {
render() {
let classes = 'display-settings-container';
if ( this.props.existing ) {
classes += ' existing';
}
let display_settings = [];
for ( var setting_key in PRODUCTS_BLOCK_DISPLAY_SETTINGS ) {
display_settings.push( );
}
let description = null;
if ( ! this.props.existing ) {
description =
{ __( 'Choose which products you\'d like to display:' ) }
;
}
return (
{ description }
{ display_settings }
);
}
}
/**
* The products block when in Edit mode.
*/
class ProductsBlockSettingsEditor extends React.Component {
/**
* Constructor.
*/
constructor( props ) {
super( props );
this.state = {
display: props.selected_display,
menu_visible: props.selected_display ? false : true,
expanded_group: '',
}
this.updateDisplay = this.updateDisplay.bind( this );
}
/**
* Update the display settings for the block.
*
* @param value String
*/
updateDisplay( value ) {
// If not a group update display.
let new_state = {
display: value,
menu_visible: false,
expanded_group: '',
};
const is_group = 'undefined' !== PRODUCTS_BLOCK_DISPLAY_SETTINGS[ value ].group_container && PRODUCTS_BLOCK_DISPLAY_SETTINGS[ value ].group_container;
if ( is_group ) {
// If the group has not been expanded, expand it.
new_state = {
menu_visible: true,
expanded_group: value,
}
// If the group has already been expanded, collapse it.
if ( this.state.expanded_group === PRODUCTS_BLOCK_DISPLAY_SETTINGS[ value ].group_container ) {
new_state.expanded_group = '';
}
}
this.setState( new_state );
// Only update the display setting if a non-group setting was selected.
if ( ! is_group ) {
this.props.update_display_callback( value );
}
}
/**
* Render the display settings dropdown and any extra contextual settings.
*/
render() {
let extra_settings = null;
if ( 'specific' === this.state.display ) {
extra_settings = ;
} else if ( 'category' === this.state.display ) {
extra_settings = ;
} else if ( 'attribute' === this.state.display ) {
extra_settings =
}
const menu = this.state.menu_visible ? : null;
let heading = null;
if ( this.state.display ) {
var menu_link = { this.setState( { menu_visible: true } ) } }>{ __( 'Display different products' ) };
if ( this.state.menu_visible ) {
menu_link = { this.setState( { menu_visible: false } ) } }>{ __( 'Cancel' ) };
}
heading = (
);
}
}
/**
* One product in the product block preview.
*/
class ProductPreview extends React.Component {
render() {
const { attributes, product } = this.props;
let image = null;
if ( product.images.length ) {
image =
}
let title = null;
if ( attributes.display_title ) {
title =
{ product.name }
}
let price = null;
if ( attributes.display_price ) {
price =
{ product.price }
}
let add_to_cart = null;
if ( attributes.display_add_to_cart ) {
add_to_cart = { __( 'Add to cart' ) }
}
return (