Skip to content

Commit

Permalink
Support new Figma share URL
Browse files Browse the repository at this point in the history
<#239>

Figma changed URL structure for the share URL from "/file/..." to
"/<anything>/...". This patch updates the URL checking regexp according
to their updated embed document.

close #239
  • Loading branch information
pocka committed May 17, 2024
1 parent 6ad61ea commit 34721f5
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
19 changes: 19 additions & 0 deletions packages/examples/stories/tests/issues/239.stories.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React from "react";

import { Button } from "../../Button";

export default {
title: "Tests/Issues/#239",
render() {
return <Button>Button</Button>;
},
};

export const NewURL = {
parameters: {
design: {
type: "figma",
url: "https://www.figma.com/design/Klm6pxIZSaJFiOMX5FpTul9F/storybook-addon-designs-sample?node-id=0%3A1&t=QfPVIRalrysutNxH-1",
},
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { IFrame } from "./IFrame";
import { FigmaConfig, IFrameConfigBase } from "../../config";

export const figmaURLPattern =
/https:\/\/([w.-]+.)?figma.com\/(file|proto)\/([0-9a-zA-Z]{22,128})(?:\/.*)?$/;
/https:\/\/[\w\.-]+\.?figma.com\/([\w-]+)\/([0-9a-zA-Z]{22,128})(?:\/.*)?$/;

Check warning on line 10 in packages/storybook-addon-designs/src/manager/components/Figma.tsx

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

packages/storybook-addon-designs/src/manager/components/Figma.tsx#L10

Unnecessary escape character: \..

export const isFigmaURL = (url: string) => figmaURLPattern.test(url);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export const Figspec: FC<Props> = ({ config }) => {
throw new Error(config.url + " is not a valid Figma URL.");
}

const [, , , fileKey] = match;
const [, , fileKey] = match;

const url = new URL(config.url);

Expand Down

0 comments on commit 34721f5

Please sign in to comment.