react-viewport-height 1.2.2 → 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.
Files changed (3) hide show
  1. package/README.md +21 -22
  2. package/lib/index.js +1 -1
  3. package/package.json +59 -62
package/README.md CHANGED
@@ -6,14 +6,15 @@
6
6
  [![Open issues](https://img.shields.io/github/issues-raw/dimazuien/react-viewport-height)](https://github.com/dimazuien/react-viewport-height/issues)
7
7
  [![Open pull requests](https://img.shields.io/github/issues-pr-raw/dimazuien/react-viewport-height)](https://github.com/dimazuien/react-viewport-height/pulls)
8
8
  [![GitHub Stars](https://img.shields.io/github/stars/dimazuien/react-viewport-height)](https://github.com/dimazuien/react-viewport-height/stargazers)
9
- ![CircleCI status](https://img.shields.io/circleci/build/github/dimazuien/react-viewport-height/main?label=circleci)
10
- ![Code scanning](https://img.shields.io/github/workflow/status/dimazuien/react-viewport-height/CodeQL?label=code%20scanning)
9
+ ![CI status](https://img.shields.io/github/actions/workflow/status/dimazuien/react-viewport-height/ci.yml?branch=main&label=ci)
10
+ ![Code scanning](https://img.shields.io/github/actions/workflow/status/dimazuien/react-viewport-height/codeql-analysis.yml?branch=main)
11
11
 
12
- A utility for React to set 100vh equal to the actual browser inner window height.
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
- Since `vh` has troubles on mobile browsers (primarily because of the address bar), there are several tricks to fix it. This package implements the one from [this article](https://css-tricks.com/the-trick-to-viewport-units-on-mobile/).
14
+ The package is maintained, but for new code, prefer the standard alternatives:
15
15
 
16
- _The solution for this was introduced in the [CSS Values and Units Module Level 4](https://www.w3.org/TR/css-values-4) which is [widely supported now](https://caniuse.com/viewport-unit-variants). Instead of using this package, you can use the `dvh` unit if your project doesn't need to support older browsers. [Read more about new units.](https://web.dev/viewport-units/)_
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.
17
18
 
18
19
  ## Usage
19
20
 
@@ -22,26 +23,24 @@ npm install react-viewport-height
22
23
  ```
23
24
 
24
25
  ```jsx
25
- // index.js
26
26
  import useVH from 'react-viewport-height';
27
- import './index.css';
28
27
 
29
- const App = () => {
30
- useVH();
31
-
32
- return <div className="app" />;
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
+ );
33
43
  };
34
44
  ```
35
45
 
36
- ```css
37
- /* index.css */
38
- .app {
39
- min-height: calc(var(--vh, 1vh) * 100);
40
- }
41
- ```
42
-
43
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).
44
-
45
- ## Support
46
-
47
- If you like this package and want to support it, you can do it on [Patreon](https://www.patreon.com/dimazuien)
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()}(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=new 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=[],c=!0,l=!1;try{if(i=(r=r.call(e)).next,0===t){if(Object(r)!==r)return;c=!1}else for(;!(c=(n=i.call(r)).done)&&(a.push(n.value),a.length!==t);c=!0);}catch(e){l=!0,o=e}finally{try{if(!c&&null!=r.return&&(u=r.return(),Object(u)!==u))return}finally{if(l)throw o}}return a}}(e,t)||function(e,t){if(e){if("string"==typeof e)return n(e,t);var r=Object.prototype.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],c=u[1],l=(0,r.useCallback)((function(){var e=Number((.01*window.innerHeight).toFixed(2));document.documentElement.style.setProperty(o,"".concat(e,"px")),c(e)}),[c]);return(0,r.useEffect)((function(){return"undefined"!=typeof window&&(i+=1,l(),window.addEventListener("resize",l)),function(){window.removeEventListener("resize",l),0==(i-=1)&&document.documentElement.style.removeProperty(o)}}),[l]),a};return 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.2.2",
4
- "description": "A utility for React to set 100vh equal to the actual browser inner window height.",
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
- "_postinstall": "husky install",
36
+ "prepare": "husky",
40
37
  "build": "webpack",
41
- "dts": "npx npm-dts generate -e src/index",
38
+ "dts": "npm-dts generate -e src/index --tsc=\"-p tsconfig.build.json\"",
42
39
  "lint": "eslint .",
43
40
  "test": "jest",
44
- "prepublishOnly": "pinst --disable",
45
- "release": "semantic-release",
46
- "postpublish": "pinst --enable"
41
+ "release": "semantic-release"
47
42
  },
48
43
  "devDependencies": {
49
- "@babel/core": "7.22.9",
50
- "@babel/preset-env": "7.22.9",
51
- "@babel/preset-react": "7.22.5",
52
- "@babel/preset-typescript": "7.22.5",
53
- "@commitlint/cli": "17.6.7",
54
- "@commitlint/config-conventional": "17.6.7",
55
- "@semantic-release/changelog": "6.0.3",
56
- "@semantic-release/commit-analyzer": "10.0.1",
57
- "@semantic-release/git": "10.0.1",
58
- "@semantic-release/github": "9.0.4",
59
- "@semantic-release/npm": "10.0.4",
60
- "@semantic-release/release-notes-generator": "11.0.4",
61
- "@testing-library/dom": "9.3.1",
62
- "@testing-library/jest-dom": "5.17.0",
63
- "@testing-library/react": "14.0.0",
64
- "@testing-library/user-event": "14.4.3",
65
- "@types/jest": "29.5.3",
66
- "@types/react": "18.2.17",
67
- "@types/react-dom": "18.2.7",
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
- "@types/testing-library__jest-dom": "5.14.9",
70
- "@typescript-eslint/eslint-plugin": "6.2.0",
71
- "@typescript-eslint/parser": "6.2.0",
72
- "babel-loader": "9.1.3",
73
- "commitizen": "4.3.0",
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.46.0",
71
+ "eslint": "8.57.1",
76
72
  "eslint-config-airbnb": "19.0.4",
77
- "eslint-config-prettier": "8.9.0",
78
- "eslint-plugin-import": "2.28.0",
79
- "eslint-plugin-jest-dom": "5.0.1",
80
- "eslint-plugin-jsx-a11y": "6.7.1",
81
- "eslint-plugin-prettier": "5.0.0",
82
- "eslint-plugin-react": "7.33.1",
83
- "eslint-plugin-react-hooks": "4.6.0",
84
- "eslint-plugin-simple-import-sort": "10.0.0",
85
- "eslint-plugin-testing-library": "5.11.0",
86
- "husky": "8.0.3",
87
- "jest": "29.6.2",
88
- "jest-environment-jsdom": "29.6.2",
89
- "lint-staged": "13.2.3",
90
- "npm-dts": "1.3.12",
91
- "pinst": "3.0.0",
92
- "prettier": "3.0.0",
93
- "react": "18.2.0",
94
- "react-dom": "18.2.0",
95
- "semantic-release": "21.0.7",
96
- "ts-jest": "29.1.1",
97
- "ts-node": "10.9.1",
98
- "typescript": "5.1.6",
99
- "webpack": "5.88.2",
100
- "webpack-cli": "5.1.4"
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
  }