Skip to content
This repository was archived by the owner on Jun 20, 2022. It is now read-only.

Commit fc74682

Browse files
committed
fix: fix internal theme usage
It fixes a bug with custom texts defined in theme.
1 parent 12f50d6 commit fc74682

File tree

7 files changed

+3275
-2876
lines changed

7 files changed

+3275
-2876
lines changed

package.json

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -25,49 +25,49 @@
2525
}
2626
],
2727
"devDependencies": {
28-
"@babel/cli": "^7.6.0",
29-
"@babel/core": "^7.6.0",
28+
"@babel/cli": "^7.7.0",
29+
"@babel/core": "^7.7.2",
3030
"@babel/plugin-external-helpers": "^7.2.0",
31-
"@babel/plugin-proposal-class-properties": "^7.5.5",
32-
"@babel/plugin-transform-modules-commonjs": "^7.6.0",
33-
"@babel/plugin-transform-runtime": "^7.6.0",
34-
"@babel/preset-env": "^7.6.0",
35-
"@babel/preset-react": "^7.0.0",
36-
"@emotion/core": "^10.0.17",
37-
"@emotion/styled": "^10.0.17",
38-
"@xstyled/emotion": "^1.11.0",
39-
"@xstyled/styled-components": "^1.11.0",
40-
"@xstyled/system": "^1.11.0",
31+
"@babel/plugin-proposal-class-properties": "^7.7.0",
32+
"@babel/plugin-transform-modules-commonjs": "^7.7.0",
33+
"@babel/plugin-transform-runtime": "^7.6.2",
34+
"@babel/preset-env": "^7.7.1",
35+
"@babel/preset-react": "^7.7.0",
36+
"@emotion/core": "^10.0.22",
37+
"@emotion/styled": "^10.0.23",
38+
"@xstyled/emotion": "^1.15.0",
39+
"@xstyled/styled-components": "^1.15.0",
40+
"@xstyled/system": "^1.14.0",
4141
"babel-eslint": "^10.0.2",
4242
"babel-jest": "^24.8.0",
4343
"babel-plugin-annotate-pure-calls": "^0.4.0",
44-
"babel-plugin-emotion": "^10.0.19",
44+
"babel-plugin-emotion": "^10.0.23",
4545
"babel-plugin-styled-components": "^1.10.6",
4646
"babel-plugin-transform-rename-import": "^2.3.0",
4747
"bundlesize": "^0.18.0",
4848
"conventional-github-releaser": "^3.1.3",
49-
"cross-env": "^6.0.0",
49+
"cross-env": "^6.0.3",
5050
"emotion-theming": "^10.0.19",
51-
"eslint": "^6.4.0",
51+
"eslint": "^6.6.0",
5252
"eslint-config-airbnb": "^18.0.1",
53-
"eslint-config-prettier": "^6.3.0",
53+
"eslint-config-prettier": "^6.7.0",
5454
"eslint-plugin-import": "^2.18.2",
5555
"eslint-plugin-jsx-a11y": "^6.2.3",
56-
"eslint-plugin-react": "^7.14.3",
57-
"eslint-plugin-react-hooks": "^2.0.1",
56+
"eslint-plugin-react": "^7.16.0",
57+
"eslint-plugin-react-hooks": "^2.3.0",
5858
"jest": "^24.8.0",
59-
"lerna": "^3.16.4",
60-
"react": "^16.9.0",
61-
"react-dom": "^16.9.0",
62-
"reakit": "^1.0.0-beta.7",
63-
"rollup": "^1.21.4",
59+
"lerna": "^3.19.0",
60+
"react": "^16.12.0",
61+
"react-dom": "^16.12.0",
62+
"reakit": "^1.0.0-beta.12",
63+
"rollup": "^1.27.4",
6464
"rollup-plugin-babel": "^4.3.3",
6565
"rollup-plugin-commonjs": "^10.0.2",
6666
"rollup-plugin-node-resolve": "^5.2.0",
6767
"rollup-plugin-replace": "^2.2.0",
6868
"rollup-plugin-size-snapshot": "^0.10.0",
6969
"rollup-plugin-terser": "^5.1.2",
7070
"shx": "^0.3.2",
71-
"styled-components": "^4.3.2"
71+
"styled-components": "^4.4.1"
7272
}
7373
}

packages/core-em/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@
2424
"access": "public"
2525
},
2626
"dependencies": {
27-
"@babel/runtime": "^7.6.0",
28-
"@xstyled/emotion": "^1.11.0",
29-
"@xstyled/util": "^1.11.0",
30-
"polished": "^3.4.1",
27+
"@babel/runtime": "^7.7.2",
28+
"@xstyled/emotion": "^1.15.0",
29+
"@xstyled/util": "^1.14.0",
30+
"polished": "^3.4.2",
3131
"prop-desc": "^1.0.0",
3232
"prop-types": "^15.7.2",
3333
"react-flatten-children": "^1.0.0",

packages/core-sc/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@
2424
"access": "public"
2525
},
2626
"dependencies": {
27-
"@babel/runtime": "^7.6.0",
28-
"@xstyled/styled-components": "^1.11.0",
29-
"@xstyled/util": "^1.11.0",
30-
"polished": "^3.4.1",
27+
"@babel/runtime": "^7.7.2",
28+
"@xstyled/styled-components": "^1.15.0",
29+
"@xstyled/util": "^1.14.0",
30+
"polished": "^3.4.2",
3131
"prop-desc": "^1.0.0",
3232
"prop-types": "^15.7.2",
3333
"react-flatten-children": "^1.0.0",
@@ -41,6 +41,6 @@
4141
},
4242
"devDependencies": {
4343
"@xstyled/styled-components": "^1.10.0",
44-
"@xstyled/system": "^1.11.0"
44+
"@xstyled/system": "^1.14.0"
4545
}
4646
}

packages/shared/core/util/factories.js

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react'
2-
import styled from '@xstyled/x'
2+
import styled, { useTheme } from '@xstyled/x'
33
import { omit } from '@xstyled/util'
44
import { systemProps } from './system'
55
import { mergeClone } from './misc'
@@ -21,18 +21,9 @@ function getThemeCache(theme) {
2121
return cache
2222
}
2323

24-
export function createInnerComponent({ name, render, theme = {} }) {
25-
const InnerComponent = React.forwardRef(function InnerComponent(props, ref) {
26-
const { as, safeProps } = useProps(props)
27-
return render({ ref, as, ...safeProps }, { theme, ...props })
28-
})
29-
InnerComponent.displayName = name
30-
return InnerComponent
31-
}
32-
3324
function computeTheme(baseTheme, customTheme) {
3425
const theme = mergeClone(baseTheme, customTheme)
35-
if (!theme.colors || !theme.colors.modes) return baseTheme
26+
if (!theme.colors || !theme.colors.modes) return theme
3627
return {
3728
...theme,
3829
colors: {
@@ -42,17 +33,40 @@ function computeTheme(baseTheme, customTheme) {
4233
}
4334
}
4435

45-
export function createComponent({ name, render, theme = {}, propTypes }) {
46-
theme = Array.isArray(theme) ? mergeClone(...theme) : theme
47-
const InnerComponent = createInnerComponent({ name, render, theme })
36+
function getTheme(name, baseTheme, customTheme) {
37+
const themeCache = getThemeCache(customTheme)
38+
themeCache[name] = themeCache[name] || computeTheme(baseTheme, customTheme)
39+
return themeCache[name]
40+
}
41+
42+
export function createInnerComponent({ name, render, theme: baseTheme = {} }) {
43+
const InnerComponent = React.forwardRef(function InnerComponent(props, ref) {
44+
const customTheme = useTheme()
45+
const theme = getTheme(name, baseTheme, customTheme)
46+
const { as, safeProps } = useProps(props)
47+
return render({ ref, as, ...safeProps }, { theme, ...props })
48+
})
49+
InnerComponent.displayName = name
50+
return InnerComponent
51+
}
52+
53+
export function createComponent({
54+
name,
55+
render,
56+
theme: themeArg = {},
57+
propTypes,
58+
}) {
59+
const baseTheme = Array.isArray(themeArg) ? mergeClone(...themeArg) : themeArg
60+
const InnerComponent = createInnerComponent({
61+
name,
62+
render,
63+
theme: baseTheme,
64+
})
4865
const Component = styled(InnerComponent)`
4966
${p => {
50-
const cache = getThemeCache(p.theme)
51-
cache[name] = cache[name] || computeTheme(theme, p.theme)
52-
const props = { ...p, theme: cache[name] }
53-
const componentStyle = props.theme.components
54-
? props.theme.components[name]
55-
: null
67+
const theme = getTheme(name, baseTheme, p.theme)
68+
const props = { ...p, theme }
69+
const componentStyle = theme.components ? theme.components[name] : null
5670
return componentStyle ? componentStyle(props) : null
5771
}}
5872
`

website/package.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,20 @@
77
"serve": "gatsby serve"
88
},
99
"dependencies": {
10-
"@bundle-analyzer/gatsby-plugin": "^0.4.0",
11-
"@emotion/core": "^10.0.17",
12-
"@emotion/styled": "^10.0.17",
10+
"@bundle-analyzer/gatsby-plugin": "^0.5.1",
11+
"@emotion/core": "^10.0.22",
12+
"@emotion/styled": "^10.0.23",
1313
"@smooth-ui/core-sc": "^10.1.0",
1414
"emotion-theming": "^10.0.19",
15-
"gatsby": "^2.15.19",
16-
"gatsby-plugin-layout": "^1.1.8",
17-
"react": "^16.8.6",
18-
"react-dom": "^16.8.6",
19-
"reakit": "^1.0.0-beta.7",
15+
"gatsby": "^2.18.2",
16+
"gatsby-plugin-layout": "^1.1.15",
17+
"react": "^16.12.0",
18+
"react-dom": "^16.12.0",
19+
"reakit": "^1.0.0-beta.12",
2020
"smooth-code-landers": "^1.3.2",
21-
"smooth-doc": "^2.12.3",
21+
"smooth-doc": "^2.14.2",
2222
"smooth-ui-em-next": "npm:@smooth-ui/core-em@canary",
2323
"smooth-ui-sc-next": "npm:@smooth-ui/core-sc@canary",
24-
"styled-components": "^4.2.0"
24+
"styled-components": "^4.4.1"
2525
}
2626
}

0 commit comments

Comments
 (0)