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

Mini Cart drawer: print width in PHP #9329

Merged
merged 3 commits into from
May 5, 2023
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
2 changes: 2 additions & 0 deletions assets/js/base/components/drawer/style.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
: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);
}

Expand Down
7 changes: 1 addition & 6 deletions assets/js/blocks/mini-cart/mini-cart-contents/block.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,7 @@ type MiniCartContentsBlockProps = {
export const MiniCartContentsBlock = (
props: MiniCartContentsBlockProps
): JSX.Element => {
const {
children,
attributes: { width },
} = props;

document.documentElement.style.setProperty( '--drawer-width', width );
const { children } = props;

return <>{ children }</>;
};
3 changes: 3 additions & 0 deletions src/BlockTypes/MiniCartContents.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ protected function enqueue_assets( array $attributes ) {
);

$parsed_style = '';
if ( array_key_exists( 'width', $attributes ) ) {
$parsed_style .= ':root{--drawer-width: ' . esc_html( $attributes['width'] ) . '}';
}

foreach ( $styles as $style ) {
$selector = is_array( $style['selector'] ) ? implode( ',', $style['selector'] ) : $style['selector'];
Expand Down
2 changes: 0 additions & 2 deletions tests/e2e/specs/shopper/mini-cart.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,6 @@ describe( 'Shopper → Mini Cart', () => {
'.wc-block-components-quantity-selector__button--plus'
);

await page.waitForTimeout( 500 );

await page.click(
'.wc-block-components-quantity-selector__button--plus'
);
Expand Down