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

A Sass to JavaScript and React compiler

trafficstars

  $ npm install --global styled-scss

styled-scss compiles Sass with dynamic variables to a styled-components runtime


Take your Sass file

// page.scss

$bgColor: black;

@styled.button SpecialButton($primary: bool, $color: string) {
  display: inline-block;
  background: $bgColor;
  border-color: $color;

  @if $primary {
    background-color: $color;
    border-color: $bgColor;
  }
}

Run styled-scss on it

$ styled page.scss

Get styled-components

// pageStyles.js

import styled from "styled-components";
export const SpecialButton = styled.button`
  display: inline-block;
  background: black;
  border-color: ${props => props.color};
  ${({ color, primary }) =>
    primary &&
    css`
      background-color: ${color};
      border-color: black;
    `};
`;

Docs

Type generation

styled-scss can also generate type interfaces to go along with the code! Right now it can only do Reason, but TypeScript and Flow should be supported soon

$ styled page.scss --types reason

I don't like styled-components though!

styled-scss can also output to an Emotion runtime! Just pass the --runtime flag to the CLI

$ styled page.scss --runtime emotion