-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
55 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.wp-storybook-figma-embed { | ||
width: 100%; | ||
border: none; | ||
} |