Skip to content
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
3 changes: 0 additions & 3 deletions lib/experimental/editor-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ function gutenberg_enable_experiments() {
if ( $gutenberg_experiments && array_key_exists( 'gutenberg-color-randomizer', $gutenberg_experiments ) ) {
wp_add_inline_script( 'wp-block-editor', 'window.__experimentalEnableColorRandomizer = true', 'before' );
}
if ( $gutenberg_experiments && array_key_exists( 'gutenberg-group-grid-variation', $gutenberg_experiments ) ) {
wp_add_inline_script( 'wp-block-editor', 'window.__experimentalEnableGroupGridVariation = true', 'before' );
}
if ( gutenberg_is_experiment_enabled( 'gutenberg-no-tinymce' ) ) {
wp_add_inline_script( 'wp-block-library', 'window.__experimentalDisableTinymce = true', 'before' );
}
Expand Down
13 changes: 0 additions & 13 deletions lib/experiments-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,19 +101,6 @@ function gutenberg_initialize_experiments_settings() {
'id' => 'gutenberg-form-blocks',
)
);

add_settings_field(
'gutenberg-group-grid-variation',
__( 'Grid variation for Group block ', 'gutenberg' ),
'gutenberg_display_experiment_field',
'gutenberg-experiments',
'gutenberg_experiments_section',
array(
'label' => __( 'Test the Grid layout type as a new variation of Group block.', 'gutenberg' ),
'id' => 'gutenberg-group-grid-variation',
)
);

add_settings_field(
'gutenberg-no-tinymce',
__( 'Disable TinyMCE and Classic block', 'gutenberg' ),
Expand Down
81 changes: 74 additions & 7 deletions packages/block-editor/src/layouts/grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ import {
Flex,
FlexItem,
RangeControl,
__experimentalToggleGroupControl as ToggleGroupControl,
__experimentalToggleGroupControlOption as ToggleGroupControlOption,
__experimentalUnitControl as UnitControl,
__experimentalParseQuantityAndUnitFromRawValue as parseQuantityAndUnitFromRawValue,
} from '@wordpress/components';
import { useState } from '@wordpress/element';

/**
* Internal dependencies
Expand Down Expand Up @@ -64,13 +67,24 @@ export default {
layout = {},
onChange,
} ) {
return layout?.columnCount ? (
<GridLayoutColumnsControl layout={ layout } onChange={ onChange } />
) : (
<GridLayoutMinimumWidthControl
layout={ layout }
onChange={ onChange }
/>
return (
<>
<GridLayoutTypeControl
layout={ layout }
onChange={ onChange }
/>
{ layout?.columnCount ? (
<GridLayoutColumnsControl
layout={ layout }
onChange={ onChange }
/>
) : (
<GridLayoutMinimumWidthControl
layout={ layout }
onChange={ onChange }
/>
) }
</>
);
},
toolBarControls: function DefaultLayoutToolbarControls() {
Expand Down Expand Up @@ -221,3 +235,56 @@ function GridLayoutColumnsControl( { layout, onChange } ) {
/>
);
}

// Enables switching between grid types
function GridLayoutTypeControl( { layout, onChange } ) {
const { columnCount, minimumColumnWidth } = layout;

/**
* When switching, temporarily save any custom values set on the
* previous type so we can switch back without loss.
*/
const [ tempColumnCount, setTempColumnCount ] = useState(
columnCount || 3
);
const [ tempMinimumColumnWidth, setTempMinimumColumnWidth ] = useState(
minimumColumnWidth || '12rem'
);

const isManual = !! columnCount ? 'manual' : 'auto';

const onChangeType = ( value ) => {
if ( value === 'manual' ) {
setTempMinimumColumnWidth( minimumColumnWidth || '12rem' );
} else {
setTempColumnCount( columnCount || 3 );
}
onChange( {
...layout,
columnCount: value === 'manual' ? tempColumnCount : null,
minimumColumnWidth:
value === 'auto' ? tempMinimumColumnWidth : null,
} );
};

return (
<ToggleGroupControl
__nextHasNoMarginBottom={ true }
label={ __( 'Type' ) }
value={ isManual }
onChange={ onChangeType }
isBlock={ true }
>
<ToggleGroupControlOption
key={ 'manual' }
value="manual"
label={ __( 'Manual' ) }
/>
<ToggleGroupControlOption
key={ 'auto' }
value="auto"
label={ __( 'Auto' ) }
/>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If Auto is the default should it be on the left?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know! Is the default usually on the left? Happy to switch it.

</ToggleGroupControl>
);
}
9 changes: 3 additions & 6 deletions packages/block-library/src/group/variations.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,7 @@ const variations = [
blockAttributes.layout?.orientation === 'vertical',
icon: stack,
},
];

if ( window?.__experimentalEnableGroupGridVariation ) {
variations.push( {
{
name: 'group-grid',
title: __( 'Grid' ),
description: __( 'Arrange blocks in a grid.' ),
Expand All @@ -54,7 +51,7 @@ if ( window?.__experimentalEnableGroupGridVariation ) {
isActive: ( blockAttributes ) =>
blockAttributes.layout?.type === 'grid',
icon: grid,
} );
}
},
];

export default variations;