Skip to content

Commit

Permalink
Use a CSS media query to show/hide the PDF embed
Browse files Browse the repository at this point in the history
  • Loading branch information
luisherranz committed Sep 11, 2023
1 parent 76fc226 commit 1b0c801
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
3 changes: 1 addition & 2 deletions packages/block-library/src/file/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ static function ( $matches ) {
$processor->next_tag();
$processor->set_attribute( 'data-wp-interactive', '' );
$processor->next_tag( 'object' );
$processor->set_attribute( 'data-wp-bind--hidden', '!selectors.core.file.hasPdfPreview' );
$processor->set_attribute( 'hidden', true );
$processor->set_attribute( 'data-wp-style--display', 'selectors.core.file.hasPdfPreview' );
return $processor->get_updated_html();
}

Expand Down
7 changes: 6 additions & 1 deletion packages/block-library/src/file/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,19 @@
margin-bottom: 1em;
}

@media (max-width: 768px) {
.wp-block-file__embed {
display: none;
}
}

//This needs a low specificity so it won't override the rules from the button element if defined in theme.json.
:where(.wp-block-file__button) {
border-radius: 2em;
padding: 0.5em 1em;
display: inline-block;

&:is(a) {

&:hover,
&:visited,
&:focus,
Expand Down
4 changes: 2 additions & 2 deletions packages/block-library/src/file/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import { store } from '@wordpress/interactivity';
/**
* Internal dependencies
*/
import { browserSupportsPdfs as hasPdfPreview } from './utils';
import { browserSupportsPdfs } from './utils';

store( {
selectors: {
core: {
file: {
hasPdfPreview,
hasPdfPreview: browserSupportsPdfs() ? 'inherit' : 'none',
},
},
},
Expand Down

0 comments on commit 1b0c801

Please sign in to comment.