@vibe/hooks 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as useClickOutside } from "./useClickOutside";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type RefObject } from "react";
|
|
2
|
+
import { type GenericEventCallback } from "@vibe/shared";
|
|
3
|
+
export default function useClickOutside({ ref, callback, ignoreClasses, eventName }: {
|
|
4
|
+
ref: RefObject<HTMLElement>;
|
|
5
|
+
callback: GenericEventCallback;
|
|
6
|
+
ignoreClasses?: string[];
|
|
7
|
+
eventName?: keyof HTMLElementEventMap | string;
|
|
8
|
+
}): void;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{useCallback as e,useRef as t}from"react";import{isClient as r,useEventListener as a}from"@vibe/shared";function c({ref:c,callback:n,ignoreClasses:o,eventName:l="click"}){const i=e((e=>{if(!c||!c.current||c.current.contains(e.target))return;o&&e.target instanceof HTMLElement&&e.target.closest(o.join(","))||n(e)}),[c,n,o]),s=t(r()?document.body:null);a({eventName:l,ref:s,callback:i,capture:!0}),a({eventName:"touchend",ref:s,callback:i,capture:!0})}export{c as default};
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/useClickOutside/index.ts"],"sourcesContent":["import { useCallback, useRef, type RefObject } from \"react\";\nimport { type GenericEventCallback, isClient, useEventListener } from \"@vibe/shared\";\n\nexport default function useClickOutside({\n ref,\n callback,\n ignoreClasses,\n eventName = \"click\"\n}: {\n ref: RefObject<HTMLElement>;\n callback: GenericEventCallback;\n ignoreClasses?: string[];\n eventName?: keyof HTMLElementEventMap | string;\n}) {\n const onClickOutsideListener = useCallback(\n (event: MouseEvent) => {\n if (!ref || !ref.current || ref.current.contains(event.target as Node)) {\n return;\n }\n\n const shouldIgnoreClasses = ignoreClasses && event.target instanceof HTMLElement;\n if (shouldIgnoreClasses && event.target.closest(ignoreClasses.join(\",\"))) {\n return;\n }\n\n callback(event);\n },\n\n [ref, callback, ignoreClasses]\n );\n\n const documentRef = useRef(isClient() ? document.body : null);\n\n useEventListener({\n eventName,\n ref: documentRef,\n callback: onClickOutsideListener,\n capture: true\n });\n\n useEventListener({\n eventName: \"touchend\",\n ref: documentRef,\n callback: onClickOutsideListener,\n capture: true\n });\n}\n"],"names":["useClickOutside","ref","callback","ignoreClasses","eventName","onClickOutsideListener","useCallback","event","current","contains","target","HTMLElement","closest","join","documentRef","useRef","isClient","document","body","useEventListener","capture"],"mappings":"8GAGwB,SAAAA,GAAgBC,IACtCA,EAAGC,SACHA,EAAQC,cACRA,EAAaC,UACbA,EAAY,UAOZ,MAAMC,EAAyBC,GAC5BC,IACC,IAAKN,IAAQA,EAAIO,SAAWP,EAAIO,QAAQC,SAASF,EAAMG,QACrD,OAG0BP,GAAiBI,EAAMG,kBAAkBC,aAC1CJ,EAAMG,OAAOE,QAAQT,EAAcU,KAAK,OAInEX,EAASK,EAAM,GAGjB,CAACN,EAAKC,EAAUC,IAGZW,EAAcC,EAAOC,IAAaC,SAASC,KAAO,MAExDC,EAAiB,CACff,YACAH,IAAKa,EACLZ,SAAUG,EACVe,SAAS,IAGXD,EAAiB,CACff,UAAW,WACXH,IAAKa,EACLZ,SAAUG,EACVe,SAAS,GAEb"}
|
package/package.json
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vibe/hooks",
|
|
3
|
+
"version": "3.0.0",
|
|
4
|
+
"description": "Vibe sub-package for React hooks",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/mondaycom/vibe.git",
|
|
8
|
+
"directory": "packages/hooks"
|
|
9
|
+
},
|
|
10
|
+
"bugs": {
|
|
11
|
+
"url": "https://github.com/mondaycom/vibe/issues"
|
|
12
|
+
},
|
|
13
|
+
"homepage": "https://github.com/mondaycom/vibe#readme",
|
|
14
|
+
"author": "monday.com",
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"type": "module",
|
|
17
|
+
"main": "dist/index.js",
|
|
18
|
+
"types": "dist/index.d.ts",
|
|
19
|
+
"files": [
|
|
20
|
+
"dist"
|
|
21
|
+
],
|
|
22
|
+
"exports": {
|
|
23
|
+
"./package.json": "./package.json",
|
|
24
|
+
".": {
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"import": "./dist/index.js",
|
|
27
|
+
"default": "./dist/index.js"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"scripts": {
|
|
31
|
+
"build": "rollup -c",
|
|
32
|
+
"test": "vitest run",
|
|
33
|
+
"lint": "eslint \"./src/**/*.{js,jsx,ts,tsx}\""
|
|
34
|
+
},
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"@vibe/shared": "3.0.6",
|
|
37
|
+
"classnames": "^2.5.1",
|
|
38
|
+
"es-toolkit": "^1.39.10"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@testing-library/react": "^12.1.2",
|
|
42
|
+
"@testing-library/user-event": "^13.5.0",
|
|
43
|
+
"@testing-library/react-hooks": "^7.0.2",
|
|
44
|
+
"@vibe/config": "3.0.5",
|
|
45
|
+
"react": "^16.13.0",
|
|
46
|
+
"react-dom": "^16.13.0",
|
|
47
|
+
"react-test-renderer": "16",
|
|
48
|
+
"typescript": "^4.7.3",
|
|
49
|
+
"vitest": "^1.6.0"
|
|
50
|
+
},
|
|
51
|
+
"peerDependencies": {
|
|
52
|
+
"react": ">=16.9.0",
|
|
53
|
+
"react-dom": ">=16.9.0"
|
|
54
|
+
},
|
|
55
|
+
"sideEffects": [
|
|
56
|
+
"*.scss",
|
|
57
|
+
"*.css",
|
|
58
|
+
"*.scss.js",
|
|
59
|
+
"*.css.js"
|
|
60
|
+
],
|
|
61
|
+
"eslintConfig": {
|
|
62
|
+
"extends": [
|
|
63
|
+
"../../node_modules/@vibe/config/.eslintrc.cjs"
|
|
64
|
+
]
|
|
65
|
+
}
|
|
66
|
+
}
|