File tree Expand file tree Collapse file tree
packages/storybook-addon-designs/src/manager/components Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -29,8 +29,10 @@ export const Figma: FC<Props> = ({ config }) => {
2929 return config ;
3030 }
3131
32- const embedHost = config . embedHost || location . hostname ;
33- const url = `https://www.figma.com/embed?embed_host=${ embedHost } &url=${ config . url } ` ;
32+ const url = createEmbedURL (
33+ config . url ,
34+ config . embedHost || location . hostname ,
35+ ) ;
3436
3537 return {
3638 url,
@@ -40,3 +42,15 @@ export const Figma: FC<Props> = ({ config }) => {
4042
4143 return < IFrame defer config = { iframeConfig } /> ;
4244} ;
45+
46+ function createEmbedURL ( encodedURL : string , embedHost : string ) {
47+ const url = new URL ( encodedURL ) ;
48+ url . hostname = url . hostname . replace ( / ^ w w w \. / , "embed." ) ;
49+ url . searchParams . delete ( "embed_origin" ) ;
50+ url . searchParams . set ( "embed-host" , embedHost ) ;
51+ for ( const [ key , value ] of url . searchParams ) {
52+ url . searchParams . delete ( key ) ;
53+ url . searchParams . set ( key . replace ( / _ / g, "-" ) , value ) ;
54+ }
55+ return url . href ;
56+ }
You can’t perform that action at this time.
0 commit comments