项目作者: bronsondunbar

项目描述 :
Button component for React [NPM Package]
高级语言: CSS
项目地址: git://github.com/bronsondunbar/library-button-component.git
创建时间: 2018-04-26T13:29:13Z
项目社区:https://github.com/bronsondunbar/library-button-component

开源协议:

下载


Button Component

Button component for React

Install and save component as a dependency

  1. npm install --save library-button-component

Import component into your app

  1. import Button from 'library-button-component'

Create and assign button states with empty values

  1. constructor(props) {
  2. super(props)
  3. this.state = {
  4. buttonAction: '',
  5. buttonCode: '',
  6. buttonText: ''
  7. }
  8. }

Create the function that will handle mouse click events

  1. handleButtonClick(event) {
  2. this.setState ({
  3. buttonAction: 'Click'
  4. });
  5. }

Create the function that will handle mouse hover enter and exit events

  1. handleButtonHoverOver(event) {
  2. this.setState ({
  3. buttonAction: 'Hover',
  4. buttonCode: event.target.innerHTML,
  5. buttonText: event.target.textContent
  6. });
  7. event.target.innerHTML = "Hovering..."
  8. }
  9. handleButtonHoverExit(event) {
  10. event.target.innerHTML = this.state.buttonCode;
  11. }

Render the component with the functions we created as well as any other props that are needed

  1. render () {
  2. return (
  3. <ButtonComponent
  4. buttonCategory="default"
  5. buttonSize="default"
  6. buttonText="Default"
  7. handleButtonClick={this.handleButtonClick.bind(this)}
  8. handleButtonHoverOver={this.handleButtonHoverOver.bind(this)}
  9. handleButtonHoverExit={this.handleButtonHoverExit.bind(this)} ></ButtonComponent>
  10. )
  11. }
Prop Values
buttonCategory default, primary, success, danger, info
buttonSize large
buttonText String
buttonSymbol * Font Awesome class
handleButtonClick handleButtonClick function
handleButtonHoverOver handleButtonHoverOver function
handleButtonHoverExit handleButtonHoverExit function
  • Font Awesome needs to included in project for symbols to display