jobiqo-cl
Version:
[](https://circleci.com/gh/jobiqo/jobiqo-cl)
135 lines (113 loc) • 3.77 kB
JavaScript
;
Object.defineProperty(exports, '__esModule', { value: true });
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
var React = require('react');
var React__default = _interopDefault(React);
var checkedPkgs = {};
/**
* When in dev mode, checks that styles for a given @reach package are loaded.
*/
exports.checkStyles = function checkStyles() {};
if (process.env.NODE_ENV !== "production") {
exports.checkStyles = function checkStyles(pkg) {
// only check once per package
if (checkedPkgs[pkg]) return;
checkedPkgs[pkg] = true;
if (process.env.NODE_ENV !== "test" && parseInt(window.getComputedStyle(document.body).getPropertyValue("--reach-" + pkg), 10) !== 1) {
console.warn("@reach/" + pkg + " styles not found. If you are using a bundler like webpack or parcel include this in the entry file of your app before any of your own styles:\n\n import \"@reach/" + pkg + "/styles.css\";\n\n Otherwise you'll need to include them some other way:\n\n <link rel=\"stylesheet\" type=\"text/css\" href=\"node_modules/@reach/" + pkg + "/styles.css\" />\n\n For more information visit https://ui.reach.tech/styling.\n ");
}
};
}
/**
* Passes or assigns an arbitrary value to a ref function or object.
*/
function assignRef(ref, value) {
if (ref == null) return;
if (typeof ref === "function") {
ref(value);
} else {
try {
ref.current = value;
} catch (error) {
throw new Error("Cannot assign value \"" + value + "\" to ref \"" + ref + "\"");
}
}
}
/**
* Joins strings to format IDs for compound components.
*/
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 _len2 = arguments.length, refs = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
refs[_key2] = arguments[_key2];
}
return React.useMemo(function () {
if (refs.every(function (ref) {
return ref == null;
})) {
return null;
}
return function (node) {
refs.forEach(function (ref) {
assignRef(ref, node);
});
}; // eslint-disable-next-line react-hooks/exhaustive-deps
}, refs);
}
/**
* Returns the previous value of a reference after a component update.
*/
function usePrevious(value) {
var ref = React.useRef();
React.useEffect(function () {
ref.current = value;
}, [value]);
return ref.current;
}
/**
* Call an effect after a component update, skipping the initial mount.
*/
function useUpdateEffect(effect, deps) {
var mounted = React.useRef(false);
React.useEffect(function () {
if (mounted.current) {
effect();
} else {
mounted.current = true;
} // eslint-disable-next-line react-hooks/exhaustive-deps
}, deps);
}
/**
* 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) {
return function (event) {
theirHandler && theirHandler(event);
if (!event.defaultPrevented) {
return ourHandler(event);
}
};
}
exports.assignRef = assignRef;
exports.makeId = makeId;
exports.noop = noop;
exports.useForkedRef = useForkedRef;
exports.usePrevious = usePrevious;
exports.useUpdateEffect = useUpdateEffect;
exports.wrapEvent = wrapEvent;