Skip to content

Support for object as props to css-constructor #4

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

Merged
merged 2 commits into from
Jun 13, 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: 7 additions & 2 deletions api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 5 additions & 1 deletion example/entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import React from 'react';
import ReactDOM from 'react-dom';
import Hello from './hello';

let color = {
sampleColor: 'papayawhip'
}

ReactDOM.render(
<Hello color='papayawhip'/>,
<Hello color={color} />,
document.getElementById('container')
);
2 changes: 1 addition & 1 deletion example/hello.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down