• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
seegatesite header

Seegatesite.com

Seegatesite.com - Programming Tutorial , Sharing , How and Learn Together

  • TOOLS
    • Bootstrap Navbar Online Generator
    • Customize Sidebar Menu Bootstrap 3
    • Bootstrap Demo
  • ADVERTISE
  • CATEGORIES
    • Android
    • Blogging Tips
    • Database
    • CSS
    • Info Gadget
    • Javascript
    • Linux
    • PHP
    • Various
    • WordPress
  • Q&A
  • GUEST POST
  • PHP
  • JAVASCRIPT
  • JQUERY
  • ANGULAR
  • WORDPRESS
  • SEO
  • REACT
🏠 » Javascript » Tutorial Create Simple Block UI Using React JS

Tutorial Create Simple Block UI Using React JS

By Sigit Prasetya Nugroho ∙ June 10, 2020 ∙ Javascript ∙ Leave a Comment

Share : TwitterFacebookTelegramWhatsapp

Creating a web-based application admin, of course, We don’t forget to add  Block UI components to the application. Likewise, when I was learning React JS, when I arrived at the HTTP Request session, a system needed a part to block the user from accessing other events or actions while waiting for the HTTP request process to finish.

Tutorial Create Block Ui Reactjs For Beginners

Under the title of the article, I will share how to create a simple Block Page UI without the help of a plugin. Why make it yourself when the Block UI plugin is easily found on repositories like npmjs?

A little story … I spent all day searching and using the BlockUI React plugin that fit the criteria that I was looking for. After being tested several times when getting a plugin that is good enough, some bugs might be inconvenient for me to find a solution.

If you can make it simpler, get up, and work on it so that the results are more satisfying. At least for self-satisfaction. LOL Okay, just start the tutorial.

Table of Contents

  • 1 How to make JS React Block UI
  • 2 Conclusion

How to make JS React Block UI

Create a new component named BlockUI.jsx

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import React from "react";
import "./BlockUI.css";
const BlockUI = props => {
  if (!props.blocking) {
    return "";
  } else {
    return (
      <div className="block-ui-container">
        <div className="block-ui-overlay" />
        <div className="block-ui-message-container">
          <div className="block-ui-message">
            <h4>{props.title}</h4>
            <div className="loading-indicator">
              <svg id="indicator" viewBox="0 0 100 100">
                <circle id="circle" cx="50" cy="50" r="45" />
              </svg>
            </div>
          </div>
        </div>
      </div>
    );
  }
};
 
BlockUI.defaultProps = {
  blocking: false,
  title: "Loading"
};
 
export default BlockUI;

Create a new CSS file with the name BlockUI.css

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
.loading-indicator {
  text-align: center;
}
 
.block-ui {
  position: relative;
  min-height: 3em;
}
 
.block-ui-container {
  position: absolute;
  z-index: 1010;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  height: 100%;
  width: 100%;
  min-height: 2em;
  cursor: wait;
  overflow: hidden;
}
 
.block-ui-container:focus {
  outline: none;
}
 
.block-ui-overlay {
  width: 100%;
  height: 100%;
  opacity: 0.75;
  filter: alpha(opacity=50);
  background-color: rgb(184, 184, 184);
}
 
.block-ui-message-container {
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
  text-align: center;
  transform: translateY(-50%);
  z-index: 10001;
}
 
.block-ui-message {
  color: #333;
  background: none;
  z-index: 1011;
}
 
#indicator {
  width: 100px;
  height: 100px;
  position: absolute;
  top: calc(50% - 50px);
  left: calc(50% - 50px);
  animation: spin 1s linear infinite;
}
 
#circle {
  fill: none;
  stroke: rgba(255, 255, 255, 0.5);
  stroke-linecap: round;
  stroke-width: 4;
  animation: draw 3s ease-in-out infinite;
}
 
@keyframes draw {
  0% {
    stroke-dasharray: 20, 282.6;
  }
  50% {
    stroke-dasharray: 200, 282.6;
  }
  100% {
    stroke-dasharray: 20, 282.6;
  }
}
 
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

You can change the loading bar with your desire.

Easy way to block page :

1
<BlockUI blocking=true />

The property :

  • blocking: default value is false. To activate the BlockUI component, please set blocking to true.
  • title: default value, “Loading.” To make a title on the active Block UI overlay.

Example:

The following example is the use of the ReactJS Block Page UI to make API requests using Axios ReactJS.

1
2
3
4
5
6
7
8
9
10
this.setState({
      blocking: true
    });
    axios.get("https://5ezbs.sse.codesandbox.io/user").then(res => {
      console.log(res.data);
      this.setState({
        blocking: false,
        user: res.data[0]
      });
    });

Here is the full code sample above.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import React from "react";
import "./styles.css";
import BlockUI from "./BlockUI/BlockUI";
import axios from "axios";
class App extends React.Component {
  state = {
    blocking: false,
    user: {}
  };
 
  callApiHandler = () => {
    this.setState({
      blocking: true
    });
    axios.get("https://5ezbs.sse.codesandbox.io/user").then(res => {
      console.log(res.data);
      this.setState({
        blocking: false,
        user: res.data[0]
      });
    });
  };
 
  render() {
    return (
      <div className="App">
        <h1>Example simple block UI</h1>
        <button onClick={this.callApiHandler}>test block</button>
        <h4>Result</h4>
        {Object.keys(this.state.user).length > 0 ? (
          <div>
            Name : {this.state.user.name}
            <br />
            Age : {this.state.user.age}
            <br />
            <img src={this.state.user.image} alt={this.state.user.name} />
          </div>
        ) : (
          ""
        )}
 
        <BlockUI blocking={this.state.blocking} />
      </div>
    );
  }
}
export default App;

Run tests and see the result.

 

To try it directly, please play with the following playground.

Conclusion

Using the blockui component above is easy way to block the user when system is proccessing or initializing

For simple ui components, you should make it yourself without the help of an external plugin. Why? The application will be lighter, and the system will run according to your wishes.

Thus my short tutorial on how to create a React block UI component . Read the other article about react blog here

Another Javascript Related Post :

  • Adept Using Datatables Plugin In 10 Minutes For Beginners (Tutorial)
  • The Using Of Reactstrap And React-Table, Suitable For Beginners
  • How To Implement Login Page And Protected Route ReactJS
  • Complete Tutorial React Router Dom For Beginners (Easy-To-Understand)
  • The Right Way Understanding React Lifecycle For Beginners
  • [Problem Solved] React Error: ENOSPC: System limit for number of file watchers reached

Avatar for Sigit Prasetya Nugroho

About Sigit Prasetya Nugroho

This site is a personal Blog of Sigit Prasetya Nugroho, a Desktop developer and freelance web developer working in PHP, MySQL, WordPress.

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Welcome to my Home,

Avatar for Sigit Prasetya NugrohoThis site is a personal Blog of Sigit Prasetya Nugroho, a Desktop developer and freelance web developer working in PHP, MySQL, WordPress.



Popular Articles

Checked checkbox AdminLTE Bootstrap in Jquery

November 4, 2014 By Sigit Prasetya Nugroho 7 Comments

Simple create date format validation with jqueryUI

December 21, 2014 By Sigit Prasetya Nugroho Leave a Comment

Create Simple Progress Bar for Fake Online Generator with Jquery

January 10, 2015 By Sigit Prasetya Nugroho Leave a Comment

22+ Coolest Free Jquery Plugin For Premium Theme

October 3, 2015 By Sigit Prasetya Nugroho Leave a Comment

Easy Build Your Anti Copy Paste Plugin

October 6, 2015 By Sigit Prasetya Nugroho Leave a Comment

Popular Tags

adminlte (15) adsense (13) adsense tips (4) affiliate amazon (13) amazon (12) Android (8) angular (16) angular 4 (12) angular 5 (4) asin grabber (3) Bootstrap (27) codeigniter (5) create wordpress theme (5) crud (8) css (6) free wordpress theme (7) google adsense (4) imacros (4) increase traffic (6) jquery (34) laravel (10) laravel 5 (5) learn android (5) modal dialog (5) mysql (6) nodeJs (4) optimize seo (4) pdo (6) php (30) plugin (53) pos (7) Publisher Tips (5) react (3) Reactjs (7) SEO (37) theme (17) tutorial angular (5) tutorial angular 4 (6) tutorial javascript (10) tutorial javascript beginners (4) twitter (3) widget (3) wordpress (18) wordpress plugin (13) XMLRPC (5)




  • About
  • Contact Us
  • Disclaimer
  • Privacy Policy
  • Terms and Conditions

©2021 Seegatesite.com