Allow themes to remove the Mini Cart title on overridden template parts (https://github.com/woocommerce/woocommerce-blocks/pull/8779)

* Allow themes to remove the Mini Cart title on overridden template parts

* Remove unused file
This commit is contained in:
Albert Juhé Lluveras 2023-03-22 08:23:52 +01:00 committed by GitHub
parent 82c59ffb29
commit 5235f6c392
4 changed files with 11 additions and 7 deletions

View File

@ -1,5 +0,0 @@
const Block = ( { children }: { children: JSX.Element } ): JSX.Element => {
return <>{ children }</>;
};
export default Block;

View File

@ -41,6 +41,7 @@ registerCheckoutBlock( {
registerCheckoutBlock( { registerCheckoutBlock( {
metadata: miniCartTitleMetadata, metadata: miniCartTitleMetadata,
force: false,
component: lazy( component: lazy(
() => () =>
import( import(

View File

@ -6,7 +6,6 @@ import { registerBlockComponent } from '@woocommerce/blocks-registry';
/** /**
* Internal dependencies * Internal dependencies
*/ */
import type { CheckoutBlockOptions } from './types';
import { import {
assertBlockName, assertBlockName,
assertBlockParent, assertBlockParent,
@ -14,6 +13,7 @@ import {
assertBlockComponent, assertBlockComponent,
} from './utils'; } from './utils';
import { registeredBlocks } from './registered-blocks'; import { registeredBlocks } from './registered-blocks';
import type { CheckoutBlockOptions } from './types';
/** /**
* Main API for registering a new checkout block within areas. * Main API for registering a new checkout block within areas.
@ -34,6 +34,13 @@ export const registerCheckoutBlock = (
component: options.component, component: options.component,
} ); } );
// Infer the `force` value from whether the block is locked or not. But
// allow overriding it on block registration.
const force =
typeof options.force === 'boolean'
? options.force
: Boolean( options.metadata?.attributes?.lock?.default?.remove );
/** /**
* Store block metadata for later lookup. * Store block metadata for later lookup.
*/ */
@ -41,6 +48,6 @@ export const registerCheckoutBlock = (
blockName: options.metadata.name, blockName: options.metadata.name,
metadata: options.metadata, metadata: options.metadata,
component: options.component, component: options.component,
force: !! options.metadata?.attributes?.lock?.default?.remove, force,
}; };
}; };

View File

@ -46,6 +46,7 @@ export type RegisteredBlocks = Record< string, RegisteredBlock >;
export type CheckoutBlockOptions = { export type CheckoutBlockOptions = {
metadata: CheckoutBlockOptionsMetadata; metadata: CheckoutBlockOptionsMetadata;
force?: boolean;
component: component:
| LazyExoticComponent< React.ComponentType< unknown > > | LazyExoticComponent< React.ComponentType< unknown > >
| ( () => JSX.Element | null ) | ( () => JSX.Element | null )