content logo

React Buttons:

Success Button with Shape Change Effect using React

In this post, we have a button using React. This button has no background but has a white border. The corners of this button are curved and the border has a radius. This button also has a white title. By clicking on this button, the button will turn into a green circle with a success sign in the middle.

#

React Success Button

#

CSS Button Shape Change

#

Dynamic Javascript Button

#

HTML Save Button 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>
                                                                            
html, body {
  background-color: #2c3e50;
}
.name {
  color: #fff;
}
button {
  outline: 0 !important;
}
button.awesome-btn {
  overflow: hidden;
  width: 250px;
  height: 75px;
  -webkit-appearance: none;
  border: 3px solid #fff;
  border-radius: 50px;
  padding: 0.5em 1em;
  color: #fff;
  font-size: 1.5em;
  background-color: transparent;
  transition: all ease 0.25s;
}
button.awesome-btn:hover {
  background-color: #fff;
  color: #2c3e50;
}
button.awesome-btn.checked {
  width: 75px;
  height: 75px;
  border: 3px solid #2ecc71;
  background-color: #2ecc71;
  border: 50%;
}
button.awesome-btn.checked:hover {
  color: #fff;
}
class AwesomeButton extends React.Component {
  constructor() {
    super();
    this.state = {
      status: false,
      text: 'Save',
      class: '' };
  }
  click() {
    this.setState({
      status: !this.state.status,
      text: !this.state.status ? String.fromCharCode('10003') : 'Save',
      class: !this.state.status ? 'checked' : '' });
  }
  render() {
    return /*#__PURE__*/(
      React.createElement("button", {
        className: `awesome-btn ` + this.state.class,
        onClick: this.click.bind(this) }, this.state.text));
  }}
const App = class App extends React.Component {
  render() {
    return /*#__PURE__*/(
      React.createElement("div", { className: "container-fluid", style: {
          marginTop: '1em' } }, /*#__PURE__*/
      React.createElement("div", { className: "row" }, /*#__PURE__*/
      React.createElement("div", { className: "col-12 text-center" }, /*#__PURE__*/
      React.createElement(AwesomeButton, null))), /*#__PURE__*/
      React.createElement("div", { className: "row" }, /*#__PURE__*/
      React.createElement("div", { className: "col-12 text-center", style: {
          marginTop: '.5em' } }, /*#__PURE__*/
      React.createElement("p", { className: "name" }, "Some Text.")))));
  }};
ReactDOM.render( /*#__PURE__*/React.createElement(App, null), document.getElementById('root'));
<link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha.6/css/bootstrap.min.css'>
<script src='https://cdnjs.cloudflare.com/ajax/libs/react/15.4.2/react.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/react/15.4.2/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/twitter-bootstrap/4.0.0-alpha.6/css/bootstrap.min.css'>
<script src='https://cdnjs.cloudflare.com/ajax/libs/react/15.4.2/react.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/react/15.4.2/react-dom.min.js'></script>
<style>
html, body {
  background-color: #2c3e50;
}
.name {
  color: #fff;
}
button {
  outline: 0 !important;
}
button.awesome-btn {
  overflow: hidden;
  width: 250px;
  height: 75px;
  -webkit-appearance: none;
  border: 3px solid #fff;
  border-radius: 50px;
  padding: 0.5em 1em;
  color: #fff;
  font-size: 1.5em;
  background-color: transparent;
  transition: all ease 0.25s;
}
button.awesome-btn:hover {
  background-color: #fff;
  color: #2c3e50;
}
button.awesome-btn.checked {
  width: 75px;
  height: 75px;
  border: 3px solid #2ecc71;
  background-color: #2ecc71;
  border: 50%;
}
button.awesome-btn.checked:hover {
  color: #fff;
}
</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>
class AwesomeButton extends React.Component {
  constructor() {
    super();
    this.state = {
      status: false,
      text: 'Save',
      class: '' };
  }
  click() {
    this.setState({
      status: !this.state.status,
      text: !this.state.status ? String.fromCharCode('10003') : 'Save',
      class: !this.state.status ? 'checked' : '' });
  }
  render() {
    return /*#__PURE__*/(
      React.createElement("button", {
        className: `awesome-btn ` + this.state.class,
        onClick: this.click.bind(this) }, this.state.text));
  }}
const App = class App extends React.Component {
  render() {
    return /*#__PURE__*/(
      React.createElement("div", { className: "container-fluid", style: {
          marginTop: '1em' } }, /*#__PURE__*/
      React.createElement("div", { className: "row" }, /*#__PURE__*/
      React.createElement("div", { className: "col-12 text-center" }, /*#__PURE__*/
      React.createElement(AwesomeButton, null))), /*#__PURE__*/
      React.createElement("div", { className: "row" }, /*#__PURE__*/
      React.createElement("div", { className: "col-12 text-center", style: {
          marginTop: '.5em' } }, /*#__PURE__*/
      React.createElement("p", { className: "name" }, "Some Text.")))));
  }};
ReactDOM.render( /*#__PURE__*/React.createElement(App, null), document.getElementById('root'));
</script>

</body>
</html>
Preview