1.0.4 • Published 5 years ago

react-png-button v1.0.4

Weekly downloads
5
License
MIT
Repository
github
Last release
5 years ago

React Plug-N'-Go Button

react-png-button is a highly customizable & scalable React Component that renders a collection a preset of production ready buttons. This component makes use of the useContext hook API to let the programmer add his or her own desired classes, on top of being able to globally modify all buttons in the application to suit your needs.

NPM JavaScript Style Guide

Install

npm install --save react-png-button

Showcase

Click here to see interactive full showcase

Showcase

Block Buttons

Logo Buttons

Features

  1. A highly customizable, scalable, and production ready component.
  2. Usage of the useContext hook API to offer maximum flexibility.

Context API

By using a Provider, the developer will gain access to extra functionalities, such as more options to globally or specifically customize each button. After setting up the Provider, the developer will have access to the context by accesing it with the useContext API. Below is a table of all the context methods:

MethodArgumentsFunctionality
setGlobalClassName(className: string)setGlobalClassName will set the global button className that serves as the basis of all the buttons from this package, excluding the LogoButtons. Here is the preset global class.
setCustomClassname(classNameKey: string, className: string)setCustomClassname provides the developer with a way to introduce his or her own buttons carrying their respective CSS. Directly below is an example of how to do this, and how to access the custom buttons anywhere in the application.
setStyle(style: React.CSSProperties)setStyle works very similar to setGlobalClassName, by using it the developer may globally set the buton CSS style properties. It's often used when the developer may only want to make small changes to the default class (e.g. changing only the border-radius CSS property).

Below is a code snippet that:

  1. Applies the Provider component to the application.
  2. Makes use of useContext to access the context object.
  3. Usage of setGlobalClassName.
  4. Usage of setCustomClassname.
  5. Usage of setStyle.

index.js

import React from 'react'
import ReactDOM from 'react-dom'
import { Provider } from 'react-png-button'

import './index.css'
import App from './App'

ReactDOM.render(<Provider><App /></Provider>, document.getElementById('root'))

App.js

import React, { useContext, useEffect } from 'react'
// CSS
import classes from './App.module.css'
// JSX
import Button, { Context } from 'react-png-button'

const app = () => {
  const context = useContext(Context)

  const onClick = () => {
    context.setGlobalClassName(classes.Button)
  }

  useEffect(() => {
    context.setStyle({ width: '100%' })
    context.setCustomClassname('custom', classes.Custom)
  }, [])

  return (
    <Button button='primary' onClick={onClick}>Click me!</Button>
    <Button button='custom'>A custom button.</Button>
  )
}

export default app

Props

PropsFunctionality
buttonString type property to
blockButtonBoolean type prop that applies a width of 100% to the button CSS properties.
referenceReact reference RefObject.
onClickFunction type property for the respective event handler.
onMouseEnterFunction type property for the respective event handler.
onMouseLeaveFunction type property for the respective event handler.
disabledBoolean type prop that will disable the button functionality and set a disabled CSS class.
HTML PropertiesHTML button properties such as type, name, value, form, formAction, etc. For more information, check the MDN docs about buttons, react-png-button includes support for all properties.

Basic Usage (Requires React.js v^16.8.0)

Edit React Plug-N'-Go Button

import React, { Component } from 'react'
import Button, { LogoButton } from 'react-png-button'

const component = () => {
    return (
    <Button button='primary'>
      React Plug-N'-Go Button
    </Button>
    <LogoButton button='facebook'>
      Sign up with Facebook type button
    </LogoButton>
  )
}

Global Button CSS Class

.Button {
  position: relative;
  outline: none;
  cursor: pointer;
  font: inherit;
  width: fit-content;
  user-select: none;
  border-width: 1px;
  border-style: solid;
  border-radius: 4px;
  line-height: 1.5;
  font-weight: 600;
  padding: 10px 16px;
  box-shadow: none;
  transition: background-color .1s ease-in-out, border-color .15s ease-in-out,box-shadow .15s ease-in-out, opacity ease 0.15s, transform ease 0.15s;
}

.Button:active {
  transform: scale(0.95);
}

License

MIT © rmolinamir

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.0

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago