0.2.1 • Published 4 years ago

@react-cmpt/use-portal v0.2.1

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

use-portal

React partals with hooks

CI Build Status npm GitHub license

Usage

Installation

yarn add @react-cmpt/use-portal

usePortal

optionstypedefaultexplain
initialAppendbooleantrueWhether to append the child node in the mounted state
attrNamestring"react-cmpt-container"setAttribute qualifiedName
attrValuestring""setAttribute value
returntypeexplain
getChildfunctionCallback for obtaining the current container mount child node.
getContainerfunctionCallback for obtaining the container element.
appendChildfunctionManually append the child node. (Default current node)
removeChildfunctionManually remove the child node. (Default current node)
import { usePortal } from "@react-cmpt/use-portal";

const App = () => {
  const { getChild, getContainer, appendChild, removeChild } = usePortal();
};

Portal

propstypedefaultexplain
attrNamestring"react-cmpt-container"setAttribute qualifiedName
attrValuestring""setAttribute value
portalKeystringundefinedcreatePortal key
import { Portal } from "@react-cmpt/use-portal";

const App = () => {
  return (
    <Portal>
      <span>{"hello"}</span>
    </Portal>
  );
};

useEventPortal

optionstypedefaultexplain
defaultVisiablebooleanfalseinitial visiable value
attrNamestring"react-cmpt-container"setAttribute qualifiedName
attrValuestring""setAttribute value
portalKeystringundefinedcreatePortal key
returntypeexplain
PortalReact.ReactNodePortal holder
visiablebooleanWhether the element is visible
onShowfunctionShow trigger event
onClosefunctionHide trigger event
getChildfunctionCallback for obtaining the current container mount child node.
getContainerfunctionCallback for obtaining the container element.
import { useEventPortal } from "@react-cmpt/use-portal";

const App = () => {
  const {
    Portal,
    visiable,
    onShow,
    onClose,
    getChild,
    getContainer,
  } = useEventPortal({});

  return (
    <Portal>
      <span>{"hello"}</span>
    </Portal>
  );
};

Dev

# example
yarn example

# build package
yarn build

# tests
yarn test

workflow

https://github.com/react-cmpt/rc-demo

License

MIT