@reach/utils
Advanced tools
Comparing version 0.6.1 to 0.6.4
import { useRef, useMemo, useEffect } from "react"; | ||
var checkedPkgs = {}; | ||
/** | ||
* When in dev mode, checks that styles for a given @reach package are loaded. | ||
*/ | ||
@@ -19,2 +22,6 @@ var checkStyles = function checkStyles() {}; | ||
export { checkStyles }; | ||
/** | ||
* Passes or assigns an arbitrary value to a ref function or object. | ||
*/ | ||
export function assignRef(ref, value) { | ||
@@ -33,2 +40,6 @@ if (ref == null) return; | ||
} | ||
/** | ||
* Get the scrollbar offset distance. | ||
*/ | ||
export function getScrollbarOffset() { | ||
@@ -43,8 +54,27 @@ try { | ||
} | ||
export function makeId(id, index) { | ||
return id + "--" + index; | ||
/** | ||
* Joins strings to format IDs for compound components. | ||
*/ | ||
export function makeId() { | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
return args.join("--"); | ||
} | ||
/** | ||
* No-op function. | ||
*/ | ||
export function noop() {} | ||
/** | ||
* Passes or assigns a value to multiple refs (typically a DOM node). Useful for | ||
* dealing with components that need an explicit ref for DOM calculations but | ||
* also forwards refs assigned by an app. | ||
*/ | ||
export function useForkedRef() { | ||
for (var _len = arguments.length, refs = new Array(_len), _key = 0; _key < _len; _key++) { | ||
refs[_key] = arguments[_key]; | ||
for (var _len2 = arguments.length, refs = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { | ||
refs[_key2] = arguments[_key2]; | ||
} | ||
@@ -66,2 +96,6 @@ | ||
} | ||
/** | ||
* Returns the previous value of a reference after a component update. | ||
*/ | ||
export function usePrevious(value) { | ||
@@ -74,2 +108,6 @@ var ref = useRef(); | ||
} | ||
/** | ||
* Call an effect after a component update, skipping the initial mount. | ||
*/ | ||
export function useUpdateEffect(effect, deps) { | ||
@@ -86,2 +124,8 @@ var mounted = useRef(false); | ||
} | ||
/** | ||
* Wraps a lib-defined event handler and a user-defined event handler, returning | ||
* a single handler that allows a user to prevent lib-defined handlers from | ||
* firing. | ||
*/ | ||
export function wrapEvent(theirHandler, ourHandler) { | ||
@@ -88,0 +132,0 @@ return function (event) { |
@@ -12,3 +12,3 @@ import * as React from "react"; | ||
/** | ||
* Assigns a given value to a variable ref. | ||
* Passes or assigns an arbitrary value to a ref function or object. | ||
* | ||
@@ -26,13 +26,17 @@ * @param ref | ||
/** | ||
* Appends a given index to a ID for easy ID formatting. | ||
* Joins strings to format IDs for compound components. | ||
* | ||
* @param id | ||
* @param index | ||
* @param args | ||
*/ | ||
export function makeId(id: string | number, index: string | number): string; | ||
export function makeId(...args: (string | number)[]): string; | ||
/** | ||
* Assigns multiple refs to the same value (typically a DOM node). | ||
* Useful for dealing with components that need an explicit ref | ||
* for DOM calculations but also accept user-passed refs. | ||
* No-op function. | ||
*/ | ||
export function noop(): void; | ||
/** | ||
* Passes or assigns a value to multiple refs (typically a DOM node). Useful for | ||
* dealing with components that need an explicit ref for DOM calculations but | ||
* also forwards refs assigned by an app. | ||
* | ||
@@ -44,4 +48,3 @@ * @param refs Refs to fork | ||
/** | ||
* Returns the most recent previous value of a given value | ||
* before an update. | ||
* Returns the previous value of a reference after a component update. | ||
* | ||
@@ -53,3 +56,3 @@ * @param value | ||
/** | ||
* Call an effect only after a component has mounted. | ||
* Call an effect after a component update, skipping the initial mount. | ||
* | ||
@@ -62,5 +65,5 @@ * @param effect Effect to call | ||
/** | ||
* Wraps a lib-defined event handler and a user-defined event handler, | ||
* returning a single handler that allows a user to prevent lib-defined | ||
* handlers from firing. | ||
* Wraps a lib-defined event handler and a user-defined event handler, returning | ||
* a single handler that allows a user to prevent lib-defined handlers from | ||
* firing. | ||
* | ||
@@ -67,0 +70,0 @@ * @param theirHandler User-supplied event handler |
53
index.js
@@ -7,2 +7,3 @@ "use strict"; | ||
exports.makeId = makeId; | ||
exports.noop = noop; | ||
exports.useForkedRef = useForkedRef; | ||
@@ -17,2 +18,5 @@ exports.usePrevious = usePrevious; | ||
var checkedPkgs = {}; | ||
/** | ||
* When in dev mode, checks that styles for a given @reach package are loaded. | ||
*/ | ||
@@ -35,2 +39,5 @@ var checkStyles = function checkStyles() {}; | ||
/** | ||
* Passes or assigns an arbitrary value to a ref function or object. | ||
*/ | ||
function assignRef(ref, value) { | ||
@@ -49,3 +56,7 @@ if (ref == null) return; | ||
} | ||
/** | ||
* Get the scrollbar offset distance. | ||
*/ | ||
function getScrollbarOffset() { | ||
@@ -60,10 +71,30 @@ try { | ||
} | ||
/** | ||
* Joins strings to format IDs for compound components. | ||
*/ | ||
function makeId(id, index) { | ||
return id + "--" + index; | ||
function makeId() { | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
return args.join("--"); | ||
} | ||
/** | ||
* No-op function. | ||
*/ | ||
function noop() {} | ||
/** | ||
* Passes or assigns a value to multiple refs (typically a DOM node). Useful for | ||
* dealing with components that need an explicit ref for DOM calculations but | ||
* also forwards refs assigned by an app. | ||
*/ | ||
function useForkedRef() { | ||
for (var _len = arguments.length, refs = new Array(_len), _key = 0; _key < _len; _key++) { | ||
refs[_key] = arguments[_key]; | ||
for (var _len2 = arguments.length, refs = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { | ||
refs[_key2] = arguments[_key2]; | ||
} | ||
@@ -85,3 +116,7 @@ | ||
} | ||
/** | ||
* Returns the previous value of a reference after a component update. | ||
*/ | ||
function usePrevious(value) { | ||
@@ -94,3 +129,7 @@ var ref = (0, _react.useRef)(); | ||
} | ||
/** | ||
* Call an effect after a component update, skipping the initial mount. | ||
*/ | ||
function useUpdateEffect(effect, deps) { | ||
@@ -107,3 +146,9 @@ var mounted = (0, _react.useRef)(false); | ||
} | ||
/** | ||
* Wraps a lib-defined event handler and a user-defined event handler, returning | ||
* a single handler that allows a user to prevent lib-defined handlers from | ||
* firing. | ||
*/ | ||
function wrapEvent(theirHandler, ourHandler) { | ||
@@ -110,0 +155,0 @@ return function (event) { |
{ | ||
"name": "@reach/utils", | ||
"version": "0.6.1", | ||
"version": "0.6.4", | ||
"description": "Internal, shared utilities for Reach UI.", | ||
@@ -23,3 +23,3 @@ "main": "index.js", | ||
], | ||
"gitHead": "c1e249448a3672ccc65698218f0f38ef9814ab90" | ||
"gitHead": "c20cdf7f2dd6b9eabe5461138daf320e2833aa41" | ||
} |
@@ -5,2 +5,5 @@ import { useRef, useMemo, useEffect } from "react"; | ||
/** | ||
* When in dev mode, checks that styles for a given @reach package are loaded. | ||
*/ | ||
let checkStyles = () => {}; | ||
@@ -40,2 +43,5 @@ | ||
/** | ||
* Passes or assigns an arbitrary value to a ref function or object. | ||
*/ | ||
export function assignRef(ref, value) { | ||
@@ -54,2 +60,5 @@ if (ref == null) return; | ||
/** | ||
* Get the scrollbar offset distance. | ||
*/ | ||
export function getScrollbarOffset() { | ||
@@ -64,6 +73,19 @@ try { | ||
export function makeId(id, index) { | ||
return `${id}--${index}`; | ||
/** | ||
* Joins strings to format IDs for compound components. | ||
*/ | ||
export function makeId(...args) { | ||
return args.join("--"); | ||
} | ||
/** | ||
* No-op function. | ||
*/ | ||
export function noop() {} | ||
/** | ||
* Passes or assigns a value to multiple refs (typically a DOM node). Useful for | ||
* dealing with components that need an explicit ref for DOM calculations but | ||
* also forwards refs assigned by an app. | ||
*/ | ||
export function useForkedRef(...refs) { | ||
@@ -83,2 +105,5 @@ return useMemo(() => { | ||
/** | ||
* Returns the previous value of a reference after a component update. | ||
*/ | ||
export function usePrevious(value) { | ||
@@ -92,2 +117,5 @@ const ref = useRef(); | ||
/** | ||
* Call an effect after a component update, skipping the initial mount. | ||
*/ | ||
export function useUpdateEffect(effect, deps) { | ||
@@ -105,2 +133,7 @@ const mounted = useRef(false); | ||
/** | ||
* Wraps a lib-defined event handler and a user-defined event handler, returning | ||
* a single handler that allows a user to prevent lib-defined handlers from | ||
* firing. | ||
*/ | ||
export function wrapEvent(theirHandler, ourHandler) { | ||
@@ -107,0 +140,0 @@ return event => { |
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
14328
422