@magusn/components
Advanced tools
| import * as React from 'react'; | ||
| let hi = 'blah'; | ||
| export function usePageVisibility(onVisibilityChange) { | ||
| // init with a page visiblity listener | ||
| React.useEffect(() => { | ||
| if (!process.browser) return; | ||
| if (typeof onVisibilityChange !== 'function') return; | ||
| function handleVisibilityChange() { | ||
| const { visibilityState } = document; | ||
| const isVisible = visibilityState === Visibility.visible; | ||
| onVisibilityChange(isVisible); | ||
| // console.debug('usePageVisibility', 'handleVisibilityChange', { | ||
| // visibilityState, | ||
| // isVisible, | ||
| // }); | ||
| } | ||
| // console.debug('usePageVisibility', 'setup'); | ||
| document.addEventListener(eventName, handleVisibilityChange, false); | ||
| return function cleanup() { | ||
| // console.debug('usePageVisibility', 'cleanup'); | ||
| document.removeEventListener(eventName, handleVisibilityChange, false); | ||
| }; | ||
| }, []); | ||
| } | ||
| const eventName = 'visibilitychange'; | ||
| const Visibility = { | ||
| visible: 'visible', | ||
| hidden: 'hidden', | ||
| }; |
+9
-20
| { | ||
| "name": "@magusn/components", | ||
| "version": "0.2.3", | ||
| "gitHead": "47bd21f5d85c6aba674a55c2535aee6ba37b4218", | ||
| "version": "0.3.0", | ||
| "gitHead": "152685b27b8c70d85a128c319d63b8fb89213e7c", | ||
| "description": "common components", | ||
| "author": "magus", | ||
| "license": "MIT", | ||
| "publishConfig": { | ||
| "access": "public" | ||
| }, | ||
| "repository": "magus/@magusn/components", | ||
@@ -21,32 +24,18 @@ "main": "src/index.js", | ||
| "test:unit": "cross-env CI=1 react-scripts test --env=jsdom", | ||
| "test:watch": "react-scripts test --env=jsdom", | ||
| "predeploy": "cd example && yarn install && yarn run build", | ||
| "deploy": "gh-pages -d example/build" | ||
| "test:watch": "react-scripts test --env=jsdom" | ||
| }, | ||
| "peerDependencies": { | ||
| "react": "^16.0.0" | ||
| "react": "^17.0.2", | ||
| "react-dom": "^17.0.2" | ||
| }, | ||
| "devDependencies": { | ||
| "babel-eslint": "^10.0.3", | ||
| "@magusn/eslint-config-magusn": "^0.2.1", | ||
| "cross-env": "^7.0.2", | ||
| "eslint": "7", | ||
| "eslint-config-prettier": "^6.7.0", | ||
| "eslint-config-standard": "^14.1.0", | ||
| "eslint-config-standard-react": "^9.2.0", | ||
| "eslint-plugin-import": "^2.18.2", | ||
| "eslint-plugin-jest": "^25.3.0", | ||
| "eslint-plugin-node": "^11.0.0", | ||
| "eslint-plugin-prettier": "^3.1.1", | ||
| "eslint-plugin-promise": "^4.2.1", | ||
| "eslint-plugin-react": "^7.17.0", | ||
| "eslint-plugin-react-hooks": "^4.3.0", | ||
| "eslint-plugin-standard": "^4.0.1", | ||
| "gh-pages": "^2.2.0", | ||
| "microbundle-crl": "^0.13.10", | ||
| "npm-run-all": "^4.1.5", | ||
| "prettier": "^2.0.4", | ||
| "react": "^16.13.1", | ||
| "react-dom": "^16.13.1", | ||
| "react-scripts": "^3.4.1" | ||
| } | ||
| } |
+1
-0
| export { Button } from './Button'; | ||
| export { ExampleComponent } from './ExampleComponent'; | ||
| export { usePageVisibility } from './usePageVisibility'; |
4518
14.64%8
-61.9%10
11.11%56
115.38%2
100%