0.6.32 • Published 2 years ago

popup-sensor v0.6.32

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

codecov Node.js CI release-please

Installing

Using npm:

npm i --save popup-sensor

Using yarn:

yarn add --dev popup-sensor

Usage

Here are examples of how you can use popup-sensor.

Simply open a popup window

import Popup from 'popup-sensor'

const onClick = () => {
  const popupInstance = new Popup({})

  popupInstance.open({
    title: 'Google',
    url: 'https://www.google.com/',
  })
}

One-liner

import Popup from 'popup-sensor'

const onClick = () => {
  new Popup({}).open({
    title: 'Google',
    url: 'https://www.google.com/',
  })
}

Catch the close event of popup window

import Popup from 'popup-sensor'

const onPopupClose = () => {
  console.log('popup close event')
}

const onClick = () => {
  const popupInstance = new Popup({ onClose: onPopupClose })

  popupInstance.open({
    title: 'Google',
    url: 'https://www.google.com/',
  })
}

One-liner

import Popup from 'popup-sensor'

const onPopupClose = () => {
  console.log('popup close event')
}

const onClick = () => {
  new Popup({ onClose: onPopupClose }).open({
    title: 'Google',
    url: 'https://www.google.com/',
  })
}

Track location and dispatch action

import * as queryString from 'query-string'
import Popup from 'popup-sensor'
import { EPopupAction } from 'popup-sensor/types'

const onLocationChange = (location: Location) => {
  const locationSearch = queryString.parse(location.search)

  return locationSearch.code ? EPopupAction.CLOSE : EPopupAction.NONE
}

const onClick = () => {
  const popupInstance = new Popup({ onLocationChange })

  popupInstance.open({
    title: 'Google',
    url: 'https://www.google.com/',
  })
}

One-liner

import * as queryString from 'query-string'
import Popup from 'popup-sensor'
import { EPopupAction } from 'popup-sensor/types'

const onLocationChange = (location: Location) => {
  return queryString.parse(location.search).code
    ? EPopupAction.CLOSE
    : EPopupAction.NONE
}

const onClick = () => {
  new Popup({ onLocationChange }).open({
    title: 'Google',
    url: 'https://www.google.com/',
  })
}

Running the tests

Tests are written with jest

Unit tests

Using jest:

yarn run test

Deployment

Deployment is done with Travis.

Built With

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Authors

See also the list of contributors who participated in this project.

License

This project is licensed under the MIT License - see the LICENSE.md file for details

0.6.32

2 years ago

0.6.31

2 years ago

0.6.30

2 years ago

0.6.28

3 years ago

0.6.27

4 years ago

0.6.26

4 years ago

0.6.25

4 years ago

0.6.24

4 years ago

0.6.23

4 years ago

0.6.22

4 years ago

0.6.21

4 years ago

0.6.20

4 years ago

0.6.19

4 years ago

0.6.18

4 years ago

0.6.17

4 years ago

0.6.16

4 years ago

0.6.15

4 years ago

0.6.14

4 years ago

0.6.13

4 years ago

0.6.12

4 years ago

0.6.11

4 years ago

0.6.10

4 years ago

0.6.9

4 years ago

0.6.8

4 years ago

0.6.7

4 years ago

0.6.6

4 years ago

0.6.5

4 years ago

0.6.4

4 years ago

0.6.3

4 years ago

0.6.2

4 years ago

0.5.0

4 years ago

0.6.0

4 years ago

0.4.0

4 years ago

0.3.1

4 years ago

0.3.0

4 years ago

0.0.0

4 years ago