From ee1f96f952d04dec9e6afee4151f38206b99aea0 Mon Sep 17 00:00:00 2001 From: vikramsunilpatil Date: Tue, 13 Jun 2017 08:39:48 +0000 Subject: [PATCH 1/2] support for object as props to css-constructor --- api.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/api.js b/api.js index c462cfa..caa3cfc 100644 --- a/api.js +++ b/api.js @@ -59,11 +59,16 @@ let fillProps = (rawCSS, props) => { let matches = rawCSS.match(re); if (matches && matches.length) { for (let match of matches) { - let keyword = match; + let keyword = match, replaceWord, propKeys; keyword = keyword.replace('{this.props.', ''); keyword = keyword.substring(0, keyword.length-1); // remove } keyword = keyword.trim(); - rawCSS = rawCSS.replace(match, props[keyword]); + replaceWord = props; + propKeys = keyword.split('.'); + for (let i = 0; i < propKeys.length; i++) { + replaceWord = replaceWord[propKeys[i]]; + } + rawCSS = rawCSS.replace(match, replaceWord); } } return rawCSS; From 3ae40e1f168b031e330bb303deb55b507b7e4d30 Mon Sep 17 00:00:00 2001 From: vikramsunilpatil Date: Tue, 13 Jun 2017 09:25:17 +0000 Subject: [PATCH 2/2] example showing the passing of props to css-constructor --- example/entry.js | 6 +++++- example/hello.js | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/example/entry.js b/example/entry.js index 51aeb4d..82f5769 100644 --- a/example/entry.js +++ b/example/entry.js @@ -2,7 +2,11 @@ import React from 'react'; import ReactDOM from 'react-dom'; import Hello from './hello'; +let color = { + sampleColor: 'papayawhip' +} + ReactDOM.render( - , + , document.getElementById('container') ); diff --git a/example/hello.js b/example/hello.js index 30a39b1..36cb4b0 100644 --- a/example/hello.js +++ b/example/hello.js @@ -15,7 +15,7 @@ export default class Hello extends React.Component { text-align: center; /* Use props in your CSS */ - color: {this.props.color}; + color: {this.props.color.sampleColor}; /* Pseudo selectors */ &:hover {