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

Commit

Permalink
Prevent shrinkColumns value when switching the layout type of Product…
Browse files Browse the repository at this point in the history
… Collection (#11905)
  • Loading branch information
kmanijak committed Nov 23, 2023
1 parent 225b272 commit 684d923
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
/**
* Internal dependencies
*/
import { DisplayLayoutControlProps, LayoutOptions } from '../types';
import { DisplayLayoutToolbarProps, LayoutOptions } from '../types';

const getHelpText = ( layoutOptions: LayoutOptions ) => {
switch ( layoutOptions ) {
Expand All @@ -40,13 +40,14 @@ const getHelpText = ( layoutOptions: LayoutOptions ) => {

const DEFAULT_VALUE = LayoutOptions.GRID;

const LayoutOptionsControl = ( props: DisplayLayoutControlProps ) => {
const { type, columns } = props.displayLayout;
const LayoutOptionsControl = ( props: DisplayLayoutToolbarProps ) => {
const { type, columns, shrinkColumns } = props.displayLayout;
const setDisplayLayout = ( displayLayout: LayoutOptions ) => {
props.setAttributes( {
displayLayout: {
type: displayLayout,
columns,
shrinkColumns,
},
} );
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ import { list, grid } from '@wordpress/icons';
import {
DisplayLayoutToolbarProps,
ProductCollectionDisplayLayout,
LayoutOptions,
} from '../types';

const DisplayLayoutToolbar = ( props: DisplayLayoutToolbarProps ) => {
const { type, columns } = props.displayLayout;
const { type, columns, shrinkColumns } = props.displayLayout;
const setDisplayLayout = (
displayLayout: ProductCollectionDisplayLayout
) => {
Expand All @@ -25,14 +26,24 @@ const DisplayLayoutToolbar = ( props: DisplayLayoutToolbarProps ) => {
{
icon: list,
title: __( 'List view', 'woo-gutenberg-products-block' ),
onClick: () => setDisplayLayout( { type: 'list', columns } ),
isActive: type === 'list',
onClick: () =>
setDisplayLayout( {
type: LayoutOptions.STACK,
columns,
shrinkColumns,
} ),
isActive: type === LayoutOptions.STACK,
},
{
icon: grid,
title: __( 'Grid view', 'woo-gutenberg-products-block' ),
onClick: () => setDisplayLayout( { type: 'flex', columns } ),
isActive: type === 'flex',
onClick: () =>
setDisplayLayout( {
type: LayoutOptions.GRID,
columns,
shrinkColumns,
} ),
isActive: type === LayoutOptions.GRID,
},
];

Expand Down
2 changes: 1 addition & 1 deletion assets/js/blocks/product-collection/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export enum LayoutOptions {
export interface ProductCollectionDisplayLayout {
type: LayoutOptions;
columns: number;
shrinkColumns?: boolean;
shrinkColumns: boolean;
}

export enum ETimeFrameOperator {
Expand Down

0 comments on commit 684d923

Please sign in to comment.