Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@interop-ui/react-dismissable-layer

Package Overview
Dependencies
Maintainers
3
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@interop-ui/react-dismissable-layer - npm Package Compare versions

Comparing version 0.0.1-7 to 0.2.0-rc.1

60

dist/index.d.ts
import * as React from "react";
type DismissableLayerProps = {
children: (args: ReturnType<typeof usePointerDownOutside> & ReturnType<typeof useFocusOutside> & {
ref: React.RefObject<any>;
style: React.CSSProperties;
}) => React.ReactElement;
import * as Radix from "@interop-ui/react-primitive";
import { Primitive } from "@interop-ui/react-primitive";
export interface DismissableLayerProps extends DismissableLayerImplProps {
}
export const DismissableLayer: React.ForwardRefExoticComponent<DismissableLayerProps & React.RefAttributes<HTMLDivElement>>;
type PrimitiveDivProps = Radix.ComponentPropsWithoutRef<typeof Primitive.div>;
interface DismissableLayerImplProps extends PrimitiveDivProps {
/**
* When `true`, hover/focus/click interactions will be disabled on elements outside the `DismissableLayer`.
* Users will need to click twice on outside elements to interact with them:
* Once to close the `DismissableLayer`, and again to trigger the element.
* When `true`, hover/focus/click interactions will be disabled on elements outside
* the `DismissableLayer`. Users will need to click twice on outside elements to
* interact with them: once to close the `DismissableLayer`, and again to trigger the element.
*/

@@ -19,6 +21,6 @@ disableOutsidePointerEvents?: boolean;

/**
* Event handler called when the a pointer event happens outside of the `DismissableLayer`.
* Event handler called when the a `pointerdown` event happens outside of the `DismissableLayer`.
* Can be prevented.
*/
onPointerDownOutside?: (event: MouseEvent | TouchEvent) => void;
onPointerDownOutside?: (event: PointerDownOutsideEvent) => void;
/**

@@ -28,36 +30,20 @@ * Event handler called when the focus moves outside of the `DismissableLayer`.

*/
onFocusOutside?: (event: React.FocusEvent) => void;
onFocusOutside?: (event: FocusOutsideEvent) => void;
/**
* Event handler called when an interaction happens outside the `DismissableLayer`.
* Specifically, when a pointer event happens outside of the `DismissableLayer` or focus moves outside of it.
* Specifically, when a `pointerdown` event happens outside or focus moves outside of it.
* Can be prevented.
*/
onInteractOutside?: (event: MouseEvent | TouchEvent | React.FocusEvent) => void;
onInteractOutside?: (event: PointerDownOutsideEvent | FocusOutsideEvent) => void;
/** Callback called when the `DismissableLayer` should be dismissed */
onDismiss?: () => void;
};
export function DismissableLayer(props: DismissableLayerProps): JSX.Element;
/**
* Sets up mousedown/touchstart listeners which listens for pointer down events outside a react subtree.
*
* We use `mousedown` rather than click` for 2 reasons:
* - to mimic layer dismissing behaviour present in OS which usually happens on mousedown
* - to enable to us call `event.preventDefault()` and prevent focus from happening.
*
* Returns props to pass to the node we want to check for outside events.
*/
declare function usePointerDownOutside(onPointerDownOutsideProp?: (event: MouseEvent | TouchEvent) => void): {
onMouseDownCapture: (event: React.MouseEvent<Element, MouseEvent>) => void;
onTouchStartCapture: (event: React.TouchEvent<Element>) => void;
};
/**
* Listens for when focus moves outside a react subtree.
* Returns props to pass to the root (node) of the subtree we want to check.
*/
declare function useFocusOutside(onFocusOutside?: (event: React.FocusEvent) => void): {
onBlurCapture: (event: React.FocusEvent) => void;
onFocusCapture: () => void;
};
export const Root: typeof DismissableLayer;
}
type PointerDownOutsideEvent = CustomEvent<{
originalEvent: PointerEvent;
}>;
type FocusOutsideEvent = CustomEvent<{
originalEvent: FocusEvent;
}>;
export const Root: React.ForwardRefExoticComponent<DismissableLayerProps & React.RefAttributes<HTMLDivElement>>;
//# sourceMappingURL=index.d.ts.map

@@ -1,2 +0,2 @@

var e,t,n=require("@interop-ui/react-utils"),r=n.useCallbackRef,u=n.useDisableBodyPointerEvents,o=(e={},t=require("react"),Object.keys(t).forEach((function(n){"default"!==n&&"__esModule"!==n&&Object.defineProperty(e,n,{enumerable:!0,get:function(){return t[n]}})})),e);function i(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function c(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?i(Object(n),!0).forEach((function(t){a(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):i(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function a(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function l(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){if("undefined"==typeof Symbol||!(Symbol.iterator in Object(e)))return;var n=[],r=!0,u=!1,o=void 0;try{for(var i,c=e[Symbol.iterator]();!(r=(i=c.next()).done)&&(n.push(i.value),!t||n.length!==t);r=!0);}catch(e){u=!0,o=e}finally{try{r||null==c.return||c.return()}finally{if(u)throw o}}return n}(e,t)||function(e,t){if(!e)return;if("string"==typeof e)return f(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return f(e,t)}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function f(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}var s=l(C(),2),d=s[0],v=s[1],y=l(D(),2),m=y[0],b=y[1],p=l(C("TotalLayerCountWithDisabledOutsidePointerEventsProvider"),2),O=p[0],E=p[1],h=l(D("RunningLayerCountWithDisabledOutsidePointerEventsProvider"),2),w=h[0],P=h[1];function g(e){var t=0===b(),n=o.createElement(j,e);return t?o.createElement(d,null,o.createElement(O,null,n)):n}function j(e){var t=e.children,n=e.disableOutsidePointerEvents,i=void 0!==n&&n,a=e.onEscapeKeyDown,l=e.onPointerDownOutside,f=e.onFocusOutside,s=e.onInteractOutside,d=e.onDismiss,y=o.useRef(null),p=v(),O=b()+1,h=O===p,g=E(i),j=P()+(i?1:0),C=j<g;u({disabled:i}),function(e){var t=r(e);o.useEffect((function(){var e=function(e){"Escape"===e.key&&t(e)};return document.addEventListener("keydown",e),function(){return document.removeEventListener("keydown",e)}}),[t])}((function(e){h&&(null==a||a(e),e.defaultPrevented||null==d||d())}));var D=function(e){var t=r(e),n=o.useRef(!1);o.useEffect((function(){var e=function(e){n.current||t(e),n.current=!1};return document.addEventListener("mousedown",e),document.addEventListener("touchstart",e),function(){document.removeEventListener("mousedown",e),document.removeEventListener("touchstart",e)}}),[t]);var u=function(){n.current=!0};return{onMouseDownCapture:u,onTouchStartCapture:u}}((function(e){C||(null==l||l(e),null==s||s(e),e.defaultPrevented||null==d||d())})),L=function(e){var t=o.useRef(0);return{onBlurCapture:function(n){n.persist(),t.current=window.setTimeout((function(){null==e||e(n)}),0)},onFocusCapture:function(){window.clearTimeout(t.current)}}}((function(e){null==f||f(e),null==s||s(e),e.defaultPrevented||null==d||d()})),S=g>0&&!C;return o.createElement(m,{runningCount:O},o.createElement(w,{runningCount:j},t(c(c({ref:y,style:S?{pointerEvents:"auto"}:{}},D),L))))}function C(e){var t=o.createContext({total:0,setTotal:function(){}}),n=function(e){var n=e.children,r=l(o.useState(0),2),u=r[0],i=r[1],c=o.useMemo((function(){return{total:u,setTotal:i}}),[u,i]);return o.createElement(t.Provider,{value:c},n)};return e&&(n.displayName=e),[n,function(){var e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0],n=o.useContext(t),r=n.total,u=n.setTotal;return o.useLayoutEffect((function(){if(e)return u((function(e){return e+1})),function(){return u((function(e){return e-1}))}}),[e,u]),r}]}function D(e){var t=o.createContext(0),n=function(e){var n=e.children,r=e.runningCount;return o.createElement(t.Provider,{value:r},n)};return e&&(n.displayName=e),[n,function(){return o.useContext(t)||0}]}exports.DismissableLayer=g;var L=g;exports.Root=L;
var e,t,n,r=require("@interop-ui/react-use-escape-keydown").useEscapeKeydown,o=require("@interop-ui/react-use-callback-ref").useCallbackRef,u=require("@interop-ui/react-use-body-pointer-events").useBodyPointerEvents,i=require("@interop-ui/react-primitive").Primitive,s=require("@interop-ui/primitive").composeEventHandlers,a=(e={},t=require("react"),Object.keys(t).forEach((function(n){"default"!==n&&"__esModule"!==n&&Object.defineProperty(e,n,{enumerable:!0,get:function(){return t[n]}})})),e),c=(n=require("@babel/runtime/helpers/extends"))&&n.__esModule?n.default:n;const[l,d]=P(),[f,v]=y(),[p,E]=P("TotalLayerCountWithDisabledOutsidePointerEventsProvider"),[m,b]=y("RunningLayerCountWithDisabledOutsidePointerEventsProvider"),C=/*#__PURE__*/a.forwardRef(((e,t)=>{const n=0===v(),r=/*#__PURE__*/a.createElement(w,c({},e,{ref:t}));return n?/*#__PURE__*/a.createElement(l,null,/*#__PURE__*/a.createElement(p,null,r)):r}));exports.DismissableLayer=C;const w=/*#__PURE__*/a.forwardRef(((e,t)=>{const{disableOutsidePointerEvents:n=!1,onEscapeKeyDown:l,onPointerDownOutside:p,onFocusOutside:C,onInteractOutside:w,onDismiss:P,...y}=e,L=d(),D=v()+1,O=D===L,g=E(n),h=b()+(n?1:0),q=h<g;u({disabled:n}),r((e=>{O&&(null==l||l(e),e.defaultPrevented||null==P||P())}));const{onPointerDownCapture:x}=function(e){const t=o(e),n=a.useRef(!1);return a.useEffect((()=>{const e=e=>{const r=e.target;if(r&&!n.current){const n=new CustomEvent("dismissableLayer.pointerDownOutside",{bubbles:!1,cancelable:!0,detail:{originalEvent:e}});r.addEventListener("dismissableLayer.pointerDownOutside",t,{once:!0}),r.dispatchEvent(n)}n.current=!1},r=window.setTimeout((()=>{document.addEventListener("pointerdown",e)}),0);return()=>{window.clearTimeout(r),document.removeEventListener("pointerdown",e)}}),[t]),{onPointerDownCapture:()=>n.current=!0}}((e=>{q||(null==p||p(e),null==w||w(e),e.defaultPrevented||null==P||P())})),{onBlurCapture:R,onFocusCapture:T}=function(e){const t=o(e),n=a.useRef(!1);return a.useEffect((()=>{const e=e=>{const r=e.target;if(r&&!n.current){const n=new CustomEvent("dismissableLayer.focusOutside",{bubbles:!1,cancelable:!0,detail:{originalEvent:e}});r.addEventListener("dismissableLayer.focusOutside",t,{once:!0}),r.dispatchEvent(n)}};return document.addEventListener("focusin",e),()=>document.removeEventListener("focusin",e)}),[t]),{onFocusCapture:()=>n.current=!0,onBlurCapture:()=>n.current=!1}}((e=>{null==C||C(e),null==w||w(e),e.defaultPrevented||null==P||P()})),B=g>0&&!q;/*#__PURE__*/return a.createElement(f,{runningCount:D},/*#__PURE__*/a.createElement(m,{runningCount:h},/*#__PURE__*/a.createElement(i.div,c({},y,{ref:t,style:{pointerEvents:B?"auto":void 0,...y.style},onPointerDownCapture:s(e.onPointerDownCapture,x),onBlurCapture:s(e.onBlurCapture,R),onFocusCapture:s(e.onFocusCapture,T)}))))}));function P(e){const t=/*#__PURE__*/a.createContext({total:0,setTotal:()=>{}}),n=({children:e})=>{const[n,r]=a.useState(0),o=a.useMemo((()=>({total:n,setTotal:r})),[n,r]);/*#__PURE__*/return a.createElement(t.Provider,{value:o},e)};return[n,function(e=!0){const{total:n,setTotal:r}=a.useContext(t);return a.useLayoutEffect((()=>{if(e)return r((e=>e+1)),()=>r((e=>e-1))}),[e,r]),n}]}function y(e){const t=/*#__PURE__*/a.createContext(0),n=e=>{const{children:n,runningCount:r}=e;/*#__PURE__*/return a.createElement(t.Provider,{value:r},n)};return[n,function(){return a.useContext(t)||0}]}const L=C;exports.Root=L;
//# sourceMappingURL=index.js.map

@@ -1,2 +0,2 @@

import{useCallbackRef as e,useDisableBodyPointerEvents as t}from"@interop-ui/react-utils";import*as n from"react";function r(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function o(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?r(Object(n),!0).forEach((function(t){u(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):r(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function u(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}const[c,s]=v(),[i,l]=b(),[a,d]=v("TotalLayerCountWithDisabledOutsidePointerEventsProvider"),[f,m]=b("RunningLayerCountWithDisabledOutsidePointerEventsProvider");export function DismissableLayer(e){const t=0===l(),r=n.createElement(p,e);return t?n.createElement(c,null,n.createElement(a,null,r)):r}function p(r){const{children:u,disableOutsidePointerEvents:c=!1,onEscapeKeyDown:a,onPointerDownOutside:p,onFocusOutside:v,onInteractOutside:b,onDismiss:y}=r,E=n.useRef(null),O=s(),P=l()+1,w=P===O,C=d(c),g=m()+(c?1:0),h=g<C;t({disabled:c}),function(t){const r=e(t);n.useEffect((()=>{const e=e=>{"Escape"===e.key&&r(e)};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)}),[r])}((e=>{w&&(null==a||a(e),e.defaultPrevented||null==y||y())}));const j=function(t){const r=e(t),o=n.useRef(!1);n.useEffect((()=>{const e=e=>{o.current||r(e),o.current=!1};return document.addEventListener("mousedown",e),document.addEventListener("touchstart",e),()=>{document.removeEventListener("mousedown",e),document.removeEventListener("touchstart",e)}}),[r]);const u=()=>{o.current=!0};return{onMouseDownCapture:u,onTouchStartCapture:u}}((e=>{h||(null==p||p(e),null==b||b(e),e.defaultPrevented||null==y||y())})),D=function(e){const t=n.useRef(0);return{onBlurCapture:n=>{n.persist(),t.current=window.setTimeout((()=>{null==e||e(n)}),0)},onFocusCapture:()=>{window.clearTimeout(t.current)}}}((e=>{null==v||v(e),null==b||b(e),e.defaultPrevented||null==y||y()})),L=C>0&&!h;return n.createElement(i,{runningCount:P},n.createElement(f,{runningCount:g},u(o(o({ref:E,style:L?{pointerEvents:"auto"}:{}},j),D))))}function v(e){const t=n.createContext({total:0,setTotal:()=>{}}),r=({children:e})=>{const[r,o]=n.useState(0),u=n.useMemo((()=>({total:r,setTotal:o})),[r,o]);return n.createElement(t.Provider,{value:u},e)};return e&&(r.displayName=e),[r,function(e=!0){const{total:r,setTotal:o}=n.useContext(t);return n.useLayoutEffect((()=>{if(e)return o((e=>e+1)),()=>o((e=>e-1))}),[e,o]),r}]}function b(e){const t=n.createContext(0),r=e=>{const{children:r,runningCount:o}=e;return n.createElement(t.Provider,{value:o},r)};return e&&(r.displayName=e),[r,function(){return n.useContext(t)||0}]}export const Root=DismissableLayer;
import{useEscapeKeydown as e}from"@interop-ui/react-use-escape-keydown";import{useCallbackRef as t}from"@interop-ui/react-use-callback-ref";import{useBodyPointerEvents as n}from"@interop-ui/react-use-body-pointer-events";import{Primitive as r}from"@interop-ui/react-primitive";import{composeEventHandlers as o}from"@interop-ui/primitive";import*as u from"react";import i from"@babel/runtime/helpers/esm/extends";const[s,a]=E(),[c,l]=C(),[d,m]=E("TotalLayerCountWithDisabledOutsidePointerEventsProvider"),[p,f]=C("RunningLayerCountWithDisabledOutsidePointerEventsProvider");export const DismissableLayer=/*#__PURE__*/u.forwardRef(((e,t)=>{const n=0===l(),r=/*#__PURE__*/u.createElement(v,i({},e,{ref:t}));return n?/*#__PURE__*/u.createElement(s,null,/*#__PURE__*/u.createElement(d,null,r)):r}));/*#__PURE__*/const v=/*#__PURE__*/u.forwardRef(((s,d)=>{const{disableOutsidePointerEvents:v=!1,onEscapeKeyDown:E,onPointerDownOutside:C,onFocusOutside:b,onInteractOutside:w,onDismiss:L,...P}=s,y=a(),D=l()+1,O=D===y,g=m(v),h=f()+(v?1:0),x=h<g;n({disabled:v}),e((e=>{O&&(null==E||E(e),e.defaultPrevented||null==L||L())}));const{onPointerDownCapture:R}=function(e){const n=t(e),r=u.useRef(!1);return u.useEffect((()=>{const e=e=>{const t=e.target;if(t&&!r.current){const r=new CustomEvent("dismissableLayer.pointerDownOutside",{bubbles:!1,cancelable:!0,detail:{originalEvent:e}});t.addEventListener("dismissableLayer.pointerDownOutside",n,{once:!0}),t.dispatchEvent(r)}r.current=!1},t=window.setTimeout((()=>{document.addEventListener("pointerdown",e)}),0);return()=>{window.clearTimeout(t),document.removeEventListener("pointerdown",e)}}),[n]),{onPointerDownCapture:()=>r.current=!0}}((e=>{x||(null==C||C(e),null==w||w(e),e.defaultPrevented||null==L||L())})),{onBlurCapture:T,onFocusCapture:F}=function(e){const n=t(e),r=u.useRef(!1);return u.useEffect((()=>{const e=e=>{const t=e.target;if(t&&!r.current){const r=new CustomEvent("dismissableLayer.focusOutside",{bubbles:!1,cancelable:!0,detail:{originalEvent:e}});t.addEventListener("dismissableLayer.focusOutside",n,{once:!0}),t.dispatchEvent(r)}};return document.addEventListener("focusin",e),()=>document.removeEventListener("focusin",e)}),[n]),{onFocusCapture:()=>r.current=!0,onBlurCapture:()=>r.current=!1}}((e=>{null==b||b(e),null==w||w(e),e.defaultPrevented||null==L||L()})),B=g>0&&!x;/*#__PURE__*/return u.createElement(c,{runningCount:D},/*#__PURE__*/u.createElement(p,{runningCount:h},/*#__PURE__*/u.createElement(r.div,i({},P,{ref:d,style:{pointerEvents:B?"auto":void 0,...P.style},onPointerDownCapture:o(s.onPointerDownCapture,R),onBlurCapture:o(s.onBlurCapture,T),onFocusCapture:o(s.onFocusCapture,F)}))))}));function E(e){const t=/*#__PURE__*/u.createContext({total:0,setTotal:()=>{}}),n=({children:e})=>{const[n,r]=u.useState(0),o=u.useMemo((()=>({total:n,setTotal:r})),[n,r]);/*#__PURE__*/return u.createElement(t.Provider,{value:o},e)};return[n,function(e=!0){const{total:n,setTotal:r}=u.useContext(t);return u.useLayoutEffect((()=>{if(e)return r((e=>e+1)),()=>r((e=>e-1))}),[e,r]),n}]}function C(e){const t=/*#__PURE__*/u.createContext(0),n=e=>{const{children:n,runningCount:r}=e;/*#__PURE__*/return u.createElement(t.Provider,{value:r},n)};return[n,function(){return u.useContext(t)||0}]}export const Root=DismissableLayer;
//# sourceMappingURL=index.module.js.map
{
"name": "@interop-ui/react-dismissable-layer",
"version": "0.0.1-7",
"version": "0.2.0-rc.1",
"license": "MIT",

@@ -15,12 +15,14 @@ "source": "src/index.ts",

"scripts": {
"build": "parcel build src/index.ts --no-cache",
"clean": "rm -rf dist",
"version": "yarn version",
"prepublish": "yarn clean && yarn build"
"version": "yarn version"
},
"dependencies": {
"@interop-ui/react-utils": "0.0.1-16"
"@babel/runtime": "^7.13.10",
"@interop-ui/primitive": "0.2.0-rc.1",
"@interop-ui/react-primitive": "0.2.0-rc.1",
"@interop-ui/react-use-body-pointer-events": "0.2.0-rc.1",
"@interop-ui/react-use-callback-ref": "0.2.0-rc.1",
"@interop-ui/react-use-escape-keydown": "0.2.0-rc.1"
},
"devDependencies": {
"parcel": "^2.0.0-beta.1",
"react-remove-scroll": "^2.4.0"

@@ -30,3 +32,12 @@ },

"react": "^16.8 || ^17.0"
}
},
"homepage": "https://radix-ui.com/primitives",
"repository": {
"type": "git",
"url": "git+https://github.com/radix-ui/primitives.git"
},
"bugs": {
"url": "https://github.com/radix-ui/primitives/issues"
},
"stableVersion": "0.1.0"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc