content logo

React Progress Bars:

Amazing Progress Bar on Button Border using React

The opinion of viewers always matters. In this code, we will introduce the Amazing Progress Bar on Bottom Border using React, which allows you to contact your viewers on your website. With the help of this React Progress Bar, you can be aware of your audience's ideas about your website, and as a result, you can improve it as possible. This Rounded Progress Bar allows your viewers to fill out the form and, in the end, send their opinion or message about your website easily.

You can see the following preview of the React Form Progress Bar below. As you see, this Simple Progress Bar Code has an orange and white theme. The above and bottom of this code are orange, and the main page is white. This Border Progress Bar Code includes three sections that people can fill out. The first field is designed for their name, the second one for their email address, and the last one is designed for their messages. After filling out all sections, they should press the “Send” button in white color. As soon as you put the cursor off the mouse on this button, it changed to orange.

#

React Progress Bar

#

Border Progress Bar Code

#

React Form Progress Bar

#

Simple Progress Bar Code

#

Rounded Progress Bar

<!-- This script got from frontendfreecode.com -->
<div class="container">
    <div id="root">
    </div>
</div><a style="font-size: 8pt; text-decoration: none" target="_blank" href="http://frontendfreecode.com">Free Frontend</a>
                                                                            
body {
	background-color: #e27a29;
	padding-top: 50px;
	padding-bottom: 50px;
	text-align: center;
}
#root {
	background-color: #FFFFFF;
	max-width: 600px;
	width: 100%;
	height: 100%;
	text-align: left;
	margin: 0 auto;
	padding: 100px;
	border-radius: 4px;
	box-shadow: 10px 10px 100px 10px #b56d34;
}
#root .heading {
	position: relative;
	margin-bottom: 50px;
}
#root .heading h1 {
	font-size: 30px;
	display: inline;
}
#root .heading img {
	position: absolute;
	height: 60px;
	top: -10px;
}
#root input[type=text], #root textarea {
	border: none;
	height: 50px;
	font-size: 22px;
	width: 100%;
	padding: 10px 0;
}
#root input[type=text]::placeholder, #root textarea::placeholder {
	color: #d8d6d4;
}
#root input[type=text]:focus, #root textarea:focus {
	outline: none;
}
#root textarea {
	padding-top: 25px;
}
#root input[type=text] {
	border-bottom: 1px solid #d8d6d4;
}
button {
	border-radius: 25px;
	height: 50px;
	width: 150px;
	background-color: #FFFFFF;
	color: #d8d6d4;
	border: 2px solid #d8d6d4;
	font-size: 15px;
	transition: all 1s ease 0s;
	outline: none;
	cursor: pointer;
	position: relative;
}
button .text {
	position: absolute;
	display: block;
	z-index: 10;
	color: #d8d6d4;
	top: 15px;
	left: 53px;
}
button .round {
	position: absolute;
	z-index: 9;
	background-color: transparent;
	border-radius: 50%;
	height: 50px;
	width: 50px;
	transition: all 1s ease 0s;
	top: -2px;
	left: 50px;
}
button .progress-top, button .progress-bottom {
	transition: all 1s ease 0s;
	position: absolute;
	border: 2px solid #e27a29;
	border-radius: 25px;
	height: 46px;
	width: 146px;
	top: -2px;
	left: -2px;
	display: block;
	clip: rect(25px, 0px, 0px, 0px);
}
button .progress-bottom {
	border: 2px solid #e27a29;
	transform: rotate(-180deg);
	clip: rect(0px, 50px, 0px, 0px);
}
button.valid-form {
	border: 2px solid #e27a29;
}
button.valid-form .text {
	color: #FFFFF;
}
button.valid-form .round {
	background-color: #e27a29;
	color: #FFFFF;
	border-radius: 25px;
	height: 50px;
	width: 149px;
	left: 0;
}
const inputDatas = [
    {
        id: 'name',
        name: 'name',
        label: 'Name',
        value: '',
        hasError: false,
        type: 'text',
        validation: 'name'
    },
    {
        id: 'email',
        name: 'email',
        label: 'Email',
        value: '',
        hasError: false,
        type: 'text',
        validation: 'email'
    },
    {
        id: 'message',
        name: 'message',
        label: 'Message',
        value: '',
        hasError: false,
        type: 'textarea',
        validation: 'message'
    }];
const ProgressForm = React.createClass({
    displayName: "ProgressForm",
    getInitialState() {
        return {
            inputDatas,
            progressPercent: 0,
            submitButton: false
        };
    },
    componentDidMount() {
        this._initialInputVerification();
    },
    _initialInputVerification() {
        const self = this;
        this.state.inputDatas.forEach((item, index) => {
            self._setAndValidateInput(index, item.value);
        });
        this._calculatePercent();
    },
    _calculatePercent() {
        const total = this.state.inputDatas.length;
        let done = 0;
        let progressPercent;
        this.state.inputDatas.forEach(item => {
            if (item.hasError === false) {
                done += 1;
            }
        });
        progressPercent = 1 * done / total * 100;
        this.setState({ progressPercent });
    },
    _onSubmit(e) {
        e.preventDefault();
        this._onSubmitFormHandler();
    },
    _onChange(e) {
        const value = e.target.value;
        const index = _.findIndex(inputDatas, { name: e.target.name });
        this._onChangeInputHandler(index, value);
    },
    _setAndValidateInput(index, inputValue) {
        const inputDataArray = this.state.inputDatas;
        inputDataArray[index].value = inputValue;
        inputDataArray[index].hasError = false;
        const mailFormat = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
        const nameFormat = /^[a-zA-Z-. ]{2,30}$/;
        const messageFormat = /^[a-zA-Z0-9-. ]{2,250}$/;
        switch (inputDataArray[index].validation) {
            case 'email':
                inputDataArray[index].hasError = !inputDataArray[index].value.match(mailFormat);
                break;
            case 'name':
                inputDataArray[index].hasError = !inputDataArray[index].value.match(nameFormat);
                break;
            case 'message':
                inputDataArray[index].hasError = !inputDataArray[index].value.match(messageFormat);
                break;
            default:
                inputDataArray[index].hasError = true;
                break;
        }
        this.setState({
            inputDatas: inputDataArray,
            submitButton: false
        });
    },
    _onChangeInputHandler(index, value) {
        this._setAndValidateInput(index, value);
        this._calculatePercent();
    },
    _onSubmitFormHandler() {
        if (this.state.progressPercent >= 100) {
            this.setState({
                submitButton: true
            });
        }
    },
    getFormElements() {
        return inputDatas.map((element, index) => {
            const { type, id, name, value, label } = element;
            if (type === 'text') {
                return /*#__PURE__*/(
                    React.createElement("div", null, /*#__PURE__*/
                        React.createElement("input", {
                            indexValue: index,
                            type: "text", id: id,
                            name: name,
                            placeholder: label,
                            value: value,
                            onChange: this._onChange
                        })));
            } else if (type === 'textarea') {
                return /*#__PURE__*/(
                    React.createElement("div", null, /*#__PURE__*/
                        React.createElement("textarea", {
                            id: id,
                            indexValue: index,
                            name: name,
                            placeholder: label,
                            onChange: this._onChange
                        },
                            value)));
            }
        });
    },
    getProgressButtonStyles() {
        let progressCompleteBottom = {};
        let progressCompleteTop = {};
        let textStyle = {};
        let buttonClass = '';
        if (this.state.submitButton) {
            buttonClass = 'valid-form';
            progressCompleteBottom = {
                clip: `rect(25px, 150px, 50px, 0px)`
            };
            progressCompleteTop = {
                clip: `rect(25px, 150px, 50px, 0px)`
            };
            textStyle = {
                color: '#FFFFFF'
            };
        } else if (this.state.progressPercent >= 100) {
            progressCompleteBottom = {
                clip: `rect(25px, 150px, 50px, 0px)`
            };
            progressCompleteTop = {
                clip: `rect(25px, 150px, 50px, 0px)`
            };
            textStyle = {
                color: '#e27a29'
            };
        } else if (this.state.progressPercent > 50) {
            const percentAbove50 = this.state.progressPercent - 50;
            progressCompleteBottom = {
                clip: `rect(25px, 150px, 50px, 0px)`
            };
            progressCompleteTop = {
                clip: `rect(0px,    ${percentAbove50 * 300 / 100}px, 50px, 0px)`
            };
        } else if (this.state.progressPercent <= 50) {
            progressCompleteBottom = {
                clip: `rect(25px, ${this.state.progressPercent * 300 / 100}px, 50px, 0px)`
            };
        }
        return {
            progressCompleteBottom,
            progressCompleteTop,
            textStyle,
            buttonClass
        };
    },
    getProgressButton() {
        const {
            progressCompleteBottom,
            progressCompleteTop,
            textStyle,
            buttonClass } =
            this.getProgressButtonStyles();
        return /*#__PURE__*/(
            React.createElement("button", { onClick: this.submit, className: buttonClass }, /*#__PURE__*/
                React.createElement("span", { className: "text", style: textStyle }, "SEND"), /*#__PURE__*/
                React.createElement("span", { className: "round" }), /*#__PURE__*/
                React.createElement("span", { className: "progress-top", style: progressCompleteBottom }), /*#__PURE__*/
                React.createElement("span", { className: "progress-bottom", style: progressCompleteTop })));
    },
    render() {
        return /*#__PURE__*/(
            React.createElement("div", null, /*#__PURE__*/
                React.createElement("div", { className: "heading" }, /*#__PURE__*/
                    React.createElement("h1", null, "We love mail"), /*#__PURE__*/
                    React.createElement("img", { src: "http://frontendfreecode.com/img/star.png" })), /*#__PURE__*/
                React.createElement("div", null, /*#__PURE__*/
                    React.createElement("form", { onSubmit: this._onSubmit },
                        this.getFormElements(),
                        this.getProgressButton()))));
    }
});
React.render( /*#__PURE__*/React.createElement(ProgressForm, null), document.getElementById('root'));
<script src='https://cdnjs.cloudflare.com/ajax/libs/react/0.13.0/react.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.4/lodash.min.js'></script>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<!-- This script got from frontendfreecode.com -->

<script src='https://cdnjs.cloudflare.com/ajax/libs/react/0.13.0/react.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.4/lodash.min.js'></script>
<style>
body {
	background-color: #e27a29;
	padding-top: 50px;
	padding-bottom: 50px;
	text-align: center;
}
#root {
	background-color: #FFFFFF;
	max-width: 600px;
	width: 100%;
	height: 100%;
	text-align: left;
	margin: 0 auto;
	padding: 100px;
	border-radius: 4px;
	box-shadow: 10px 10px 100px 10px #b56d34;
}
#root .heading {
	position: relative;
	margin-bottom: 50px;
}
#root .heading h1 {
	font-size: 30px;
	display: inline;
}
#root .heading img {
	position: absolute;
	height: 60px;
	top: -10px;
}
#root input[type=text], #root textarea {
	border: none;
	height: 50px;
	font-size: 22px;
	width: 100%;
	padding: 10px 0;
}
#root input[type=text]::placeholder, #root textarea::placeholder {
	color: #d8d6d4;
}
#root input[type=text]:focus, #root textarea:focus {
	outline: none;
}
#root textarea {
	padding-top: 25px;
}
#root input[type=text] {
	border-bottom: 1px solid #d8d6d4;
}
button {
	border-radius: 25px;
	height: 50px;
	width: 150px;
	background-color: #FFFFFF;
	color: #d8d6d4;
	border: 2px solid #d8d6d4;
	font-size: 15px;
	transition: all 1s ease 0s;
	outline: none;
	cursor: pointer;
	position: relative;
}
button .text {
	position: absolute;
	display: block;
	z-index: 10;
	color: #d8d6d4;
	top: 15px;
	left: 53px;
}
button .round {
	position: absolute;
	z-index: 9;
	background-color: transparent;
	border-radius: 50%;
	height: 50px;
	width: 50px;
	transition: all 1s ease 0s;
	top: -2px;
	left: 50px;
}
button .progress-top, button .progress-bottom {
	transition: all 1s ease 0s;
	position: absolute;
	border: 2px solid #e27a29;
	border-radius: 25px;
	height: 46px;
	width: 146px;
	top: -2px;
	left: -2px;
	display: block;
	clip: rect(25px, 0px, 0px, 0px);
}
button .progress-bottom {
	border: 2px solid #e27a29;
	transform: rotate(-180deg);
	clip: rect(0px, 50px, 0px, 0px);
}
button.valid-form {
	border: 2px solid #e27a29;
}
button.valid-form .text {
	color: #FFFFF;
}
button.valid-form .round {
	background-color: #e27a29;
	color: #FFFFF;
	border-radius: 25px;
	height: 50px;
	width: 149px;
	left: 0;
}
</style>

</head>
<body>
<div class="container">
    <div id="root">
    </div>
</div><div id="bcl"><a style="font-size:8pt;text-decoration:none;" href="http://www.devanswer.com">Free Frontend</a></div>
<script>
const inputDatas = [
    {
        id: 'name',
        name: 'name',
        label: 'Name',
        value: '',
        hasError: false,
        type: 'text',
        validation: 'name'
    },
    {
        id: 'email',
        name: 'email',
        label: 'Email',
        value: '',
        hasError: false,
        type: 'text',
        validation: 'email'
    },
    {
        id: 'message',
        name: 'message',
        label: 'Message',
        value: '',
        hasError: false,
        type: 'textarea',
        validation: 'message'
    }];
const ProgressForm = React.createClass({
    displayName: "ProgressForm",
    getInitialState() {
        return {
            inputDatas,
            progressPercent: 0,
            submitButton: false
        };
    },
    componentDidMount() {
        this._initialInputVerification();
    },
    _initialInputVerification() {
        const self = this;
        this.state.inputDatas.forEach((item, index) => {
            self._setAndValidateInput(index, item.value);
        });
        this._calculatePercent();
    },
    _calculatePercent() {
        const total = this.state.inputDatas.length;
        let done = 0;
        let progressPercent;
        this.state.inputDatas.forEach(item => {
            if (item.hasError === false) {
                done += 1;
            }
        });
        progressPercent = 1 * done / total * 100;
        this.setState({ progressPercent });
    },
    _onSubmit(e) {
        e.preventDefault();
        this._onSubmitFormHandler();
    },
    _onChange(e) {
        const value = e.target.value;
        const index = _.findIndex(inputDatas, { name: e.target.name });
        this._onChangeInputHandler(index, value);
    },
    _setAndValidateInput(index, inputValue) {
        const inputDataArray = this.state.inputDatas;
        inputDataArray[index].value = inputValue;
        inputDataArray[index].hasError = false;
        const mailFormat = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
        const nameFormat = /^[a-zA-Z-. ]{2,30}$/;
        const messageFormat = /^[a-zA-Z0-9-. ]{2,250}$/;
        switch (inputDataArray[index].validation) {
            case 'email':
                inputDataArray[index].hasError = !inputDataArray[index].value.match(mailFormat);
                break;
            case 'name':
                inputDataArray[index].hasError = !inputDataArray[index].value.match(nameFormat);
                break;
            case 'message':
                inputDataArray[index].hasError = !inputDataArray[index].value.match(messageFormat);
                break;
            default:
                inputDataArray[index].hasError = true;
                break;
        }
        this.setState({
            inputDatas: inputDataArray,
            submitButton: false
        });
    },
    _onChangeInputHandler(index, value) {
        this._setAndValidateInput(index, value);
        this._calculatePercent();
    },
    _onSubmitFormHandler() {
        if (this.state.progressPercent >= 100) {
            this.setState({
                submitButton: true
            });
        }
    },
    getFormElements() {
        return inputDatas.map((element, index) => {
            const { type, id, name, value, label } = element;
            if (type === 'text') {
                return /*#__PURE__*/(
                    React.createElement("div", null, /*#__PURE__*/
                        React.createElement("input", {
                            indexValue: index,
                            type: "text", id: id,
                            name: name,
                            placeholder: label,
                            value: value,
                            onChange: this._onChange
                        })));
            } else if (type === 'textarea') {
                return /*#__PURE__*/(
                    React.createElement("div", null, /*#__PURE__*/
                        React.createElement("textarea", {
                            id: id,
                            indexValue: index,
                            name: name,
                            placeholder: label,
                            onChange: this._onChange
                        },
                            value)));
            }
        });
    },
    getProgressButtonStyles() {
        let progressCompleteBottom = {};
        let progressCompleteTop = {};
        let textStyle = {};
        let buttonClass = '';
        if (this.state.submitButton) {
            buttonClass = 'valid-form';
            progressCompleteBottom = {
                clip: `rect(25px, 150px, 50px, 0px)`
            };
            progressCompleteTop = {
                clip: `rect(25px, 150px, 50px, 0px)`
            };
            textStyle = {
                color: '#FFFFFF'
            };
        } else if (this.state.progressPercent >= 100) {
            progressCompleteBottom = {
                clip: `rect(25px, 150px, 50px, 0px)`
            };
            progressCompleteTop = {
                clip: `rect(25px, 150px, 50px, 0px)`
            };
            textStyle = {
                color: '#e27a29'
            };
        } else if (this.state.progressPercent > 50) {
            const percentAbove50 = this.state.progressPercent - 50;
            progressCompleteBottom = {
                clip: `rect(25px, 150px, 50px, 0px)`
            };
            progressCompleteTop = {
                clip: `rect(0px,    ${percentAbove50 * 300 / 100}px, 50px, 0px)`
            };
        } else if (this.state.progressPercent <= 50) {
            progressCompleteBottom = {
                clip: `rect(25px, ${this.state.progressPercent * 300 / 100}px, 50px, 0px)`
            };
        }
        return {
            progressCompleteBottom,
            progressCompleteTop,
            textStyle,
            buttonClass
        };
    },
    getProgressButton() {
        const {
            progressCompleteBottom,
            progressCompleteTop,
            textStyle,
            buttonClass } =
            this.getProgressButtonStyles();
        return /*#__PURE__*/(
            React.createElement("button", { onClick: this.submit, className: buttonClass }, /*#__PURE__*/
                React.createElement("span", { className: "text", style: textStyle }, "SEND"), /*#__PURE__*/
                React.createElement("span", { className: "round" }), /*#__PURE__*/
                React.createElement("span", { className: "progress-top", style: progressCompleteBottom }), /*#__PURE__*/
                React.createElement("span", { className: "progress-bottom", style: progressCompleteTop })));
    },
    render() {
        return /*#__PURE__*/(
            React.createElement("div", null, /*#__PURE__*/
                React.createElement("div", { className: "heading" }, /*#__PURE__*/
                    React.createElement("h1", null, "We love mail"), /*#__PURE__*/
                    React.createElement("img", { src: "http://frontendfreecode.com/img/star.png" })), /*#__PURE__*/
                React.createElement("div", null, /*#__PURE__*/
                    React.createElement("form", { onSubmit: this._onSubmit },
                        this.getFormElements(),
                        this.getProgressButton()))));
    }
});
React.render( /*#__PURE__*/React.createElement(ProgressForm, null), document.getElementById('root'));
</script>

</body>
</html>
Preview