styled-jsx icon indicating copy to clipboard operation
styled-jsx copied to clipboard

Using SASS styles inside <style jsx>

Open vladejs opened this issue 9 years ago • 13 comments

Is that possible? I am used to SASS and want to use it in my next app. Currently, I have this code:

p {
    color: red;
}

p.span {
  color: blue;
}

And I wanna make it like this:

p {
    color: red;

    &.span {
      color: blue;
    }
}

If I do that, it doesn't throws errors, but the indented style gets ignored.

vladejs avatar May 22 '17 15:05 vladejs

Not yet but it might be very soon thanks to #190

giuseppeg avatar May 22 '17 15:05 giuseppeg

Currently, if I import a SASS file I get it compiled thanxs to webpack, but I don't know if I can do this:

import React from 'react'
import buttonStyles from './button.scss'

export default props => (<div>
  <p>
    Hello Sr
  </p>
  <style jsx>
    {`${buttonStyles}`}
  </style>
</div>)

vladejs avatar May 22 '17 15:05 vladejs

you can but they won't be scoped

giuseppeg avatar May 22 '17 15:05 giuseppeg

So there's no way to make it scoped?

vladejs avatar May 22 '17 16:05 vladejs

no yet, but with Plugins it will be possible and very easy.

giuseppeg avatar May 22 '17 16:05 giuseppeg

thanks, but how long do I need to wait in order to use plugins?

2017-05-22 12:49 GMT-04:00 Giuseppe [email protected]:

no yet, but with Plugins it will be possible and very easy.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/zeit/styled-jsx/issues/205#issuecomment-303156642, or mute the thread https://github.com/notifications/unsubscribe-auth/AMDUAgbNP75xbX2ztTVUhvbJurQTV19_ks5r8byAgaJpZM4Nif3V .

vladejs avatar May 22 '17 16:05 vladejs

@vladejs I already have a Pull Request ready but we won't include it in the next release yet. So my guess is that probably in a couple of weeks we will be able to release a version that introduces plugins.

giuseppeg avatar May 22 '17 17:05 giuseppeg

This would be an awesome addition. Any news on this?

pexxi avatar Jul 12 '17 06:07 pexxi

@pexxi we might have to postpone this feature to when dynamic styles support is implemented (#81).

giuseppeg avatar Jul 12 '17 07:07 giuseppeg

Hello, not sure this is the right place for this question. I am using styled jsx with the sass plugin. Works well but I have encountered a small issue trying to use js variable inside the style. It seems that simple variable use works for simple values, but not when used in more complex case like parameter of a mixin. Below is a small example of what I am trying to do. The color is applied correctly but the media query will not work as expected (always evaluates to true). ` const bp = 'medium' const col = 'yellow'

    <style jsx>{`
      @import 'styles/css/foundation.scss';
      .layout{
        width: 100%;
        @include breakpoint($bp) {
          max-width: 80%;
          background-color: ${col};
        }
      }
      `}</style>

`

I have seen this in the readme

Plugins won't transform expressions

If I understand correctly, what I want to do is currently not supported right? Is there any plan to support this in the future? And if I wanted to help support this, where should I look? By the way, thanks for the great work.

fredsh avatar Feb 21 '18 20:02 fredsh

@fredsh I'm testing the same styled-jsx plugin and I can't get the imported .scss files to hot-reload or even reload with a page refresh. Have you achieve that??

cristianzamar avatar Mar 16 '18 15:03 cristianzamar

Any update on this?

Or atleast using postcss plugins for css nesting and container-query?

With javascript functions and variables, we don't really need css vars (and the ugly syntax) or mixins but nesting and container query support would be very nice.

HansUXdev avatar May 22 '19 04:05 HansUXdev

Hello, not sure this is the right place for this question. I am using styled jsx with the sass plugin. Works well but I have encountered a small issue trying to use js variable inside the style. It seems that simple variable use works for simple values, but not when used in more complex case like parameter of a mixin. Below is a small example of what I am trying to do. The color is applied correctly but the media query will not work as expected (always evaluates to true).

 <style jsx>{`
   @import 'styles/css/foundation.scss';
   .layout{
     width: 100%;
     @include breakpoint($bp) { // 👈🤏👀 `$${bp}`?
       max-width: 80%;
       background-color: ${col};
     }
   }
   `}</style>

This is a non-issue. Javascript vars are 👍, and only suffer the same dynamic limitations as styled-jsx itself (build time execution, not run time).

adam-zhu avatar May 22 '20 07:05 adam-zhu