0.0.10 • Published 1 year ago

friendzone v0.0.10

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

friendzone

The boundary no events can cross. It's a React component library that captures and manages event propagation for its child elements. It provides a way to stop the propagation of certain event categories (e.g., mouse, keyboard, clipboard) and optionally logs the event information for debugging purposes.

Components

  • EventBoundary
  • EventBlackHole
  • OnClickBoundary

Usage Example

EventBoundary

EventBoundary attributes are trace, onEvent and logName.

AttributeTypeDescription
trace"clipboard","drag","form","keyboard","media","mouse","pointer","window"
onEvent(eventType: string, event: Event) => void
logNamestringFor debugging purpose
import {  EventBoundary } from "friendzone";

function App() {
  return (
    <div
      style={{
        padding: 10,
        border: "1px solid black",
      }}
      onClick={() => {
        console.log("parent");
      }}
    >
      <EventBoundary trace={["mouse"]} onEvent={(_, e) => {}>
        <div
          style={{
            padding: 10,
            border: "1px solid red",
          }}
          onClick={() => {
            console.log("child");
          }}
        >
          click
        </div>
       </EventBoundary>
    </div>
  );
}

export default App;

EventBlackHole

EventBlackHole attributes are absorbOnly and logName.

AttributeTypeDescription
absorbOnly"clipboard","drag","form","keyboard","media","mouse","pointer","window"
logNamestringFor debugging purpose
import { EventBlackHole, EventBoundary, OnClickBoundary } from "friendzone";

function App() {
  return (
    <div
      style={{
        padding: 10,
        border: "1px solid black",
      }}
      onClick={() => {
        console.log("parent");
      }}
    >
      <EventBlackHole absorbOnly={["keyboard"]}>
        <div
          style={{
            padding: 10,
            border: "1px solid red",
          }}
          onClick={() => {
            console.log("child");
          }}
        >
          click
        </div>
      </EventBlackHole>
    </div>
  );
}

export default App;

OnClickBoundary

No attributes.

import { OnClickBoundary } from "friendzone";

function App() {
  return (
    <div
      style={{
        padding: 10,
        border: "1px solid black",
      }}
      onClick={() => {
        console.log("parent");
      }}
    >
      <OnClickBoundary>
        // On click boundary will prevent parent from getting triggered
        <div
          style={{
            padding: 10,
            border: "1px solid red",
          }}
          onClick={() => {
            console.log("child");
          }}
        >
          click
        </div>
      </OnClickBoundary>
    </div>
  );
}

export default App;
0.0.10

1 year ago

0.0.9

1 year ago

0.0.8

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago