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. Stack component quickly layout components through Flexbox, support vertical and horizontal stacking, and support custom spacing and wrap.
Stack Interactive is used to alignItems, justifyContent, and set the direction of the stack.
Syntax:
<Stack direction={direction} alignItems={alignment} justifyContent={justifyContent}> <Button >....</Button> </Stack>
Creating React Application And Installing Module:
Step 1: Create a React application using the following command:
npx create-react-app foldername
Step 2: After creating your project folder i.e. foldername, move to it using the following command:
cd foldername
Step 3: After creating the ReactJS application, Install the required module using the following command:
npm install rsuite
Project Structure: It will look like the following:
Example 1: Now write down the following code in the App.js file. Here, App is our default component where we have written our code. In this example, we will learn about direction and justifyContent in Stack Interactive.
Javascript
import React,{useState} from 'react' ; import 'rsuite/dist/rsuite.min.css' ; import Stack from 'rsuite/Stack' ; import Button from '@mui/material/Button' ; import { Radio, RadioGroup } from 'rsuite' ; export default function App(){ const [justifyContent, setJustifyContent] = React.useState( 'flex-start' ); const [alignItems, setAlignItems] = React.useState( 'flex-start' ); const [direction, setDirection] = React.useState( 'row' ); return ( <div> <h1 style={{color: 'green' }}>neveropen</h1> <h3>React Suite Stack Interactive</h3> <Stack spacing={6} direction={direction} alignItems={alignItems} justifyContent={justifyContent} > <Button style={{color: 'white' ,background: 'green' }}>Item 1</Button> <Button style={{color: 'white' ,background: 'red' }}>Item 2</Button> <Button style={{color: 'black' ,background: 'yellow' }}>Item 3</Button> <Button style={{color: 'white' ,background: 'violet' }} >Item 4</Button> </Stack> <hr /> <Stack> <label>direction:</label> <RadioGroup inline value={direction} onChange={setDirection}> <Radio value= "row" >row</Radio> <Radio value= "row-reverse" >row-reverse</Radio> <Radio value= "column" >column</Radio> <Radio value= "column-reverse" >column-reverse</Radio> </RadioGroup> </Stack> <Stack> <label>justifyContent:</label> <RadioGroup inline value={justifyContent} onChange={setJustifyContent}> <Radio value= "flex-start" >flex-start</Radio> <Radio value= "center" >center</Radio> <Radio value= "flex-end" >flex-end</Radio> <Radio value= "space-between" >space-between</Radio> <Radio value= "space-around" >space-around</Radio> </RadioGroup> </Stack> </div> ) } |
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 will learn about alignItems in Stack Interactive
Javascript
import React,{useState} from 'react' ; import 'rsuite/dist/rsuite.min.css' ; import Stack from 'rsuite/Stack' ; import Button from '@mui/material/Button' ; import { Radio, RadioGroup } from 'rsuite' ; export default function App(){ const [justifyContent, setJustifyContent] = React.useState( 'flex-start' ); const [alignItems, setAlignItems] = React.useState( 'flex-start' ); const [direction, setDirection] = React.useState( 'column' ); return ( <div> <h1 style={{color: 'green' }}>neveropen</h1> <h3>React Suite Stack Interactive</h3> <Stack spacing={6} direction={direction} alignItems={alignItems} justifyContent={justifyContent} > <Button style={{color: 'white' ,background: 'green' }}>Item 1</Button> <Button style={{color: 'white' ,background: 'red' }}>Item 2</Button> <Button style={{color: 'black' ,background: 'yellow' }}>Item 3</Button> <Button style={{color: 'white' ,background: 'violet' }} >Item 4</Button> </Stack> <hr /> <Stack> <label>alignItems:</label> <RadioGroup inline value={alignItems} onChange={setAlignItems}> <Radio value= "flex-start" >flex-start</Radio> <Radio value= "center" >center</Radio> <Radio value= "flex-end" >flex-end</Radio> <Radio value= "stretch" >stretch</Radio> <Radio value= "baseline" >baseline</Radio> </RadioGroup> </Stack> </div> ) } |
Output:
Reference: https://rsuitejs.com/components/stack/#interactive