Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Block supports: allow "all" as a value for __experimentalDefaultControls #38972

Closed
wants to merge 3 commits into from
Closed
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
31 changes: 27 additions & 4 deletions packages/block-editor/src/hooks/border.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,7 @@ export function BorderPanel( props ) {
return null;
}

const defaultBorderControls = getBlockSupport( props.name, [
BORDER_SUPPORT_KEY,
'__experimentalDefaultControls',
] );
const defaultBorderControls = getDefaultBorderControls( props.name );

const createResetAllFilter = (
borderAttribute,
Expand Down Expand Up @@ -213,3 +210,29 @@ export function removeBorderAttribute( style, attribute ) {
},
} );
}

/**
* Returns an object containing default controls. A control key with a `true` value
* means that the control will be shown in the panel by default.
*
* @param {string|Object} blockType Block name or block type object.
*
* @return {Object} Default controls key/value pairs.
*/
export function getDefaultBorderControls( blockType ) {
const defaultBorderControls = getBlockSupport( blockType, [
BORDER_SUPPORT_KEY,
'__experimentalDefaultControls',
] );

if ( defaultBorderControls === 'all' ) {
return {
color: true,
radius: true,
width: true,
style: true,
};
}

return defaultBorderControls;
}
30 changes: 26 additions & 4 deletions packages/block-editor/src/hooks/color.js
Original file line number Diff line number Diff line change
Expand Up @@ -489,10 +489,7 @@ export function ColorEdit( props ) {
const enableContrastChecking =
Platform.OS === 'web' && ! gradient && ! style?.color?.gradient;

const defaultColorControls = getBlockSupport( props.name, [
COLOR_SUPPORT_KEY,
'__experimentalDefaultControls',
] );
const defaultColorControls = getDefaultColorControls( props.name );

return (
<ColorPanel
Expand Down Expand Up @@ -620,6 +617,31 @@ export const withColorPaletteStyles = createHigherOrderComponent(
}
);

/**
* Returns an object containing default controls. A control key with a `true` value
* means that the control will be shown in the panel by default.
*
* @param {string|Object} blockType Block name or block type object.
*
* @return {Object} Default controls key/value pairs.
*/
export function getDefaultColorControls( blockType ) {
const defaultColorControls = getBlockSupport( blockType, [
COLOR_SUPPORT_KEY,
'__experimentalDefaultControls',
] );

if ( defaultColorControls === 'all' ) {
return {
text: true,
background: true,
link: true,
};
}

return defaultColorControls;
}

const MIGRATION_PATHS = {
linkColor: [ [ 'style', 'elements', 'link', 'color', 'text' ] ],
textColor: [ [ 'textColor' ], [ 'style', 'color', 'text' ] ],
Expand Down
30 changes: 26 additions & 4 deletions packages/block-editor/src/hooks/dimensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,7 @@ export function DimensionsPanel( props ) {
return null;
}

const defaultSpacingControls = getBlockSupport( props.name, [
SPACING_SUPPORT_KEY,
'__experimentalDefaultControls',
] );
const defaultSpacingControls = getDefaultDimensionsControls( props.name );

const createResetAllFilter = ( attribute ) => ( newAttributes ) => ( {
...newAttributes,
Expand Down Expand Up @@ -196,3 +193,28 @@ export function useIsDimensionsSupportValid( blockName, feature ) {

return true;
}

/**
* Returns an object containing default controls. A control key with a `true` value
* means that the control will be shown in the panel by default.
*
* @param {string|Object} blockType Block name or block type object.
*
* @return {Object} Default controls key/value pairs.
*/
export function getDefaultDimensionsControls( blockType ) {
const defaultDimensionsControls = getBlockSupport( blockType, [
SPACING_SUPPORT_KEY,
'__experimentalDefaultControls',
] );

if ( defaultDimensionsControls === 'all' ) {
return {
padding: true,
margin: true,
blockGap: true,
};
}

return defaultDimensionsControls;
}
34 changes: 30 additions & 4 deletions packages/block-editor/src/hooks/typography.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,7 @@ export function TypographyPanel( props ) {

if ( isDisabled || ! isSupported ) return null;

const defaultControls = getBlockSupport( props.name, [
TYPOGRAPHY_SUPPORT_KEY,
'__experimentalDefaultControls',
] );
const defaultControls = getDefaultTypographyControls( props.name );

const createResetAllFilter = ( attribute ) => ( newAttributes ) => ( {
...newAttributes,
Expand Down Expand Up @@ -250,3 +247,32 @@ function useIsTypographyDisabled( props = {} ) {

return configs.filter( Boolean ).length === configs.length;
}

/**
* Returns an object containing default controls. A control key with a `true` value
* means that the control will be shown in the panel by default.
*
* @param {string|Object} blockType Block name or block type object.
*
* @return {Object} Default controls key/value pairs.
*/
export function getDefaultTypographyControls( blockType ) {
const defaultTypographyControls = getBlockSupport( blockType, [
TYPOGRAPHY_SUPPORT_KEY,
'__experimentalDefaultControls',
] );

if ( defaultTypographyControls === 'all' ) {
return {
fontFamily: true,
fontSize: true,
fontAppearance: true,
lineHeight: true,
textDecoration: true,
textTransform: true,
letterSpacing: true,
};
}

return defaultTypographyControls;
}