React Bootstrap Waves effect

React Waves effect - Bootstrap 4 & Material Design

Note: We are transitioning MDB4 to a legacy version and focusing on developing MDB5. While we'll continue to support for the transition period, we encourage you to migrate to MDB5. We're offering a 50% discount on MDB5 PRO to help with your transition, enabling you to leverage the full potential of the latest version. You can find more information here.
get 50% discount on MDB5 PRO

React Bootstrap waves effect is an impression of circular overlay movement, triggered by clicking the object, flowing from the center of the click. By default, waves are added to buttons, masks, and navbar's links as in examples below.


Example

        
            
        import React from "react";
        import { MDBBtn, MDBCardImage } from "mdbreact";

        const WavesPage = () => {
          return (
            <div>
              <MDBBtn color="primary">Click me</MDBBtn>

              <MDBCardImage
                className="img-fluid"
                src="https://mdbootstrap.com/img/Photos/Horizontal/Nature/6-col/img%20(54).webp"
                waves
              />
            </div>
          );
        }

        export default WavesPage;
      
        
    

Customization

You can add waves effect to any element. The Waves component requires object with cursor's time and position. We will have to set up a function and store the cursor information in state.

        
            
        import React from "react";
        import { MDBWaves } from "mdbreact";

        class CustomComponent extends React.Component {
          constructor(props) {
            super(props);
            this.state = {
              cursorPos: {}
            };
          }

          handleClick = e => {
            e.stopPropagation();
            // Waves - Get Cursor Position
            let cursorPos = {
              top: e.clientY,
              left: e.clientX,
              time: Date.now() // time indicates particular clicks
            };
            this.setState({ cursorPos: cursorPos });
          };

          render() {
            return (
              <div
                onMouseUp={this.handleClick}
                onTouchStart={this.handleClick}
              >
                <img src="https://mdbootstrap.com/img/Photos/Horizontal/Nature/6-col/img%20(54).webp" />
                <MDBWaves
                  cursorPos={this.state.cursorPos}
                />
              </div>
            );
          }
        }

        export default CustomComponent;
        
        
    

React Waves effect - API

In this section you will find advanced information about the Waves component. You will find out which modules are required, what are the possibilities of configuring the component, and what events and methods you can use to work with it.


Imports

        
            
      import React from 'react';
      import { MDBWaves } from 'mdbreact';
      
        
    

Usage

Use MDBWaves component as a child of the component on which you want to achieve waves effect.
Add click events to the component to find out the cursor position and pass those information to the Waves component.

        
            
      import React from "react";
      import { MDBWaves } from "mdbreact";

      class CustomComponent extends React.Component {
        constructor(props) {
          super(props);
          this.state = {
            cursorPos: {}
          };
        }

        handleClick = e => {
          e.stopPropagation();
          // Waves - Get Cursor Position
          let cursorPos = {
            top: e.clientY,
            left: e.clientX,
            time: Date.now() // time indicates particular clicks
          };
          this.setState({ cursorPos: cursorPos });
        };

        render() {

          return (
            <div
              onMouseUp={this.handleClick}
              onTouchStart={this.handleClick}
            >
              <img src="https://mdbootstrap.com/img/Photos/Horizontal/Nature/6-col/img%20(54).webp" />
              <MDBWaves
                cursorPos={this.state.cursorPos}
              />
            </div>
          );
        }
      }

      export default CustomComponent;
      
        
    

API Reference: Waves Properties

The table below shows the configuration options of the MDBWaves component.

Name Type Default Description Example
cursorPos Object Required! The position and time of cursor click event. <MDBWaves cursorPos={{ top, left, time }} />
dark Boolean false Change wave color to dark. <MDBWaves cursorPos={this.state.cursorPos} dark />