@hanzogui/compose-refs 2.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/LICENSE +21 -0
- package/dist/cjs/compose-refs.cjs +48 -0
- package/dist/cjs/compose-refs.native.js +57 -0
- package/dist/cjs/compose-refs.native.js.map +1 -0
- package/dist/cjs/index.cjs +18 -0
- package/dist/cjs/index.native.js +21 -0
- package/dist/cjs/index.native.js.map +1 -0
- package/dist/esm/compose-refs.mjs +12 -0
- package/dist/esm/compose-refs.mjs.map +1 -0
- package/dist/esm/compose-refs.native.js +18 -0
- package/dist/esm/compose-refs.native.js.map +1 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/index.mjs +2 -0
- package/dist/esm/index.mjs.map +1 -0
- package/dist/esm/index.native.js +2 -0
- package/dist/esm/index.native.js.map +1 -0
- package/package.json +43 -0
- package/src/compose-refs.tsx +39 -0
- package/src/index.ts +1 -0
- package/types/compose-refs.d.ts +19 -0
- package/types/compose-refs.d.ts.map +1 -0
- package/types/index.d.ts +2 -0
- package/types/index.d.ts.map +1 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 Nate Wienert
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf,
|
|
6
|
+
__hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all) __defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: !0
|
|
11
|
+
});
|
|
12
|
+
},
|
|
13
|
+
__copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
15
|
+
get: () => from[key],
|
|
16
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
|
+
});
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
26
|
+
value: mod,
|
|
27
|
+
enumerable: !0
|
|
28
|
+
}) : target, mod)),
|
|
29
|
+
__toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
30
|
+
value: !0
|
|
31
|
+
}), mod);
|
|
32
|
+
var compose_refs_exports = {};
|
|
33
|
+
__export(compose_refs_exports, {
|
|
34
|
+
composeRefs: () => composeRefs,
|
|
35
|
+
setRef: () => setRef,
|
|
36
|
+
useComposedRefs: () => useComposedRefs
|
|
37
|
+
});
|
|
38
|
+
module.exports = __toCommonJS(compose_refs_exports);
|
|
39
|
+
var React = __toESM(require("react"), 1);
|
|
40
|
+
function setRef(ref, value) {
|
|
41
|
+
typeof ref == "function" ? ref(value) : ref && (ref.current = value);
|
|
42
|
+
}
|
|
43
|
+
function composeRefs(...refs) {
|
|
44
|
+
return node => refs.forEach(ref => setRef(ref, node));
|
|
45
|
+
}
|
|
46
|
+
function useComposedRefs(...refs) {
|
|
47
|
+
return React.useCallback(composeRefs(...refs), refs);
|
|
48
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf,
|
|
8
|
+
__hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all) __defProp(target, name, {
|
|
11
|
+
get: all[name],
|
|
12
|
+
enumerable: !0
|
|
13
|
+
});
|
|
14
|
+
},
|
|
15
|
+
__copyProps = (to, from, except, desc) => {
|
|
16
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
17
|
+
get: () => from[key],
|
|
18
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
19
|
+
});
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
23
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
24
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
25
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
26
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
27
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
28
|
+
value: mod,
|
|
29
|
+
enumerable: !0
|
|
30
|
+
}) : target, mod)),
|
|
31
|
+
__toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
32
|
+
value: !0
|
|
33
|
+
}), mod);
|
|
34
|
+
var compose_refs_exports = {};
|
|
35
|
+
__export(compose_refs_exports, {
|
|
36
|
+
composeRefs: () => composeRefs,
|
|
37
|
+
setRef: () => setRef,
|
|
38
|
+
useComposedRefs: () => useComposedRefs
|
|
39
|
+
});
|
|
40
|
+
module.exports = __toCommonJS(compose_refs_exports);
|
|
41
|
+
var React = __toESM(require("react"), 1);
|
|
42
|
+
function setRef(ref, value) {
|
|
43
|
+
typeof ref == "function" ? ref(value) : ref && (ref.current = value);
|
|
44
|
+
}
|
|
45
|
+
function composeRefs() {
|
|
46
|
+
for (var _len = arguments.length, refs = new Array(_len), _key = 0; _key < _len; _key++) refs[_key] = arguments[_key];
|
|
47
|
+
return function (node) {
|
|
48
|
+
return refs.forEach(function (ref) {
|
|
49
|
+
return setRef(ref, node);
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
function useComposedRefs() {
|
|
54
|
+
for (var _len = arguments.length, refs = new Array(_len), _key = 0; _key < _len; _key++) refs[_key] = arguments[_key];
|
|
55
|
+
return React.useCallback(composeRefs(...refs), refs);
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=compose-refs.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","compose_refs_exports","__export","composeRefs","setRef","useComposedRefs","module","exports","React","__toESM","require","ref","current","_len","arguments","length","refs","Array","_key","node","forEach"],"sources":["../../src/compose-refs.tsx"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBAAA;EAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;IAAAC,KAAA;EAAA,IAAAH,GAAA;AAAA,IAAAI,oBAAA;AAAAC,QAAA,CAAAD,oBAAA;EAAAE,WAAA,EAAAA,CAAA,KAAAA,WAAA;EAAAC,MAAA,EAAAA,CAAA,KAAAA,MAAA;EAAAC,eAAA,EAAAA,CAAA,KAAAA;AAAA;AAGAC,MAAA,CAAAC,OAAuB,GAAAX,YAAA,CAAAK,oBAAA;AAahB,IAAAO,KAAS,GAAAC,OAAU,CAAAC,OAAqB,CAAU;AACvD,SAAWN,OAAQO,GAAA,EAAAX,KAAA;EAKrB,OAAAW,GAAA,iBAAAA,GAAA,CAAAX,KAAA,IAAAW,GAAA,KAAAA,GAAA,CAAAC,OAAA,GAAAZ,KAAA;AAMO;AACL,SAAOG,WAAaA,CAAA;EACtB,SAAAU,IAAA,GAAAC,SAAA,CAAAC,MAAA,EAAAC,IAAA,OAAAC,KAAA,CAAAJ,IAAA,GAAAK,IAAA,MAAAA,IAAA,GAAAL,IAAA,EAAAK,IAAA,IAMOF,IAAA,CAASE,IAAA,IAAAJ,SAAA,CAAAI,IAAsB;EACpC,OAAO,UAAMC,IAAA;IACf,OAAAH,IAAA,CAAAI,OAAA,WAAAT,GAAA","ignoreList":[]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
|
6
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
7
|
+
get: () => from[key],
|
|
8
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
9
|
+
});
|
|
10
|
+
return to;
|
|
11
|
+
},
|
|
12
|
+
__reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
13
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
14
|
+
value: !0
|
|
15
|
+
}), mod);
|
|
16
|
+
var index_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(index_exports);
|
|
18
|
+
__reExport(index_exports, require("./compose-refs.cjs"), module.exports);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __copyProps = (to, from, except, desc) => {
|
|
8
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
9
|
+
get: () => from[key],
|
|
10
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
11
|
+
});
|
|
12
|
+
return to;
|
|
13
|
+
},
|
|
14
|
+
__reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
16
|
+
value: !0
|
|
17
|
+
}), mod);
|
|
18
|
+
var index_exports = {};
|
|
19
|
+
module.exports = __toCommonJS(index_exports);
|
|
20
|
+
__reExport(index_exports, require("./compose-refs.native.js"), module.exports);
|
|
21
|
+
//# sourceMappingURL=index.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","index_exports","module","exports"],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;EAAAC,KAAA;AAAA,IAAAH,GAAA;AAAA,IAAAI,aAAA;AAAAC,MAAA,CAAAC,OAAA,GAAAP,YAAc,CAAAK,aAAA","ignoreList":[]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
function setRef(ref, value) {
|
|
3
|
+
typeof ref == "function" ? ref(value) : ref && (ref.current = value);
|
|
4
|
+
}
|
|
5
|
+
function composeRefs(...refs) {
|
|
6
|
+
return node => refs.forEach(ref => setRef(ref, node));
|
|
7
|
+
}
|
|
8
|
+
function useComposedRefs(...refs) {
|
|
9
|
+
return React.useCallback(composeRefs(...refs), refs);
|
|
10
|
+
}
|
|
11
|
+
export { composeRefs, setRef, useComposedRefs };
|
|
12
|
+
//# sourceMappingURL=compose-refs.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["React","setRef","ref","value","current","composeRefs","refs","node","forEach","useComposedRefs","useCallback"],"sources":["../../src/compose-refs.tsx"],"sourcesContent":[null],"mappings":"AAGA,YAAYA,KAAA,MAAW;AAahB,SAASC,OAAUC,GAAA,EAAqBC,KAAA,EAAU;EACnD,OAAOD,GAAA,IAAQ,aACjBA,GAAA,CAAIC,KAAK,IACAD,GAAA,KACPA,GAAA,CAAkCE,OAAA,GAAUD,KAAA;AAElD;AAMO,SAASE,YAAA,GAAkBC,IAAA,EAAwB;EACxD,OAAQC,IAAA,IAAYD,IAAA,CAAKE,OAAA,CAASN,GAAA,IAAQD,MAAA,CAAOC,GAAA,EAAKK,IAAI,CAAC;AAC7D;AAMO,SAASE,gBAAA,GAAsBH,IAAA,EAAwB;EAC5D,OAAON,KAAA,CAAMU,WAAA,CAAYL,WAAA,CAAY,GAAGC,IAAI,GAAGA,IAAI;AACrD","ignoreList":[]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
function setRef(ref, value) {
|
|
3
|
+
typeof ref == "function" ? ref(value) : ref && (ref.current = value);
|
|
4
|
+
}
|
|
5
|
+
function composeRefs() {
|
|
6
|
+
for (var _len = arguments.length, refs = new Array(_len), _key = 0; _key < _len; _key++) refs[_key] = arguments[_key];
|
|
7
|
+
return function (node) {
|
|
8
|
+
return refs.forEach(function (ref) {
|
|
9
|
+
return setRef(ref, node);
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
function useComposedRefs() {
|
|
14
|
+
for (var _len = arguments.length, refs = new Array(_len), _key = 0; _key < _len; _key++) refs[_key] = arguments[_key];
|
|
15
|
+
return React.useCallback(composeRefs(...refs), refs);
|
|
16
|
+
}
|
|
17
|
+
export { composeRefs, setRef, useComposedRefs };
|
|
18
|
+
//# sourceMappingURL=compose-refs.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["React","setRef","ref","value","current","composeRefs","_len","arguments","length","refs","Array","_key","node","forEach"],"sources":["../../src/compose-refs.tsx"],"sourcesContent":[null],"mappings":"AAGA,YAAYA,KAAA,MAAW;AAahB,SAASC,OAAUC,GAAA,EAAqBC,KAAA,EAAU;EACnD,OAAOD,GAAA,IAAQ,aACjBA,GAAA,CAAIC,KAAK,IACAD,GAAA,KACPA,GAAA,CAAkCE,OAAA,GAAUD,KAAA;AAElD;AAMO,SAASE,YAAA;EACd,SAAQC,IAAA,GAAAC,SAAiB,CAAAC,MAAS,EAAAC,IAAA,GAAQ,IAAAC,KAAO,CAAKJ,IAAI,CAAC,EAAAK,IAAA,MAAAA,IAAA,GAAAL,IAAA,EAAAK,IAAA,IAC7DF,IAAA,CAAAE,IAAA,IAAAJ,SAAA,CAAAI,IAAA;EAMO,OAAS,UAAAC,IAAA;IACd,OAAOH,IAAM,CAAAI,OAAA,WAAYX,GAAA;MAC3B,OAAAD,MAAA,CAAAC,GAAA,EAAAU,IAAA","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA,cAAc","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA,cAAc","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA,cAAc","ignoreList":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@hanzogui/compose-refs",
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"gitHead": "a49cc7ea6b93ba384e77a4880ae48ac4a5635c14",
|
|
5
|
+
"source": "src/index.ts",
|
|
6
|
+
"files": [
|
|
7
|
+
"src",
|
|
8
|
+
"types",
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
11
|
+
"type": "module",
|
|
12
|
+
"sideEffects": false,
|
|
13
|
+
"main": "dist/cjs",
|
|
14
|
+
"module": "dist/esm",
|
|
15
|
+
"types": "./types/index.d.ts",
|
|
16
|
+
"exports": {
|
|
17
|
+
"./package.json": "./package.json",
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./types/index.d.ts",
|
|
20
|
+
"react-native": "./dist/esm/index.native.js",
|
|
21
|
+
"browser": "./dist/esm/index.mjs",
|
|
22
|
+
"module": "./dist/esm/index.mjs",
|
|
23
|
+
"import": "./dist/esm/index.mjs",
|
|
24
|
+
"require": "./dist/cjs/index.cjs",
|
|
25
|
+
"default": "./dist/esm/index.mjs"
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"publishConfig": {
|
|
29
|
+
"access": "public"
|
|
30
|
+
},
|
|
31
|
+
"scripts": {
|
|
32
|
+
"build": "hanzo-gui-build",
|
|
33
|
+
"watch": "hanzo-gui-build --watch",
|
|
34
|
+
"clean": "hanzo-gui-build clean"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@hanzogui/build": "workspace:*",
|
|
38
|
+
"react": ">=19"
|
|
39
|
+
},
|
|
40
|
+
"peerDependencies": {
|
|
41
|
+
"react": ">=19"
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// from radix
|
|
2
|
+
// https://raw.githubusercontent.com/radix-ui/primitives/main/packages/react/compose-refs/src/composeRefs.tsx
|
|
3
|
+
|
|
4
|
+
import * as React from 'react'
|
|
5
|
+
|
|
6
|
+
type PossibleRef<T> =
|
|
7
|
+
| React.Ref<T>
|
|
8
|
+
| React.ForwardedRef<T>
|
|
9
|
+
| React.RefObject<T>
|
|
10
|
+
| React.Dispatch<React.SetStateAction<T | null>>
|
|
11
|
+
| undefined
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Set a given ref to a given value
|
|
15
|
+
* This utility takes care of different types of refs: callback refs and RefObject(s)
|
|
16
|
+
*/
|
|
17
|
+
export function setRef<T>(ref: PossibleRef<T>, value: T) {
|
|
18
|
+
if (typeof ref === 'function') {
|
|
19
|
+
ref(value)
|
|
20
|
+
} else if (ref) {
|
|
21
|
+
;(ref as React.MutableRefObject<T>).current = value
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* A utility to compose multiple refs together
|
|
27
|
+
* Accepts callback refs and RefObject(s)
|
|
28
|
+
*/
|
|
29
|
+
export function composeRefs<T>(...refs: PossibleRef<T>[]) {
|
|
30
|
+
return (node: T) => refs.forEach((ref) => setRef(ref, node))
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* A custom hook that composes multiple refs
|
|
35
|
+
* Accepts callback refs and RefObject(s)
|
|
36
|
+
*/
|
|
37
|
+
export function useComposedRefs<T>(...refs: PossibleRef<T>[]) {
|
|
38
|
+
return React.useCallback(composeRefs(...refs), refs)
|
|
39
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './compose-refs'
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
type PossibleRef<T> = React.Ref<T> | React.ForwardedRef<T> | React.RefObject<T> | React.Dispatch<React.SetStateAction<T | null>> | undefined;
|
|
3
|
+
/**
|
|
4
|
+
* Set a given ref to a given value
|
|
5
|
+
* This utility takes care of different types of refs: callback refs and RefObject(s)
|
|
6
|
+
*/
|
|
7
|
+
export declare function setRef<T>(ref: PossibleRef<T>, value: T): void;
|
|
8
|
+
/**
|
|
9
|
+
* A utility to compose multiple refs together
|
|
10
|
+
* Accepts callback refs and RefObject(s)
|
|
11
|
+
*/
|
|
12
|
+
export declare function composeRefs<T>(...refs: PossibleRef<T>[]): (node: T) => void;
|
|
13
|
+
/**
|
|
14
|
+
* A custom hook that composes multiple refs
|
|
15
|
+
* Accepts callback refs and RefObject(s)
|
|
16
|
+
*/
|
|
17
|
+
export declare function useComposedRefs<T>(...refs: PossibleRef<T>[]): (node: T) => void;
|
|
18
|
+
export {};
|
|
19
|
+
//# sourceMappingURL=compose-refs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compose-refs.d.ts","sourceRoot":"","sources":["../src/compose-refs.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,KAAK,WAAW,CAAC,CAAC,IACd,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,GACZ,KAAK,CAAC,YAAY,CAAC,CAAC,CAAC,GACrB,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,GAClB,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,GAC9C,SAAS,CAAA;AAEb;;;GAGG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,GAAG,EAAE,WAAW,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,QAMtD;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,WAAW,CAAC,CAAC,CAAC,EAAE,IAC9C,MAAM,CAAC,UAChB;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,WAAW,CAAC,CAAC,CAAC,EAAE,qBAE3D"}
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAA"}
|