Open In App

ReactJS Semantic UI Portal Addons

Improve
Improve
Like Article
Like
Save
Share
Report

Semantic UI is a modern framework used in developing seamless designs for the website. It gives the user a lightweight experience with its components. It uses the predefined CSS and JQuery languages to incorporate them into different frameworks.

In this article, we will find out how to use Portal Addons in ReactJS Semantic UI. Portal Addons are used to render them anywhere on the page.

Property:

  • Controlled: The controlled property is used to make a controlled portal. The controlled property is basically handled to control the component in React JS.
  • Variations: The variation property is used to improve the qualities of elements like their color, size, etc . The variation is clashing. They are used for modifying elements.
  • content: The content is property is used to describe the header, menu, etc. The content property is used to extend the elements.
  • Behaviors: Behaviors is the property in Semantic UI is used  for setting the validation, to  get the API request.

Syntax:

<Portal>Children content</Portal>

 

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. folder name, move to it using the following command.
    cd foldername
  • Step 3: Install semantic UI in your given directory.
 npm install semantic-ui-react semantic-ui-css

Project Structure: It will look like the following.

Step to Run Application: Run the application  from the root directory of the project, using the following command.

npm start

Example 1: this is the basic example which shows how to use portal addons.

App.js




import React, { Component } from 'react'
import { Button, Grid, Header, Segment, Portal } from 'semantic-ui-react'
  
const styleLink = document.createElement("link");
styleLink.rel = "stylesheet";
styleLink.href = 
document.head.appendChild(styleLink);
  
export default class PortalExamplePortal extends Component {
  state = {
      
    open: false,
  }
  
  Open = () => {
    this.setState({ open: true })
      
  }
  
  Close = () => {
    this.setState({ open: false })
      
  }
  
  
  render() {
    const {  open } = this.state
  
    return (
      <div id='gfg'>
      <Grid columns={2}>
        <Grid.Column>
          <Portal
            closeOnTriggerClick
            openOnTriggerClick
            trigger={
              <Button
                content={open ? 'Close Portal' : 'Open Portal'}
                negative={open}
                positive={!open}
              />
            }
            onOpen={this.Open}
            onClose={this.Close}
          >
            <Segment
              style={{
                left: '25%',
                position: 'fixed',
                top: '2%',
                zIndex: 1000,
              }}
            >
              <Header><h1>GeeksforGeeks</h1></Header>
              <p>Computer Science Portal</p>              
            </Segment>
          </Portal>
        </Grid.Column>
      </Grid>
      </div>
    )
  }
}


index.css




#gfg {
  margin: 40px;
}


Output:

Reference: https://react.semantic-ui.com/addons/portal



Last Updated : 22 Jul, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads