@paprika/helpers
Description
JavaScript and React helper utilities.
Installation
yarn add @paprika/helpers
or with npm:
npm install @paprika/helpers
Usage
Import the helper function you want to use by name from the Paprika helpers
package:
import { helperFunction } from "@paprika/helpers";
Polyfills must be imported directly from their source in the lib
folder. For example:
import "@paprika/helpers/lib/polyfills/elementClosest";
Contents
Get a hash table of components from chilren
argument where the displayName
property of child
matches an item provided in the types
argument with the keys of the return object matching the items in types
.
Get the props
object from the target
argument component type if it exists in children
argument.
isDevEnv()
Returns true if NODE_ENV
is undefined
or "development".
Custom PropTypes
A variety of custom React prop types including:
ShirtSizes
AlignTypes
deprecated
InputValidTypes
FocusPropTypes
RefOf
DOM Functions
isElementContainsFocus(element)
Returns true
if the document.activeElement
is the element
argument, or any descendent of element
.
Components
<LockBodyScroll>
Sets body overlow
to hidden
.
<Portal>
Wrapper for ReactDOM.createPortal
.
Hooks
useDebounce(value, delay)
Provides a value
after a specified delay
.
useForwardDomRef(ref, parentRef)
Set parentRef
to ref
.
useMountedRef()
Provides a ref with a current
value of true
if component is (still) mounted.
usePrevious(value)
Provides the previous value of the value
argument.
Polyfills
elementClosest
IE polyfill for Element.closest()
.
elementScroll
IE polyfill for Element.scroll()
, Element.scrollTo()
, Element.scrollBy()
.
Links