Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify the embed default size for the case of Figma Embed blocks to allow supporting wide view using the native aspect ratio classes provided by the editor #9

Merged
merged 1 commit into from
May 29, 2024
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
27 changes: 27 additions & 0 deletions includes/FigmaBlock/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public function setup() {

add_action( 'enqueue_block_editor_assets', [ $this, 'block_editor_assets' ] );
add_filter( 'rest_request_after_callbacks', [ $this, 'filter_rest_request_after_callbacks' ], 10, 3 );
add_filter( 'embed_defaults', [ $this, 'embed_defaults_for_figma_block' ], 10, 2 );
}

/**
Expand Down Expand Up @@ -105,4 +106,30 @@ public function filter_rest_request_after_callbacks( $response, array $handler,

return $response;
}

/**
* Modify the embed default size for the case of Figma Embed blocks to allow supporting wide view using the native
* aspect ratio classes provided by the editor.
*
* @param int[] $size The array of dimensions for the size
* @param string $url The URL that should be embedded.
*
* @return int[]
*/
public function embed_defaults_for_figma_block( $size, $url ) {
if ( empty( $url ) ) {
return $size;
}

$domain = wp_parse_url( $url, PHP_URL_HOST );

if ( 'www.figma.com' !== $domain ) {
return $size;
}

return [
'width' => 600,
'height' => 452,
];
}
}
2 changes: 1 addition & 1 deletion src/assets/js/icon.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export const IconColor = () => (
width="95.0226"
height="142.534"
fill="black"
fill-opacity="0"
fillOpacity="0"
transform="translate(1.46603 2.19946) scale(3)"
/>
<Path
Expand Down