Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Reorganise Columns controls and fix undefined problem in Product Collection settings #11937

Merged
merged 3 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,13 @@ import {
import { DisplayLayoutToolbarProps } from '../types';
import { getDefaultDisplayLayout } from '../constants';

const toggleLabel = __(
'Shrink columns to fit',
'woo-gutenberg-products-block'
);

const columnsLabel = __( 'Columns', 'woo-gutenberg-products-block' );
const toggleLabel = __( 'Responsive', 'woo-gutenberg-products-block' );
const toggleHelp = __(
'Reduce the number of columns to better fit smaller screens and spaces.',
'Automatically adjust the number of columns to better fit smaller screens.',
'woo-gutenberg-products-block'
);

const getColumnsLabel = ( shrinkColumns: boolean ) =>
shrinkColumns
? __( 'Max Columns', 'woo-gutenberg-products-block' )
: __( 'Columns', 'woo-gutenberg-products-block' );

const ColumnsControl = ( props: DisplayLayoutToolbarProps ) => {
const { type, columns, shrinkColumns } = props.displayLayout;
const showColumnsControl = type === 'flex';
Expand Down Expand Up @@ -63,33 +55,32 @@ const ColumnsControl = ( props: DisplayLayoutToolbarProps ) => {
return showColumnsControl ? (
<>
<ToolsPanelItem
hasValue={ () =>
defaultLayout?.shrinkColumns !== shrinkColumns
}
label={ columnsLabel }
hasValue={ () => defaultLayout?.columns !== columns }
isShownByDefault
onDeselect={ onPanelDeselect }
>
<ToggleControl
checked={ !! shrinkColumns }
label={ toggleLabel }
help={ toggleHelp }
onChange={ onShrinkColumnsToggleChange }
<RangeControl
label={ columnsLabel }
onChange={ onColumnsChange }
value={ columns }
min={ 2 }
max={ Math.max( 6, columns ) }
/>
</ToolsPanelItem>
<ToolsPanelItem
label={ toggleLabel }
hasValue={ () =>
defaultLayout?.columns !== columns ||
defaultLayout?.type !== type
defaultLayout?.shrinkColumns !== shrinkColumns
}
isShownByDefault
onDeselect={ onPanelDeselect }
>
<RangeControl
label={ getColumnsLabel( !! shrinkColumns ) }
onChange={ onColumnsChange }
value={ columns }
min={ 2 }
max={ Math.max( 6, columns ) }
<ToggleControl
checked={ !! shrinkColumns }
label={ toggleLabel }
help={ toggleHelp }
onChange={ onShrinkColumnsToggleChange }
/>
</ToolsPanelItem>
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const SELECTORS = {
onSaleControlLabel: 'Show only products on sale',
inheritQueryFromTemplateControl:
'.wc-block-product-collection__inherit-query-control',
shrinkColumnsToFit: 'Shrink columns to fit',
shrinkColumnsToFit: 'Responsive',
productSearchLabel: 'Search',
productSearchButton: '.wp-block-search__button wp-element-button',
};
Expand Down
Loading