{"name":"react-portal","version":"4.3.0","description":"To make your life with React Portals easier.","main":"lib/index.js","module":"es/index.js","sideEffects":false,"jsnext:main":"es/index.js","browserslist":"last 2 versions, ie 11","repository":{"type":"git","url":"git+https://github.com/tajo/react-portal.git"},"author":{"name":"Vojtech Miksu","email":"vojtech@miksu.cz"},"license":"MIT","scripts":{"build":"npm run clean && npm run build-es && npm run build-cjs","build-es":"babel ./src --out-dir ./es","build-cjs":"cross-env BABEL_ENV=commonjs babel ./src --out-dir ./lib","build:examples":"cross-env webpack","clean":"rimraf es lib build","prepublish":"cross-env NODE_ENV=production npm run build","lint":"eslint webpack.config.js src/**/*.js","format":"prettier --write \"**/*.js\"","test":"cross-env BABEL_ENV=commonjs jest --no-cache","react":"enzyme-adapter-react-install 16"},"tags":["react"],"jest":{"setupFiles":["raf/polyfill"]},"keywords":["react","react-component","modal","lightbox","react-portal","portal","transportation"],"dependencies":{"prop-types":"^15.5.8"},"devDependencies":{"babel-cli":"^6.8.0","babel-core":"^6.8.0","babel-eslint":"^8.0.1","babel-jest":"^21.2.0","babel-loader":"^7.1.1","babel-preset-env":"^1.6.1","babel-preset-react":"^6.3.13","cross-env":"^5.0.1","enzyme":"^3.1.0","enzyme-adapter-react-helper":"^1.2.2","eslint":"^4.3.0","eslint-plugin-prettier":"^2.1.2","jest":"^21.2.1","prettier":"^1.5.3","raf":"^3.4.0","react":"^15.0.0-0 || ^16.0.0-0 || ^17.0.0-0","react-dom":"^15.0.0-0 || ^16.0.0-0 || ^17.0.0-0","rimraf":"^2.5.0","webpack":"^3.4.1"},"peerDependencies":{"react":"^16.0.0-0 || ^17.0.0-0 || ^18.0.0-0 || ^19.0.0","react-dom":"^16.0.0-0 || ^17.0.0-0 || ^18.0.0-0 || ^19.0.0"},"_id":"react-portal@4.3.0","gitHead":"bb926ad7b9fb2d1f8e75e1bb497411bc96f85b15","bugs":{"url":"https://github.com/tajo/react-portal/issues"},"homepage":"https://github.com/tajo/react-portal#readme","_nodeVersion":"22.4.0","_npmVersion":"10.8.1","dist":{"integrity":"sha512-qs/2uKq1ifB3J1+K8ExfgUvCDZqlqCkfOEhqTELEDTfosloKiuzOzc7hl7IQ/7nohiFZD41BUYU0boAsIsGYHw==","shasum":"92ca3492b1309883134f317a6aa88004534c860f","tarball":"http://registry-npm.ywwl.com/react-portal/download/react-portal-4.3.0.tgz","fileCount":16,"unpackedSize":39223,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIEq0j0vbNOBKEmDkZ+KG3VsAG1oWHvIS4kWpMs6Lxt9PAiBjkTo7TbtZt9MluVApVUEYqT91GO2BaH0g53ENj1Z9GA=="}],"size":8307,"noattachment":false,"key":"/react-portal/-/react-portal-4.3.0.tgz"},"_npmUser":{"name":"miksu","email":"vojtech@miksu.cz"},"directories":{},"maintainers":[{"name":"miksu","email":"vojtech@miksu.cz"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/react-portal_4.3.0_1738124099835_0.2858544252437656"},"_hasShrinkwrap":false,"readme":"React-portal\n============\n[![npm version](https://img.shields.io/npm/v/react-portal.svg?style=flat-square)](https://www.npmjs.com/package/react-portal)\n[![npm downloads](https://img.shields.io/npm/dm/react-portal.svg?style=flat-square)](https://www.npmjs.com/package/react-portal)\n[![Build Status](https://travis-ci.org/tajo/react-portal.svg?branch=master)](https://travis-ci.org/tajo/react-portal)\n\n> Struggling with modals, lightboxes or loading bars in React? React-portal creates a new top-level React tree and injects its children into it. That's necessary for proper styling (especially positioning).\n\n*Looking for v3 documentation? Go [here](READMEv3.MD).*\n\n## Features\n\n- **uses React v16 and its official API for creating portals**\n- **has a fallback for React v15**\n- transports its children into a new React Portal which is appended by default to **document.body**\n- can target user specified DOM element\n- supports server-side rendering\n- supports returning arrays (no wrapper divs needed)\n- `<Portal />` and `<PortalWithState />` so there is no compromise between flexibility and convenience\n- doesn't produce any DOM mess\n- provides **close on ESC** and **close on outside mouse click** out of the box\n- **no dependencies**, minimalistic\n\n## Installation\n\n```shell\nyarn add react react-dom react-portal\n```\n\n## Usage\n\n### Portal\n\n```jsx \nimport { Portal } from 'react-portal';\n\n<Portal>\n  This text is portaled at the end of document.body!\n</Portal>\n\n<Portal node={document && document.getElementById('san-francisco')}>\n  This text is portaled into San Francisco!\n</Portal>\n```\n\nThat's it! Do you want to toggle portal? It's a plain React component, so you can simply do:\n\n```jsx\n{isOpen && <Portal>Sometimes portaled?</Portal>}\n```\n\n  **This gives you absolute flexibility and control** and I would recommend you to use it as a basic building block for your components like modals or notifications. **This code also works with server-side rendering**. If you think about just using official `ReactDOM.createPortal()`, you would have to check for existence of DOM environment.\n\nReact-portal used to come packed with some extra goodies because sometimes **you are ok with giving up some flexibility for convenience**. For that case, V4 introduces another component that handles its own state for you:\n\n### PortalWithState\n\n```jsx \nimport { PortalWithState } from 'react-portal';\n\n<PortalWithState closeOnOutsideClick closeOnEsc>\n  {({ openPortal, closePortal, isOpen, portal }) => (\n    <React.Fragment>\n      <button onClick={openPortal}>\n        Open Portal\n      </button>\n      {portal(\n        <p>\n          This is more advanced Portal. It handles its own state.{' '}\n          <button onClick={closePortal}>Close me!</button>, hit ESC or\n          click outside of me.\n        </p>\n      )}\n    </React.Fragment>\n  )}\n</PortalWithState>\n```\n\nDon't let this example intimidate you! `PortalWithState` **expects one child, a function**. This function gets a few parameters (mostly functions) and returns a React component.\n\n### There are 4 optional parameters:\n\n- **openPortal** - function that you can call to open the portal\n- **closePortal** - function that you can call to close the portal\n- **portal** - the part of component that should be portaled needs to be wrapped by this function\n- **isOpen** - boolean, tells you if portal is open/closed\n\n### `<PortalWithState />` accepts this optional props:\n\n- **node** - same as `<Portal>`, you can target a custom DOM element\n- **closeOnOutsideClick** - boolean, portal closes when you click outside of it\n- **closeOnEsc** - boolean, portal closes when the ESC key is hit \n- **defaultOpen** - boolean, the starting state of portal is being open\n- **onOpen** - function, will get triggered after portal is open\n- **onClose** - function, will get triggered after portal is closed\n\nAlso notice, that **the example returns a [Fragment](https://reactjs.org/docs/fragments.html) since React 16.2 supports it**! You can also return:\n- an array - available from React v16, remember to add `key` attribute\n- regular component - the example would be wrapped by a div, not a fragment\n\nIf you start running into limits of `<PortalWithState />` (complex animations), you probably want to use `<Portal />` instead and build a component tailored to your specific taste.\n\n## Run Examples\n\n```shell\ngit clone https://github.com/tajo/react-portal\ncd react-portal\nyarn install\nyarn build:examples\nopen examples/index.html\n```\n\n## Contributions Welcome!\n\n```shell\ngit clone https://github.com/tajo/react-portal\ncd react-portal\nyarn install\nyarn build:examples --watch\nopen examples/index.html\n```\n\n### Run Tests\n\n```\nyarn test\n```\n\n## Author\n\nVojtech Miksu 2017, [miksu.cz](https://miksu.cz), [@vmiksu](https://twitter.com/vmiksu)\n","publish_time":1738124100026,"_cnpm_publish_time":1738124100026,"dist-tags":{"latest":"4.3.0","next":"4.0.0-rc.0"}}