@radix-ui/react-use-rect 0.0.0-20250116175529

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/README.md ADDED
@@ -0,0 +1,13 @@
1
+ # `react-use-rect`
2
+
3
+ ## Installation
4
+
5
+ ```sh
6
+ $ yarn add @radix-ui/react-use-rect
7
+ # or
8
+ $ npm install @radix-ui/react-use-rect
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ This is an internal utility, not intended for public usage.
@@ -0,0 +1,9 @@
1
+ import { Measurable } from '@radix-ui/rect';
2
+
3
+ /**
4
+ * Use this custom hook to get access to an element's rect (getBoundingClientRect)
5
+ * and observe it along time.
6
+ */
7
+ declare function useRect(measurable: Measurable | null): DOMRect | undefined;
8
+
9
+ export { useRect };
@@ -0,0 +1,9 @@
1
+ import { Measurable } from '@radix-ui/rect';
2
+
3
+ /**
4
+ * Use this custom hook to get access to an element's rect (getBoundingClientRect)
5
+ * and observe it along time.
6
+ */
7
+ declare function useRect(measurable: Measurable | null): DOMRect | undefined;
8
+
9
+ export { useRect };
package/dist/index.js ADDED
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], 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", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // packages/react/use-rect/src/index.ts
31
+ var src_exports = {};
32
+ __export(src_exports, {
33
+ useRect: () => useRect
34
+ });
35
+ module.exports = __toCommonJS(src_exports);
36
+
37
+ // packages/react/use-rect/src/useRect.tsx
38
+ var React = __toESM(require("react"));
39
+ var import_rect = require("@radix-ui/rect");
40
+ function useRect(measurable) {
41
+ const [rect, setRect] = React.useState();
42
+ React.useEffect(() => {
43
+ if (measurable) {
44
+ const unobserve = (0, import_rect.observeElementRect)(measurable, setRect);
45
+ return () => {
46
+ setRect(void 0);
47
+ unobserve();
48
+ };
49
+ }
50
+ return;
51
+ }, [measurable]);
52
+ return rect;
53
+ }
54
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/index.ts", "../src/useRect.tsx"],
4
+ "sourcesContent": ["export { useRect } from './useRect';\n", "import * as React from 'react';\nimport { observeElementRect } from '@radix-ui/rect';\n\nimport type { Measurable } from '@radix-ui/rect';\n\n/**\n * Use this custom hook to get access to an element's rect (getBoundingClientRect)\n * and observe it along time.\n */\nfunction useRect(measurable: Measurable | null) {\n const [rect, setRect] = React.useState<DOMRect>();\n React.useEffect(() => {\n if (measurable) {\n const unobserve = observeElementRect(measurable, setRect);\n return () => {\n setRect(undefined);\n unobserve();\n };\n }\n return;\n }, [measurable]);\n return rect;\n}\n\nexport { useRect };\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,YAAuB;AACvB,kBAAmC;AAQnC,SAAS,QAAQ,YAA+B;AAC9C,QAAM,CAAC,MAAM,OAAO,IAAU,eAAkB;AAChD,EAAM,gBAAU,MAAM;AACpB,QAAI,YAAY;AACd,YAAM,gBAAY,gCAAmB,YAAY,OAAO;AACxD,aAAO,MAAM;AACX,gBAAQ,MAAS;AACjB,kBAAU;AAAA,MACZ;AAAA,IACF;AACA;AAAA,EACF,GAAG,CAAC,UAAU,CAAC;AACf,SAAO;AACT;",
6
+ "names": []
7
+ }
package/dist/index.mjs ADDED
@@ -0,0 +1,21 @@
1
+ // packages/react/use-rect/src/useRect.tsx
2
+ import * as React from "react";
3
+ import { observeElementRect } from "@radix-ui/rect";
4
+ function useRect(measurable) {
5
+ const [rect, setRect] = React.useState();
6
+ React.useEffect(() => {
7
+ if (measurable) {
8
+ const unobserve = observeElementRect(measurable, setRect);
9
+ return () => {
10
+ setRect(void 0);
11
+ unobserve();
12
+ };
13
+ }
14
+ return;
15
+ }, [measurable]);
16
+ return rect;
17
+ }
18
+ export {
19
+ useRect
20
+ };
21
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/useRect.tsx"],
4
+ "sourcesContent": ["import * as React from 'react';\nimport { observeElementRect } from '@radix-ui/rect';\n\nimport type { Measurable } from '@radix-ui/rect';\n\n/**\n * Use this custom hook to get access to an element's rect (getBoundingClientRect)\n * and observe it along time.\n */\nfunction useRect(measurable: Measurable | null) {\n const [rect, setRect] = React.useState<DOMRect>();\n React.useEffect(() => {\n if (measurable) {\n const unobserve = observeElementRect(measurable, setRect);\n return () => {\n setRect(undefined);\n unobserve();\n };\n }\n return;\n }, [measurable]);\n return rect;\n}\n\nexport { useRect };\n"],
5
+ "mappings": ";AAAA,YAAY,WAAW;AACvB,SAAS,0BAA0B;AAQnC,SAAS,QAAQ,YAA+B;AAC9C,QAAM,CAAC,MAAM,OAAO,IAAU,eAAkB;AAChD,EAAM,gBAAU,MAAM;AACpB,QAAI,YAAY;AACd,YAAM,YAAY,mBAAmB,YAAY,OAAO;AACxD,aAAO,MAAM;AACX,gBAAQ,MAAS;AACjB,kBAAU;AAAA,MACZ;AAAA,IACF;AACA;AAAA,EACF,GAAG,CAAC,UAAU,CAAC;AACf,SAAO;AACT;",
6
+ "names": []
7
+ }
package/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "@radix-ui/react-use-rect",
3
+ "version": "0.0.0-20250116175529",
4
+ "license": "MIT",
5
+ "exports": {
6
+ ".": {
7
+ "import": {
8
+ "types": "./dist/index.d.mts",
9
+ "default": "./dist/index.mjs"
10
+ },
11
+ "require": {
12
+ "types": "./dist/index.d.ts",
13
+ "default": "./dist/index.js"
14
+ }
15
+ }
16
+ },
17
+ "source": "./src/index.ts",
18
+ "main": "./dist/index.js",
19
+ "module": "./dist/index.mjs",
20
+ "types": "./dist/index.d.ts",
21
+ "files": [
22
+ "dist",
23
+ "README.md"
24
+ ],
25
+ "sideEffects": false,
26
+ "scripts": {
27
+ "clean": "rm -rf dist"
28
+ },
29
+ "dependencies": {
30
+ "@radix-ui/rect": "workspace:*"
31
+ },
32
+ "peerDependencies": {
33
+ "@types/react": "*",
34
+ "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
35
+ },
36
+ "peerDependenciesMeta": {
37
+ "@types/react": {
38
+ "optional": true
39
+ }
40
+ },
41
+ "homepage": "https://radix-ui.com/primitives",
42
+ "repository": {
43
+ "type": "git",
44
+ "url": "git+https://github.com/radix-ui/primitives.git"
45
+ },
46
+ "bugs": {
47
+ "url": "https://github.com/radix-ui/primitives/issues"
48
+ }
49
+ }