开发了一个ripple effect组件

目前来看网上的除了material-ui的ripple-effect效果很棒之外,其他的ripple组件都不够完美。git

因此开发了这个ripple effect组件,用svg实现,很容易使用,效果也很舒服。
你们快来试试手,能够提需求或者pr,来支持更多的配置,顺便点个star。github

地址

github地址
github.com/soWhiteSoCo…bash

项目演示
sowhitesocoll.github.io/dodo-ripple…svg

安装

yarn add 'dodo-ripple'
复制代码

使用

直接看成block使用的时候,会认为是一个普通的div。ui

import { RippleBlock } from 'dodo-ripple'

<RippleBlock className="btn">
  Click Here
</RippleBlock>
复制代码

也能够用装饰器的方式,可是只能装饰React Element。this

import { withRipple } from 'dodo-ripple'

const Button = withRipple(
  <button className="btn">Click Here</button>
)
复制代码

若是只使用ripple的话会比较麻烦,须要经过ref组件而后手动触发createRipple,而且须要手动写点样式。spa

import { Ripple } from 'dodo-ripple'

class Button extends React.Component {
  $ripple = React.createRef()

  handleMouseDown = e => {
    this.$ripple.current.createRipple(e)
    this.props.onMouseDown && this.props.onMouseDown(e)
  }

  render() {
    const { children, className, ...rest } = this.props

    return (
      <button 
        {...rest}
        className={classnames('btn', 'do-ripple-block', className)} 
        onMouseDown={this.handleMouseDown} 
      >
        <span className="do-ripple-content">{children}</span>
        <Ripple ref={this.$ripple} rippleColor="#39f"/>
      </button>
    )
  }
}
复制代码
相关文章
相关标签/搜索