Tuesday, November 26, 2024
Google search engine
HomeLanguagesReact Suite FlexboxGrid Layout

React Suite FlexboxGrid Layout

React Suite is a front-end library designed for the middle platform and back-end products. React Suite FlexboxGrid component allows the user to use 24 grids as it is a grid layout component.

The justify prop defines the horizontal arrangement of the FlexboxGrid component. It can be either set to “center”, “start”, “end”, “space-around” or “space-between”.

Syntax:

<FlexboxGrid justify=""></FlexboxGrid>

Prerequisite:

Creating React Application and Module installation:

Step 1: Create the react project folder, for that open the terminal, and write the command npm create-react-app folder name, if you have already installed create-react-app globally. If you haven’t, install create-react-app globally using the command npm -g create-react-app or install locally by npm i create-react-app.

npm create-react-app project

Step 2: After creating your project folder(i.e. project), move to it by using the following command.

cd project

Step 3:  now install the dependency by using the following command:

npm install rsuite

Project Structure: It will look like this:

 

Example 1: We are importing the FlexboxGrid Component from rsuite, and to apply the default styles of the components, we are importing “rsuite/dist/rsuite.min.css”. Within the FlexboxGrid component, we are adding FlexboxGrid.Item component with some numbers and adding some styles to it which we have defined in the style. To the FlexboxGrid Component, we have mentioned justifying prop to “start”, “center” and “end”, which shows the respective results.

App.js




import { FlexboxGrid } from "rsuite";
import "rsuite/dist/rsuite.min.css";
  
function App() {
  const style = {
    width: 30,
    display: "block",
    border: "2px solid green",
    textAlign: "center",
  };
  return (
    <div className="App">
      <h4> React Suite FlexboxGrid Layout </h4>
      <p style={{ textAlign: "center" }}>justify="start"</p>
  
      <FlexboxGrid justify="start">
        <FlexboxGrid.Item style={style}>1</FlexboxGrid.Item>
        <FlexboxGrid.Item style={style}>2</FlexboxGrid.Item>
        <FlexboxGrid.Item style={style}>3</FlexboxGrid.Item>
        <FlexboxGrid.Item style={style}>4</FlexboxGrid.Item>
      </FlexboxGrid>
      <hr />
      <p style={{ textAlign: "center" }}>justify="end"</p>
  
      <FlexboxGrid justify="end">
        <FlexboxGrid.Item style={style}>1</FlexboxGrid.Item>
        <FlexboxGrid.Item style={style}>2</FlexboxGrid.Item>
        <FlexboxGrid.Item style={style}>3</FlexboxGrid.Item>
        <FlexboxGrid.Item style={style}>4</FlexboxGrid.Item>
      </FlexboxGrid>
      <hr />
      <p style={{ textAlign: "center" }}>justify="center"</p>
  
      <FlexboxGrid justify="center">
        <FlexboxGrid.Item style={style}>1</FlexboxGrid.Item>
        <FlexboxGrid.Item style={style}>2</FlexboxGrid.Item>
        <FlexboxGrid.Item style={style}>3</FlexboxGrid.Item>
        <FlexboxGrid.Item style={style}>4</FlexboxGrid.Item>
      </FlexboxGrid>
    </div>
  );
}
  
export default App;


Step to Run Application: Run the application using the following command from the project’s root directory.

npm start

Output:

 

Example 2: In this example, we are setting the justify prop to “space-between” and “space-around”.

App.js




import { FlexboxGrid } from "rsuite";
import "rsuite/dist/rsuite.min.css";
  
function App() {
  const style = {
    width: 30,
    display: "block",
    border: "2px solid green",
    textAlign: "center",
  };
  return (
    <div className="App">
      <h4> React Suite FlexboxGrid Layout </h4>
      <p style={{ textAlign: "center" }}>justify="space-around"</p>
  
      <FlexboxGrid justify="space-around">
        <FlexboxGrid.Item style={style}>1</FlexboxGrid.Item>
        <FlexboxGrid.Item style={style}>2</FlexboxGrid.Item>
        <FlexboxGrid.Item style={style}>3</FlexboxGrid.Item>
        <FlexboxGrid.Item style={style}>4</FlexboxGrid.Item>
      </FlexboxGrid>
      <hr />
      <p style={{ textAlign: "center" }}>justify= space-between</p>
  
      <FlexboxGrid justify="space-between">
        <FlexboxGrid.Item style={style}>1</FlexboxGrid.Item>
        <FlexboxGrid.Item style={style}>2</FlexboxGrid.Item>
        <FlexboxGrid.Item style={style}>3</FlexboxGrid.Item>
        <FlexboxGrid.Item style={style}>4</FlexboxGrid.Item>
      </FlexboxGrid>
    </div>
  );
}
  
export default App;


Step to Run Application: Run the application using the following command from the project’s root directory.

npm start

Output:

 

Reference:- https://rsuitejs.com/components/flexbox-grid/#layout

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

RELATED ARTICLES

Most Popular

Recent Comments