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

feature request: support template literal #22

Open
Pyrolistical opened this issue Oct 23, 2016 · 4 comments
Open

feature request: support template literal #22

Pyrolistical opened this issue Oct 23, 2016 · 4 comments

Comments

@Pyrolistical
Copy link

Pyrolistical commented Oct 23, 2016

I love inline-css, but I don't like the mental gymnastics I need to do to convert css into a js object.

Could we add template literal support to allow us to write more vanilla css?

for example we could convert this:

const styles =  cssInJs({
  myButton: {
    border: 'solid 1px #ccc',
    backgroundColor: 'lightgray',

    ':hover': {
      borderColor: '#ddd',

      ':active': {
        borderColor: '#eee'
      }
    },

    '[disabled]': {
      opacity: .5,
    }
  },

  '@media only screen and (max-width: 480px)': {
    myButton: {
      borderWidth: 0
    }
  }
})

to

const styles =  cssInJs(`
  .myButton {
    border: solid 1px #ccc
    background-color: lightgray

    &:hover {
      border-color: #ddd

      &:active {
        border-color: #eee
      }
    }

    &[disabled] {
      opacity: .5
    }

    @media only screen and (max-width: 480px) {
      border-width: 0
    }
  }
`)

the output would be the same

const styles = {
  myButton: 'example_js_styles_button'
}
@Pyrolistical Pyrolistical changed the title cssInJs template literal tag instead of function? feature request: cssInJs template literal tag instead of function Oct 23, 2016
@adamseckel
Copy link

👍

@Pyrolistical Pyrolistical changed the title feature request: cssInJs template literal tag instead of function feature request: cssInJs string literal Oct 24, 2016
@Pyrolistical
Copy link
Author

babel does some silly things with tagged template literals, going to simplify and try to just add support for string literal instead

Pyrolistical added a commit to Pyrolistical/babel-plugin-css-in-js that referenced this issue Oct 24, 2016
@Pyrolistical
Copy link
Author

Pyrolistical commented Oct 24, 2016

added proof of concept with passing unit test:
https://github.com/Pyrolistical/babel-plugin-css-in-js/tree/string-literal-poc

  it('works with template literal as argument', () => {
    const css = testTransformed({
      from: 'var styles = cssInJS(`.foo { margin-top: -10px }`);',
      to:   'var styles = { foo: "test-styles-foo" };'
    });

    testStyleRule(css, 'test-styles-foo', 'margin-top: -10');
  });

@Pyrolistical Pyrolistical changed the title feature request: cssInJs string literal feature request: support template literal Oct 24, 2016
@martinandert
Copy link
Owner

Hi @Pyrolistical, nice work! Could you please provide a proper PR that I can merge? Also please add a few lines to the README explaining the new feature. Thanks!

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

No branches or pull requests

3 participants