Code Monkey home page Code Monkey logo

react-ripple's Introduction

React Ripple

React Component to Make Google Material Design Ripple Effect. It's adopted from angular-ripple

DEMO

Install

You can import react-ripple to your react component file like this and process it with your preprocessor.;

You can install it via NPM

npm install react-ripple-effect

Usage

Usage With Predefined Ripple Button

import React from 'react';
import ReactDOM from 'react-dom';

import { RippleButton } from 'react-ripple-effect';

class App extends React.Component {

  render(){
    return(
      <RippleButton>Click On Me!</RippleButton>
    )
  }

}


ReactDOM.render(<App />, document.getElementById("app"))

Usage Standalone Ripple Component

import React from 'react';

import { Ripple } from 'react-ripple-effect';

class RippleButton extends React.Component {

  constructor() {
    super();
    this.state = {
      cursorPos: {}
    }
  }

  render () {
    return (
      <button
        className="Ripple-parent"
        onMouseUp={ this.handleClick.bind(this) }
        onTouchend={ this.handleClick.bind(this) } >
        { this.props.children }
        <Ripple cursorPos={ this.state.cursorPos } />
      </button>
    )
  }

  handleClick(e){
    // Get Cursor Position
    let cursorPos = {
      top: e.clientY,
      left: e.clientX,
      // Prevent Component duplicates do ripple effect at the same time
      time: Date.now()
    }
    this.setState({ cursorPos: cursorPos })
  }

}

export default RippleButton;

Props

cursorPos (Object)

You need to describe the cursor position ( when parent is clicked ) with the structure like the object bellow

let cursorPos = {
  top: e.clientY,
  left: e.clientX,
  // Prevent Component duplicates do ripple effect at the same time
  time: Date.now()
}

Thank You for Making this useful~

Let's talk about some projects with me

Just Contact Me At:

License

MIT Copyright (c) 2016 - forever Naufal Rabbani

react-ripple's People

Contributors

bosnaufal avatar

Watchers

James Cloos avatar Vu Nguyen avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.