Skip to content

Commit

Permalink
Modify the embed default size for the case of Figma Embed blocks to a…
Browse files Browse the repository at this point in the history
…llow supporting wide view using the native aspect ratio classes provided by the editor
  • Loading branch information
kmgalanakis committed May 17, 2024
1 parent 64f0f03 commit 5f43ef7
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
33 changes: 33 additions & 0 deletions includes/FigmaBlock/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ 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 +107,35 @@ 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 {
* Indexed array of the embed width and height in pixels.
*
* @type int $0 The embed width.
* @type int $1 The embed height.
* }
* @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 = 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

0 comments on commit 5f43ef7

Please sign in to comment.