diff --git a/demo/index.js b/demo/index.js index f7ab576..d3ca7b8 100644 --- a/demo/index.js +++ b/demo/index.js @@ -8,7 +8,7 @@ import style from './style.less' ReactDOM.render(( - +
props => ( - {theme => ( - + {({ emotion, ...theme }) => ( + )} ) diff --git a/src/OIO/index.js b/src/OIO/index.js index cee72ac..4ffc4c3 100644 --- a/src/OIO/index.js +++ b/src/OIO/index.js @@ -1,12 +1,9 @@ import React, { Component } from 'react' -import { injectGlobal } from 'emotion' +import createEmotion from 'create-emotion' import PropTypes from 'prop-types' import { OIOContext } from './context' import normalize from './normalize' -// Normalize -injectGlobal`${normalize}` // eslint-disable-line no-unused-expressions - export default class OIO extends Component { static propTypes = { children: PropTypes.node, @@ -14,6 +11,7 @@ export default class OIO extends Component { fontFamily: PropTypes.string, fontSize: PropTypes.string, fontWeights: PropTypes.object, + nonce: PropTypes.string, style: PropTypes.object, textSizeScaleRatio: PropTypes.number, textSizeMultiplier: PropTypes.number @@ -31,11 +29,24 @@ export default class OIO extends Component { semibold: '600', bold: '700' }, + nonce: undefined, style: {}, textSizeScaleRatio: 1.125, textSizeMultiplier: 1 } + constructor(props) { + super(props) + this.emotion = createEmotion({ + nonce: props.nonce + }) + + // eslint-disable-next-line no-unused-expressions + this.emotion.injectGlobal`${normalize}` + } + + emotion = null + render() { const { children, @@ -49,6 +60,7 @@ export default class OIO extends Component { } = this.props const contextProps = { + emotion: this.emotion, fontFamily, fontSize, fontWeights, diff --git a/src/Text/index.js b/src/Text/index.js index 45ba32e..46af6af 100644 --- a/src/Text/index.js +++ b/src/Text/index.js @@ -7,7 +7,6 @@ // ======================================================= import React, { Component } from 'react' -import { css, cx } from 'emotion' import PropTypes from 'prop-types' import { withOIOContext } from '../OIO/context' import generateStyleObject from '../utils/generateStyleObject' @@ -60,6 +59,8 @@ export default class Text extends Component { children: PropTypes.node, className: PropTypes.string, color: PropTypes.string, + // TODO: USE REAL EMOTION INSTANCE + emotion: PropTypes.object.isRequired, fontFamily: PropTypes.string, generatedStyleObject: PropTypes.object.isRequired, lineHeight: PropTypes.string, @@ -84,6 +85,7 @@ export default class Text extends Component { } render() { + const { css, cx } = this.props.emotion const styles = { ...this.props.style, ...this.props.generatedStyleObject