cristian valdivia
cristian valdivia

Reputation: 43

How to add linear-gradient color to Slider?

I want to add linear-gradient to Material-UI Slider as color. Is it possible? I try everything.

color: 'linear-gradient(180deg, #29ABE2 0%, #00EAA6 100%)'

Upvotes: 4

Views: 7079

Answers (1)

Ryan Cogswell
Ryan Cogswell

Reputation: 81016

linear-gradient creates an image not a color. So you need to use it in CSS that specifies an image (e.g. background-image).

Below is an example of a Slider using a gradient.

import React from "react";
import { makeStyles, withStyles } from "@material-ui/core/styles";
import Slider from "@material-ui/core/Slider";

const useStyles = makeStyles({
  root: {
    width: 200
  }
});

const CustomSlider = withStyles({
  rail: {
    backgroundImage: "linear-gradient(.25turn, #f00, #00f)"
  },
  track: {
    backgroundImage: "linear-gradient(.25turn, #f00, #00f)"
  }
})(Slider);

export default function ContinuousSlider() {
  const classes = useStyles();
  const [value, setValue] = React.useState(30);

  const handleChange = (event, newValue) => {
    setValue(newValue);
  };

  return (
    <div className={classes.root}>
      <CustomSlider
        value={value}
        onChange={handleChange}
        aria-labelledby="continuous-slider"
      />
    </div>
  );
}

Edit Gradient Slider

Upvotes: 7

Related Questions