content logo

React Buttons:

Custom React Button Designer with Setting Panel

This code can be useful for you if you have a website that offers sample code and template for users to design their website and help users to design their website template. The code we have in this post was created with the help of React. There is a button in the middle of the page. Using the panel on the left side of the screen, you can change the size of the button or its text or the icon next to it.

#

Custom React Button Code

#

HTML Button Designer Panel

#

HTML Buttons Icon

#

CSS Button Designing Tool

<!-- 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>
                                                                            
body {
	width: 100%;
	min-height: 100vh;
	background: #1d1f20;
	font-family: "Roboto", sans-serif;
}
html {
	box-sizing: border-box;
}
*, *:before, *:after {
	box-sizing: inherit;
}
.App {
	display: flex;
}
.View {
	justify-content: center;
	display: flex;
	flex-grow: 4;
	align-items: center;
	min-height: 100vh;
}
input[type=text], select {
	border: none;
	width: 100%;
	padding: 0.5rem 1rem;
	background: #2c2f30;
	line-height: 45px;
	height: 45px;
	color: #ccc;
}
.Controller {
	padding: 20px;
	background: #242627;
	flex-grow: 1;
}
.Controller-item {
	border-bottom: 1px solid #2c2f30;
	padding: 20px 0;
}
.Controller-item:last-child {
	border: none;
}
.Controller-item-label {
	margin: 0.5rem 0 0.2rem;
	display: block;
	color: #99a0a3;
}
.Controller-inline {
	color: #99a0a3;
	padding: 5px 0;
	display: inline-flex;
}
.Controller-inline label {
	margin: 0 10px;
}
.Button {
	background: #00bcd4;
	color: #fff;
	padding: 0.5rem 2rem 0.4rem;
	text-decoration: none;
	border-radius: 2px;
	box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
}
.Button.Button-small {
	padding: 0.3rem 1rem;
	font-size: 0.8rem;
}
.Button.Button-large {
	padding: 1rem 4rem 1rem;
	font-size: 2rem;
}
.Button-icon {
	margin-right: 10px;
}
class Button extends React.Component {
  constructor(props) {
    super(props);
  }
  render() {
    const { text, icon, size } = this.props;
    return /*#__PURE__*/(
      React.createElement("div", { className: "View" }, /*#__PURE__*/
      React.createElement("a", { href: "#", className: `Button Button-${size}` },
      icon && /*#__PURE__*/
      React.createElement("span", { className: "Button-icon" }, /*#__PURE__*/React.createElement("i", { className: `zmdi zmdi-${icon}` })), /*#__PURE__*/
      React.createElement("span", null, text))));
  }}
class Controller extends React.Component {
  constructor(props) {
    super(props);
    this.state = {};
  }
  updateInputValue(e) {
    this.props.getText(e.target.value);
  }
  updateIconValue(e) {
    this.props.getIcon(e.target.value);
  }
  updateSizeValue(e) {
    this.props.getSize(e.target.value);
  }
  render() {
    return /*#__PURE__*/(
      React.createElement("div", { className: "Controller" }, /*#__PURE__*/
      React.createElement("div", { className: "Controller-item" }, /*#__PURE__*/
      React.createElement("span", { className: "Controller-item-label" }, "Button Text"), /*#__PURE__*/
      React.createElement("input", { type: "text", onChange: this.updateInputValue.bind(this) })), /*#__PURE__*/
      React.createElement("div", { className: "Controller-item" }, /*#__PURE__*/
      React.createElement("span", { className: "Controller-item-label" }, "Button Icon"), /*#__PURE__*/
      React.createElement("select", { onChange: this.updateIconValue.bind(this) }, /*#__PURE__*/
      React.createElement("option", { value: "" }, "No icon"), /*#__PURE__*/
      React.createElement("option", { value: "group" }, "group"), /*#__PURE__*/
      React.createElement("option", { value: "rss" }, "rss"), /*#__PURE__*/
      React.createElement("option", { value: "shape" }, "shape"), /*#__PURE__*/
      React.createElement("option", { value: "spinner" }, "spinner"), /*#__PURE__*/
      React.createElement("option", { value: "amazon" }, "amazon"), /*#__PURE__*/
      React.createElement("option", { value: "skype" }, "skype"))), /*#__PURE__*/
      React.createElement("div", { className: "Controller-item" }, /*#__PURE__*/
      React.createElement("span", { className: "Controller-item-label" }, "Button Size"), /*#__PURE__*/
      React.createElement("div", { className: "Controller-inputs" }, /*#__PURE__*/
      React.createElement("div", { className: "Controller-inline" }, /*#__PURE__*/React.createElement("input", { type: "radio",
        value: "small", name: "size",
        onChange: this.updateSizeValue.bind(this) }), /*#__PURE__*/
      React.createElement("label", null, "Small")), /*#__PURE__*/
      React.createElement("div", { className: "Controller-inline" }, /*#__PURE__*/React.createElement("input", { type: "radio",
        value: "normal", name: "size",
        onChange: this.updateSizeValue.bind(this) }), /*#__PURE__*/
      React.createElement("label", null, "Normal")), /*#__PURE__*/
      React.createElement("div", { className: "Controller-inline" }, /*#__PURE__*/React.createElement("input", { type: "radio",
        value: "large", name: "size",
        onChange: this.updateSizeValue.bind(this) }), /*#__PURE__*/
      React.createElement("label", null, "Large"))))));
  }}
class App extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      text: 'Default',
      icon: '',
      size: '' };
  }
  getText(text) {
    this.setState({
      text: text ? text : 'Default' });
  }
  getIcon(icon) {
    if (icon) {
      this.setState({ icon });
    }
  }
  getSize(size) {
    if (size) {
      this.setState({ size });
    }
  }
  render() {
    const { text, icon, size } = this.state;
    return /*#__PURE__*/(
      React.createElement("div", { className: "App" }, /*#__PURE__*/
      React.createElement(Controller, {
        getText: this.getText.bind(this),
        getIcon: this.getIcon.bind(this),
        getSize: this.getSize.bind(this) }), /*#__PURE__*/
      React.createElement(Button, {
        icon: icon,
        text: text,
        size: size })));
  }}
ReactDOM.render( /*#__PURE__*/
React.createElement(App, null),
document.getElementById('root'));
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css">
    <link rel='stylesheet' href='https://fonts.googleapis.com/css?family=Roboto'>
    <link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/material-design-iconic-font/2.2.0/css/material-design-iconic-font.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/normalize/5.0.0/normalize.min.css">
    <link rel='stylesheet' href='https://fonts.googleapis.com/css?family=Roboto'>
    <link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/material-design-iconic-font/2.2.0/css/material-design-iconic-font.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>
body {
	width: 100%;
	min-height: 100vh;
	background: #1d1f20;
	font-family: "Roboto", sans-serif;
}
html {
	box-sizing: border-box;
}
*, *:before, *:after {
	box-sizing: inherit;
}
.App {
	display: flex;
}
.View {
	justify-content: center;
	display: flex;
	flex-grow: 4;
	align-items: center;
	min-height: 100vh;
}
input[type=text], select {
	border: none;
	width: 100%;
	padding: 0.5rem 1rem;
	background: #2c2f30;
	line-height: 45px;
	height: 45px;
	color: #ccc;
}
.Controller {
	padding: 20px;
	background: #242627;
	flex-grow: 1;
}
.Controller-item {
	border-bottom: 1px solid #2c2f30;
	padding: 20px 0;
}
.Controller-item:last-child {
	border: none;
}
.Controller-item-label {
	margin: 0.5rem 0 0.2rem;
	display: block;
	color: #99a0a3;
}
.Controller-inline {
	color: #99a0a3;
	padding: 5px 0;
	display: inline-flex;
}
.Controller-inline label {
	margin: 0 10px;
}
.Button {
	background: #00bcd4;
	color: #fff;
	padding: 0.5rem 2rem 0.4rem;
	text-decoration: none;
	border-radius: 2px;
	box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
}
.Button.Button-small {
	padding: 0.3rem 1rem;
	font-size: 0.8rem;
}
.Button.Button-large {
	padding: 1rem 4rem 1rem;
	font-size: 2rem;
}
.Button-icon {
	margin-right: 10px;
}
</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 Button extends React.Component {
  constructor(props) {
    super(props);
  }
  render() {
    const { text, icon, size } = this.props;
    return /*#__PURE__*/(
      React.createElement("div", { className: "View" }, /*#__PURE__*/
      React.createElement("a", { href: "#", className: `Button Button-${size}` },
      icon && /*#__PURE__*/
      React.createElement("span", { className: "Button-icon" }, /*#__PURE__*/React.createElement("i", { className: `zmdi zmdi-${icon}` })), /*#__PURE__*/
      React.createElement("span", null, text))));
  }}
class Controller extends React.Component {
  constructor(props) {
    super(props);
    this.state = {};
  }
  updateInputValue(e) {
    this.props.getText(e.target.value);
  }
  updateIconValue(e) {
    this.props.getIcon(e.target.value);
  }
  updateSizeValue(e) {
    this.props.getSize(e.target.value);
  }
  render() {
    return /*#__PURE__*/(
      React.createElement("div", { className: "Controller" }, /*#__PURE__*/
      React.createElement("div", { className: "Controller-item" }, /*#__PURE__*/
      React.createElement("span", { className: "Controller-item-label" }, "Button Text"), /*#__PURE__*/
      React.createElement("input", { type: "text", onChange: this.updateInputValue.bind(this) })), /*#__PURE__*/
      React.createElement("div", { className: "Controller-item" }, /*#__PURE__*/
      React.createElement("span", { className: "Controller-item-label" }, "Button Icon"), /*#__PURE__*/
      React.createElement("select", { onChange: this.updateIconValue.bind(this) }, /*#__PURE__*/
      React.createElement("option", { value: "" }, "No icon"), /*#__PURE__*/
      React.createElement("option", { value: "group" }, "group"), /*#__PURE__*/
      React.createElement("option", { value: "rss" }, "rss"), /*#__PURE__*/
      React.createElement("option", { value: "shape" }, "shape"), /*#__PURE__*/
      React.createElement("option", { value: "spinner" }, "spinner"), /*#__PURE__*/
      React.createElement("option", { value: "amazon" }, "amazon"), /*#__PURE__*/
      React.createElement("option", { value: "skype" }, "skype"))), /*#__PURE__*/
      React.createElement("div", { className: "Controller-item" }, /*#__PURE__*/
      React.createElement("span", { className: "Controller-item-label" }, "Button Size"), /*#__PURE__*/
      React.createElement("div", { className: "Controller-inputs" }, /*#__PURE__*/
      React.createElement("div", { className: "Controller-inline" }, /*#__PURE__*/React.createElement("input", { type: "radio",
        value: "small", name: "size",
        onChange: this.updateSizeValue.bind(this) }), /*#__PURE__*/
      React.createElement("label", null, "Small")), /*#__PURE__*/
      React.createElement("div", { className: "Controller-inline" }, /*#__PURE__*/React.createElement("input", { type: "radio",
        value: "normal", name: "size",
        onChange: this.updateSizeValue.bind(this) }), /*#__PURE__*/
      React.createElement("label", null, "Normal")), /*#__PURE__*/
      React.createElement("div", { className: "Controller-inline" }, /*#__PURE__*/React.createElement("input", { type: "radio",
        value: "large", name: "size",
        onChange: this.updateSizeValue.bind(this) }), /*#__PURE__*/
      React.createElement("label", null, "Large"))))));
  }}
class App extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      text: 'Default',
      icon: '',
      size: '' };
  }
  getText(text) {
    this.setState({
      text: text ? text : 'Default' });
  }
  getIcon(icon) {
    if (icon) {
      this.setState({ icon });
    }
  }
  getSize(size) {
    if (size) {
      this.setState({ size });
    }
  }
  render() {
    const { text, icon, size } = this.state;
    return /*#__PURE__*/(
      React.createElement("div", { className: "App" }, /*#__PURE__*/
      React.createElement(Controller, {
        getText: this.getText.bind(this),
        getIcon: this.getIcon.bind(this),
        getSize: this.getSize.bind(this) }), /*#__PURE__*/
      React.createElement(Button, {
        icon: icon,
        text: text,
        size: size })));
  }}
ReactDOM.render( /*#__PURE__*/
React.createElement(App, null),
document.getElementById('root'));
</script>

</body>
</html>
Preview