-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: work with Vite out of the box, updated types
- the package now works with Vite and other modern bundles out of the box - the sizes object can now be either `null`, or an object with numeric width and height properties (never null)
- Loading branch information
Showing
10 changed files
with
2,841 additions
and
2,431 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
[ignore] | ||
dist/ | ||
|
||
[include] | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// @flow | ||
import * as React from 'react'; | ||
import ResizeListener from './ResizeListener'; | ||
|
||
const defaultReporter = (target: ?HTMLElement) => ({ | ||
width: target != null ? target.offsetWidth : null, | ||
height: target != null ? target.offsetHeight : null, | ||
}); | ||
|
||
export default function useResizeAware( | ||
reporter: typeof defaultReporter = defaultReporter | ||
) { | ||
const [sizes, setSizes] = React.useState(reporter(null)); | ||
const onResize = React.useCallback(ref => setSizes(reporter(ref.current)), [ | ||
reporter, | ||
]); | ||
const resizeListenerNode = React.useMemo( | ||
() => <ResizeListener onResize={onResize} />, | ||
[onResize] | ||
); | ||
|
||
return [resizeListenerNode, sizes]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "react-resize-aware", | ||
"version": "3.1.3", | ||
"version": "4.0.0", | ||
"description": "A React hook that makes it possible to listen to element resize events.", | ||
"homepage": "https://github.com/FezVrasta/react-resize-aware#readme", | ||
"author": "Federico Zivolo <[email protected]>", | ||
|
@@ -23,21 +23,26 @@ | |
"query", | ||
"react-component" | ||
], | ||
"main": "dist/index.js", | ||
"umd:main": "dist/index.umd.js", | ||
"source": "src/index.js", | ||
"type": "module", | ||
"main": "./dist/index.umd.js", | ||
"module": "./dist/index.modern.js", | ||
"source": "./src/index.js", | ||
"exports": { | ||
"require": "./dist/index.cjs", | ||
"default": "./dist/index.modern.js" | ||
}, | ||
"scripts": { | ||
"start": "microbundle watch", | ||
"prepare": "microbundle --name useResizeAware --jsx jsx --jsxImportSource react --globals react/jsx-runtime=jsx && cp -f dist/index.umd.js docs/react-resize-aware.js && flow-copy-source src dist && cp src/index.d.ts dist/index.d.ts" | ||
"prepare": "rm -rf dist && microbundle --jsx 'React.createElement' --jsxImportSource react --globals react/jsx-runtime=jsx && flow-copy-source src dist && cp ./dist/index.js.flow ./dist/index.umd.js.flow && cp ./src/index.d.ts ./dist" | ||
}, | ||
"files": [ | ||
"dist/*", | ||
"src/*" | ||
], | ||
"devDependencies": { | ||
"flow-bin": "^0.113.0", | ||
"flow-bin": "0.199.1", | ||
"flow-copy-source": "^2.0.9", | ||
"microbundle": "0.12.0-next.6", | ||
"microbundle": "^0.15.1", | ||
"react": "16.12.0" | ||
}, | ||
"peerDependencies": { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
// @flow | ||
export { default } from './useResizeAware'; | ||
import useResizeAware from "./useResizeAware"; | ||
export default useResizeAware; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.