Skip to content

Commit d1bb270

Browse files
author
Andrey Okonetchnikov
committed
feat: Make library agnostic of how styles are rendered
Only return styles object instead of rendering with styled-components so rendering can happen in userland with any possible solution. BREAKING CHANGE: API of the components has been updated to use render props pattern instead of rendering JSX elements with the library
1 parent 03c7e39 commit d1bb270

File tree

5 files changed

+41
-148
lines changed

5 files changed

+41
-148
lines changed

package-lock.json

Lines changed: 12 additions & 91 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,10 @@
4444
"react-apollo": "^2.5.2",
4545
"react-dom": "^16.8.4",
4646
"react-google-font-loader": "^1.0.5",
47-
"styled-components": "^4.1.3",
4847
"subscriptions-transport-ws": "^0.9.16"
4948
},
5049
"peerDependencies": {
51-
"react": ">=16.8",
52-
"styled-components": "^4"
50+
"react": ">=16.8"
5351
},
5452
"devDependencies": {
5553
"@babel/core": "^7.4.0",

src/Frame.tsx

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
11
import * as React from "react"
2-
import styled from "styled-components"
32
import Query from "./Query"
43

5-
const NodeWrapper = styled("div")`
6-
position: relative;
7-
`
8-
94
export interface INode {
105
nodeName: string
11-
children?: any
12-
styles?: object
6+
children?: (styles: object) => JSX.Element
137
}
148

159
interface IFrame extends INode {
@@ -29,17 +23,14 @@ export default function Frame({ frameName, nodeName, children }: IFrame) {
2923
const { size } = frame
3024
const { image } = frame.children[0]
3125

32-
return (
33-
<NodeWrapper
34-
style={{
35-
...size,
36-
background: `url(${image})`,
37-
backgroundSize: "cover"
38-
}}
39-
>
40-
{children}
41-
</NodeWrapper>
42-
)
26+
const styles = {
27+
...size,
28+
position: "relative",
29+
background: `url(${image})`,
30+
backgroundSize: "cover"
31+
}
32+
33+
return children(styles)
4334
}}
4435
</Query>
4536
)

src/Group.tsx

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
1-
import * as React from "react";
2-
import styled from "styled-components"
1+
import * as React from "react"
32
import Query from "./Query"
4-
import { INode } from "./Frame";
5-
6-
const NodeWrapper = styled("div")`
7-
position: relative;
8-
`
3+
import { INode } from "./Frame"
94

105
export default function Group({ nodeName, children }: INode) {
116
return (
@@ -18,17 +13,14 @@ export default function Group({ nodeName, children }: INode) {
1813
const frame = data.file.pages[0].frames[0]
1914
const { size, position } = frame.children[0]
2015

21-
return (
22-
<NodeWrapper
23-
style={{
24-
...size,
25-
top: position.y,
26-
left: position.x
27-
}}
28-
>
29-
{children}
30-
</NodeWrapper>
31-
)
16+
const styles = {
17+
...size,
18+
position: "relative",
19+
top: position.y,
20+
left: position.x
21+
}
22+
23+
return children(styles)
3224
}}
3325
</Query>
3426
)

src/Text.tsx

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
11
import * as React from "react"
2-
import styled from "styled-components"
32
import { rgba } from "polished"
43
import GoogleFontLoader from "react-google-font-loader"
54
import Query from "./Query"
65
import { INode } from "./Frame"
76

8-
const NodeWrapper = styled("div")`
9-
position: absolute;
10-
`
11-
12-
export default function Text({ nodeName, children, styles }: INode) {
7+
export default function Text({ nodeName, children }: INode) {
138
return (
149
<Query
1510
variables={{
@@ -45,18 +40,14 @@ export default function Text({ nodeName, children, styles }: INode) {
4540
}
4641
]}
4742
/>
48-
<NodeWrapper
49-
style={{
50-
...style,
51-
...size,
52-
left: relativeX,
53-
top: relativeY,
54-
color,
55-
...styles
56-
}}
57-
>
58-
{children}
59-
</NodeWrapper>
43+
{children({
44+
...style,
45+
...size,
46+
position: "absolute",
47+
left: relativeX,
48+
top: relativeY,
49+
color
50+
})}
6051
</React.Fragment>
6152
)
6253
}}

0 commit comments

Comments
 (0)