0.0.4 • Published 6 years ago

react-opium-button v0.0.4

Weekly downloads
11
License
MIT
Repository
github
Last release
6 years ago

react-opium-button

A light-weight react button with inline state indicator.

Codepen demo

Features

  • Automatically generates a darker color from a given solid or gradient color for the hover/focus effect
  • Hover color can also be provided manually
  • Loading indicators with SVG animations
  • Optional different text while loading
  • Success indicator

Installation

npm i react-opium-button

Usage

Basic example

import React, { Component } from 'react';
import Button from 'react-opium-button';
import 'react-opium-button/style.css';

class App extends Component {
  contructor(props) {
    super(props);
    this.state = { buttonState: 'normal' };
  }

  handleClick() {
    console.log('button clicked');
  }

  render() {
    return (
      <div style={{ margin: '200px auto', maxWidth: '400px' }}>
        <Button
          text="Save"
          padding="10px 50px"
          background="#ee0979"
          color="#ffffff"
          state={this.state.buttonState}
          onClick={this.handleClick} />
      </div>
    );
  }
}

export default App;

Advanced usage

Extend the plugin to make your own settings as default.

// ./myModifiedButton.js
import Button from 'react-opium-button';

class myModifiedButton extends Button {
  static defaultProps = {
    background: '#ff0000',
    color: '#2e2e2e',
    dimensions: '100px 40px',
    border: '2px solid #ff0000',
    rounded: true
  }
}

export default myModifiedButton;

Customizations

PropTypeDefaultDescription
textStringClick me!Button text
backgroundString#e8eaebBackground color of the button. It can be solid or gradient color with hex values. It automatically calculates a darker color for hover effect, however, you can also specify a hover color with a '|' separator, e.g. '#ff0000|#000000'
colorString#2e2e2eText color, should be a hex value, optionally specify hover color as '#ff0000|#000000'
dimensionsStringauto autoIf the button needs to be of specific width or height, e.g. 150px 30px
paddingString5pxCSS padding e.g. 10px 50px
borderStringnoneCSS border e.g. 2px solid #e2e3e5
radiusNumber0Border radius
fullBooleanfalseOccupies full width if set true
roundedBooleanfalseMakes the button corners rounded
stateStringnormalButton state: normal, loading or success
loaderTypeStringcircleLoading animation type, it can be set as circle, dots, ripple, disk or gooey
loadingTextStringnullIf set, it will show this text in place of loading animation
onClickFunction-onClick handler