1.0.7 • Published 2 years ago

react-popapka v1.0.7

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

react-popapka

Simple react popup function

NPM JavaScript Style Guide

Install

npm install --save react-popapka

Usage

import React, { Component } from 'react'

import { PopapkaContainer, popapka, closePopapka } from 'react-popapka';
import 'react-popapka/dist/index.css';

class Example extends Component {

  popapka = null

  open = () => {
    this.popapka = popapka({
      title: "this is my modal!!",
      content: (<div>this is content of my modal</div>),
      positiveButton: () => { closePopapka(this.popapka) },
      animation: 'bub'
    })
  }

  render() {
    return (
      <div>
        <PopapkaContainer />
        <button onClick={ this.open }>Open Popapka</button>
      </div>
    )
  }
}

Explain

Place the <PopapkaContainer /> component once into your application tree. It will be used as a wrapper for all modals. Don't forget to import the default styles from react-popapka/dist/index.css

Your component with <PopapkaContainer /> will be like this:

import React, { Component } from 'react'

import { PopapkaContainer } from 'react-popapka';
import 'react-popapka/src/popapka.scss'

class Example extends Component {
  render() {
    return (
      <div>
        <PopapkaContainer />
        // Other components
      </div>
    )
  }
}

Other functions can be called from other components. You don't need to worry about maintaining the global state. Popapka saves its state by itself.

Popapka

Simple usage: Will open a small modal window with just your text

popapka('alert')

Add more functionalities:

popapka({
  title: "this is my modal!!",
  content: (<div>this is content of my modal</div>),
  animation: 'bub'
})

closePopapka

Close popapka by index number of opened popapka. If you only have one popapka, you can simply call closePopapka(0). In complex cases, popapka function return its own index. closePopapka() without parameters will close latest opened popapka.

closeAllPopapka

closeAllPopapka() will close all opened popapka.

API

popapka(parameters, settings);

parameters object:

keytypedefaultDescription
titleStringTitle of popapka. On top of modal and bold highlighted
contentString or jsxMain text
positiveButtonfunctionAdd 'OK' button at bottom with your callback
animationone of the below animationsopacityAnimation for appear and disappear popapka
closeinside, outsidePosition of close button. Will not be displayed if nothing is passed

settings object:

keytypedefaultDescription
classNameStringpopapkaAdd custom class to popapka window

animations list:

typeDescription
opacityFade in with a change in opacity
fromTopA little drop from above
bubAppeared from the center with resizing and opacity

License

MIT © r1ddev

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago