content logo

React Progress Bars:

React Gradient Progress Bar Settings with Input Fields

In this post, you can see a different code to change your website's design. This is the React Gradient Progress Bar Settings with Input Fields. If you want to add a different code to your website and show your viewer’s opinion, this Progress Bar with React can be a great idea. Many people use these kinds of codes to attract more viewers. With the help of this Gradient Progress Bar Code, you can ask your users to fill out the form and rank your progression. This allows you to be aware of others' opinions about your website, and improve it.

At the bottom of this page, you can see this Progress Bar Settings Code preview that shows its performance. This form has a white background, and it is totally simple. There are two fields above this code with white background and a gray border. The first field is designed for progress, and the second line is used for goals. When your viewers enter a specific number in each field, their opinion will be represented with a colorful line at the bottom of the page. This Free Responsive Progress Bar shows the idea of your viewers about your website.

#

Progress Bar with React

#

Gradient Progress Bar Code

#

Progress Bar Settings Code

#

Free Responsive Progress Bar

<!-- This script got from frontendfreecode.com -->
<div id="app"></div><a style="font-size: 8pt; text-decoration: none" target="_blank" href="http://frontendfreecode.com">Free Frontend</a>
                                                                            
.block {
  display: block;
}
.mbq {
  margin-bottom: 0.25rem;
}
.mb1 {
  margin-bottom: 1rem;
}
.progress-container {
  background: #ccc;
  height: 10px;
  width: 99%;
  margin-left: auto;
  margin-right: auto;
  display: block;
  border-radius: 10px;
  position: fixed;
  bottom: 2%;
  left: 50%;
  transform: translateX(-50%);
}
.progress-bar {
  position: absolute;
  left: 0;
  height: 10px;
  border-radius: 10px;
  background-color: #0da1d4;
  background-image: linear-gradient(90deg, #0da1d4 0%, #1dd07e 100%);
  display: block;
  transition: width 0.3s ease-in;
}
class ProgressContainer extends React.Component {
  constructor() {
    super();
    const progressInit = 2;
    const goalInit = 5;
    this.state = {
      progress: progressInit,
      validProgress: progressInit,
      goal: goalInit,
      validGoal: goalInit };
    this.changeProgress = this.changeProgress.bind(this);
    this.changeGoal = this.changeGoal.bind(this);
  }
  changeProgress(event) {
    if (event.target.value) {
      this.setState({ progress: event.target.value });
      this.setState({ validProgress: event.target.value });
    } else {
      this.setState({ progress: event.target.value });
    }
  }
  changeGoal(event) {
    if (event.target.value) {
      this.setState({ goal: event.target.value });
      this.setState({ validGoal: event.target.value });
    } else {
      this.setState({ goal: event.target.value });
    }
  }
  render() {
    return /*#__PURE__*/(
      React.createElement("div", null, /*#__PURE__*/
      React.createElement("label", { className: "block mbq" }, "Progress"), /*#__PURE__*/
      React.createElement("input", { type: "text", className: "mb1", value: this.state.progress, onChange: this.changeProgress }), /*#__PURE__*/
      React.createElement("label", { className: "block mbq" }, "Goal"), /*#__PURE__*/
      React.createElement("input", { type: "text", value: this.state.goal, onChange: this.changeGoal }), /*#__PURE__*/
      React.createElement("div", { className: "progress-container" }, /*#__PURE__*/
      React.createElement(ProgressBar, {
        progress: this.state.validProgress,
        goal: this.state.validGoal }))));
  }}
class ProgressBar extends React.Component {
  calculateProgress(progress, goal) {
    if (Number(progress) === 0) {
      return 0.75 + "%";
    }
    if (Number(goal) >= Number(progress)) {
      return progress / goal * 100 + "%";
    } else {
      return 100 + "%";
    }
  }
  render() {
    const { progress, goal } = this.props;
    return /*#__PURE__*/(
      React.createElement("div", {
        className: "progress-bar",
        style: { width: this.calculateProgress(progress, goal) } }));
  }}
ReactDOM.render( /*#__PURE__*/
React.createElement(ProgressContainer, null),
document.getElementById("app"));
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css">
<script crossorigin src="https://unpkg.com/react@18/umd/react.production.min.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@18/umd/react-dom.production.min.js"></script>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<!-- This script got from frontendfreecode.com -->

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css">
<script crossorigin src="https://unpkg.com/react@18/umd/react.production.min.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@18/umd/react-dom.production.min.js"></script>
<style>
.block {
  display: block;
}
.mbq {
  margin-bottom: 0.25rem;
}
.mb1 {
  margin-bottom: 1rem;
}
.progress-container {
  background: #ccc;
  height: 10px;
  width: 99%;
  margin-left: auto;
  margin-right: auto;
  display: block;
  border-radius: 10px;
  position: fixed;
  bottom: 2%;
  left: 50%;
  transform: translateX(-50%);
}
.progress-bar {
  position: absolute;
  left: 0;
  height: 10px;
  border-radius: 10px;
  background-color: #0da1d4;
  background-image: linear-gradient(90deg, #0da1d4 0%, #1dd07e 100%);
  display: block;
  transition: width 0.3s ease-in;
}
</style>

</head>
<body>
<div id="app"></div><div id="bcl"><a style="font-size:8pt;text-decoration:none;" href="http://www.devanswer.com">Free Frontend</a></div>
<script>
class ProgressContainer extends React.Component {
  constructor() {
    super();
    const progressInit = 2;
    const goalInit = 5;
    this.state = {
      progress: progressInit,
      validProgress: progressInit,
      goal: goalInit,
      validGoal: goalInit };
    this.changeProgress = this.changeProgress.bind(this);
    this.changeGoal = this.changeGoal.bind(this);
  }
  changeProgress(event) {
    if (event.target.value) {
      this.setState({ progress: event.target.value });
      this.setState({ validProgress: event.target.value });
    } else {
      this.setState({ progress: event.target.value });
    }
  }
  changeGoal(event) {
    if (event.target.value) {
      this.setState({ goal: event.target.value });
      this.setState({ validGoal: event.target.value });
    } else {
      this.setState({ goal: event.target.value });
    }
  }
  render() {
    return /*#__PURE__*/(
      React.createElement("div", null, /*#__PURE__*/
      React.createElement("label", { className: "block mbq" }, "Progress"), /*#__PURE__*/
      React.createElement("input", { type: "text", className: "mb1", value: this.state.progress, onChange: this.changeProgress }), /*#__PURE__*/
      React.createElement("label", { className: "block mbq" }, "Goal"), /*#__PURE__*/
      React.createElement("input", { type: "text", value: this.state.goal, onChange: this.changeGoal }), /*#__PURE__*/
      React.createElement("div", { className: "progress-container" }, /*#__PURE__*/
      React.createElement(ProgressBar, {
        progress: this.state.validProgress,
        goal: this.state.validGoal }))));
  }}
class ProgressBar extends React.Component {
  calculateProgress(progress, goal) {
    if (Number(progress) === 0) {
      return 0.75 + "%";
    }
    if (Number(goal) >= Number(progress)) {
      return progress / goal * 100 + "%";
    } else {
      return 100 + "%";
    }
  }
  render() {
    const { progress, goal } = this.props;
    return /*#__PURE__*/(
      React.createElement("div", {
        className: "progress-bar",
        style: { width: this.calculateProgress(progress, goal) } }));
  }}
ReactDOM.render( /*#__PURE__*/
React.createElement(ProgressContainer, null),
document.getElementById("app"));
</script>

</body>
</html>
Preview