@react-spectrum/utils
Advanced tools
Comparing version 3.0.0-nightly.706 to 3.0.0-nightly.709
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.0.0-nightly.706+f5f16024", | ||
"version": "3.0.0-nightly.709+116f300e", | ||
"description": "Spectrum UI components in React", | ||
@@ -23,6 +23,6 @@ "license": "Apache-2.0", | ||
"@babel/runtime": "^7.6.2", | ||
"@react-aria/i18n": "3.0.0-nightly.706+f5f16024", | ||
"@react-aria/ssr": "3.0.1-nightly.2384+f5f16024", | ||
"@react-aria/utils": "3.0.0-nightly.706+f5f16024", | ||
"@react-types/shared": "3.0.0-nightly.706+f5f16024", | ||
"@react-aria/i18n": "3.0.0-nightly.709+116f300e", | ||
"@react-aria/ssr": "3.0.1-nightly.2387+116f300e", | ||
"@react-aria/utils": "3.0.0-nightly.709+116f300e", | ||
"@react-types/shared": "3.0.0-nightly.709+116f300e", | ||
"clsx": "^1.1.1" | ||
@@ -36,3 +36,3 @@ }, | ||
}, | ||
"gitHead": "f5f16024617a0ce88805cf845a5db16d94cc6ace" | ||
"gitHead": "116f300e4e8a6e0eb5cc2945b7a11a659f173c02" | ||
} |
@@ -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
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
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
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
156011
1547