Initial commit
This commit is contained in:
commit
78f8d225ee
21173 changed files with 2907774 additions and 0 deletions
41
node_modules/@radix-ui/react-compose-refs/dist/index.mjs
generated
vendored
Normal file
41
node_modules/@radix-ui/react-compose-refs/dist/index.mjs
generated
vendored
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
// packages/react/compose-refs/src/compose-refs.tsx
|
||||
import * as React from "react";
|
||||
function setRef(ref, value) {
|
||||
if (typeof ref === "function") {
|
||||
return ref(value);
|
||||
} else if (ref !== null && ref !== void 0) {
|
||||
ref.current = value;
|
||||
}
|
||||
}
|
||||
function composeRefs(...refs) {
|
||||
return (node) => {
|
||||
let hasCleanup = false;
|
||||
const cleanups = refs.map((ref) => {
|
||||
const cleanup = setRef(ref, node);
|
||||
if (!hasCleanup && typeof cleanup == "function") {
|
||||
hasCleanup = true;
|
||||
}
|
||||
return cleanup;
|
||||
});
|
||||
if (hasCleanup) {
|
||||
return () => {
|
||||
for (let i = 0; i < cleanups.length; i++) {
|
||||
const cleanup = cleanups[i];
|
||||
if (typeof cleanup == "function") {
|
||||
cleanup();
|
||||
} else {
|
||||
setRef(refs[i], null);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
function useComposedRefs(...refs) {
|
||||
return React.useCallback(composeRefs(...refs), refs);
|
||||
}
|
||||
export {
|
||||
composeRefs,
|
||||
useComposedRefs
|
||||
};
|
||||
//# sourceMappingURL=index.mjs.map
|
||||
Loading…
Add table
Add a link
Reference in a new issue