content logo

React Buttons:

Generate Buttons using React JS

In this post, we have a button in the middle of the page. Clicking this button will create a delay button. Clicking again will create a new button. All of these buttons are in a row with equal distances. The buttons also have an effect when the mouse is placed on each. The style of the buttons is similar and they were made by React.

#

New Button Creation Code

#

HTML React Button Generation

#

Add Button Element using React

#

Generate Button Javascript Code

<!-- This script got from frontendfreecode.com -->
<div id="root"></div><a style="font-size: 8pt; text-decoration: none" target="_blank" href="http://frontendfreecode.com">Free Frontend</a>
                                                                            
.button {
  padding: 10px 15px;
  border: 2px solid #333;
  color: #000;
  display: inline-block;
  border-radius: 5px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transform: scale(1);
  box-shadow: 0px 3px 10px 3px rgba(0, 0, 0, 0.3);
  outline: none;
  transition: 0.5s;
}
.button:before {
  content: "";
  position: absolute;
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, white 0%, white 49%, rgba(183, 222, 237, 0.8) 50%, rgba(183, 222, 237, 0.8) 50%);
  background-size: 300%;
  background-position: 0% 0%;
  transition: 0.5s;
  top: 0;
  left: 0;
  z-index: -1;
}
.button:after {
  content: "";
  position: absolute;
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, rgba(183, 222, 237, 0.8) 0%, rgba(183, 222, 237, 0.8) 49%, white 50%, white 500%);
  background-size: 300%;
  background-position: 95% 95%;
  transition: 0.5s;
  top: 0;
  left: 0;
  z-index: -1;
}
.button:hover {
  background-position: 95% 95%;
  color: #fff;
  transform: scale(1.05);
  -webkit-transition: 0.5s cubic-bezier(0, 1, 0.99, 1);
  box-shadow: 0px 5px 10px 3px rgba(0, 0, 0, 0.2);
  transition: 0.5s cubic-bezier(0, 1, 0.99, 1);
}
.button:hover:before {
  background-position: 95% 95%;
  transition: 0.5s;
}
.button:hover:after {
  background-position: 0% 0%;
  transition: 0.15s;
}
.button:active {
  transform: scale(0.95);
  box-shadow: 0px 1px 5px 1px rgba(0, 0, 0, 0.5);
}
.button:disabled {
  cursor: not-allowed;
  filter: brightness(80%);
  opacity: 0.5;
}
.button:disabled:hover {
  background-position: 0% 0%;
  color: #000;
  transform: scale(1);
  transition: 0.5s cubic-bezier(0, 1, 0.99, 1);
}
.button:disabled:hover:before {
  background-position: 0% 0%;
  transition: 0.5s;
}
.button:disabled:hover:after {
  background-position: 95% 95%;
  transition: 0.15s;
}
.button:disabled:active {
  transform: scale(1);
  box-shadow: 0px 1px 5px 1px rgba(0, 0, 0, 0.5);
}
function _defineProperty(obj, key, value) {if (key in obj) {Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true });} else {obj[key] = value;}return obj;}var Button = function (props) {
  var disabled = props.disabled ? props.disabled : false;
  return /*#__PURE__*/(
    React.createElement("div", { className: "button-container" }, /*#__PURE__*/
    React.createElement("button", {
      className: "button",
      onClick: props.onBtnClick,
      disabled: disabled },
    props.text)));
};
class HomePage extends React.Component {
  constructor(props) {
    super(props);_defineProperty(this, "handleBtnClick",
    () => {
      this.setState(function (prevState) {
        let disabled = false;
        let text = 'Replicate!';
        if (Math.random() < .3) {
          disabled = true;
          text = 'Nah...';
        }
        let btn = /*#__PURE__*/React.createElement(Button, { onBtnClick: this.handleBtnClick, disabled: disabled, text: text });
        prevState.buttons.push(btn);
        return prevState;
      });
    });this.state = { buttons: [/*#__PURE__*/React.createElement(Button, { onBtnClick: this.handleBtnClick, disabled: false, text: "Replicate!" })] };this.styles = { display: 'flex', flexWrap: 'wrap', minHeight: '100vh', justifyContent: 'space-around', alignItems: 'center', background: '#047DBF' };}
  render() {
    return /*#__PURE__*/(
      React.createElement("div", { style: this.styles },
      this.state.buttons));
  }}
ReactDOM.render( /*#__PURE__*/
React.createElement(HomePage, null),
document.querySelector('#root'));
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css">
<script src='https://cdnjs.cloudflare.com/ajax/libs/react/15.6.1/react.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/react/15.6.1/react-dom.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 src='https://cdnjs.cloudflare.com/ajax/libs/react/15.6.1/react.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/react/15.6.1/react-dom.min.js'></script>
<style>
.button {
  padding: 10px 15px;
  border: 2px solid #333;
  color: #000;
  display: inline-block;
  border-radius: 5px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transform: scale(1);
  box-shadow: 0px 3px 10px 3px rgba(0, 0, 0, 0.3);
  outline: none;
  transition: 0.5s;
}
.button:before {
  content: "";
  position: absolute;
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, white 0%, white 49%, rgba(183, 222, 237, 0.8) 50%, rgba(183, 222, 237, 0.8) 50%);
  background-size: 300%;
  background-position: 0% 0%;
  transition: 0.5s;
  top: 0;
  left: 0;
  z-index: -1;
}
.button:after {
  content: "";
  position: absolute;
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, rgba(183, 222, 237, 0.8) 0%, rgba(183, 222, 237, 0.8) 49%, white 50%, white 500%);
  background-size: 300%;
  background-position: 95% 95%;
  transition: 0.5s;
  top: 0;
  left: 0;
  z-index: -1;
}
.button:hover {
  background-position: 95% 95%;
  color: #fff;
  transform: scale(1.05);
  -webkit-transition: 0.5s cubic-bezier(0, 1, 0.99, 1);
  box-shadow: 0px 5px 10px 3px rgba(0, 0, 0, 0.2);
  transition: 0.5s cubic-bezier(0, 1, 0.99, 1);
}
.button:hover:before {
  background-position: 95% 95%;
  transition: 0.5s;
}
.button:hover:after {
  background-position: 0% 0%;
  transition: 0.15s;
}
.button:active {
  transform: scale(0.95);
  box-shadow: 0px 1px 5px 1px rgba(0, 0, 0, 0.5);
}
.button:disabled {
  cursor: not-allowed;
  filter: brightness(80%);
  opacity: 0.5;
}
.button:disabled:hover {
  background-position: 0% 0%;
  color: #000;
  transform: scale(1);
  transition: 0.5s cubic-bezier(0, 1, 0.99, 1);
}
.button:disabled:hover:before {
  background-position: 0% 0%;
  transition: 0.5s;
}
.button:disabled:hover:after {
  background-position: 95% 95%;
  transition: 0.15s;
}
.button:disabled:active {
  transform: scale(1);
  box-shadow: 0px 1px 5px 1px rgba(0, 0, 0, 0.5);
}
</style>

</head>
<body>
<div id="root"></div><div id="bcl"><a style="font-size:8pt;text-decoration:none;" href="http://www.devanswer.com">Free Frontend</a></div>
<script>
function _defineProperty(obj, key, value) {if (key in obj) {Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true });} else {obj[key] = value;}return obj;}var Button = function (props) {
  var disabled = props.disabled ? props.disabled : false;
  return /*#__PURE__*/(
    React.createElement("div", { className: "button-container" }, /*#__PURE__*/
    React.createElement("button", {
      className: "button",
      onClick: props.onBtnClick,
      disabled: disabled },
    props.text)));
};
class HomePage extends React.Component {
  constructor(props) {
    super(props);_defineProperty(this, "handleBtnClick",
    () => {
      this.setState(function (prevState) {
        let disabled = false;
        let text = 'Replicate!';
        if (Math.random() < .3) {
          disabled = true;
          text = 'Nah...';
        }
        let btn = /*#__PURE__*/React.createElement(Button, { onBtnClick: this.handleBtnClick, disabled: disabled, text: text });
        prevState.buttons.push(btn);
        return prevState;
      });
    });this.state = { buttons: [/*#__PURE__*/React.createElement(Button, { onBtnClick: this.handleBtnClick, disabled: false, text: "Replicate!" })] };this.styles = { display: 'flex', flexWrap: 'wrap', minHeight: '100vh', justifyContent: 'space-around', alignItems: 'center', background: '#047DBF' };}
  render() {
    return /*#__PURE__*/(
      React.createElement("div", { style: this.styles },
      this.state.buttons));
  }}
ReactDOM.render( /*#__PURE__*/
React.createElement(HomePage, null),
document.querySelector('#root'));
</script>

</body>
</html>
Preview