Skip to content

Commit 1f86f73

Browse files
authored
fix: Set frameName as a context when Frame is used (#2)
Setting `frameName` in the context of the query ensures that the components inside the `<Frame>` are getting proper styles that are defined inside appropriate Figma frames. Closes #1
1 parent d1bb270 commit 1f86f73

File tree

3 files changed

+23
-9
lines changed

3 files changed

+23
-9
lines changed

src/File.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import gql from "graphql-tag"
44

55
export const FigmaContext = React.createContext({
66
fileId: null,
7-
pageName: null
7+
pageName: null,
8+
frameName: null
89
})
910

1011
export const rectFragment = gql`
@@ -142,7 +143,8 @@ export default function File({ fileId, pageName, children }: IFile) {
142143
<FigmaContext.Provider
143144
value={{
144145
fileId,
145-
pageName
146+
pageName,
147+
frameName: null
146148
}}
147149
>
148150
{children({ data })}

src/Frame.tsx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as React from "react"
22
import Query from "./Query"
3+
import { FigmaContext } from "./File"
34

45
export interface INode {
56
nodeName: string
@@ -30,7 +31,21 @@ export default function Frame({ frameName, nodeName, children }: IFrame) {
3031
backgroundSize: "cover"
3132
}
3233

33-
return children(styles)
34+
return (
35+
<FigmaContext.Consumer>
36+
{({ fileId, pageName }) => (
37+
<FigmaContext.Provider
38+
value={{
39+
fileId,
40+
pageName,
41+
frameName
42+
}}
43+
>
44+
{children(styles)}
45+
</FigmaContext.Provider>
46+
)}
47+
</FigmaContext.Consumer>
48+
)
3449
}}
3550
</Query>
3651
)

src/Query.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,13 @@ interface IQuery {
66
variables: any
77
children?: any
88
}
9-
export default function Query({
10-
children,
11-
variables,
12-
}: IQuery) {
9+
export default function Query({ children, variables }: IQuery) {
1310
return (
1411
<FigmaContext.Consumer>
15-
{({ fileId, pageName }) => (
12+
{({ fileId, pageName, frameName }) => (
1613
<ApolloQuery
1714
query={FIGMA_FILE_QUERY}
18-
variables={{ fileId, pageName, ...variables }}
15+
variables={{ fileId, pageName, frameName, ...variables }}
1916
>
2017
{({ loading, data, error }) => {
2118
if (error) {

0 commit comments

Comments
 (0)