@react-spectrum/utils
Advanced tools
Comparing version 3.2.1 to 3.3.0
var { | ||
mergeProps, | ||
useLayoutEffect | ||
useLayoutEffect, | ||
useResizeObserver | ||
} = require("@react-aria/utils"); | ||
exports.useResizeObserver = useResizeObserver; | ||
var { | ||
@@ -498,39 +501,2 @@ useLocale | ||
exports.useHasChild = useHasChild; | ||
function $b2b0dc8855ecaa21f16e256977c2acae$var$hasResizeObserver() { | ||
return typeof window.ResizeObserver !== 'undefined'; | ||
} | ||
function useResizeObserver(options) { | ||
const { | ||
ref, | ||
onResize | ||
} = options; | ||
useEffect(() => { | ||
if (!ref) { | ||
return; | ||
} | ||
if (!$b2b0dc8855ecaa21f16e256977c2acae$var$hasResizeObserver()) { | ||
window.addEventListener('resize', onResize, false); | ||
return () => { | ||
window.removeEventListener('resize', onResize, false); | ||
}; | ||
} else { | ||
const resizeObserverInstance = new window.ResizeObserver(entries => { | ||
if (!entries.length) { | ||
return; | ||
} | ||
onResize(); | ||
}); | ||
resizeObserverInstance.observe(ref.current); | ||
return () => { | ||
resizeObserverInstance.unobserve(ref.current); | ||
}; | ||
} | ||
}, [onResize, ref]); | ||
} | ||
exports.useResizeObserver = useResizeObserver; | ||
const $dfba26b46b2b2f027a9d4ad19567e6fd$var$MOBILE_SCREEN_WIDTH = 700; | ||
@@ -537,0 +503,0 @@ |
@@ -1,2 +0,3 @@ | ||
import { mergeProps, useLayoutEffect } from "@react-aria/utils"; | ||
import { mergeProps, useLayoutEffect, useResizeObserver } from "@react-aria/utils"; | ||
export { useResizeObserver }; | ||
import { useLocale } from "@react-aria/i18n"; | ||
@@ -411,37 +412,2 @@ import _babelRuntimeHelpersEsmObjectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose"; | ||
} | ||
function $cca005946acc2b62e95b87abbbd38b64$var$hasResizeObserver() { | ||
return typeof window.ResizeObserver !== 'undefined'; | ||
} | ||
export function useResizeObserver(options) { | ||
const { | ||
ref, | ||
onResize | ||
} = options; | ||
useEffect(() => { | ||
if (!ref) { | ||
return; | ||
} | ||
if (!$cca005946acc2b62e95b87abbbd38b64$var$hasResizeObserver()) { | ||
window.addEventListener('resize', onResize, false); | ||
return () => { | ||
window.removeEventListener('resize', onResize, false); | ||
}; | ||
} else { | ||
const resizeObserverInstance = new window.ResizeObserver(entries => { | ||
if (!entries.length) { | ||
return; | ||
} | ||
onResize(); | ||
}); | ||
resizeObserverInstance.observe(ref.current); | ||
return () => { | ||
resizeObserverInstance.unobserve(ref.current); | ||
}; | ||
} | ||
}, [onResize, ref]); | ||
} | ||
const $db7f8d67f553ae22a3f659d9cb2a$var$MOBILE_SCREEN_WIDTH = 700; | ||
@@ -448,0 +414,0 @@ export function useIsMobileDevice() { |
@@ -33,9 +33,5 @@ import { ReactElement, ReactNode, RefObject, CSSProperties, HTMLAttributes } from "react"; | ||
export function useHasChild(query: string, ref: RefObject<HTMLElement>): boolean; | ||
type useResizeObserverOptionsType<T> = { | ||
ref: RefObject<T>; | ||
onResize: () => void; | ||
}; | ||
export function useResizeObserver<T extends HTMLElement>(options: useResizeObserverOptionsType<T>): void; | ||
export { useResizeObserver } from '@react-aria/utils'; | ||
export function useIsMobileDevice(): boolean; | ||
//# sourceMappingURL=types.d.ts.map |
{ | ||
"name": "@react-spectrum/utils", | ||
"version": "3.2.1", | ||
"version": "3.3.0", | ||
"description": "Spectrum UI components in React", | ||
@@ -23,10 +23,10 @@ "license": "Apache-2.0", | ||
"@babel/runtime": "^7.6.2", | ||
"@react-aria/i18n": "^3.1.1", | ||
"@react-aria/ssr": "^3.0.0", | ||
"@react-aria/utils": "^3.2.1", | ||
"@react-types/shared": "^3.2.0", | ||
"@react-aria/i18n": "^3.1.2", | ||
"@react-aria/ssr": "^3.0.1", | ||
"@react-aria/utils": "^3.3.0", | ||
"@react-types/shared": "^3.2.1", | ||
"clsx": "^1.1.1" | ||
}, | ||
"peerDependencies": { | ||
"react": "^16.8.0" | ||
"react": "^16.8.0 || ^17.0.0-rc.1" | ||
}, | ||
@@ -36,3 +36,3 @@ "publishConfig": { | ||
}, | ||
"gitHead": "d050016e6876b20e4d8a95ba5fb5630d78e75a60" | ||
"gitHead": "0778f71a3c13e1e24388a23b6d525e3b9f5b98f1" | ||
} |
@@ -1,40 +0,13 @@ | ||
import {RefObject, useEffect} from 'react'; | ||
/* | ||
* Copyright 2020 Adobe. All rights reserved. | ||
* This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. You may obtain a copy | ||
* of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under | ||
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
* OF ANY KIND, either express or implied. See the License for the specific language | ||
* governing permissions and limitations under the License. | ||
*/ | ||
function hasResizeObserver() { | ||
return typeof window.ResizeObserver !== 'undefined'; | ||
} | ||
type useResizeObserverOptionsType<T> = { | ||
ref: RefObject<T>, | ||
onResize: () => void | ||
} | ||
export function useResizeObserver<T extends HTMLElement>(options: useResizeObserverOptionsType<T>) { | ||
const {ref, onResize} = options; | ||
useEffect(() => { | ||
if (!ref) {return; } | ||
if (!hasResizeObserver()) { | ||
window.addEventListener('resize', onResize, false); | ||
return () => { | ||
window.removeEventListener('resize', onResize, false); | ||
}; | ||
} else { | ||
const resizeObserverInstance = new window.ResizeObserver((entries) => { | ||
if (!entries.length) { | ||
return; | ||
} | ||
onResize(); | ||
}); | ||
resizeObserverInstance.observe(ref.current); | ||
return () => { | ||
resizeObserverInstance.unobserve(ref.current); | ||
}; | ||
} | ||
}, [onResize, ref]); | ||
} | ||
export {useResizeObserver} from '@react-aria/utils'; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
155925
1547
+ Addedreact@17.0.2(transitive)
- Removedprop-types@15.8.1(transitive)
- Removedreact@16.14.0(transitive)
- Removedreact-is@16.13.1(transitive)
Updated@react-aria/i18n@^3.1.2
Updated@react-aria/ssr@^3.0.1
Updated@react-aria/utils@^3.3.0
Updated@react-types/shared@^3.2.1