React Suite is a popular front-end library with a set of React components that are designed for the middle platform and back-end products. The Button component is used to fire an action when the user clicks on it.
In this article, we will be seeing React Suite Loading button. The loading button is used to give the virtual cue to the user that something is loading. To change a normal button to the Loading Button the loading property of the Button component is used.
React Suite Button Loading Components:
- Button: This is the most basic button component used to display a simple button.
React Suite Button Loading Props:
- loading: It is a boolean property of the Button component used to show a loading button.
- color: This property of the Button component is used to change the color of the button. The color property can have any one of seven values: red, orange, yellow, green, cyan, blue, or violet.
Syntax:
<Button loading> ... </Button>
Note: The child component of the Button won’t be visible when the button is in a loading state.
Creating React Application And Installing Module:
Step 1: Create a React application using the following command:
npx create-react-app foldername
Step 2: Move to the newly created project folder using the following command:
cd foldername
Step 3: After creating the ReactJS application, Install the required module ( rsuite in this case ) using the following command:
npm install rsuite
Project Structure: After completing the above steps, the project structure will look like the following:
Example 1: Now write down the following code in the App.js file. Here, App is our default component. In this example, we used the loading property of the Button component to show the loading button.
Javascript
import React from "react" ; import { Button } from "rsuite" ; // Default CSS import "rsuite/dist/rsuite.min.css" ; function App() { const ButtonStyle = { margin: "0px 20px" }; return ( <div className= "App" style={{ textAlign: "center" , padding: "0 30px" }}> <header style={{ display: "block" , marginBottom: "20px" }}> <h3 style={{ color: "green" }}> neveropen</h3> <h5>React Suite Button Loading</h5> </header> <Button loading style={ButtonStyle}> Loading Button 1</Button> <Button loading appearance= "primary" style={ButtonStyle}>Loading Button 2</Button> </div > ); } export default App; |
Step to Run Application: Run the application using the following command from the root directory of the project:
npm start
Output: Now open your browser and go to http://localhost:3000/, you will see the following output:
Example 2: In this example, we used the color property along with the loading property of the button to change the color of the Loading Button.
Javascript
import React from "react" ; import { Button } from "rsuite" ; // Default CSS import "rsuite/dist/rsuite.min.css" ; function App() { const ButtonStyle = { margin: "10px 10px" }; return ( <div className= "App" style={{ textAlign: "center" , padding: "0 30px" }}> <header style={{ display: "block" , marginBottom: "20px" }}> <h3 style={{ color: "green" }}> neveropen</h3> <h5>React Suite Button Loading - Color Variation</h5> </header> <Button loading color= "red" appearance= "primary" style={ButtonStyle}> Red Loading Button </Button> <Button loading color= "violet" appearance= "primary" style={ButtonStyle}> Violet Loading Button </Button> <Button loading color= "green" appearance= "primary" style={ButtonStyle}> Green Loading Button </Button> <Button loading color= "yellow" appearance= "primary" style={ButtonStyle}> Yellow Loading Button </Button> <br /> <Button loading color= "orange" appearance= "primary" style={ButtonStyle}> Ornage Loading Button </Button> <Button loading color= "blue" appearance= "primary" style={ButtonStyle}> Blue Loading Button </Button> <Button loading color= "cyan" appearance= "primary" style={ButtonStyle}> Cyan Loading Button </Button> </div > ); } export default App; |
Output:
Reference: https://rsuitejs.com/components/button/#loading