Wednesday, July 3, 2024
HomeLanguagesReactReactJS Semantic UI Dimmer Module

ReactJS Semantic UI Dimmer Module

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, JQuery language to incorporate in different frameworks.

In this article, we will know how to use Dimmer Module in ReactJS Semantic UI. Dimmer Module is used to focus the attention of the user on a particular section or a segment of the page.

Properties:

  • Content Dimmer: dimmer can display content.
  • Page Dimmer: A dimmer can be formatted to fixed on the page.

States:

  • Active: It is used to dim its parent container.

 

Syntax:

<Dimmer/>

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: 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: In this example, we have shown a dim effect to focus the attention of the user. This dim effect is shown when the user clicks on the Dim button. The original button to also present to get back to a normal state. 

App.js




import React, { Component } from 'react'
import { Button, Dimmer, Header, Icon } from 'semantic-ui-react'
  
const styleLink = document.createElement("link");
styleLink.rel = "stylesheet";
styleLink.href = 
document.head.appendChild(styleLink);
  
export default class App extends Component {
  state = {}
  
  GetDIM = () => this.setState({ dim: true })
  HideDIM = () => this.setState({ dim: false })
  
  render() {
    const { dim } = this.state
  
    return (
      <div>
        <Dimmer.Dimmable dimmed={dim}>
          <Header as='h3'>neveropen </Header>
          Semantic UI
          <Dimmer active={dim} />
          <br />
          <Icon name='react' size='huge' />
        </Dimmer.Dimmable>
  
        <Button onClick={this.GetDIM} content='Dim' />
        <Button onClick={this.HideDIM} content='Original' />
      </div>
    )
  }
}


Output: 

Example 2: In this example, we have shown a loading effect to focus the attention of the user. This loading effect is shown when the user clicks on the load button. The original button to also present to get back to a normal state. 

App.js




import React, { Component } from 'react'
import { Button, Dimmer, Header, Icon, Loader } from 'semantic-ui-react'
  
const styleLink = document.createElement("link");
styleLink.rel = "stylesheet";
styleLink.href = 
document.head.appendChild(styleLink);
  
export default class App extends Component {
  state = {}
  
  GetDIM = () => this.setState({ dim: true })
  HideDIM = () => this.setState({ dim: false })
  
  render() {
    const { dim } = this.state
  
    return (
      <div>
        <Dimmer.Dimmable dimmed={dim}>
          <Header as='h3'>neveropen </Header>
          Semantic UI
          <Dimmer active={dim} inverted >
            <Loader>Loading</Loader>
          </Dimmer>
          <br />
          <Icon name='react' size='huge' />
        </Dimmer.Dimmable>
  
        <Button onClick={this.GetDIM} content='load' />
        <Button onClick={this.HideDIM} content='Original' />
      </div>
    )
  }
}


Output:

Reference: https://react.semantic-ui.com/modules/dimmer/

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!

Dominic Rubhabha Wardslaus
Dominic Rubhabha Wardslaushttps://neveropen.dev
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments