Skip to content

Commit

Permalink
Add body-class when block is in use
Browse files Browse the repository at this point in the history
  • Loading branch information
carstingaxion committed May 28, 2024
1 parent 1ddbc50 commit 293ca9a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
23 changes: 23 additions & 0 deletions inc/block-styles/namespace.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,28 @@ function bootstrap() :void {
'inline_style' => '.wp-block-group.is-style-label-overview-landscape { --label-printing-doc-width: 29.7cm; --label-printing-doc-height: 21cm }',
]
);

\add_filter('body_class', __NAMESPACE__ . '\\body_class');
}

/**
* Add a CSS class to the <body> element if 'label-printing' block is present and is a singular-view.
*
* @see https://developer.wordpress.org/reference/hooks/body_class/
* @see https://developer.wordpress.org/reference/functions/has_block/
*
* @param string[] $classes
*
* @return string[]
*/
function body_class( array $classes ): array {

if ( ! \is_singular() || \is_admin() ) {
return $classes;
}

if ( \has_block( 'figuren-theater/label-printing' ) ) {
$classes[] = 'is-label-printing';
}
return $classes;
}
7 changes: 3 additions & 4 deletions src/block-editor/blocks/label-printing/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,9 @@ body.is-label-printing {
}

@media print {

html,
body,
.wp-site-blocks {
// html,
body.is-label-printing,
.is-label-printing .wp-site-blocks {
margin: 0 !important;
padding: 0 !important;
}
Expand Down

0 comments on commit 293ca9a

Please sign in to comment.