Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disallow functions as value of style prop in libs related to React Native #2014

Merged
merged 6 commits into from
Sep 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/green-zoos-greet.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@emotion/native': major
'@emotion/primitives': major
'@emotion/primitives-core': major
---

Updated `css-to-react-native` dependency to the 3.x version - it comes with some breaking changes listed [here](https://github.com/styled-components/css-to-react-native/releases/tag/v3.0.0).
7 changes: 7 additions & 0 deletions .changeset/selfish-pans-enjoy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@emotion/native': major
'@emotion/primitives': major
'@emotion/primitives-core': major
---

Functions are no longer accepted as values for the `style` prop. This unifies the behavior with the web version of Emotion as `style`'s equivalent is `className` prop and functions are not resolved for it.
8 changes: 1 addition & 7 deletions __mocks__/react-primitives.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,2 @@
// @flow
/* eslint-env jest */
module.exports = {
...jest.requireActual('react-primitives'),
View: 'View',
Image: 'Image',
Text: 'Text'
}
export * from 'react-primitives/lib/index.web'
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,9 @@
"react-helmet": "^5.2.0",
"react-icons": "^2.2.7",
"react-live": "1.10.0",
"react-native": "^0.61.5",
"react-native-web": "0.9.6",
"react-primitives": "^0.7.0",
"react-native": "^0.63.2",
"react-native-web": "0.13.12",
"react-primitives": "^0.8.1",
"react-router-dom": "^4.2.2",
"react-scripts": "1.1.5",
"react-test-renderer": "16.8.6",
Expand Down
2 changes: 1 addition & 1 deletion packages/native/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"@types/react-native": "^0.63.2",
"dtslint": "^0.3.0",
"react": "^16.11.0",
"react-native": "^0.61.5"
"react-native": "^0.63.2"
},
"dependencies": {
"@emotion/primitives-core": "11.0.0-next.17"
Expand Down
125 changes: 80 additions & 45 deletions packages/native/test/__snapshots__/native-styled.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ exports[`Emotion native styled primitive should work with \`withComponent\` 1`]
<Text
decor="hotpink"
style={
Object {
"color": "hotpink",
}
Array [
Object {
"color": "hotpink",
},
undefined,
]
}
>
Mike
Expand All @@ -17,9 +20,12 @@ exports[`Emotion native styled should pass props in withComponent 1`] = `
<View
color="green"
style={
Object {
"backgroundColor": "green",
}
Array [
Object {
"backgroundColor": "green",
},
undefined,
]
}
/>
`;
Expand All @@ -28,9 +34,12 @@ exports[`Emotion native styled should pass props in withComponent 2`] = `
<Text
color="hotpink"
style={
Object {
"backgroundColor": "hotpink",
}
Array [
Object {
"backgroundColor": "hotpink",
},
undefined,
]
}
/>
`;
Expand All @@ -45,23 +54,30 @@ exports[`Emotion native styled should render <Image /> 1`] = `
}
}
style={
Object {
"borderBottomLeftRadius": 2,
"borderBottomRightRadius": 2,
"borderTopLeftRadius": 2,
"borderTopRightRadius": 2,
}
Array [
Object {
"borderBottomLeftRadius": 2,
"borderBottomRightRadius": 2,
"borderTopLeftRadius": 2,
"borderTopRightRadius": 2,
},
undefined,
]
}
/>
`;

exports[`Emotion native styled should render primitive with style prop 1`] = `
<Text
style={
Object {
"color": "hotpink",
"padding": 10,
}
Array [
Object {
"color": "hotpink",
},
Object {
"padding": 10,
},
]
}
>
Emotion primitives
Expand All @@ -72,10 +88,13 @@ exports[`Emotion native styled should render styles correctly from all nested st
<Text
backgroundColor="blue"
style={
Object {
"backgroundColor": "blue",
"color": "hotpink",
}
Array [
Object {
"backgroundColor": "blue",
"color": "hotpink",
},
undefined,
]
}
>
Hello World
Expand All @@ -86,13 +105,16 @@ exports[`Emotion native styled should render the primitive on changing the props
<Text
decor="hotpink"
style={
Object {
"color": "hotpink",
"paddingBottom": 20,
"paddingLeft": 20,
"paddingRight": 20,
"paddingTop": 20,
}
Array [
Object {
"color": "hotpink",
"paddingBottom": 20,
"paddingLeft": 20,
"paddingRight": 20,
"paddingTop": 20,
},
undefined,
]
}
>
Emotion Primitives
Expand All @@ -103,11 +125,16 @@ exports[`Emotion native styled should render the primitive when styles applied u
<Text
back="red"
style={
Object {
"backgroundColor": "red",
"color": "red",
"fontSize": 40,
}
Array [
Object {
"backgroundColor": "red",
"color": "red",
"fontSize": 20,
},
Object {
"fontSize": 40,
},
]
}
>
Emotion Primitives
Expand All @@ -117,9 +144,12 @@ exports[`Emotion native styled should render the primitive when styles applied u
exports[`Emotion native styled should style any other component 1`] = `
<Text
style={
Object {
"color": "hotpink",
}
Array [
Object {
"color": "hotpink",
},
undefined,
]
}
>
Hello World
Expand All @@ -129,10 +159,12 @@ exports[`Emotion native styled should style any other component 1`] = `
exports[`Emotion native styled should work with StyleSheet.create API 1`] = `
<Text
style={
Object {
"color": "red",
"fontSize": 10,
}
Array [
Object {
"fontSize": 10,
},
74,
]
}
>
Emotion primitives
Expand All @@ -142,9 +174,12 @@ exports[`Emotion native styled should work with StyleSheet.create API 1`] = `
exports[`Emotion native styled should work with theming from @emotion/react 1`] = `
<Text
style={
Object {
"color": "magenta",
}
Array [
Object {
"color": "magenta",
},
undefined,
]
}
>
Hello World
Expand Down
2 changes: 1 addition & 1 deletion packages/primitives-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
],
"license": "MIT",
"dependencies": {
"css-to-react-native": "^2.2.1"
"css-to-react-native": "^3.0.0"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be a changeset for this, no?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

},
"peerDependencies": {
"@emotion/react": "^11.0.0-next.17",
Expand Down
8 changes: 1 addition & 7 deletions packages/primitives-core/src/styled.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,6 @@ export function createStyled(
mergedProps.theme = React.useContext(ThemeContext)
}

let stylesWithStyleProp = styles
if (props.style) {
stylesWithStyleProp = styles.concat(props.style)
}
const emotionStyles = css.apply(mergedProps, stylesWithStyleProp)

let newProps = {}

for (let key in props) {
Expand All @@ -66,7 +60,7 @@ export function createStyled(
}
}

newProps.style = emotionStyles
newProps.style = [css.apply(mergedProps, styles), props.style]
newProps.ref = ref

// $FlowFixMe
Expand Down
4 changes: 2 additions & 2 deletions packages/primitives/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"peerDependencies": {
"@babel/core": "^7.0.0",
"react": ">=16.8.0",
"react-primitives": "^0.7.0"
"react-primitives": "^0.8.1"
},
"peerDependenciesMeta": {
"@babel/core": {
Expand All @@ -31,7 +31,7 @@
"enzyme": "^3.7.0",
"enzyme-adapter-react-16": "^1.6.0",
"react": "^16.11.0",
"react-primitives": "^0.7.0"
"react-primitives": "^0.8.1"
},
"homepage": "https://emotion.sh",
"license": "MIT",
Expand Down
Loading