简体   繁体   中英

How to use scss file with create-react-app?

I am using chartist.js for making chart component. I am importing scss file into my component but the scss styling does not work. Check the code below:

chart.js:

import React, { Component } from 'react';
import ChartistGraph from "react-chartist";
import Legend from "chartist-plugin-legend";

import './piechart.scss';

let options = {
  width:400,
  height:500,
  labelInterpolationFnc: function(value) {
    return value[0]
  },
  plugins: [
        Legend()
    ]
};


class Chart extends Component {

  render(){
    return(
      <div>
          <div className="center">
          <ChartistGraph data={data} options={options} type="Pie"/>
          </div>
      </div>

    )}

}

export default Chart;

piechart.scss:

.ct-legend {
    position: relative;
    z-index: 10;

    li {
        position: relative;
        padding-left: 23px;
        margin-bottom: 3px;
    }

    li:before {
        width: 12px;
        height: 12px;
        position: absolute;
        left: 0;
        content: '';
        border: 3px solid transparent;
        border-radius: 2px;
    }

    li.inactive:before {
        background: transparent;
    }

    &.ct-legend-inside {
        position: absolute;
        top: 0;
        right: 0;
    }

    @for $i from 0 to length($ct-series-colors) {
        .ct-series-#{$i}:before {
            background-color: nth($ct-series-colors, $i + 1);
            border-color: nth($ct-series-colors, $i + 1);
        }
    }
}

Please check the below screenshot, I am not getting the Legends as required like this -> https://codeyellowbv.github.io/chartist-plugin-legend/

在此处输入图片说明

sass/scss require pre-processing. You will have to eject your project and add the required processing, here are some examples:

https://medium.com/@Connorelsea/using-sass-with-create-react-app-7125d6913760

https://medium.com/front-end-hacking/how-to-add-sass-or-scss-to-create-react-app-c303dae4b5bc

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM