* Mini Cart drawer: print width in PHP

* Remove unnecessary timeout

* Make sure classic themes have a Mini Cart contents width value set up
This commit is contained in:
Albert Juhé Lluveras 2023-05-05 11:44:41 +02:00 committed by GitHub
parent c4d8e9114e
commit 349ae658bb
4 changed files with 6 additions and 8 deletions

View File

@ -1,4 +1,6 @@
:root { :root {
/* This value might be overridden in PHP based on the attribute set by the user. */
--drawer-width: 480px;
--neg-drawer-width: calc(var(--drawer-width) * -1); --neg-drawer-width: calc(var(--drawer-width) * -1);
} }

View File

@ -15,12 +15,7 @@ type MiniCartContentsBlockProps = {
export const MiniCartContentsBlock = ( export const MiniCartContentsBlock = (
props: MiniCartContentsBlockProps props: MiniCartContentsBlockProps
): JSX.Element => { ): JSX.Element => {
const { const { children } = props;
children,
attributes: { width },
} = props;
document.documentElement.style.setProperty( '--drawer-width', width );
return <>{ children }</>; return <>{ children }</>;
}; };

View File

@ -111,6 +111,9 @@ class MiniCartContents extends AbstractBlock {
); );
$parsed_style = ''; $parsed_style = '';
if ( array_key_exists( 'width', $attributes ) ) {
$parsed_style .= ':root{--drawer-width: ' . esc_html( $attributes['width'] ) . '}';
}
foreach ( $styles as $style ) { foreach ( $styles as $style ) {
$selector = is_array( $style['selector'] ) ? implode( ',', $style['selector'] ) : $style['selector']; $selector = is_array( $style['selector'] ) ? implode( ',', $style['selector'] ) : $style['selector'];

View File

@ -304,8 +304,6 @@ describe( 'Shopper → Mini Cart', () => {
'.wc-block-components-quantity-selector__button--plus' '.wc-block-components-quantity-selector__button--plus'
); );
await page.waitForTimeout( 500 );
await page.click( await page.click(
'.wc-block-components-quantity-selector__button--plus' '.wc-block-components-quantity-selector__button--plus'
); );