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

Helper method for getting true string class names #62

Open
rtsao opened this issue Sep 30, 2016 · 1 comment
Open

Helper method for getting true string class names #62

rtsao opened this issue Sep 30, 2016 · 1 comment
Projects

Comments

@rtsao
Copy link
Owner

rtsao commented Sep 30, 2016

The .toString() technique employed by csjs can be problematic when used in conjunction with React.PropTypes.string.

Rather than requiring string coercion on behalf of the user, a helper method to return an object of true strings may be convenient.

Context: #56

@scott113341
Copy link
Collaborator

How about something like this?

const assert = require('assert');
const csjs = require('csjs');

const styles = csjs`
  .yolo { color: red; }
  .swag { color: blue; }
`.classNames();

assert(styles.yolo === 'yolo_1VebKB');
assert(styles.swag === 'swag_1VebKB');

assert(typeof styles.yolo === 'string');
assert(typeof styles.swag === 'string');

This would come with the disadvantage that all of the Composition information is lost in the case of extends:

const assert = require('assert');
const csjs = require('csjs');

const styles1 = csjs`
  .yolo { color: red; }
`.classNames();

const styles2 = csjs`
  .beans extends ${styles1.yolo} { border: 0; }
`;

// .beans doesn't extend from .yolo
assert(styles2.beans.classNames.length === 1);
assert(styles2.beans.classNames[0]=== 'beans_gdwuK');

This could potentially be remedied by checking if string arguments to the csjs template literal match up with existing scoped classes. However, this is hacky and would probably require namespacing on scoped class names, ie beans_gdwuK becomes __csjs__beans_gdwuK.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
csjs
Investigation
Development

No branches or pull requests

2 participants