Open In App

ReactJS Semantic UI TransitionablePortal Addons

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 into different frameworks.

In this article, we will find out how to use TransitionablePortal Addons in ReactJS Semantic UI. TransitionablePortal add-ons are used to render it anywhere on the page.



Property:

Syntax:



<TransitionablePortal>Children content</TransitionablePortal>

 

Creating React Application And Installing Module:

npm start

Example 1: This is the basic example that shows how to use TransitionablePortal addons.




import React, { Component } from 'react'
import { Button, Grid, Header, Segment, 
    TransitionablePortal } from 'semantic-ui-react'
  
const styleLink = document.createElement("link");
styleLink.rel = "stylesheet";
styleLink.href = 
document.head.appendChild(styleLink);
  
export default class 
  TransitionablePortalExampleTransitionablePortal 
  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>
          <TransitionablePortal
            closeOnTriggerClick
            openOnTriggerClick
            trigger={
              <Button
                content={open ? 'Close TransitionablePortal' 
                              : 'Open TransitionablePortal'}
                negative={open}
                positive={!open}
              />
            }
            onOpen={this.Open}
            onClose={this.Close}
          >
            <Segment
              style={{
                left: '32%',
                position: 'fixed',
                top: '2%',
                zIndex: 1000,
              }}
            >
              <Header><h1>GeeksforGeeks</h1></Header>
              <p>Computer Science Portal</p>
            </Segment>
          </TransitionablePortal>
        </Grid.Column>
      </Grid>
      </div>
    )
  }
}




#gfg {
    margin: 40px;
}

 

Output:

Example 2: In this example, we have set the transition to 1000 in TransitionablePortal addons.




import React, { Component } from 'react'
import { Button, Grid, Header, Segment, 
    TransitionablePortal } from 'semantic-ui-react'
  
const styleLink = document.createElement("link");
styleLink.rel = "stylesheet";
styleLink.href = 
document.head.appendChild(styleLink);
  
export default class 
  TransitionablePortalExampleTransitionablePortal 
  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>
          <TransitionablePortal
          transition = {{
            animation: 'scale',
            duration: 1000,}}
            closeOnTriggerClick
            openOnTriggerClick
            trigger={
              <Button
                content={open ? 
                  'Close TransitionablePortal'
                  'Open TransitionablePortal'}
                negative={open}
                positive={!open}
              />
            }
            onOpen={this.Open}
            onClose={this.Close}
          >
            <Segment
              style={{
                left: '32%',
                position: 'fixed',
                top: '2%',
                zIndex: 1000,
              }}
            >
              <Header><h1>GeeksforGeeks</h1></Header>
              <p>Computer Science Portal</p>
            </Segment>
          </TransitionablePortal>
        </Grid.Column>
      </Grid>
      </div>
    )
  }
}




#gfg {
    margin: 40px;
}

Output:

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


Article Tags :