├── .babelrc.js ├── .eslintignore ├── .eslintrc ├── .github ├── banner.svg └── workflows │ └── publish.yml ├── .gitignore ├── .nvmrc ├── .prettierrc ├── .storybook ├── addons.js ├── config.js └── preview-head.html ├── .travis.yml ├── LICENSE ├── README.md ├── docs ├── 0.832dfd222af123ce2f31.manager.bundle.js ├── 4.db02a1c3f1659cbe21f6.manager.bundle.js ├── 4.db02a1c3f1659cbe21f6.manager.bundle.js.LICENSE.txt ├── 5.4d53f3bd7dac3d5945b8.manager.bundle.js ├── 5.4d53f3bd7dac3d5945b8.manager.bundle.js.LICENSE.txt ├── 6.8ba05c71d52a3d82cda0.manager.bundle.js ├── 7.318ff74319aa6c7eeb31.manager.bundle.js ├── favicon.ico ├── iframe.html ├── index.html ├── main.1d1e3042.iframe.bundle.js ├── main.1d44ffca4e30d87db952.manager.bundle.js ├── runtime~main.bf4428eb.iframe.bundle.js ├── runtime~main.c70d5de959612a6c5779.manager.bundle.js ├── vendors~main.15124dc5.iframe.bundle.js ├── vendors~main.15124dc5.iframe.bundle.js.LICENSE.txt ├── vendors~main.15124dc5.iframe.bundle.js.map ├── vendors~main.7dd5fda8ce8b35154eed.manager.bundle.js └── vendors~main.7dd5fda8ce8b35154eed.manager.bundle.js.LICENSE.txt ├── package-lock.json ├── package.json ├── rollup.config.js ├── src └── NewWindow.js ├── stories ├── components │ ├── Button.js │ ├── Col.js │ ├── Container.js │ ├── Row.js │ └── TextInput.js ├── default.stories.js ├── features-prop.stories.js ├── prop-close-on-unmount.stories.js ├── text-box.stories.js ├── title-prop.stories.js └── url-prop.stories.js └── types └── NewWindow.d.ts /.babelrc.js: -------------------------------------------------------------------------------- 1 | module.exports = api => { 2 | api.cache(true) 3 | 4 | return { 5 | "presets": ["@babel/preset-env", "@babel/preset-react"], 6 | "plugins": [ 7 | '@babel/plugin-proposal-class-properties', 8 | '@babel/plugin-transform-runtime', 9 | ] 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | es 2 | umd 3 | stories 4 | -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "eslint:recommended", 4 | "plugin:react/recommended" 5 | ], 6 | "plugins": [ 7 | "react", 8 | "prettier" 9 | ], 10 | "rules": { 11 | "prettier/prettier": "error", 12 | "no-console": ["error", { "allow": ["warn", "error"] }] 13 | }, 14 | "parser": "babel-eslint", 15 | "env": { 16 | "browser": true 17 | }, 18 | "settings": { 19 | "react": { 20 | "version": "detect" 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /.github/banner.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.github/workflows/publish.yml: -------------------------------------------------------------------------------- 1 | name: Publish new versions to registry 2 | 3 | on: 4 | create: 5 | tags: 6 | - "v[0-9]+.[0-9]+.[0-9]+-**" 7 | 8 | jobs: 9 | publish: 10 | runs-on: ubuntu-latest 11 | steps: 12 | - uses: actions/checkout@v3 13 | 14 | - name: Setup node 15 | uses: actions/setup-node@v3 16 | with: 17 | node-version-file: ".nvmrc" 18 | registry-url: "https://registry.npmjs.org" 19 | 20 | - name: Get npm cache directory 21 | id: npm-cache-dir 22 | run: | 23 | echo "::set-output name=dir::$(npm config get cache)" 24 | - uses: actions/cache@v3 25 | with: 26 | path: ${{ steps.npm-cache-dir.outputs.dir }} 27 | key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} 28 | restore-keys: | 29 | ${{ runner.os }}-node- 30 | 31 | - name: Install dependencies 32 | run: npm i 33 | 34 | - name: Build assets 35 | run: npm run build 36 | 37 | - name: Publish to registry 38 | env: 39 | NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} 40 | run: npm publish 41 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | es 3 | umd 4 | lib 5 | *.log 6 | -------------------------------------------------------------------------------- /.nvmrc: -------------------------------------------------------------------------------- 1 | v18.12.1 2 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "singleQuote": true, 3 | "semi": false 4 | } 5 | -------------------------------------------------------------------------------- /.storybook/addons.js: -------------------------------------------------------------------------------- 1 | import '@storybook/addon-actions/register'; 2 | import '@storybook/addon-links/register'; 3 | -------------------------------------------------------------------------------- /.storybook/config.js: -------------------------------------------------------------------------------- 1 | import { configure } from '@storybook/react' 2 | 3 | const req = require.context('../stories', true, /\.stories\.js$/) 4 | function loadStories() { 5 | req.keys().forEach(filename => req(filename)) 6 | } 7 | 8 | configure(loadStories, module) -------------------------------------------------------------------------------- /.storybook/preview-head.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "stable" 4 | cache: 5 | directories: 6 | - node_modules 7 | script: 8 | - npm run lint 9 | - npm run build 10 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Rubens Mariuzzo 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![React New Window - Pop new windows in React, using window.open API.](.github/banner.svg)](#features) 2 | 3 | > Inspired by [David Gilbertson's article](https://medium.com/hackernoon/using-a-react-16-portal-to-do-something-cool-2a2d627b0202). 4 | 5 | 6 | 7 | ## Features 8 | 9 | - **Only 3.68KB** (gzipped!). 10 | - **Support the full `window.open` api**. 11 | - **Built for React 16** (uses `ReactDOM.createPortal`). 12 | - **Handler for blocked popups** (via `onBlock` prop). 13 | - **Center popups** according to the parent _window_ or _screen_. 14 | 15 | ## Installation 16 | 17 | ```sh 18 | npm i react-new-window --save 19 | ``` 20 | 21 | ## Usage 22 | 23 | ```js 24 | import React from 'react' 25 | import NewWindow from 'react-new-window' 26 | 27 | const Demo = () => ( 28 | 29 |

Hi 👋

30 |
31 | ) 32 | ``` 33 | 34 | When **``** is mounted a popup window will be opened. When unmounted then the popup will be closed. 35 | 36 | The `children` contents is what will be rendered into the new popup window. In that case `Hi 👋` will be the content. The content can include any react-stateful code. 37 | 38 | ## Documentation 39 | 40 | | Properties | Type | Default | Description | 41 | | ---------------- | --------------------- | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | 42 | | `url` | `String` | ` ` | The URL to open, if specified any `children` will be overriden ([more details on `url`](https://developer.mozilla.org/en-US/docs/Web/API/Window/open)). | 43 | | `name` | `String` | ` ` | The name of the window ([more details on `windowName`](https://developer.mozilla.org/en-US/docs/Web/API/Window/open)). | 44 | | `title` | `String` | ` ` | The title of the new window document. | 45 | | `features` | `Object` | `{}` | The set of window features ([more details on `windowFeatures`](https://developer.mozilla.org/en-US/docs/Web/API/Window/open#Window_features)). | 46 | | `onUnload` | `Function` | `undefined` | A function to be triggered before the new window unload. | 47 | | `onBlock` | `Function` | `undefined` | A function to be triggered when the new window could not be opened. | 48 | | `onOpen` | `Function(w: Window)` | `undefined` | A function to be triggered when window open by library. | 49 | | `center` | `String` | `parent` | Indicate how to center the new window. Valid values are: `parent` or `screen`. `parent` will center the new window according to its _parent_ window. `screen` will center the new window according to the _screen_. | 50 | | `copyStyles` | `Boolean` | `true` | If specified, copy styles from parent window's document. | 51 | | `closeOnUnmount` | `Boolean` | `true` | If specified, close the new window on unmount. | 52 | 53 | ## Tests 54 | 55 | Tests are manually done using Storybook. It can be run locally with: `yarn storybook`. 56 | 57 | ## Development 58 | 59 | To start contributing to this project, please do: 60 | 61 | 1. Fork and clone this repo. 62 | 2. Do your work. 63 | 3. Create a PR. 64 | 65 | ## Releases 66 | 67 | The release process consists of two operations: 68 | 69 | 1. Create new version using: `npm version` 70 | 2. [This GitHub action](.github/workflows/publish.yml) will publish the new version to NPM. 71 | 72 | ### Prior work 73 | 74 | - [react-popout](https://github.com/JakeGinnivan/react-popout). 75 | 76 | --- 77 | 78 |
79 | 80 | Made with :heart: by [Rubens Mariuzzo](https://github.com/rmariuzzo). 81 | 82 | [MIT License](LICENSE) 83 | 84 |
85 | -------------------------------------------------------------------------------- /docs/4.db02a1c3f1659cbe21f6.manager.bundle.js.LICENSE.txt: -------------------------------------------------------------------------------- 1 | /** 2 | * Prism: Lightweight, robust, elegant syntax highlighting 3 | * 4 | * @license MIT 5 | * @author Lea Verou 6 | * @namespace 7 | * @public 8 | */ 9 | -------------------------------------------------------------------------------- /docs/5.4d53f3bd7dac3d5945b8.manager.bundle.js.LICENSE.txt: -------------------------------------------------------------------------------- 1 | /*! 2 | * OverlayScrollbars 3 | * https://github.com/KingSora/OverlayScrollbars 4 | * 5 | * Version: 1.13.0 6 | * 7 | * Copyright KingSora | Rene Haas. 8 | * https://github.com/KingSora 9 | * 10 | * Released under the MIT license. 11 | * Date: 02.08.2020 12 | */ 13 | -------------------------------------------------------------------------------- /docs/6.8ba05c71d52a3d82cda0.manager.bundle.js: -------------------------------------------------------------------------------- 1 | (window.webpackJsonp=window.webpackJsonp||[]).push([[6],{846:function(module,__webpack_exports__,__webpack_require__){"use strict";__webpack_require__.r(__webpack_exports__),__webpack_require__.d(__webpack_exports__,"getScrollAreaStyles",(function(){return getScrollAreaStyles}));__webpack_require__(18),__webpack_require__(56);var _templateObject,react__WEBPACK_IMPORTED_MODULE_2__=__webpack_require__(0),react__WEBPACK_IMPORTED_MODULE_2___default=__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_2__),_storybook_theming__WEBPACK_IMPORTED_MODULE_3__=__webpack_require__(51);var hsResizeObserverDummyAnimation=Object(_storybook_theming__WEBPACK_IMPORTED_MODULE_3__.d)(_templateObject||(_templateObject=function _taggedTemplateLiteral(strings,raw){return raw||(raw=strings.slice(0)),Object.freeze(Object.defineProperties(strings,{raw:{value:Object.freeze(raw)}}))}(["0%{z-index:0}to{z-index:-1}"]))),getScrollAreaStyles=function getScrollAreaStyles(theme){return{"html.os-html, html.os-html>.os-host":{display:"block",overflow:"hidden",boxSizing:"border-box",height:"100%!important",width:"100%!important",minWidth:"100%!important",minHeight:"100%!important",margin:"0!important",position:"absolute!important"},"html.os-html>.os-host>.os-padding":{position:"absolute"},"body.os-dragging, body.os-dragging *":{cursor:"default"},".os-host, .os-host-textarea":{position:"relative",overflow:"visible!important",flexDirection:"column",flexWrap:"nowrap",justifyContent:"flex-start",alignContent:"flex-start",alignItems:"flex-start"},".os-host-flexbox":{overflow:"hidden!important",display:"flex"},".os-host-flexbox>.os-size-auto-observer":{height:"inherit!important"},".os-host-flexbox>.os-content-glue":{flexGrow:1,flexShrink:0},".os-host-flexbox>.os-size-auto-observer, .os-host-flexbox>.os-content-glue":{minHeight:0,minWidth:0,flexGrow:0,flexShrink:1,flexBasis:"auto"},"#os-dummy-scrollbar-size":{position:"fixed",opacity:0,visibility:"hidden",overflow:"scroll",height:500,width:500},"#os-dummy-scrollbar-size>div":{width:"200%",height:"200%",margin:10},"#os-dummy-scrollbar-size, .os-viewport":{},".os-viewport-native-scrollbars-invisible#os-dummy-scrollbar-size, .os-viewport-native-scrollbars-invisible.os-viewport":{scrollbarWidth:"none!important"},".os-viewport-native-scrollbars-invisible#os-dummy-scrollbar-size::-webkit-scrollbar, .os-viewport-native-scrollbars-invisible.os-viewport::-webkit-scrollbar, .os-viewport-native-scrollbars-invisible#os-dummy-scrollbar-size::-webkit-scrollbar-corner, .os-viewport-native-scrollbars-invisible.os-viewport::-webkit-scrollbar-corner":{display:"none!important",width:"0!important",height:"0!important",visibility:"hidden!important",background:"0 0!important"},".os-content-glue":{boxSizing:"inherit",maxHeight:"100%",maxWidth:"100%",width:"100%",pointerEvents:"none"},".os-padding":{boxSizing:"inherit",direction:"inherit",position:"absolute",overflow:"visible",padding:0,margin:0,left:0,top:0,bottom:0,right:0,width:"auto!important",height:"auto!important",zIndex:1},".os-host-overflow>.os-padding":{overflow:"hidden"},".os-viewport":{direction:"inherit!important",boxSizing:"inherit!important",resize:"none!important",outline:"0!important",position:"absolute",overflow:"hidden",top:0,left:0,bottom:0,right:0,padding:0,margin:0},".os-content-arrange":{position:"absolute",zIndex:-1,minHeight:1,minWidth:1,pointerEvents:"none"},".os-content":{direction:"inherit",boxSizing:"border-box!important",position:"relative",display:"block",height:"100%",width:"100%",visibility:"visible"},".os-content:before, .os-content:after":{content:"''",display:"table",width:0,height:0,lineHeight:0,fontSize:0},".os-content>.os-textarea":{boxSizing:"border-box!important",direction:"inherit!important",background:"0 0!important",outline:"0 transparent!important",overflow:"hidden!important",position:"absolute!important",display:"block!important",top:"0!important",left:"0!important",margin:"0!important",borderRadius:"0!important",float:"none!important",filter:"none!important",border:"0!important",resize:"none!important",transform:"none!important",maxWidth:"none!important",maxHeight:"none!important",boxShadow:"none!important",perspective:"none!important",opacity:"1!important",zIndex:"1!important",clip:"auto!important",verticalAlign:"baseline!important",padding:0},".os-host-rtl>.os-padding>.os-viewport>.os-content>.os-textarea":{right:"0!important"},".os-content>.os-textarea-cover":{zIndex:-1,pointerEvents:"none"},".os-content>.os-textarea[wrap=off]":{whiteSpace:"pre!important",margin:"0!important"},".os-text-inherit":{fontFamily:"inherit",fontSize:"inherit",fontWeight:"inherit",fontStyle:"inherit",fontVariant:"inherit",textTransform:"inherit",textDecoration:"inherit",textIndent:"inherit",textAlign:"inherit",textShadow:"inherit",textOverflow:"inherit",letterSpacing:"inherit",wordSpacing:"inherit",lineHeight:"inherit",unicodeBidi:"inherit",direction:"inherit",color:"inherit",cursor:"text"},".os-resize-observer, .os-resize-observer-host":{boxSizing:"inherit",display:"block",opacity:0,position:"absolute",top:0,left:0,height:"100%",width:"100%",overflow:"hidden",pointerEvents:"none",zIndex:-1},".os-resize-observer-host":{padding:"inherit",border:"inherit",borderColor:"transparent",borderStyle:"solid",boxSizing:"border-box"},".os-resize-observer-host:after":{content:"''"},".os-resize-observer-host>.os-resize-observer, .os-resize-observer-host:after":{height:"200%",width:"200%",padding:"inherit",border:"inherit",margin:0,display:"block",boxSizing:"content-box"},".os-resize-observer.observed, object.os-resize-observer":{boxSizing:"border-box!important"},".os-size-auto-observer":{boxSizing:"inherit!important",height:"100%",width:"inherit",maxWidth:1,position:"relative",float:"left",maxHeight:1,overflow:"hidden",zIndex:-1,padding:0,margin:0,pointerEvents:"none",flexGrow:"inherit",flexShrink:0,flexBasis:0},".os-size-auto-observer>.os-resize-observer":{width:"1000%",height:"1000%",minHeight:1,minWidth:1},".os-resize-observer-item":{position:"absolute",top:0,right:0,bottom:0,left:0,overflow:"hidden",zIndex:-1,opacity:0,direction:"ltr!important",flex:"none!important"},".os-resize-observer-item-final":{position:"absolute",left:0,top:0,transition:"none!important",flex:"none!important"},".os-resize-observer":{animationDuration:".001s",animationName:"".concat(hsResizeObserverDummyAnimation)},".os-host-transition>.os-scrollbar, .os-host-transition>.os-scrollbar-corner":{transition:"opacity .3s,visibility .3s,top .3s,right .3s,bottom .3s,left .3s"},"html.os-html>.os-host>.os-scrollbar":{position:"absolute",zIndex:999999},".os-scrollbar, .os-scrollbar-corner":{position:"absolute",opacity:1,zIndex:1},".os-scrollbar-corner":{bottom:0,right:0,height:10,width:10,backgroundColor:"transparent"},".os-scrollbar":{pointerEvents:"none",padding:2,boxSizing:"border-box",background:0},".os-scrollbar-track":{pointerEvents:"auto",position:"relative",height:"100%",width:"100%",padding:"0!important",border:"0!important"},".os-scrollbar-handle":{pointerEvents:"auto",position:"absolute",width:"100%",height:"100%"},".os-scrollbar-handle-off, .os-scrollbar-track-off":{pointerEvents:"none"},".os-scrollbar.os-scrollbar-unusable, .os-scrollbar.os-scrollbar-unusable *":{pointerEvents:"none!important"},".os-scrollbar.os-scrollbar-unusable .os-scrollbar-handle":{opacity:"0!important"},".os-scrollbar-horizontal":{bottom:0,left:0,right:10,height:10},".os-scrollbar-vertical":{top:0,right:0,bottom:10,width:10},".os-host-rtl>.os-scrollbar-horizontal":{right:0},".os-host-rtl>.os-scrollbar-vertical":{right:"auto",left:0},".os-host-rtl>.os-scrollbar-corner":{right:"auto",left:0},".os-scrollbar-auto-hidden, .os-padding+.os-scrollbar-corner, .os-host-resize-disabled.os-host-scrollbar-horizontal-hidden>.os-scrollbar-corner, .os-host-scrollbar-horizontal-hidden>.os-scrollbar-horizontal, .os-host-resize-disabled.os-host-scrollbar-vertical-hidden>.os-scrollbar-corner, .os-host-scrollbar-vertical-hidden>.os-scrollbar-vertical, .os-scrollbar-horizontal.os-scrollbar-auto-hidden+.os-scrollbar-vertical+.os-scrollbar-corner, .os-scrollbar-horizontal+.os-scrollbar-vertical.os-scrollbar-auto-hidden+.os-scrollbar-corner, .os-scrollbar-horizontal.os-scrollbar-auto-hidden+.os-scrollbar-vertical.os-scrollbar-auto-hidden+.os-scrollbar-corner":{opacity:0,visibility:"hidden",pointerEvents:"none"},".os-scrollbar-corner-resize-both":{cursor:"nwse-resize"},".os-host-rtl>.os-scrollbar-corner-resize-both":{cursor:"nesw-resize"},".os-scrollbar-corner-resize-horizontal":{cursor:"ew-resize"},".os-scrollbar-corner-resize-vertical":{cursor:"ns-resize"},".os-dragging .os-scrollbar-corner.os-scrollbar-corner-resize":{cursor:"default"},".os-host-resize-disabled.os-host-scrollbar-horizontal-hidden>.os-scrollbar-vertical":{top:0,bottom:0},".os-host-resize-disabled.os-host-scrollbar-vertical-hidden>.os-scrollbar-horizontal, .os-host-rtl.os-host-resize-disabled.os-host-scrollbar-vertical-hidden>.os-scrollbar-horizontal":{right:0,left:0},".os-scrollbar:hover, .os-scrollbar-corner.os-scrollbar-corner-resize":{opacity:"1!important",visibility:"visible!important"},".os-scrollbar-corner.os-scrollbar-corner-resize":{backgroundImage:"linear-gradient(135deg, rgba(0,0,0,0) 0%, rgba(0,0,0,0) 50%, rgba(0,0,0,0.4) 50%, rgba(0,0,0,0.4) 100%)",backgroundRepeat:"no-repeat",backgroundPosition:"100% 100%",pointerEvents:"auto!important"},".os-host-rtl>.os-scrollbar-corner.os-scrollbar-corner-resize":{transform:"scale(-1,1)"},".os-host-overflow":{overflow:"hidden!important"},".os-theme-dark.os-host-rtl>.os-scrollbar-horizontal":{left:10,right:0},".os-scrollbar.os-scrollbar-unusable":{background:0},".os-scrollbar>.os-scrollbar-track":{background:0},".os-scrollbar-horizontal>.os-scrollbar-track>.os-scrollbar-handle":{minWidth:30},".os-scrollbar-vertical>.os-scrollbar-track>.os-scrollbar-handle":{minHeight:30},".os-theme-dark.os-host-transition>.os-scrollbar>.os-scrollbar-track>.os-scrollbar-handle":{transition:"background-color .3s"},".os-scrollbar>.os-scrollbar-track>.os-scrollbar-handle, .os-scrollbar>.os-scrollbar-track":{borderRadius:10},".os-scrollbar>.os-scrollbar-track>.os-scrollbar-handle":{background:theme.color.darker,opacity:.5},".os-scrollbar:hover>.os-scrollbar-track>.os-scrollbar-handle":{opacity:.6},".os-scrollbar-horizontal .os-scrollbar-handle:before, .os-scrollbar-vertical .os-scrollbar-handle:before":{content:"''",position:"absolute",left:0,right:0,top:0,bottom:0,display:"block"},".os-theme-dark.os-host-scrollbar-horizontal-hidden>.os-scrollbar-horizontal .os-scrollbar-handle:before, .os-theme-dark.os-host-scrollbar-vertical-hidden>.os-scrollbar-vertical .os-scrollbar-handle:before":{display:"none"},".os-scrollbar-horizontal .os-scrollbar-handle:before":{top:-6,bottom:-2},".os-scrollbar-vertical .os-scrollbar-handle:before":{left:-6,right:-2},".os-host-rtl.os-scrollbar-vertical .os-scrollbar-handle:before":{right:-6,left:-2}}},GlobalScrollAreaStyles=function GlobalScrollAreaStyles(){return react__WEBPACK_IMPORTED_MODULE_2___default.a.createElement(_storybook_theming__WEBPACK_IMPORTED_MODULE_3__.a,{styles:getScrollAreaStyles})};GlobalScrollAreaStyles.displayName="GlobalScrollAreaStyles",__webpack_exports__.default=GlobalScrollAreaStyles}}]); -------------------------------------------------------------------------------- /docs/7.318ff74319aa6c7eeb31.manager.bundle.js: -------------------------------------------------------------------------------- 1 | (window.webpackJsonp=window.webpackJsonp||[]).push([[7],{903:function(module,exports){module.exports=function(e,n){return n=n||{},new Promise((function(t,r){var s=new XMLHttpRequest,o=[],u=[],i={},a=function(){return{ok:2==(s.status/100|0),statusText:s.statusText,status:s.status,url:s.responseURL,text:function(){return Promise.resolve(s.responseText)},json:function(){return Promise.resolve(s.responseText).then(JSON.parse)},blob:function(){return Promise.resolve(new Blob([s.response]))},clone:a,headers:{keys:function(){return o},entries:function(){return u},get:function(e){return i[e.toLowerCase()]},has:function(e){return e.toLowerCase()in i}}}};for(var l in s.open(n.method||"get",e,!0),s.onload=function(){s.getAllResponseHeaders().replace(/^(.*?):[^\S\n]*([\s\S]*?)$/gm,(function(e,n,t){o.push(n=n.toLowerCase()),u.push([n,t]),i[n]=i[n]?i[n]+","+t:t})),t(a())},s.onerror=r,s.withCredentials="include"==n.credentials,n.headers)s.setRequestHeader(l,n.headers[l]);s.send(n.body||null)}))}}}]); -------------------------------------------------------------------------------- /docs/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rmariuzzo/react-new-window/2e576d739e9a1a2df2752d00355ee5bcf8c5385a/docs/favicon.ico -------------------------------------------------------------------------------- /docs/iframe.html: -------------------------------------------------------------------------------- 1 | Storybook

No Preview

Sorry, but you either have no stories or none are selected somehow.

  • Please check the Storybook config.
  • Try reloading the page.

If the problem persists, check the browser console, or the terminal you've run Storybook from.

-------------------------------------------------------------------------------- /docs/index.html: -------------------------------------------------------------------------------- 1 | Storybook
-------------------------------------------------------------------------------- /docs/main.1d1e3042.iframe.bundle.js: -------------------------------------------------------------------------------- 1 | (window.webpackJsonp=window.webpackJsonp||[]).push([[0],{125:function(module,__webpack_exports__,__webpack_require__){"use strict";__webpack_require__(679),__webpack_require__(3);var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_2__=__webpack_require__(0),Col=function Col(_ref){var children=_ref.children,small=_ref.small,medium=_ref.medium,large=_ref.large,extra=_ref.extra,className="col";return className+=small?" s"+small:"",className+=medium?" m"+medium:"",className+=large?" l"+large:"",className+=extra?" x"+extra:"",Object(react_jsx_runtime__WEBPACK_IMPORTED_MODULE_2__.jsx)("div",{className:className,children:children})};Col.displayName="Col",Col.__docgenInfo={description:"",methods:[],displayName:"Col"},__webpack_exports__.a=Col,"undefined"!=typeof STORYBOOK_REACT_CLASSES&&(STORYBOOK_REACT_CLASSES["stories/components/Col.js"]={name:"Col",docgenInfo:Col.__docgenInfo,path:"stories/components/Col.js"})},224:function(module,__webpack_exports__,__webpack_require__){"use strict";__webpack_require__.r(__webpack_exports__),function(module){__webpack_require__(219),__webpack_require__(46),__webpack_require__(21),__webpack_require__(26),__webpack_require__(28);var _storybook_react__WEBPACK_IMPORTED_MODULE_5__=__webpack_require__(36),req=__webpack_require__(667);Object(_storybook_react__WEBPACK_IMPORTED_MODULE_5__.configure)((function loadStories(){req.keys().forEach((function(filename){return req(filename)}))}),module)}.call(this,__webpack_require__(66)(module))},352:function(module,__webpack_exports__,__webpack_require__){"use strict";__webpack_require__(3);var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_1__=__webpack_require__(0),Row=function Row(_ref){var children=_ref.children;return Object(react_jsx_runtime__WEBPACK_IMPORTED_MODULE_1__.jsx)("div",{className:"row",children:children})};Row.displayName="Row",Row.__docgenInfo={description:"",methods:[],displayName:"Row"},__webpack_exports__.a=Row,"undefined"!=typeof STORYBOOK_REACT_CLASSES&&(STORYBOOK_REACT_CLASSES["stories/components/Row.js"]={name:"Row",docgenInfo:Row.__docgenInfo,path:"stories/components/Row.js"})},354:function(module,exports,__webpack_require__){__webpack_require__(355),__webpack_require__(510),__webpack_require__(511),module.exports=__webpack_require__(662)},42:function(module,__webpack_exports__,__webpack_require__){"use strict";var _babel_runtime_helpers_objectWithoutProperties__WEBPACK_IMPORTED_MODULE_0__=__webpack_require__(162),_babel_runtime_helpers_objectWithoutProperties__WEBPACK_IMPORTED_MODULE_0___default=__webpack_require__.n(_babel_runtime_helpers_objectWithoutProperties__WEBPACK_IMPORTED_MODULE_0__),react_jsx_runtime__WEBPACK_IMPORTED_MODULE_3__=(__webpack_require__(31),__webpack_require__(3),__webpack_require__(0)),_excluded=["children"],Button=function Button(_ref){var children=_ref.children,otherProps=_babel_runtime_helpers_objectWithoutProperties__WEBPACK_IMPORTED_MODULE_0___default()(_ref,_excluded);return Object(react_jsx_runtime__WEBPACK_IMPORTED_MODULE_3__.jsx)("button",Object.assign({className:"waves-effect waves-light btn"},otherProps,{children:children}))};Button.displayName="Button",Button.__docgenInfo={description:"",methods:[],displayName:"Button"},__webpack_exports__.a=Button,"undefined"!=typeof STORYBOOK_REACT_CLASSES&&(STORYBOOK_REACT_CLASSES["stories/components/Button.js"]={name:"Button",docgenInfo:Button.__docgenInfo,path:"stories/components/Button.js"})},421:function(module,exports){},48:function(module,__webpack_exports__,__webpack_require__){"use strict";__webpack_require__(81);var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_1__=__webpack_require__(38),_babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_1___default=__webpack_require__.n(_babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_1__),_babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_2__=__webpack_require__(39),_babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_2___default=__webpack_require__.n(_babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_2__),_babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_3__=__webpack_require__(40),_babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_3___default=__webpack_require__.n(_babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_3__),_babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_4__=__webpack_require__(41),_babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_4___default=__webpack_require__.n(_babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_4__),_babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_5__=__webpack_require__(20),_babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_5___default=__webpack_require__.n(_babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_5__),react__WEBPACK_IMPORTED_MODULE_21__=(__webpack_require__(24),__webpack_require__(334),__webpack_require__(219),__webpack_require__(46),__webpack_require__(57),__webpack_require__(29),__webpack_require__(103),__webpack_require__(104),__webpack_require__(153),__webpack_require__(69),__webpack_require__(151),__webpack_require__(62),__webpack_require__(32),__webpack_require__(100),__webpack_require__(45),__webpack_require__(3)),react__WEBPACK_IMPORTED_MODULE_21___default=__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_21__),react_dom__WEBPACK_IMPORTED_MODULE_22__=__webpack_require__(73),react_dom__WEBPACK_IMPORTED_MODULE_22___default=__webpack_require__.n(react_dom__WEBPACK_IMPORTED_MODULE_22__),prop_types__WEBPACK_IMPORTED_MODULE_23__=__webpack_require__(51),prop_types__WEBPACK_IMPORTED_MODULE_23___default=__webpack_require__.n(prop_types__WEBPACK_IMPORTED_MODULE_23__);function _createSuper(Derived){var hasNativeReflectConstruct=function _isNativeReflectConstruct(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function _createSuperInternal(){var result,Super=_babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_5___default()(Derived);if(hasNativeReflectConstruct){var NewTarget=_babel_runtime_helpers_getPrototypeOf__WEBPACK_IMPORTED_MODULE_5___default()(this).constructor;result=Reflect.construct(Super,arguments,NewTarget)}else result=Super.apply(this,arguments);return _babel_runtime_helpers_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_4___default()(this,result)}}var NewWindow=function(_React$PureComponent){_babel_runtime_helpers_inherits__WEBPACK_IMPORTED_MODULE_3___default()(NewWindow,_React$PureComponent);var _super=_createSuper(NewWindow);function NewWindow(props){var _this;return _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_1___default()(this,NewWindow),(_this=_super.call(this,props)).container=null,_this.window=null,_this.windowCheckerInterval=null,_this.released=!1,_this.state={mounted:!1},_this}return _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_2___default()(NewWindow,[{key:"render",value:function render(){return this.state.mounted?react_dom__WEBPACK_IMPORTED_MODULE_22___default.a.createPortal(this.props.children,this.container):null}},{key:"componentDidMount",value:function componentDidMount(){this.window||this.container||(this.openChild(),this.setState({mounted:!0}))}},{key:"openChild",value:function openChild(){var _this2=this,_this$props=this.props,url=_this$props.url,title=_this$props.title,name=_this$props.name,features=_this$props.features,onBlock=_this$props.onBlock,onOpen=_this$props.onOpen,center=_this$props.center;if("string"!=typeof center||void 0!==features.width&&void 0!==features.height){if("parent"===center)features.left=window.top.outerWidth/2+window.top.screenX-features.width/2,features.top=window.top.outerHeight/2+window.top.screenY-features.height/2;else if("screen"===center){var screenLeft=void 0!==window.screenLeft?window.screenLeft:window.screen.left,screenTop=void 0!==window.screenTop?window.screenTop:window.screen.top,width=window.innerWidth?window.innerWidth:document.documentElement.clientWidth?document.documentElement.clientWidth:window.screen.width,height=window.innerHeight?window.innerHeight:document.documentElement.clientHeight?document.documentElement.clientHeight:window.screen.height;features.left=width/2-features.width/2+screenLeft,features.top=height/2-features.height/2+screenTop}}else console.warn("width and height window features must be present when a center prop is provided");if(this.window=window.open(url,name,function toWindowFeatures(obj){return Object.keys(obj).reduce((function(features,name){var value=obj[name];return"boolean"==typeof value?features.push(name+"="+(value?"yes":"no")):features.push(name+"="+value),features}),[]).join(",")}(features)),this.container=this.window.document.createElement("div"),this.windowCheckerInterval=setInterval((function(){_this2.window&&!_this2.window.closed||_this2.release()}),50),this.window){if(this.window.document.title=title,this.container=this.window.document.getElementById("new-window-container"),null===this.container)this.container=this.window.document.createElement("div"),this.container.setAttribute("id","new-window-container"),this.window.document.body.appendChild(this.container);else{var staticContainer=this.window.document.getElementById("new-window-container-static");this.window.document.body.removeChild(staticContainer)}this.props.copyStyles&&setTimeout((function(){return function copyStyles(source,target){var headFrag=target.createDocumentFragment();Array.from(source.styleSheets).forEach((function(styleSheet){var rules;try{rules=styleSheet.cssRules}catch(err){console.error(err)}if(rules){var ruleText=[];Array.from(styleSheet.cssRules).forEach((function(cssRule){var type=cssRule.type;if(type!==CSSRule.UNKNOWN_RULE){var returnText="";returnText=type===CSSRule.KEYFRAMES_RULE?function getKeyFrameText(cssRule){var tokens=["@keyframes",cssRule.name,"{"];return Array.from(cssRule.cssRules).forEach((function(cssRule){tokens.push(cssRule.keyText,"{",cssRule.style.cssText,"}")})),tokens.push("}"),tokens.join(" ")}(cssRule):[CSSRule.IMPORT_RULE,CSSRule.FONT_FACE_RULE].includes(type)?function fixUrlForRule(cssRule){return cssRule.cssText.split("url(").map((function(line){return"/"===line[1]?""+line.slice(0,1)+window.location.origin+line.slice(1):line})).join("url(")}(cssRule):cssRule.cssText,ruleText.push(returnText)}}));var newStyleEl=target.createElement("style");newStyleEl.textContent=ruleText.join("\n"),headFrag.appendChild(newStyleEl)}else if(styleSheet.href){var newLinkEl=target.createElement("link");newLinkEl.rel="stylesheet",newLinkEl.href=styleSheet.href,headFrag.appendChild(newLinkEl)}})),target.head.appendChild(headFrag)}(document,_this2.window.document)}),0),"function"==typeof onOpen&&onOpen(this.window),this.window.addEventListener("beforeunload",(function(){return _this2.release()}))}else"function"==typeof onBlock?onBlock(null):console.warn("A new window could not be opened. Maybe it was blocked.")}},{key:"componentWillUnmount",value:function componentWillUnmount(){if(this.state.mounted&&this.window)if(this.props.closeOnUnmount)this.window.close();else if(this.props.children){var clone=this.container.cloneNode(!0);clone.setAttribute("id","new-window-container-static"),this.window.document.body.appendChild(clone)}}},{key:"release",value:function release(){if(!this.released){this.released=!0,clearInterval(this.windowCheckerInterval);var onUnload=this.props.onUnload;"function"==typeof onUnload&&onUnload(null)}}}]),NewWindow}(react__WEBPACK_IMPORTED_MODULE_21___default.a.PureComponent);NewWindow.defaultProps={url:"",name:"",title:"",features:{width:"600px",height:"640px"},onBlock:null,onOpen:null,onUnload:null,center:"parent",copyStyles:!0,closeOnUnmount:!0},NewWindow.propTypes={children:prop_types__WEBPACK_IMPORTED_MODULE_23___default.a.node,url:prop_types__WEBPACK_IMPORTED_MODULE_23___default.a.string,name:prop_types__WEBPACK_IMPORTED_MODULE_23___default.a.string,title:prop_types__WEBPACK_IMPORTED_MODULE_23___default.a.string,features:prop_types__WEBPACK_IMPORTED_MODULE_23___default.a.object,onUnload:prop_types__WEBPACK_IMPORTED_MODULE_23___default.a.func,onBlock:prop_types__WEBPACK_IMPORTED_MODULE_23___default.a.func,onOpen:prop_types__WEBPACK_IMPORTED_MODULE_23___default.a.func,center:prop_types__WEBPACK_IMPORTED_MODULE_23___default.a.oneOf(["parent","screen"]),copyStyles:prop_types__WEBPACK_IMPORTED_MODULE_23___default.a.bool,closeOnUnmount:prop_types__WEBPACK_IMPORTED_MODULE_23___default.a.bool},NewWindow.__docgenInfo={description:"The NewWindow class object.\n@public",methods:[{name:"openChild",docblock:"Create the new window when NewWindow component mount.",modifiers:[],params:[],returns:null,description:"Create the new window when NewWindow component mount."},{name:"release",docblock:"Release the new window and anything that was bound to it.",modifiers:[],params:[],returns:null,description:"Release the new window and anything that was bound to it."}],displayName:"NewWindow",props:{url:{defaultValue:{value:"''",computed:!1},type:{name:"string"},required:!1,description:""},name:{defaultValue:{value:"''",computed:!1},type:{name:"string"},required:!1,description:""},title:{defaultValue:{value:"''",computed:!1},type:{name:"string"},required:!1,description:""},features:{defaultValue:{value:"{ width: '600px', height: '640px' }",computed:!1},type:{name:"object"},required:!1,description:""},onBlock:{defaultValue:{value:"null",computed:!1},type:{name:"func"},required:!1,description:""},onOpen:{defaultValue:{value:"null",computed:!1},type:{name:"func"},required:!1,description:""},onUnload:{defaultValue:{value:"null",computed:!1},type:{name:"func"},required:!1,description:""},center:{defaultValue:{value:"'parent'",computed:!1},type:{name:"enum",value:[{value:"'parent'",computed:!1},{value:"'screen'",computed:!1}]},required:!1,description:""},copyStyles:{defaultValue:{value:"true",computed:!1},type:{name:"bool"},required:!1,description:""},closeOnUnmount:{defaultValue:{value:"true",computed:!1},type:{name:"bool"},required:!1,description:""},children:{type:{name:"node"},required:!1,description:""}}},__webpack_exports__.a=NewWindow,"undefined"!=typeof STORYBOOK_REACT_CLASSES&&(STORYBOOK_REACT_CLASSES["src/NewWindow.js"]={name:"NewWindow",docgenInfo:NewWindow.__docgenInfo,path:"src/NewWindow.js"})},49:function(module,__webpack_exports__,__webpack_require__){"use strict";__webpack_require__(3);var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_1__=__webpack_require__(0),Container=function Container(_ref){var children=_ref.children;return Object(react_jsx_runtime__WEBPACK_IMPORTED_MODULE_1__.jsx)("div",{className:"container",children:children})};Container.displayName="Container",Container.__docgenInfo={description:"",methods:[],displayName:"Container"},__webpack_exports__.a=Container,"undefined"!=typeof STORYBOOK_REACT_CLASSES&&(STORYBOOK_REACT_CLASSES["stories/components/Container.js"]={name:"Container",docgenInfo:Container.__docgenInfo,path:"stories/components/Container.js"})},511:function(module,__webpack_exports__,__webpack_require__){"use strict";__webpack_require__.r(__webpack_exports__);__webpack_require__(36)},662:function(module,__webpack_exports__,__webpack_require__){"use strict";__webpack_require__.r(__webpack_exports__);__webpack_require__(45),__webpack_require__(25),__webpack_require__(88),__webpack_require__(663),__webpack_require__(219),__webpack_require__(46),__webpack_require__(664),__webpack_require__(665),__webpack_require__(666);var _Users_rmariuzzo_Documents_Code_react_new_window_node_modules_storybook_client_api__WEBPACK_IMPORTED_MODULE_9__=__webpack_require__(91),_Users_rmariuzzo_Documents_Code_react_new_window_node_modules_storybook_client_logger__WEBPACK_IMPORTED_MODULE_10__=__webpack_require__(2),_Users_rmariuzzo_Documents_Code_react_new_window_storybook_config_js__WEBPACK_IMPORTED_MODULE_11__=__webpack_require__(224);function ownKeys(object,enumerableOnly){var keys=Object.keys(object);if(Object.getOwnPropertySymbols){var symbols=Object.getOwnPropertySymbols(object);enumerableOnly&&(symbols=symbols.filter((function(sym){return Object.getOwnPropertyDescriptor(object,sym).enumerable}))),keys.push.apply(keys,symbols)}return keys}function _defineProperty(obj,key,value){return key in obj?Object.defineProperty(obj,key,{value:value,enumerable:!0,configurable:!0,writable:!0}):obj[key]=value,obj}Object.keys(_Users_rmariuzzo_Documents_Code_react_new_window_storybook_config_js__WEBPACK_IMPORTED_MODULE_11__).forEach((function(key){var value=_Users_rmariuzzo_Documents_Code_react_new_window_storybook_config_js__WEBPACK_IMPORTED_MODULE_11__[key];switch(key){case"args":case"argTypes":return _Users_rmariuzzo_Documents_Code_react_new_window_node_modules_storybook_client_logger__WEBPACK_IMPORTED_MODULE_10__.a.warn("Invalid args/argTypes in config, ignoring.",JSON.stringify(value));case"decorators":return value.forEach((function(decorator){return Object(_Users_rmariuzzo_Documents_Code_react_new_window_node_modules_storybook_client_api__WEBPACK_IMPORTED_MODULE_9__.c)(decorator,!1)}));case"loaders":return value.forEach((function(loader){return Object(_Users_rmariuzzo_Documents_Code_react_new_window_node_modules_storybook_client_api__WEBPACK_IMPORTED_MODULE_9__.d)(loader,!1)}));case"parameters":return Object(_Users_rmariuzzo_Documents_Code_react_new_window_node_modules_storybook_client_api__WEBPACK_IMPORTED_MODULE_9__.e)(function _objectSpread(target){for(var i=1;i 25 | * 26 | * Copyright (c) 2014-2017, Jon Schlinkert. 27 | * Released under the MIT License. 28 | */ 29 | 30 | /** 31 | * Checks if an event is supported in the current execution environment. 32 | * 33 | * NOTE: This will not work correctly for non-generic events such as `change`, 34 | * `reset`, `load`, `error`, and `select`. 35 | * 36 | * Borrows from Modernizr. 37 | * 38 | * @param {string} eventNameSuffix Event name, e.g. "click". 39 | * @return {boolean} True if the event is supported. 40 | * @internal 41 | * @license Modernizr 3.0.0pre (Custom Build) | MIT 42 | */ 43 | 44 | /** @license React v0.19.1 45 | * scheduler-tracing.development.js 46 | * 47 | * Copyright (c) Facebook, Inc. and its affiliates. 48 | * 49 | * This source code is licensed under the MIT license found in the 50 | * LICENSE file in the root directory of this source tree. 51 | */ 52 | 53 | /** @license React v0.19.1 54 | * scheduler.development.js 55 | * 56 | * Copyright (c) Facebook, Inc. and its affiliates. 57 | * 58 | * This source code is licensed under the MIT license found in the 59 | * LICENSE file in the root directory of this source tree. 60 | */ 61 | 62 | /** @license React v16.14.0 63 | * react-dom.development.js 64 | * 65 | * Copyright (c) Facebook, Inc. and its affiliates. 66 | * 67 | * This source code is licensed under the MIT license found in the 68 | * LICENSE file in the root directory of this source tree. 69 | */ 70 | 71 | /** @license React v16.14.0 72 | * react-jsx-runtime.development.js 73 | * 74 | * Copyright (c) Facebook, Inc. and its affiliates. 75 | * 76 | * This source code is licensed under the MIT license found in the 77 | * LICENSE file in the root directory of this source tree. 78 | */ 79 | 80 | /** @license React v16.14.0 81 | * react.development.js 82 | * 83 | * Copyright (c) Facebook, Inc. and its affiliates. 84 | * 85 | * This source code is licensed under the MIT license found in the 86 | * LICENSE file in the root directory of this source tree. 87 | */ 88 | 89 | /** @license React v16.8.6 90 | * react-is.development.js 91 | * 92 | * Copyright (c) Facebook, Inc. and its affiliates. 93 | * 94 | * This source code is licensed under the MIT license found in the 95 | * LICENSE file in the root directory of this source tree. 96 | */ 97 | 98 | //! stable.js 0.1.8, https://github.com/Two-Screen/stable 99 | 100 | //! © 2018 Angry Bytes and contributors. MIT licensed. 101 | -------------------------------------------------------------------------------- /docs/vendors~main.15124dc5.iframe.bundle.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"vendors~main.15124dc5.iframe.bundle.js","sources":[],"mappings":";A","sourceRoot":""} -------------------------------------------------------------------------------- /docs/vendors~main.7dd5fda8ce8b35154eed.manager.bundle.js.LICENSE.txt: -------------------------------------------------------------------------------- 1 | /* 2 | object-assign 3 | (c) Sindre Sorhus 4 | @license MIT 5 | */ 6 | 7 | /*! 8 | * Fuse.js v3.6.1 - Lightweight fuzzy-search (http://fusejs.io) 9 | * 10 | * Copyright (c) 2012-2017 Kirollos Risk (http://kiro.me) 11 | * All Rights Reserved. Apache Software License 2.0 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | */ 15 | 16 | /*! 17 | * https://github.com/es-shims/es5-shim 18 | * @license es5-shim Copyright 2009-2020 by contributors, MIT License 19 | * see https://github.com/es-shims/es5-shim/blob/master/LICENSE 20 | */ 21 | 22 | /*! 23 | * https://github.com/paulmillr/es6-shim 24 | * @license es6-shim Copyright 2013-2016 by Paul Miller (http://paulmillr.com) 25 | * and contributors, MIT License 26 | * es6-shim: v0.35.4 27 | * see https://github.com/paulmillr/es6-shim/blob/0.35.3/LICENSE 28 | * Details and documentation: 29 | * https://github.com/paulmillr/es6-shim/ 30 | */ 31 | 32 | /*! 33 | * isobject 34 | * 35 | * Copyright (c) 2014-2017, Jon Schlinkert. 36 | * Released under the MIT License. 37 | */ 38 | 39 | /** 40 | * Checks if an event is supported in the current execution environment. 41 | * 42 | * NOTE: This will not work correctly for non-generic events such as `change`, 43 | * `reset`, `load`, `error`, and `select`. 44 | * 45 | * Borrows from Modernizr. 46 | * 47 | * @param {string} eventNameSuffix Event name, e.g. "click". 48 | * @return {boolean} True if the event is supported. 49 | * @internal 50 | * @license Modernizr 3.0.0pre (Custom Build) | MIT 51 | */ 52 | 53 | /** @license React v0.19.1 54 | * scheduler-tracing.development.js 55 | * 56 | * Copyright (c) Facebook, Inc. and its affiliates. 57 | * 58 | * This source code is licensed under the MIT license found in the 59 | * LICENSE file in the root directory of this source tree. 60 | */ 61 | 62 | /** @license React v0.19.1 63 | * scheduler.development.js 64 | * 65 | * Copyright (c) Facebook, Inc. and its affiliates. 66 | * 67 | * This source code is licensed under the MIT license found in the 68 | * LICENSE file in the root directory of this source tree. 69 | */ 70 | 71 | /** @license React v16.14.0 72 | * react-dom.development.js 73 | * 74 | * Copyright (c) Facebook, Inc. and its affiliates. 75 | * 76 | * This source code is licensed under the MIT license found in the 77 | * LICENSE file in the root directory of this source tree. 78 | */ 79 | 80 | /** @license React v16.14.0 81 | * react.development.js 82 | * 83 | * Copyright (c) Facebook, Inc. and its affiliates. 84 | * 85 | * This source code is licensed under the MIT license found in the 86 | * LICENSE file in the root directory of this source tree. 87 | */ 88 | 89 | /** @license React v16.8.6 90 | * react-is.development.js 91 | * 92 | * Copyright (c) Facebook, Inc. and its affiliates. 93 | * 94 | * This source code is licensed under the MIT license found in the 95 | * LICENSE file in the root directory of this source tree. 96 | */ 97 | 98 | /** @license React v17.0.2 99 | * react-is.development.js 100 | * 101 | * Copyright (c) Facebook, Inc. and its affiliates. 102 | * 103 | * This source code is licensed under the MIT license found in the 104 | * LICENSE file in the root directory of this source tree. 105 | */ 106 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-new-window", 3 | "description": "Pop a new window in React, using window.open API", 4 | "version": "1.0.1", 5 | "keywords": [ 6 | "react", 7 | "window", 8 | "open", 9 | "popup" 10 | ], 11 | "main": "lib/react-new-window.js", 12 | "module": "es/react-new-window.js", 13 | "browser": "umd/react-new-window.js", 14 | "repository": "git@github.com:rmariuzzo/react-new-window.git", 15 | "author": "Rubens Mariuzzo ", 16 | "license": "MIT", 17 | "files": [ 18 | "lib", 19 | "es", 20 | "umd", 21 | "types" 22 | ], 23 | "types": "./types/NewWindow.d.ts", 24 | "dependencies": { 25 | "prop-types": "^15.7.2" 26 | }, 27 | "devDependencies": { 28 | "@babel/core": "^7.15.8", 29 | "@babel/plugin-proposal-class-properties": "^7.14.5", 30 | "@babel/plugin-transform-runtime": "^7.15.8", 31 | "@babel/preset-env": "^7.15.8", 32 | "@rollup/plugin-babel": "^5.3.1", 33 | "@rollup/plugin-commonjs": "^22.0.2", 34 | "@rollup/plugin-node-resolve": "^14.1.0", 35 | "@rollup/plugin-replace": "^4.0.0", 36 | "@storybook/addon-actions": "^6.3.12", 37 | "@storybook/addon-links": "^6.3.12", 38 | "@storybook/react": "^6.3.12", 39 | "babel-eslint": "^10.1.0", 40 | "cross-env": "^7.0.3", 41 | "eslint": "^8.1.0", 42 | "eslint-plugin-prettier": "^4.0.0", 43 | "eslint-plugin-react": "^7.26.1", 44 | "husky": "^7.0.4", 45 | "prettier": "^2.4.1", 46 | "pretty-quick": "^3.1.1", 47 | "react": "^16.14.0", 48 | "react-dom": "^16.14.0", 49 | "react-test-renderer": "^17.0.2", 50 | "rimraf": "^3.0.2", 51 | "rollup": "^2.79.1", 52 | "rollup-plugin-filesize": "^9.1.2", 53 | "rollup-plugin-terser": "^7.0.2" 54 | }, 55 | "peerDependencies": { 56 | "react": "^16.0.0 || ^18.0.0", 57 | "react-dom": "^16.0.0 || ^18.0.0" 58 | }, 59 | "scripts": { 60 | "build": "cross-env NODE_ENV=production rollup -c", 61 | "clean": "rimraf 'es' 'lib' 'umd' 'docs'", 62 | "build-storybook": "cross-env NODE_ENV=test NODE_OPTIONS=--openssl-legacy-provider build-storybook -o docs", 63 | "lint": "eslint ./src", 64 | "postversion": "git push origin && git push origin --tags", 65 | "storybook": "cross-env NODE_ENV=test start-storybook -p 6006" 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /rollup.config.js: -------------------------------------------------------------------------------- 1 | import babel from '@rollup/plugin-babel' 2 | import replace from '@rollup/plugin-replace' 3 | import resolve from '@rollup/plugin-node-resolve' 4 | import commonjs from '@rollup/plugin-commonjs' 5 | import filesize from 'rollup-plugin-filesize' 6 | import { terser } from "rollup-plugin-terser"; 7 | 8 | 9 | import pkg from './package.json' 10 | 11 | const plugins = [ 12 | babel({ exclude: ['node_modules/**'], babelHelpers: 'runtime' }), 13 | resolve(), 14 | commonjs(), 15 | replace({ 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV) }), 16 | terser(), 17 | filesize() 18 | ] 19 | 20 | const globals = { 21 | react: 'React', 22 | 'react-dom': 'ReactDOM' 23 | } 24 | 25 | const external = ['react', 'react-dom'] 26 | 27 | export default [ 28 | // CommonJS 29 | { 30 | input: 'src/NewWindow.js', 31 | output: { 32 | name: 'ReactNewWindow', 33 | file: pkg.main, 34 | format: 'cjs', 35 | sourcemap: true, 36 | globals, 37 | }, 38 | external, 39 | plugins 40 | }, 41 | 42 | // browser-friendly UMD build 43 | { 44 | input: 'src/NewWindow.js', 45 | output: { 46 | name: 'ReactNewWindow', 47 | file: pkg.browser, 48 | format: 'umd', 49 | sourcemap: true, 50 | globals 51 | }, 52 | external, 53 | plugins 54 | }, 55 | 56 | // ES module build. 57 | { 58 | input: 'src/NewWindow.js', 59 | output: { 60 | file: pkg.module, 61 | format: 'es', 62 | sourcemap: true 63 | }, 64 | external, 65 | plugins 66 | } 67 | ] 68 | -------------------------------------------------------------------------------- /src/NewWindow.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Component dependencies. 3 | */ 4 | 5 | import React from 'react' 6 | import ReactDOM from 'react-dom' 7 | import PropTypes from 'prop-types' 8 | 9 | /** 10 | * The NewWindow class object. 11 | * @public 12 | */ 13 | 14 | class NewWindow extends React.PureComponent { 15 | /** 16 | * NewWindow default props. 17 | */ 18 | static defaultProps = { 19 | url: '', 20 | name: '', 21 | title: '', 22 | features: { width: '600px', height: '640px' }, 23 | onBlock: null, 24 | onOpen: null, 25 | onUnload: null, 26 | center: 'parent', 27 | copyStyles: true, 28 | closeOnUnmount: true 29 | } 30 | 31 | /** 32 | * The NewWindow function constructor. 33 | * @param {Object} props 34 | */ 35 | constructor(props) { 36 | super(props) 37 | this.container = null 38 | this.window = null 39 | this.windowCheckerInterval = null 40 | this.released = false 41 | this.state = { 42 | mounted: false 43 | } 44 | } 45 | 46 | /** 47 | * Render the NewWindow component. 48 | */ 49 | render() { 50 | if (!this.state.mounted) return null 51 | return ReactDOM.createPortal(this.props.children, this.container) 52 | } 53 | 54 | componentDidMount() { 55 | // In React 18, componentDidMount gets called twice 56 | // causing openChild to get called twice 57 | if (!this.window && !this.container) { 58 | this.openChild() 59 | this.setState({ mounted: true }) 60 | } 61 | } 62 | 63 | /** 64 | * Create the new window when NewWindow component mount. 65 | */ 66 | openChild() { 67 | const { url, title, name, features, onBlock, onOpen, center } = this.props 68 | 69 | // Prepare position of the new window to be centered against the 'parent' window or 'screen'. 70 | if ( 71 | typeof center === 'string' && 72 | (features.width === undefined || features.height === undefined) 73 | ) { 74 | console.warn( 75 | 'width and height window features must be present when a center prop is provided' 76 | ) 77 | } else if (center === 'parent') { 78 | features.left = 79 | window.top.outerWidth / 2 + window.top.screenX - features.width / 2 80 | features.top = 81 | window.top.outerHeight / 2 + window.top.screenY - features.height / 2 82 | } else if (center === 'screen') { 83 | const screenLeft = 84 | window.screenLeft !== undefined ? window.screenLeft : window.screen.left 85 | const screenTop = 86 | window.screenTop !== undefined ? window.screenTop : window.screen.top 87 | 88 | const width = window.innerWidth 89 | ? window.innerWidth 90 | : document.documentElement.clientWidth 91 | ? document.documentElement.clientWidth 92 | : window.screen.width 93 | const height = window.innerHeight 94 | ? window.innerHeight 95 | : document.documentElement.clientHeight 96 | ? document.documentElement.clientHeight 97 | : window.screen.height 98 | 99 | features.left = width / 2 - features.width / 2 + screenLeft 100 | features.top = height / 2 - features.height / 2 + screenTop 101 | } 102 | 103 | // Open a new window. 104 | this.window = window.open(url, name, toWindowFeatures(features)) 105 | this.container = this.window.document.createElement('div') 106 | // When a new window use content from a cross-origin there's no way we can attach event 107 | // to it. Therefore, we need to detect in a interval when the new window was destroyed 108 | // or was closed. 109 | this.windowCheckerInterval = setInterval(() => { 110 | if (!this.window || this.window.closed) { 111 | this.release() 112 | } 113 | }, 50) 114 | 115 | // Check if the new window was succesfully opened. 116 | if (this.window) { 117 | this.window.document.title = title 118 | 119 | // Check if the container already exists as the window may have been already open 120 | this.container = this.window.document.getElementById( 121 | 'new-window-container' 122 | ) 123 | if (this.container === null) { 124 | this.container = this.window.document.createElement('div') 125 | this.container.setAttribute('id', 'new-window-container') 126 | this.window.document.body.appendChild(this.container) 127 | } else { 128 | // Remove any existing content 129 | const staticContainer = this.window.document.getElementById( 130 | 'new-window-container-static' 131 | ) 132 | this.window.document.body.removeChild(staticContainer) 133 | } 134 | 135 | // If specified, copy styles from parent window's document. 136 | if (this.props.copyStyles) { 137 | setTimeout(() => copyStyles(document, this.window.document), 0) 138 | } 139 | 140 | if (typeof onOpen === 'function') { 141 | onOpen(this.window) 142 | } 143 | 144 | // Release anything bound to this component before the new window unload. 145 | this.window.addEventListener('beforeunload', () => this.release()) 146 | } else { 147 | // Handle error on opening of new window. 148 | if (typeof onBlock === 'function') { 149 | onBlock(null) 150 | } else { 151 | console.warn('A new window could not be opened. Maybe it was blocked.') 152 | } 153 | } 154 | } 155 | 156 | /** 157 | * Closes the opened window (if any) when NewWindow will unmount if the 158 | * prop {closeOnUnmount} is true, otherwise the NewWindow will remain open 159 | */ 160 | componentWillUnmount() { 161 | // With React 18, componentWillUnmount gets called twice 162 | // so only call componentWillUnmount when the `mounted` state 163 | // is set 164 | if (this.state.mounted && this.window) { 165 | if (this.props.closeOnUnmount) { 166 | this.window.close() 167 | } else if (this.props.children) { 168 | // Clone any children so they aren't removed when react stops rendering 169 | const clone = this.container.cloneNode(true) 170 | clone.setAttribute('id', 'new-window-container-static') 171 | this.window.document.body.appendChild(clone) 172 | } 173 | } 174 | } 175 | 176 | /** 177 | * Release the new window and anything that was bound to it. 178 | */ 179 | release() { 180 | // This method can be called once. 181 | if (this.released) { 182 | return 183 | } 184 | this.released = true 185 | 186 | // Remove checker interval. 187 | clearInterval(this.windowCheckerInterval) 188 | 189 | // Call any function bound to the `onUnload` prop. 190 | const { onUnload } = this.props 191 | 192 | if (typeof onUnload === 'function') { 193 | onUnload(null) 194 | } 195 | } 196 | } 197 | 198 | NewWindow.propTypes = { 199 | children: PropTypes.node, 200 | url: PropTypes.string, 201 | name: PropTypes.string, 202 | title: PropTypes.string, 203 | features: PropTypes.object, 204 | onUnload: PropTypes.func, 205 | onBlock: PropTypes.func, 206 | onOpen: PropTypes.func, 207 | center: PropTypes.oneOf(['parent', 'screen']), 208 | copyStyles: PropTypes.bool, 209 | closeOnUnmount: PropTypes.bool 210 | } 211 | 212 | /** 213 | * Utility functions. 214 | * @private 215 | */ 216 | 217 | /** 218 | * Copy styles from a source document to a target. 219 | * @param {Object} source 220 | * @param {Object} target 221 | * @private 222 | */ 223 | 224 | function copyStyles(source, target) { 225 | // Store style tags, avoid reflow in the loop 226 | const headFrag = target.createDocumentFragment() 227 | 228 | Array.from(source.styleSheets).forEach(styleSheet => { 229 | // For