Skip to content

Commit

Permalink
Add FigmaEmbed component
Browse files Browse the repository at this point in the history
  • Loading branch information
mirka committed Nov 14, 2024
1 parent f3db348 commit ec69ef6
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/components/src/button/stories/best-practices.mdx
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { Meta } from '@storybook/blocks';
import FigmaEmbed from '/storybook/components/figma-embed';

<Meta title="Components/Actions/Button/Best Practices" />

# Button

## Best Practices

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

<FigmaEmbed url="https://www.figma.com/board/0ZfHa37xxWoMqy7McezUNX/WordPress.org-Storybook-Sitemap?node-id=126-3728&t=p2yCPmXnDfJ4wFnK-4" title="A sample embed" height="300" />
47 changes: 47 additions & 0 deletions storybook/components/figma-embed/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* Internal dependencies
*/
import './style.scss';

// See https://www.figma.com/developers/embed#embed-a-figma-file
const CONFIG = {
'embed-host': 'wordpress-storybook',
footer: false,
'page-selector': false,
'viewport-controls': true,
};

/**
* Embed Figma links in the Storybook.
*
* @param {Object} props
* @param {string} props.url - Figma URL to embed.
* @param {string} props.title - Accessible title for the iframe.
*/
function FigmaEmbed( { url, title, ...props } ) {
const urlObj = new URL( url );

const queryParams = new URLSearchParams( urlObj.search );
Object.entries( CONFIG ).forEach( ( [ key, value ] ) => {
queryParams.set( key, value );
} );
urlObj.search = queryParams.toString();

urlObj.hostname = urlObj.hostname.replace(
'www.figma.com',
'embed.figma.com'
);

const normalizedUrl = urlObj.toString();

return (
<iframe
title={ title }
src={ normalizedUrl }
className="wp-storybook-figma-embed"
{ ...props }
/>
);
}

export default FigmaEmbed;
4 changes: 4 additions & 0 deletions storybook/components/figma-embed/style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.wp-storybook-figma-embed {
width: 100%;
border: none;
}

0 comments on commit ec69ef6

Please sign in to comment.