-
Notifications
You must be signed in to change notification settings - Fork 387
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
1 parent
33304e5
commit b3efc6b
Showing
5 changed files
with
109 additions
and
55 deletions.
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
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,35 @@ | ||
import React from 'react'; | ||
import {parseFigmaNodeUrl} from '@primer/figma-images/src/utils'; | ||
import { Link, StyledOcticon } from '@primer/react'; | ||
import {PencilIcon} from '@primer/octicons-react' | ||
|
||
type FigmaImageProps = React.ImgHTMLAttributes<HTMLImageElement> & { | ||
src: string | ||
caption?: string | ||
} | ||
|
||
const cssStyles = { | ||
width: "100%", | ||
margin: "0", | ||
"& img": { | ||
width: '100%' | ||
} | ||
} | ||
|
||
const FigmaImageDir = '/images/figma'; | ||
|
||
export const FigmaImage: React.FC<FigmaImageProps> = ({src, caption, ...props}) => { | ||
// check for missing prop | ||
if(src === undefined) throw new Error("src is required on FigmaImage component"); | ||
// get real image url | ||
const {nodeId, fileId} = parseFigmaNodeUrl(src); | ||
const imagePath = `${FigmaImageDir}/${fileId}-${nodeId}.png` | ||
// return image component | ||
return (<figure className="FigmaImage" style={cssStyles}> | ||
<img src={imagePath} {...props}/> | ||
<figcaption> | ||
{caption} | ||
<Link sx={{fontSize: '12px'}} className="link" href={src}><StyledOcticon icon={PencilIcon} sx={{mr: 2}} size="small"/>Edit in Figma</Link> | ||
</figcaption> | ||
</figure>) | ||
} |