0.1.19 • Published 8 months ago

react-dom-outside v0.1.19

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

react-dom-outside

React components for react-dom and react-native-web click outside

For a react-native version, check out react-native-outside

Example 1: Active Component

import { forwardRef } from "react",
import { dom } from "react-native",
import { Active } from "react-native-outside";
import { EventProvider } from "react-native-event";

const Component = forwardRef(({ isActive, setIsActive }, ref) => {
  return (
    <dom ref={ref}>
      <dom id="text">{isActive ? 'active' : 'not active'}</dom>
      <button
        id="toggle"
        onClick={function () {
          setIsActive(!isActive);
        }}
      />
    </dom>
  );
});

export default function App() {
  return (
    <EventProvider>
      <Active>
        <Component />
      </Active>
      <Active>
        <Component />
      </Active>
    </EventProvider>
  );
}

Example 1: Active Boundary Component

import { forwardRef, useEffect, useRef } from "react",
import { Active } from "react-native-outside";
import { EventProvider } from "react-native-event";
import { PortalProvider, Portal } from '@gorhom/portal';
import { useRef as useBoundaryRef } from 'react-ref-boundary';

// a modal for example outside the hierarchy
const PortalComponent = () => {
  const ref = useBoundaryRef(null); // react-ref-boundary ref
  const el = useRef(document.createElement('div'));
  useEffect(function () {
    container.appendChild(el.current);
  });
  return ReactDOM.createPortal(
    <button
      ref={ref}
      id="portal-click"
      OnClick={() => { /* this click will not inactivate due to react-ref-boundary ref */ }}
    />,
    el.current,
  );
}

// react-ref-boundary ref passed in
const Component = forwardRef(({ isActive, setIsActive }, ref) => {
  return (
    <dom ref={ref}>
      <dom id="text">{isActive ? 'active' : 'not active'}</dom>
      <button
        id="toggle"
        onClick={function () {
          setIsActive(!isActive);
        }}
      />
      <PortalComponent/>
    </dom>
  );
});

export default function App() {
  return (
    <EventProvider>
      <Active>
        <Component />
      </Active>
      <Active>
        <Component />
      </Active>
    </EventProvider>
  );
}

Documentation

API Docs

0.1.10

10 months ago

0.1.11

10 months ago

0.1.12

10 months ago

0.1.13

10 months ago

0.1.14

10 months ago

0.1.15

10 months ago

0.1.16

10 months ago

0.1.17

10 months ago

0.1.7

10 months ago

0.1.19

8 months ago

0.1.9

10 months ago

0.1.4

10 months ago

0.1.6

10 months ago

0.1.5

10 months ago

0.1.3

2 years ago

0.1.2

2 years ago

0.1.1

3 years ago

0.1.0

3 years ago