Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@leafygreen-ui/hooks

Package Overview
Dependencies
Maintainers
6
Versions
65
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@leafygreen-ui/hooks - npm Package Compare versions

Comparing version 8.0.0 to 8.0.1

dist/useDynamicRefs/index.d.ts

7

CHANGELOG.md
# @leafygreen-ui/hooks
## 8.0.1
### Patch Changes
- 89f439e8: - Makes `useDynamicRefs` `prefix` argument optional
- Adds tests to `useDynamicRefs`
## 8.0.0

@@ -4,0 +11,0 @@

2

dist/esm/index.js

@@ -1,2 +0,2 @@

import*as n from"react";import{useEffect as r,useState as t,useMemo as e,useRef as o,useCallback as i,useLayoutEffect as u}from"react";import c from"lodash/debounce";import a from"lodash/isUndefined";import f from"lodash/isEqual";var l=function(n,t){var e=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;r((function(){if(n&&n.current&&t&&t.current){var r=n.current.offsetTop,o=t.current,i=o.scrollTop;(r>o.offsetHeight||r<i)&&t.current.scrollTo({top:r-e,behavior:"smooth"})}}),[t,n,e])};function v(n,r){var t=Object.keys(n);if(Object.getOwnPropertySymbols){var e=Object.getOwnPropertySymbols(n);r&&(e=e.filter((function(r){return Object.getOwnPropertyDescriptor(n,r).enumerable}))),t.push.apply(t,e)}return t}function d(n){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?v(Object(t),!0).forEach((function(r){p(n,r,t[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(n,Object.getOwnPropertyDescriptors(t)):v(Object(t)).forEach((function(r){Object.defineProperty(n,r,Object.getOwnPropertyDescriptor(t,r))}))}return n}function s(n){return s="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(n){return typeof n}:function(n){return n&&"function"==typeof Symbol&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},s(n)}function p(n,r,t){return(r=function(n){var r=function(n,r){if("object"!=typeof n||null===n)return n;var t=n[Symbol.toPrimitive];if(void 0!==t){var e=t.call(n,r||"default");if("object"!=typeof e)return e;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(n)}(n,"string");return"symbol"==typeof r?r:String(r)}(r))in n?Object.defineProperty(n,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):n[r]=t,n}function y(n,r){return function(n){if(Array.isArray(n))return n}(n)||function(n,r){var t=null==n?null:"undefined"!=typeof Symbol&&n[Symbol.iterator]||n["@@iterator"];if(null!=t){var e,o,i,u,c=[],a=!0,f=!1;try{if(i=(t=t.call(n)).next,0===r){if(Object(t)!==t)return;a=!1}else for(;!(a=(e=i.call(t)).done)&&(c.push(e.value),c.length!==r);a=!0);}catch(n){f=!0,o=n}finally{try{if(!a&&null!=t.return&&(u=t.return(),Object(u)!==u))return}finally{if(f)throw o}}return c}}(n,r)||b(n,r)||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.")}()}function m(n){return function(n){if(Array.isArray(n))return g(n)}(n)||function(n){if("undefined"!=typeof Symbol&&null!=n[Symbol.iterator]||null!=n["@@iterator"])return Array.from(n)}(n)||b(n)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function b(n,r){if(n){if("string"==typeof n)return g(n,r);var t=Object.prototype.toString.call(n).slice(8,-1);return"Object"===t&&n.constructor&&(t=n.constructor.name),"Map"===t||"Set"===t?Array.from(n):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?g(n,r):void 0}}function g(n,r){(null==r||r>n.length)&&(r=n.length);for(var t=0,e=new Array(r);t<r;t++)e[t]=n[t];return e}function h(){return{width:window.innerWidth,height:window.innerHeight}}function w(){var n=y(t(null),2),e=n[0],o=n[1];return r((function(){o(h());var n=c((function(){return o(h())}),100);return window.addEventListener("resize",n),function(){return window.removeEventListener("resize",n)}}),[]),e}var O=function(n){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:8,t=w();return e((function(){if(t&&n&&n.current){var e=n.current.getBoundingClientRect(),o=e.top,i=e.bottom;return Math.max(t.height-i,o)-r}}),[t,n,r])};function j(n,t){var e=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},i=e.options,u=e.enabled,c=void 0===u||u,a=e.dependencies,f=void 0===a?[c,n]:a,l=e.element,v=o((function(){}));r((function(){v.current=t}),[t]),r((function(){if(!1!==c){if("once"===c||!0===c){var r=function(n){v.current(n)},t=d(d({},i),{},{once:"once"===c});return(null!=l?l:document).addEventListener(n,r,t),function(){(null!=l?l:document).removeEventListener(n,r,t)}}console.error("Received value of type ".concat(s(c)," for property `enabled`. Expected a boolean."))}}),f)}function S(n,r){var t=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];function e(n){var t,e=n.target;return Array.isArray(r)?r.some((function(n){var r;return null===(r=n.current)||void 0===r?void 0:r.contains(e)})):(null===(t=r.current)||void 0===t?void 0:t.contains(e))||!1}j("mousedown",(function(n){e(n)||(n.preventDefault(),n.stopPropagation())}),{enabled:t}),j("click",(function(r){e(r)||(r.stopPropagation(),n())}),{options:{capture:!0},enabled:t})}var P=function(n,r){var e=!a(n),o=y(t(""),2),i=o[0],u=o[1];return{isControlled:e,value:e?n:i,handleChange:function(n){null==r||r(n),e||u(n.target.value)},setUncontrolledValue:u}},A=new Map;function E(r){return function(){var r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return function(t){if(t){var e=r+"-"+t;if(A.get(e))return A.get(e);var o=n.createRef();return A.set(e,o),o}console.error("useDynamicRefs: Cannot get ref without key")}}(r.prefix)}var x=function(n,r){return j("keydown",(function(r){return function(n,r){27===n.keyCode&&(n.stopImmediatePropagation(),r())}(r,n)}),r)};function C(){var n=y(t({}),2)[1];return i((function(){return n({})}),[])}function T(n){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},t=r.initialValue,i=r.deps,u=void 0===i?[]:i,c=o(t);return e((function(){return{get current(){return c.current},set current(r){c.current=r,n(r)}}}),[n,c].concat(m(u)))}function I(n,r){var t=i((function(n,r){Array.isArray(n)?n.forEach(t):"function"==typeof n?n(r):n&&(n.current=r)}),[]);return T(i((function(r){return t(n,r)}),[n,t]),{initialValue:r})}var D=0;function k(n){var e=n.prefix;return function(n){var e=n.id,o=n.prefix,i=y(t(e),2),u=i[0],c=i[1];return r((function(){null==u&&c(D+=1)}),[u,o]),e||"".concat(null!=o?o:"lg","-").concat(u)}({id:n.id,prefix:e})}var L=function(){return("undefined"==typeof window?r:u).apply(void 0,arguments)};function M(n,e,o){var i=!(arguments.length>3&&void 0!==arguments[3])||arguments[3],u=y(t(),2),c=u[0],a=u[1];return r((function(){if(i){var r=new MutationObserver((function(){a(o.apply(void 0,arguments))}));return n&&r.observe(n,e),function(){return r.disconnect()}}}),[n,e,o,i]),c}function R(n){var r=o();return void 0!==r.current&&f(r.current,n)||(r.current=n),r.current}function B(n){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=e.interval,u=void 0===i?3e4:i,c=e.immediate,a=void 0===c||c,f=e.enabled,l=void 0===f||f,v=o(),d=function(){var n=function(){return"visible"===document.visibilityState},e=y(t(!0),2),o=e[0],i=e[1];return r((function(){i(n)}),[]),j("visibilitychange",(function(){i(n)})),o}()&&l;r((function(){v.current=n})),r((function(){var n;if(d)return a?e():r(),t;function r(){t(),n=setTimeout(e,u)}function t(){clearTimeout(n)}function e(){var n;Promise.resolve(null===(n=v.current)||void 0===n?void 0:n.call(v)).finally(r)}}),[u,a,d])}function U(n){var t=o();return r((function(){t.current=n})),t.current}function V(n){var r=y(t(n),2),e=r[0],i=r[1],u=o(e);return[e,function(n){i(n),u.current=n},function(){return u.current}]}function z(n){var r=y(t(!1),2),e=r[0],o=r[1];if(a(n)||"function"!=typeof n)return{onBlur:function(){},onChange:function(){}};return{onBlur:function(r){o(!0),null==n||n(r.target.value)},onChange:function(r){e&&(null==n||n(r.target.value))}}}export{l as useAutoScroll,O as useAvailableSpace,S as useBackdropClick,P as useControlledValue,E as useDynamicRefs,x as useEscapeKey,j as useEventListener,C as useForceRerender,I as useForwardedRef,k as useIdAllocator,L as useIsomorphicLayoutEffect,M as useMutationObserver,R as useObjectDependency,T as useObservedRef,B as usePoller,U as usePrevious,V as useStateRef,z as useValidation,w as useViewportSize};
import*as n from"react";import{useEffect as r,useState as t,useMemo as e,useRef as o,useCallback as i,useLayoutEffect as u}from"react";import c from"lodash/debounce";import a from"lodash/isUndefined";import{consoleOnce as f}from"@leafygreen-ui/lib";import l from"lodash/isEqual";var v=function(n,t){var e=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;r((function(){if(n&&n.current&&t&&t.current){var r=n.current.offsetTop,o=t.current,i=o.scrollTop;(r>o.offsetHeight||r<i)&&t.current.scrollTo({top:r-e,behavior:"smooth"})}}),[t,n,e])};function d(n,r){var t=Object.keys(n);if(Object.getOwnPropertySymbols){var e=Object.getOwnPropertySymbols(n);r&&(e=e.filter((function(r){return Object.getOwnPropertyDescriptor(n,r).enumerable}))),t.push.apply(t,e)}return t}function s(n){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?d(Object(t),!0).forEach((function(r){y(n,r,t[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(n,Object.getOwnPropertyDescriptors(t)):d(Object(t)).forEach((function(r){Object.defineProperty(n,r,Object.getOwnPropertyDescriptor(t,r))}))}return n}function p(n){return p="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(n){return typeof n}:function(n){return n&&"function"==typeof Symbol&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},p(n)}function y(n,r,t){return(r=function(n){var r=function(n,r){if("object"!=typeof n||null===n)return n;var t=n[Symbol.toPrimitive];if(void 0!==t){var e=t.call(n,r||"default");if("object"!=typeof e)return e;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(n)}(n,"string");return"symbol"==typeof r?r:String(r)}(r))in n?Object.defineProperty(n,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):n[r]=t,n}function m(n,r){return function(n){if(Array.isArray(n))return n}(n)||function(n,r){var t=null==n?null:"undefined"!=typeof Symbol&&n[Symbol.iterator]||n["@@iterator"];if(null!=t){var e,o,i,u,c=[],a=!0,f=!1;try{if(i=(t=t.call(n)).next,0===r){if(Object(t)!==t)return;a=!1}else for(;!(a=(e=i.call(t)).done)&&(c.push(e.value),c.length!==r);a=!0);}catch(n){f=!0,o=n}finally{try{if(!a&&null!=t.return&&(u=t.return(),Object(u)!==u))return}finally{if(f)throw o}}return c}}(n,r)||g(n,r)||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.")}()}function b(n){return function(n){if(Array.isArray(n))return h(n)}(n)||function(n){if("undefined"!=typeof Symbol&&null!=n[Symbol.iterator]||null!=n["@@iterator"])return Array.from(n)}(n)||g(n)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function g(n,r){if(n){if("string"==typeof n)return h(n,r);var t=Object.prototype.toString.call(n).slice(8,-1);return"Object"===t&&n.constructor&&(t=n.constructor.name),"Map"===t||"Set"===t?Array.from(n):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?h(n,r):void 0}}function h(n,r){(null==r||r>n.length)&&(r=n.length);for(var t=0,e=new Array(r);t<r;t++)e[t]=n[t];return e}function w(){return{width:window.innerWidth,height:window.innerHeight}}function O(){var n=m(t(null),2),e=n[0],o=n[1];return r((function(){o(w());var n=c((function(){return o(w())}),100);return window.addEventListener("resize",n),function(){return window.removeEventListener("resize",n)}}),[]),e}var j=function(n){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:8,t=O();return e((function(){if(t&&n&&n.current){var e=n.current.getBoundingClientRect(),o=e.top,i=e.bottom;return Math.max(t.height-i,o)-r}}),[t,n,r])};function S(n,t){var e=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},i=e.options,u=e.enabled,c=void 0===u||u,a=e.dependencies,f=void 0===a?[c,n]:a,l=e.element,v=o((function(){}));r((function(){v.current=t}),[t]),r((function(){if(!1!==c){if("once"===c||!0===c){var r=function(n){v.current(n)},t=s(s({},i),{},{once:"once"===c});return(null!=l?l:document).addEventListener(n,r,t),function(){(null!=l?l:document).removeEventListener(n,r,t)}}console.error("Received value of type ".concat(p(c)," for property `enabled`. Expected a boolean."))}}),f)}function P(n,r){var t=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];function e(n){var t,e=n.target;return Array.isArray(r)?r.some((function(n){var r;return null===(r=n.current)||void 0===r?void 0:r.contains(e)})):(null===(t=r.current)||void 0===t?void 0:t.contains(e))||!1}S("mousedown",(function(n){e(n)||(n.preventDefault(),n.stopPropagation())}),{enabled:t}),S("click",(function(r){e(r)||(r.stopPropagation(),n())}),{options:{capture:!0},enabled:t})}var A=function(n,r){var e=!a(n),o=m(t(""),2),i=o[0],u=o[1];return{isControlled:e,value:e?n:i,handleChange:function(n){null==r||r(n),e||u(n.target.value)},setUncontrolledValue:u}};function E(r){var t=null==r?void 0:r.prefix;return n.useMemo((function(){var r=function(r){return function(t){if(t){if(r.get(t))return r.get(t);var e=n.createRef();return r.set(t,e),e}f.error("`useDynamicRefs`: Cannot get ref without key")}}(new Map);return r}),[t])}var x=function(n,r){return S("keydown",(function(r){return function(n,r){27===n.keyCode&&(n.stopImmediatePropagation(),r())}(r,n)}),r)};function C(){var n=m(t({}),2)[1];return i((function(){return n({})}),[])}function T(n){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},t=r.initialValue,i=r.deps,u=void 0===i?[]:i,c=o(t);return e((function(){return{get current(){return c.current},set current(r){c.current=r,n(r)}}}),[n,c].concat(b(u)))}function I(n,r){var t=i((function(n,r){Array.isArray(n)?n.forEach(t):"function"==typeof n?n(r):n&&(n.current=r)}),[]);return T(i((function(r){return t(n,r)}),[n,t]),{initialValue:r})}var D=0;function k(n){var e=n.prefix;return function(n){var e=n.id,o=n.prefix,i=m(t(e),2),u=i[0],c=i[1];return r((function(){null==u&&c(D+=1)}),[u,o]),e||"".concat(null!=o?o:"lg","-").concat(u)}({id:n.id,prefix:e})}var M=function(){return("undefined"==typeof window?r:u).apply(void 0,arguments)};function L(n,e,o){var i=!(arguments.length>3&&void 0!==arguments[3])||arguments[3],u=m(t(),2),c=u[0],a=u[1];return r((function(){if(i){var r=new MutationObserver((function(){a(o.apply(void 0,arguments))}));return n&&r.observe(n,e),function(){return r.disconnect()}}}),[n,e,o,i]),c}function R(n){var r=o();return void 0!==r.current&&l(r.current,n)||(r.current=n),r.current}function B(n){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=e.interval,u=void 0===i?3e4:i,c=e.immediate,a=void 0===c||c,f=e.enabled,l=void 0===f||f,v=o(),d=function(){var n=function(){return"visible"===document.visibilityState},e=m(t(!0),2),o=e[0],i=e[1];return r((function(){i(n)}),[]),S("visibilitychange",(function(){i(n)})),o}()&&l;r((function(){v.current=n})),r((function(){var n;if(d)return a?e():r(),t;function r(){t(),n=setTimeout(e,u)}function t(){clearTimeout(n)}function e(){var n;Promise.resolve(null===(n=v.current)||void 0===n?void 0:n.call(v)).finally(r)}}),[u,a,d])}function U(n){var t=o();return r((function(){t.current=n})),t.current}function V(n){var r=m(t(n),2),e=r[0],i=r[1],u=o(e);return[e,function(n){i(n),u.current=n},function(){return u.current}]}function z(n){var r=m(t(!1),2),e=r[0],o=r[1];if(a(n)||"function"!=typeof n)return{onBlur:function(){},onChange:function(){}};return{onBlur:function(r){o(!0),null==n||n(r.target.value)},onChange:function(r){e&&(null==n||n(r.target.value))}}}export{v as useAutoScroll,j as useAvailableSpace,P as useBackdropClick,A as useControlledValue,E as useDynamicRefs,x as useEscapeKey,S as useEventListener,C as useForceRerender,I as useForwardedRef,k as useIdAllocator,M as useIsomorphicLayoutEffect,L as useMutationObserver,R as useObjectDependency,T as useObservedRef,B as usePoller,U as usePrevious,V as useStateRef,z as useValidation,O as useViewportSize};
//# sourceMappingURL=index.js.map

@@ -5,3 +5,3 @@ export { useAutoScroll } from './useAutoScroll';

export { useControlledValue } from './useControlledValue';
export { default as useDynamicRefs } from './useDynamicRefs';
export { useDynamicRefs } from './useDynamicRefs';
export { default as useEscapeKey } from './useEscapeKey';

@@ -8,0 +8,0 @@ export { default as useEventListener } from './useEventListener';

@@ -1,2 +0,2 @@

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react"),require("lodash/debounce"),require("lodash/isUndefined"),require("lodash/isEqual")):"function"==typeof define&&define.amd?define(["exports","react","lodash/debounce","lodash/isUndefined","lodash/isEqual"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self)["@leafygreen-ui/hooks"]={},e.React,e["/debounce"],e["/isUndefined"],e["/isEqual"])}(this,(function(e,t,n,r,o){"use strict";function u(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function i(e){if(e&&"object"==typeof e&&"default"in e)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(n){if("default"!==n){var r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:function(){return e[n]}})}})),t.default=e,Object.freeze(t)}var c=i(t),f=u(n),a=u(r),l=u(o);function s(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function d(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?s(Object(n),!0).forEach((function(t){p(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):s(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function v(e){return v="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},v(e)}function p(e,t,n){return(t=function(e){var t=function(e,t){if("object"!=typeof e||null===e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var r=n.call(e,t||"default");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:String(t)}(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function y(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var r,o,u,i,c=[],f=!0,a=!1;try{if(u=(n=n.call(e)).next,0===t){if(Object(n)!==n)return;f=!1}else for(;!(f=(r=u.call(n)).done)&&(c.push(r.value),c.length!==t);f=!0);}catch(e){a=!0,o=e}finally{try{if(!f&&null!=n.return&&(i=n.return(),Object(i)!==i))return}finally{if(a)throw o}}return c}}(e,t)||m(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.")}()}function b(e){return function(e){if(Array.isArray(e))return h(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||m(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function m(e,t){if(e){if("string"==typeof e)return h(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?h(e,t):void 0}}function h(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function g(){return{width:window.innerWidth,height:window.innerHeight}}function w(){var e=y(t.useState(null),2),n=e[0],r=e[1];return t.useEffect((function(){r(g());var e=f.default((function(){return r(g())}),100);return window.addEventListener("resize",e),function(){return window.removeEventListener("resize",e)}}),[]),n}function O(e,n){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},o=r.options,u=r.enabled,i=void 0===u||u,c=r.dependencies,f=void 0===c?[i,e]:c,a=r.element,l=t.useRef((function(){}));t.useEffect((function(){l.current=n}),[n]),t.useEffect((function(){if(!1!==i){if("once"===i||!0===i){var t=function(e){l.current(e)},n=d(d({},o),{},{once:"once"===i});return(null!=a?a:document).addEventListener(e,t,n),function(){(null!=a?a:document).removeEventListener(e,t,n)}}console.error("Received value of type ".concat(v(i)," for property `enabled`. Expected a boolean."))}}),f)}var S=new Map;function E(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=n.initialValue,o=n.deps,u=void 0===o?[]:o,i=t.useRef(r);return t.useMemo((function(){return{get current(){return i.current},set current(t){i.current=t,e(t)}}}),[e,i].concat(b(u)))}var j=0;e.useAutoScroll=function(e,n){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;t.useEffect((function(){if(e&&e.current&&n&&n.current){var t=e.current.offsetTop,o=n.current,u=o.scrollTop;(t>o.offsetHeight||t<u)&&n.current.scrollTo({top:t-r,behavior:"smooth"})}}),[n,e,r])},e.useAvailableSpace=function(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:8,r=w();return t.useMemo((function(){if(r&&e&&e.current){var t=e.current.getBoundingClientRect(),o=t.top,u=t.bottom;return Math.max(r.height-u,o)-n}}),[r,e,n])},e.useBackdropClick=function(e,t){var n=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];function r(e){var n,r=e.target;return Array.isArray(t)?t.some((function(e){var t;return null===(t=e.current)||void 0===t?void 0:t.contains(r)})):(null===(n=t.current)||void 0===n?void 0:n.contains(r))||!1}O("mousedown",(function(e){r(e)||(e.preventDefault(),e.stopPropagation())}),{enabled:n}),O("click",(function(t){r(t)||(t.stopPropagation(),e())}),{options:{capture:!0},enabled:n})},e.useControlledValue=function(e,n){var r=!a.default(e),o=y(t.useState(""),2),u=o[0],i=o[1];return{isControlled:r,value:r?e:u,handleChange:function(e){null==n||n(e),r||i(e.target.value)},setUncontrolledValue:i}},e.useDynamicRefs=function(e){return function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return function(t){if(t){var n=e+"-"+t;if(S.get(n))return S.get(n);var r=c.createRef();return S.set(n,r),r}console.error("useDynamicRefs: Cannot get ref without key")}}(e.prefix)},e.useEscapeKey=function(e,t){return O("keydown",(function(t){return function(e,t){27===e.keyCode&&(e.stopImmediatePropagation(),t())}(t,e)}),t)},e.useEventListener=O,e.useForceRerender=function(){var e=y(t.useState({}),2)[1];return t.useCallback((function(){return e({})}),[])},e.useForwardedRef=function(e,n){var r=t.useCallback((function(e,t){Array.isArray(e)?e.forEach(r):"function"==typeof e?e(t):e&&(e.current=t)}),[]);return E(t.useCallback((function(t){return r(e,t)}),[e,r]),{initialValue:n})},e.useIdAllocator=function(e){var n=e.prefix;return function(e){var n=e.id,r=e.prefix,o=y(t.useState(n),2),u=o[0],i=o[1];return t.useEffect((function(){null==u&&i(j+=1)}),[u,r]),n||"".concat(null!=r?r:"lg","-").concat(u)}({id:e.id,prefix:n})},e.useIsomorphicLayoutEffect=function(){return("undefined"==typeof window?t.useEffect:t.useLayoutEffect).apply(void 0,arguments)},e.useMutationObserver=function(e,n,r){var o=!(arguments.length>3&&void 0!==arguments[3])||arguments[3],u=y(t.useState(),2),i=u[0],c=u[1];return t.useEffect((function(){if(o){var t=new MutationObserver((function(){c(r.apply(void 0,arguments))}));return e&&t.observe(e,n),function(){return t.disconnect()}}}),[e,n,r,o]),i},e.useObjectDependency=function(e){var n=t.useRef();return void 0!==n.current&&l.default(n.current,e)||(n.current=e),n.current},e.useObservedRef=E,e.usePoller=function(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=n.interval,o=void 0===r?3e4:r,u=n.immediate,i=void 0===u||u,c=n.enabled,f=void 0===c||c,a=t.useRef(),l=function(){var e=function(){return"visible"===document.visibilityState},n=y(t.useState(!0),2),r=n[0],o=n[1];return t.useEffect((function(){o(e)}),[]),O("visibilitychange",(function(){o(e)})),r}()&&f;t.useEffect((function(){a.current=e})),t.useEffect((function(){var e;if(l)return i?r():t(),n;function t(){n(),e=setTimeout(r,o)}function n(){clearTimeout(e)}function r(){var e;Promise.resolve(null===(e=a.current)||void 0===e?void 0:e.call(a)).finally(t)}}),[o,i,l])},e.usePrevious=function(e){var n=t.useRef();return t.useEffect((function(){n.current=e})),n.current},e.useStateRef=function(e){var n=y(t.useState(e),2),r=n[0],o=n[1],u=t.useRef(r);return[r,function(e){o(e),u.current=e},function(){return u.current}]},e.useValidation=function(e){var n=y(t.useState(!1),2),r=n[0],o=n[1];return a.default(e)||"function"!=typeof e?{onBlur:function(){},onChange:function(){}}:{onBlur:function(t){o(!0),null==e||e(t.target.value)},onChange:function(t){r&&(null==e||e(t.target.value))}}},e.useViewportSize=w}));
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react"),require("lodash/debounce"),require("lodash/isUndefined"),require("@leafygreen-ui/lib"),require("lodash/isEqual")):"function"==typeof define&&define.amd?define(["exports","react","lodash/debounce","lodash/isUndefined","@leafygreen-ui/lib","lodash/isEqual"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self)["@leafygreen-ui/hooks"]={},e.React,e["/debounce"],e["/isUndefined"],e["@leafygreen-ui/lib"],e["/isEqual"])}(this,(function(e,t,n,r,o,u){"use strict";function i(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function c(e){if(e&&"object"==typeof e&&"default"in e)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(n){if("default"!==n){var r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:function(){return e[n]}})}})),t.default=e,Object.freeze(t)}var f=c(t),a=i(n),l=i(r),s=i(u);function d(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function v(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?d(Object(n),!0).forEach((function(t){p(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):d(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function y(e){return y="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},y(e)}function p(e,t,n){return(t=function(e){var t=function(e,t){if("object"!=typeof e||null===e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var r=n.call(e,t||"default");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:String(t)}(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function b(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var r,o,u,i,c=[],f=!0,a=!1;try{if(u=(n=n.call(e)).next,0===t){if(Object(n)!==n)return;f=!1}else for(;!(f=(r=u.call(n)).done)&&(c.push(r.value),c.length!==t);f=!0);}catch(e){a=!0,o=e}finally{try{if(!f&&null!=n.return&&(i=n.return(),Object(i)!==i))return}finally{if(a)throw o}}return c}}(e,t)||g(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.")}()}function m(e){return function(e){if(Array.isArray(e))return h(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||g(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function g(e,t){if(e){if("string"==typeof e)return h(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?h(e,t):void 0}}function h(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function w(){return{width:window.innerWidth,height:window.innerHeight}}function O(){var e=b(t.useState(null),2),n=e[0],r=e[1];return t.useEffect((function(){r(w());var e=a.default((function(){return r(w())}),100);return window.addEventListener("resize",e),function(){return window.removeEventListener("resize",e)}}),[]),n}function S(e,n){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},o=r.options,u=r.enabled,i=void 0===u||u,c=r.dependencies,f=void 0===c?[i,e]:c,a=r.element,l=t.useRef((function(){}));t.useEffect((function(){l.current=n}),[n]),t.useEffect((function(){if(!1!==i){if("once"===i||!0===i){var t=function(e){l.current(e)},n=v(v({},o),{},{once:"once"===i});return(null!=a?a:document).addEventListener(e,t,n),function(){(null!=a?a:document).removeEventListener(e,t,n)}}console.error("Received value of type ".concat(y(i)," for property `enabled`. Expected a boolean."))}}),f)}function E(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=n.initialValue,o=n.deps,u=void 0===o?[]:o,i=t.useRef(r);return t.useMemo((function(){return{get current(){return i.current},set current(t){i.current=t,e(t)}}}),[e,i].concat(m(u)))}var j=0;e.useAutoScroll=function(e,n){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;t.useEffect((function(){if(e&&e.current&&n&&n.current){var t=e.current.offsetTop,o=n.current,u=o.scrollTop;(t>o.offsetHeight||t<u)&&n.current.scrollTo({top:t-r,behavior:"smooth"})}}),[n,e,r])},e.useAvailableSpace=function(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:8,r=O();return t.useMemo((function(){if(r&&e&&e.current){var t=e.current.getBoundingClientRect(),o=t.top,u=t.bottom;return Math.max(r.height-u,o)-n}}),[r,e,n])},e.useBackdropClick=function(e,t){var n=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];function r(e){var n,r=e.target;return Array.isArray(t)?t.some((function(e){var t;return null===(t=e.current)||void 0===t?void 0:t.contains(r)})):(null===(n=t.current)||void 0===n?void 0:n.contains(r))||!1}S("mousedown",(function(e){r(e)||(e.preventDefault(),e.stopPropagation())}),{enabled:n}),S("click",(function(t){r(t)||(t.stopPropagation(),e())}),{options:{capture:!0},enabled:n})},e.useControlledValue=function(e,n){var r=!l.default(e),o=b(t.useState(""),2),u=o[0],i=o[1];return{isControlled:r,value:r?e:u,handleChange:function(e){null==n||n(e),r||i(e.target.value)},setUncontrolledValue:i}},e.useDynamicRefs=function(e){var t=null==e?void 0:e.prefix;return f.useMemo((function(){var e=function(e){return function(t){if(t){if(e.get(t))return e.get(t);var n=f.createRef();return e.set(t,n),n}o.consoleOnce.error("`useDynamicRefs`: Cannot get ref without key")}}(new Map);return e}),[t])},e.useEscapeKey=function(e,t){return S("keydown",(function(t){return function(e,t){27===e.keyCode&&(e.stopImmediatePropagation(),t())}(t,e)}),t)},e.useEventListener=S,e.useForceRerender=function(){var e=b(t.useState({}),2)[1];return t.useCallback((function(){return e({})}),[])},e.useForwardedRef=function(e,n){var r=t.useCallback((function(e,t){Array.isArray(e)?e.forEach(r):"function"==typeof e?e(t):e&&(e.current=t)}),[]);return E(t.useCallback((function(t){return r(e,t)}),[e,r]),{initialValue:n})},e.useIdAllocator=function(e){var n=e.prefix;return function(e){var n=e.id,r=e.prefix,o=b(t.useState(n),2),u=o[0],i=o[1];return t.useEffect((function(){null==u&&i(j+=1)}),[u,r]),n||"".concat(null!=r?r:"lg","-").concat(u)}({id:e.id,prefix:n})},e.useIsomorphicLayoutEffect=function(){return("undefined"==typeof window?t.useEffect:t.useLayoutEffect).apply(void 0,arguments)},e.useMutationObserver=function(e,n,r){var o=!(arguments.length>3&&void 0!==arguments[3])||arguments[3],u=b(t.useState(),2),i=u[0],c=u[1];return t.useEffect((function(){if(o){var t=new MutationObserver((function(){c(r.apply(void 0,arguments))}));return e&&t.observe(e,n),function(){return t.disconnect()}}}),[e,n,r,o]),i},e.useObjectDependency=function(e){var n=t.useRef();return void 0!==n.current&&s.default(n.current,e)||(n.current=e),n.current},e.useObservedRef=E,e.usePoller=function(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=n.interval,o=void 0===r?3e4:r,u=n.immediate,i=void 0===u||u,c=n.enabled,f=void 0===c||c,a=t.useRef(),l=function(){var e=function(){return"visible"===document.visibilityState},n=b(t.useState(!0),2),r=n[0],o=n[1];return t.useEffect((function(){o(e)}),[]),S("visibilitychange",(function(){o(e)})),r}()&&f;t.useEffect((function(){a.current=e})),t.useEffect((function(){var e;if(l)return i?r():t(),n;function t(){n(),e=setTimeout(r,o)}function n(){clearTimeout(e)}function r(){var e;Promise.resolve(null===(e=a.current)||void 0===e?void 0:e.call(a)).finally(t)}}),[o,i,l])},e.usePrevious=function(e){var n=t.useRef();return t.useEffect((function(){n.current=e})),n.current},e.useStateRef=function(e){var n=b(t.useState(e),2),r=n[0],o=n[1],u=t.useRef(r);return[r,function(e){o(e),u.current=e},function(){return u.current}]},e.useValidation=function(e){var n=b(t.useState(!1),2),r=n[0],o=n[1];return l.default(e)||"function"!=typeof e?{onBlur:function(){},onChange:function(){}}:{onBlur:function(t){o(!0),null==e||e(t.target.value)},onChange:function(t){r&&(null==e||e(t.target.value))}}},e.useViewportSize=O}));
//# sourceMappingURL=index.js.map
{
"name": "@leafygreen-ui/hooks",
"version": "8.0.0",
"version": "8.0.1",
"description": "LeafyGreen UI Kit Custom Hooks",

@@ -38,4 +38,4 @@ "main": "./dist/index.js",

"@leafygreen-ui/emotion": "^4.0.7",
"@leafygreen-ui/lib": "^11.0.0"
"@leafygreen-ui/lib": "^13.0.0"
}
}

@@ -5,3 +5,3 @@ export { useAutoScroll } from './useAutoScroll';

export { useControlledValue } from './useControlledValue';
export { default as useDynamicRefs } from './useDynamicRefs';
export { useDynamicRefs } from './useDynamicRefs';
export { default as useEscapeKey } from './useEscapeKey';

@@ -8,0 +8,0 @@ export { default as useEventListener } from './useEventListener';

@@ -17,3 +17,5 @@ {

"exclude": ["**/*.spec.*", "**/*.story.*"],
"references": []
"references": [{
"path": "../lib"
}]
}
[
{
"tags": {},
"description": "",
"description": "Returns a ref \"getter\" function for the specified namespace (prefix).\n\nCalling the ref \"getter\" with a key will return a ref for the given namespace and key",
"methods": [],
"displayName": "useDynamicRefs",
"props": {
"UseDynamicRefsProps": {
"UseDynamicRefsArgs": {
"prefix": {

@@ -10,0 +10,0 @@ "name": "prefix",

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc