Commit eee779cf authored by Jure's avatar Jure

Merge branch 'theme-provider' into 'master'

Add ThemeProvider to Root

Closes #53

See merge request !119
parents e26f8b32 8a7b231a
Pipeline #2875 passed with stage
in 1 minute and 42 seconds
......@@ -2,22 +2,21 @@ import React from 'react'
import { ConnectedRouter } from 'react-router-redux'
import { Provider } from 'react-redux'
import PropTypes from 'prop-types'
import { ThemeProvider } from 'react-css-themr'
export default class Root extends React.Component {
render() {
const { store, history, routes } = this.props
return (
<Provider store={store}>
<div>
<ConnectedRouter history={history}>{routes}</ConnectedRouter>
</div>
</Provider>
)
}
}
const Root = ({ store, history, routes, theme }) => (
<Provider store={store}>
<ConnectedRouter history={history}>
<ThemeProvider theme={theme}>{routes}</ThemeProvider>
</ConnectedRouter>
</Provider>
)
Root.propTypes = {
routes: PropTypes.node.isRequired,
history: PropTypes.object.isRequired,
store: PropTypes.object.isRequired,
theme: PropTypes.object.isRequired,
}
export default Root
import React from 'react'
import { shallow } from 'enzyme'
import { themr } from 'react-css-themr'
import createHistory from 'history/createBrowserHistory'
global.PUBSWEET_COMPONENTS = []
const Root = require('../../src/components/Root').default
const configureStore = require('../../src/store/configureStore')
const history = createHistory()
const store = configureStore(history, {})
const theme = { ThemedComponent: {testClass: 'mappedClassName'} }
const ThemedComponent = themr('ThemedComponent')(({ theme }) => (
<div className={theme.testClass}></div>
))
function makeWrapper(props = {}) {
return shallow(
<Root
store={store}
history={history}
routes={<ThemedComponent />}
theme={theme}
{...props}
/>
)
}
describe('<Root/>', () => {
it('Adds a theme to context', async () => {
const wrapper = makeWrapper({ theme })
expect(wrapper.html()).toBe('<div class="mappedClassName"></div>')
})
})
......@@ -2100,6 +2100,10 @@ hoek@4.x.x:
version "4.2.0"
resolved "https://registry.yarnpkg.com/hoek/-/hoek-4.2.0.tgz#72d9d0754f7fe25ca2d01ad8f8f9a9449a89526d"
hoist-non-react-statics@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/hoist-non-react-statics/-/hoist-non-react-statics-1.2.0.tgz#aa448cf0986d55cc40773b17174b7dd066cb7cfb"
hoist-non-react-statics@^2.2.1, hoist-non-react-statics@^2.3.0, hoist-non-react-statics@^2.3.1:
version "2.3.1"
resolved "https://registry.yarnpkg.com/hoist-non-react-statics/-/hoist-non-react-statics-2.3.1.tgz#343db84c6018c650778898240135a1420ee22ce0"
......@@ -3614,6 +3618,13 @@ react-bootstrap@^0.31.3:
uncontrollable "^4.1.0"
warning "^3.0.0"
react-css-themr@^2.1.2:
version "2.1.2"
resolved "https://registry.yarnpkg.com/react-css-themr/-/react-css-themr-2.1.2.tgz#e017514e471c232f43a754a55b49d81faf5dafb8"
dependencies:
hoist-non-react-statics "^1.2.0"
invariant "^2.2.1"
react-dom@^15.6.1:
version "15.6.2"
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-15.6.2.tgz#41cfadf693b757faf2708443a1d1fd5a02bef730"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment