开发了一个ripple effect组件

栏目: Android · 发布时间: 6年前

内容简介:目前来看网上的除了material-ui的ripple-effect效果很棒以外,其余的ripple组件都不够完美。所以开发了这个ripple effect组件,用svg实现,很容易使用,效果也很舒服。大家快来试试手,可以提需求或者pr,来支持更多的配置,顺便点个star。

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

所以开发了这个ripple effect组件,用svg实现,很容易使用,效果也很舒服。

大家快来试试手,可以提需求或者pr,来支持更多的配置,顺便点个star。

地址

安装

yarn add 'dodo-ripple'
复制代码

使用

直接当作block使用的时候,会认为是一个普通的div。

import { RippleBlock } from 'dodo-ripple'

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

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

import { withRipple } from 'dodo-ripple'

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

如果只使用ripple的话会比较麻烦,需要通过ref组件然后手动触发createRipple,并且需要手动写点样式。

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>
    )
  }
}
复制代码

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

C++语言的设计和演化

C++语言的设计和演化

[美] Bjarne Stroustrup / 裘宗燕 / 机械工业出版社 / 2002-1 / 48.00元

这本书是C++的设计者关于C++语言的最主要著作之一。作者综合性地论述了C++的历史和发展,C++中各种重要机制的本质意义和设计背景,这些机制的基本用途和使用方法,讨论了C++所适合的应用领域及其未来的发展前景。一起来看看 《C++语言的设计和演化》 这本书的介绍吧!

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器