react-viewport-height 1.2.1 → 1.3.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/README.md +22 -21
- package/index.d.ts +2 -6
- package/lib/index.js +1 -1
- package/package.json +59 -62
package/README.md
CHANGED
|
@@ -6,12 +6,15 @@
|
|
|
6
6
|
[](https://github.com/dimazuien/react-viewport-height/issues)
|
|
7
7
|
[](https://github.com/dimazuien/react-viewport-height/pulls)
|
|
8
8
|
[](https://github.com/dimazuien/react-viewport-height/stargazers)
|
|
9
|
-

|
|
10
|
+

|
|
11
11
|
|
|
12
|
-
A
|
|
12
|
+
A React hook that returns the size of one `vh` unit, 1% of the browser's inner window height, and keeps it up to date when the window resizes.
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
The package is maintained, but for new code, prefer the standard alternatives:
|
|
15
|
+
|
|
16
|
+
- **To size elements**, use the CSS `dvh`, `svh`, and `lvh` units. They follow the actual viewport height on mobile browsers and are [widely supported](https://caniuse.com/viewport-unit-variants). [Read more about the new units.](https://web.dev/viewport-units/)
|
|
17
|
+
- **To use the height in JavaScript**, use `useWindowSize` from [usehooks-ts](https://usehooks-ts.com/react-hook/use-window-size) or [react-use](https://github.com/streamich/react-use/blob/master/docs/useWindowSize.md). Both return the window's inner width and height, so `useWindowSize().height / 100` is the value that `useVH` returns.
|
|
15
18
|
|
|
16
19
|
## Usage
|
|
17
20
|
|
|
@@ -20,26 +23,24 @@ npm install react-viewport-height
|
|
|
20
23
|
```
|
|
21
24
|
|
|
22
25
|
```jsx
|
|
23
|
-
// index.js
|
|
24
26
|
import useVH from 'react-viewport-height';
|
|
25
|
-
import './index.css';
|
|
26
|
-
|
|
27
|
-
const App = () => {
|
|
28
|
-
useVH();
|
|
29
27
|
|
|
30
|
-
|
|
28
|
+
const ROW_HEIGHT = 40;
|
|
29
|
+
|
|
30
|
+
const Rows = ({ items }) => {
|
|
31
|
+
const vh = useVH();
|
|
32
|
+
const rowsThatFit = Math.floor((100 * vh) / ROW_HEIGHT);
|
|
33
|
+
|
|
34
|
+
return (
|
|
35
|
+
<ul>
|
|
36
|
+
{items.slice(0, rowsThatFit).map((item) => (
|
|
37
|
+
<li key={item} style={{ height: ROW_HEIGHT }}>
|
|
38
|
+
{item}
|
|
39
|
+
</li>
|
|
40
|
+
))}
|
|
41
|
+
</ul>
|
|
42
|
+
);
|
|
31
43
|
};
|
|
32
44
|
```
|
|
33
45
|
|
|
34
|
-
```css
|
|
35
|
-
/* index.css */
|
|
36
|
-
.app {
|
|
37
|
-
min-height: calc(var(--vh, 1vh) * 100);
|
|
38
|
-
}
|
|
39
|
-
```
|
|
40
|
-
|
|
41
46
|
Read [the documentation](https://github.com/dimazuien/react-viewport-height/blob/main/docs/index.md) for more details. You can also play with a [demo](https://codesandbox.io/s/react-viewport-height-90o4j).
|
|
42
|
-
|
|
43
|
-
## Support
|
|
44
|
-
|
|
45
|
-
If you like this package and want to support it, you can do it on [Patreon](https://www.patreon.com/dimazuien)
|
package/index.d.ts
CHANGED
|
@@ -1,16 +1,12 @@
|
|
|
1
1
|
declare module 'react-viewport-height/src/index' {
|
|
2
|
-
import useVH from 'react-viewport-height/src/useVH';
|
|
2
|
+
import useVH from 'react-viewport-height/src/useVH/index';
|
|
3
3
|
export default useVH;
|
|
4
4
|
|
|
5
5
|
}
|
|
6
|
-
declare module 'react-viewport-height/src/useVH' {
|
|
6
|
+
declare module 'react-viewport-height/src/useVH/index' {
|
|
7
7
|
const useVH: () => number;
|
|
8
8
|
export default useVH;
|
|
9
9
|
|
|
10
|
-
}
|
|
11
|
-
declare module 'react-viewport-height/tests/useVH.test' {
|
|
12
|
-
import '@testing-library/jest-dom/extend-expect';
|
|
13
|
-
|
|
14
10
|
}
|
|
15
11
|
declare module 'react-viewport-height' {
|
|
16
12
|
import main = require('react-viewport-height/src/index');
|
package/lib/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports["react-viewport-height"]=t():e["react-viewport-height"]=t()}(
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports["react-viewport-height"]=t():e["react-viewport-height"]=t()}(globalThis,function(){return function(){"use strict";var e={d:function(t,r){for(var n in r)e.o(r,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:r[n]})},o:function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r:function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{default:function(){return u}});var r=require("react");function n(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}var o="--vh",i=0,u=function(){var e,t,u=(e=(0,r.useState)(0),t=2,function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,o,i,u,a=[],l=!0,c=!1;try{if(i=(r=r.call(e)).next,0===t){if(Object(r)!==r)return;l=!1}else for(;!(l=(n=i.call(r)).done)&&(a.push(n.value),a.length!==t);l=!0);}catch(e){c=!0,o=e}finally{try{if(!l&&null!=r.return&&(u=r.return(),Object(u)!==u))return}finally{if(c)throw o}}return a}}(e,t)||function(e,t){if(e){if("string"==typeof e)return n(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?n(e,t):void 0}}(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.")}()),a=u[0],l=u[1],c=(0,r.useCallback)(function(){var e=Number((.01*window.innerHeight).toFixed(2));document.documentElement.style.setProperty(o,"".concat(e,"px")),l(e)},[l]);return(0,r.useEffect)(function(){return"undefined"!=typeof window&&(i+=1,c(),window.addEventListener("resize",c)),function(){window.removeEventListener("resize",c),0==(i-=1)&&document.documentElement.style.removeProperty(o)}},[c]),a};return t}()});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-viewport-height",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "A
|
|
3
|
+
"version": "1.3.0",
|
|
4
|
+
"description": "A React hook that returns 1% of the browser's inner window height and keeps it up to date.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "https://github.com/dimazuien/react-viewport-height.git"
|
|
@@ -19,10 +19,6 @@
|
|
|
19
19
|
"mobile"
|
|
20
20
|
],
|
|
21
21
|
"author": "Dima Zuien",
|
|
22
|
-
"funding": {
|
|
23
|
-
"type": "patreon",
|
|
24
|
-
"url": "https://www.patreon.com/dimazuien"
|
|
25
|
-
},
|
|
26
22
|
"license": "MIT",
|
|
27
23
|
"bugs": {
|
|
28
24
|
"url": "https://github.com/dimazuien/react-viewport-height/issues"
|
|
@@ -35,72 +31,73 @@
|
|
|
35
31
|
"index.d.ts"
|
|
36
32
|
],
|
|
37
33
|
"sideEffects": false,
|
|
34
|
+
"packageManager": "pnpm@12.20.0",
|
|
38
35
|
"scripts": {
|
|
39
|
-
"
|
|
36
|
+
"prepare": "husky",
|
|
40
37
|
"build": "webpack",
|
|
41
|
-
"dts": "
|
|
38
|
+
"dts": "npm-dts generate -e src/index --tsc=\"-p tsconfig.build.json\"",
|
|
42
39
|
"lint": "eslint .",
|
|
43
40
|
"test": "jest",
|
|
44
|
-
"
|
|
45
|
-
"release": "semantic-release",
|
|
46
|
-
"postpublish": "pinst --enable"
|
|
41
|
+
"release": "semantic-release"
|
|
47
42
|
},
|
|
48
43
|
"devDependencies": {
|
|
49
|
-
"@babel/core": "7.
|
|
50
|
-
"@babel/preset-env": "7.
|
|
51
|
-
"@babel/preset-react": "7.
|
|
52
|
-
"@babel/preset-typescript": "7.
|
|
53
|
-
"@commitlint/cli": "
|
|
54
|
-
"@commitlint/config-conventional": "
|
|
55
|
-
"@semantic-release/changelog": "
|
|
56
|
-
"@semantic-release/commit-analyzer": "
|
|
57
|
-
"@semantic-release/git": "
|
|
58
|
-
"@semantic-release/github": "
|
|
59
|
-
"@semantic-release/npm": "
|
|
60
|
-
"@semantic-release/release-notes-generator": "
|
|
61
|
-
"@testing-library/dom": "
|
|
62
|
-
"@testing-library/jest-dom": "
|
|
63
|
-
"@testing-library/react": "
|
|
64
|
-
"@testing-library/user-event": "14.
|
|
65
|
-
"@types/jest": "
|
|
66
|
-
"@types/
|
|
67
|
-
"@types/react
|
|
44
|
+
"@babel/core": "7.29.13",
|
|
45
|
+
"@babel/preset-env": "7.29.14",
|
|
46
|
+
"@babel/preset-react": "7.29.7",
|
|
47
|
+
"@babel/preset-typescript": "7.29.7",
|
|
48
|
+
"@commitlint/cli": "21.2.4",
|
|
49
|
+
"@commitlint/config-conventional": "21.2.4",
|
|
50
|
+
"@semantic-release/changelog": "7.0.0",
|
|
51
|
+
"@semantic-release/commit-analyzer": "13.0.1",
|
|
52
|
+
"@semantic-release/git": "11.0.1",
|
|
53
|
+
"@semantic-release/github": "12.0.11",
|
|
54
|
+
"@semantic-release/npm": "13.2.0",
|
|
55
|
+
"@semantic-release/release-notes-generator": "14.1.1",
|
|
56
|
+
"@testing-library/dom": "10.4.2",
|
|
57
|
+
"@testing-library/jest-dom": "6.9.1",
|
|
58
|
+
"@testing-library/react": "16.3.3",
|
|
59
|
+
"@testing-library/user-event": "14.6.13",
|
|
60
|
+
"@types/jest": "29.5.14",
|
|
61
|
+
"@types/node": "26.6.6",
|
|
62
|
+
"@types/react": "19.3.0",
|
|
63
|
+
"@types/react-dom": "19.3.0",
|
|
68
64
|
"@types/react-router-dom": "5.3.3",
|
|
69
|
-
"@
|
|
70
|
-
"@typescript-eslint/
|
|
71
|
-
"
|
|
72
|
-
"
|
|
73
|
-
"
|
|
65
|
+
"@typescript-eslint/eslint-plugin": "7.18.0",
|
|
66
|
+
"@typescript-eslint/parser": "7.18.0",
|
|
67
|
+
"babel-loader": "10.1.1",
|
|
68
|
+
"commitizen": "4.3.2",
|
|
69
|
+
"conventional-changelog-conventionalcommits": "9.3.1",
|
|
74
70
|
"cz-conventional-changelog": "3.3.0",
|
|
75
|
-
"eslint": "8.
|
|
71
|
+
"eslint": "8.57.1",
|
|
76
72
|
"eslint-config-airbnb": "19.0.4",
|
|
77
|
-
"eslint-config-prettier": "
|
|
78
|
-
"eslint-plugin-import": "2.
|
|
79
|
-
"eslint-plugin-jest
|
|
80
|
-
"eslint-plugin-
|
|
81
|
-
"eslint-plugin-
|
|
82
|
-
"eslint-plugin-
|
|
83
|
-
"eslint-plugin-react
|
|
84
|
-
"eslint-plugin-
|
|
85
|
-
"eslint-plugin-
|
|
86
|
-
"
|
|
87
|
-
"
|
|
88
|
-
"jest
|
|
89
|
-
"
|
|
90
|
-
"
|
|
91
|
-
"
|
|
92
|
-
"
|
|
93
|
-
"
|
|
94
|
-
"react
|
|
95
|
-
"
|
|
96
|
-
"
|
|
97
|
-
"ts-
|
|
98
|
-
"
|
|
99
|
-
"
|
|
100
|
-
"webpack
|
|
73
|
+
"eslint-config-prettier": "10.1.8",
|
|
74
|
+
"eslint-plugin-import": "2.32.0",
|
|
75
|
+
"eslint-plugin-jest": "27.9.0",
|
|
76
|
+
"eslint-plugin-jest-dom": "5.11.0",
|
|
77
|
+
"eslint-plugin-jsx-a11y": "6.10.2",
|
|
78
|
+
"eslint-plugin-prettier": "5.5.7",
|
|
79
|
+
"eslint-plugin-react": "7.37.5",
|
|
80
|
+
"eslint-plugin-react-hooks": "4.6.2",
|
|
81
|
+
"eslint-plugin-simple-import-sort": "14.0.0",
|
|
82
|
+
"eslint-plugin-testing-library": "7.16.3",
|
|
83
|
+
"husky": "9.1.7",
|
|
84
|
+
"jest": "29.7.0",
|
|
85
|
+
"jest-environment-jsdom": "30.5.2",
|
|
86
|
+
"jest-junit": "17.0.0",
|
|
87
|
+
"lint-staged": "17.6.2",
|
|
88
|
+
"npm-dts": "1.3.13",
|
|
89
|
+
"prettier": "3.10.1",
|
|
90
|
+
"react": "19.3.1",
|
|
91
|
+
"react-dom": "19.3.1",
|
|
92
|
+
"semantic-release": "25.0.9",
|
|
93
|
+
"ts-jest": "29.4.15",
|
|
94
|
+
"ts-node": "10.9.2",
|
|
95
|
+
"typescript": "5.9.3",
|
|
96
|
+
"webpack": "5.113.0",
|
|
97
|
+
"webpack-cli": "7.3.1"
|
|
101
98
|
},
|
|
102
99
|
"peerDependencies": {
|
|
103
|
-
"react": "^16.8 || ^17 || ^18",
|
|
104
|
-
"react-dom": "^16.8 || ^17 || ^18"
|
|
100
|
+
"react": "^16.8 || ^17 || ^18 || ^19",
|
|
101
|
+
"react-dom": "^16.8 || ^17 || ^18 || ^19"
|
|
105
102
|
}
|
|
106
103
|
}
|