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

Make the theme prop always exist #364

Merged
merged 1 commit into from
Oct 1, 2017
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
9 changes: 3 additions & 6 deletions packages/react-emotion/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,9 @@ const createStyled = (tag, options: { e: string }) => {
class Styled extends Component {
render() {
const { props, state } = this
this.mergedProps = props
if (state !== null && state.theme) {
this.mergedProps = omitAssign(testAlwaysTrue, {}, props, {
theme: state.theme || {}
})
}
this.mergedProps = omitAssign(testAlwaysTrue, {}, props, {
theme: (state !== null && state.theme) || props.theme || {}
})

let className = ''
let classInterpolations = []
Expand Down
22 changes: 22 additions & 0 deletions packages/react-emotion/test/__snapshots__/index.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,28 @@ exports[`styled random object expression 1`] = `
</h1>
`;

exports[`styled theme prop exists without ThemeProvider 1`] = `
.glamor-0 {
color: green;
background-color: yellow;
}

<div
className="glamor-0"
/>
`;

exports[`styled theme prop exists without ThemeProvider with a theme prop on the component 1`] = `
.glamor-0 {
color: hotpink;
background-color: yellow;
}

<div
className="glamor-0"
/>
`;

exports[`styled themes 1`] = `
.glamor-0 {
background-color: #ffd43b;
Expand Down
18 changes: 18 additions & 0 deletions packages/react-emotion/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -682,4 +682,22 @@ describe('styled', () => {
const tree = renderer.create(<SomeComponent color="hotpink" />).toJSON()
expect(tree).toMatchSnapshot()
})
test('theme prop exists without ThemeProvider', () => {
const SomeComponent = styled.div`
color: ${props => props.theme.color || 'green'};
background-color: yellow;
`
const tree = renderer.create(<SomeComponent />).toJSON()
expect(tree).toMatchSnapshot()
})
test('theme prop exists without ThemeProvider with a theme prop on the component', () => {
const SomeComponent = styled.div`
color: ${props => props.theme.color || 'green'};
background-color: yellow;
`
const tree = renderer
.create(<SomeComponent theme={{ color: 'hotpink' }} />)
.toJSON()
expect(tree).toMatchSnapshot()
})
})