1.1.0 • Published 1 year ago

react-window-open v1.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

react-window-open 👋

A customizable component that opens a new window using the window.open API

Installation

npm i react-window-open

Demo 👀

https://axelmy-projects-showcase.firebaseapp.com/react-window-open

Usage 💻

import React, { useState } from 'react'
import { NewWindow } from 'react-window-open'

const Example = () => {
    const [isOpen, setIsOpen] = useState(false)
    const [counter, setCounter] = useState(0)

    return (
        <>
            <button onClick={() => setIsOpen(!isOpen)}>{!isOpen ? 'Open' : 'Close'}</button>

            {isOpen && <NewWindow onClose={() => setIsOpen(false)}>
                <p>This text is displayed in a new window. 👀</p>
                <p>And all the states are shared ! 👌</p>
                <p>Counter in the new window : {counter}</p>
                <button onClick={() => setCounter(counter+1)}>Increment from the new window</button>
            </NewWindow>}

            <p>Counter on the original page : {counter}</p>
            <button onClick={() => setCounter(counter+1)}>Increment</button>
        </>
    )
}

export default Example

API ✔

Propertiestypedefaultdescription
topint0The bottom offset of the window
bottomint0The top offset of the window
leftint0The left offset of the window
rightint0The right offset of the window
widthint0The width of the window
heightint0The height of the window
titlestring0The title of the new window
onClosefuncA callback function called whenever the window is closed