@pluralsight/ps-design-system-util
Advanced tools
Comparing version 9.2.9 to 9.3.0
@@ -6,2 +6,13 @@ # Change Log | ||
# [9.3.0](https://github.com/pluralsight/design-system/compare/@pluralsight/ps-design-system-util@9.2.9...@pluralsight/ps-design-system-util@9.3.0) (2021-07-26) | ||
### Features | ||
* **util:** add dashify function ([51688e7](https://github.com/pluralsight/design-system/commit/51688e7385cf66780cc1b27598ca0c2a6edf7ef7)) | ||
## [9.2.9](https://github.com/pluralsight/design-system/compare/@pluralsight/ps-design-system-util@9.2.8...@pluralsight/ps-design-system-util@9.2.9) (2021-06-28) | ||
@@ -8,0 +19,0 @@ |
@@ -8,2 +8,3 @@ export * from './jest'; | ||
export { cloneElementWithRef } from './clone-element-with-ref'; | ||
export { dashify } from './dashify'; | ||
export { displayNameMatches } from './display-name-matches'; | ||
@@ -10,0 +11,0 @@ export { classNames } from './class-names'; |
@@ -23,2 +23,4 @@ "use strict"; | ||
Object.defineProperty(exports, "cloneElementWithRef", { enumerable: true, get: function () { return clone_element_with_ref_1.cloneElementWithRef; } }); | ||
var dashify_1 = require("./dashify"); | ||
Object.defineProperty(exports, "dashify", { enumerable: true, get: function () { return dashify_1.dashify; } }); | ||
var display_name_matches_1 = require("./display-name-matches"); | ||
@@ -25,0 +27,0 @@ Object.defineProperty(exports, "displayNameMatches", { enumerable: true, get: function () { return display_name_matches_1.displayNameMatches; } }); |
@@ -27,15 +27,17 @@ "use strict"; | ||
}; | ||
exports.useEvent = function (eventHandler) { return function (ref, cb) { | ||
if (cb === void 0) { cb = noop; } | ||
/* eslint-disable-next-line react-hooks/rules-of-hooks */ | ||
react_1.default.useEffect(function () { | ||
if (!can_use_dom_1.canUseDOM()) | ||
exports.useEvent = function (eventHandler) { | ||
return function (ref, cb) { | ||
if (cb === void 0) { cb = noop; } | ||
/* eslint-disable-next-line react-hooks/rules-of-hooks */ | ||
react_1.default.useEffect(function () { | ||
if (!can_use_dom_1.canUseDOM()) | ||
return noop; | ||
var el = ref.current; | ||
if (el) { | ||
return eventHandler(el, cb); | ||
} | ||
return noop; | ||
var el = ref.current; | ||
if (el) { | ||
return eventHandler(el, cb); | ||
} | ||
return noop; | ||
}, [ref, cb]); | ||
}; }; | ||
}, [ref, cb]); | ||
}; | ||
}; | ||
exports.useClickOutside = function (ref, cb) { | ||
@@ -42,0 +44,0 @@ if (cb === void 0) { cb = noop; } |
@@ -8,2 +8,3 @@ export * from './jest'; | ||
export { cloneElementWithRef } from './clone-element-with-ref'; | ||
export { dashify } from './dashify'; | ||
export { displayNameMatches } from './display-name-matches'; | ||
@@ -10,0 +11,0 @@ export { classNames } from './class-names'; |
@@ -8,2 +8,3 @@ export * from './jest'; | ||
export { cloneElementWithRef } from './clone-element-with-ref'; | ||
export { dashify } from './dashify'; | ||
export { displayNameMatches } from './display-name-matches'; | ||
@@ -10,0 +11,0 @@ export { classNames } from './class-names'; |
@@ -21,15 +21,17 @@ import React from 'react'; | ||
}; | ||
export var useEvent = function (eventHandler) { return function (ref, cb) { | ||
if (cb === void 0) { cb = noop; } | ||
/* eslint-disable-next-line react-hooks/rules-of-hooks */ | ||
React.useEffect(function () { | ||
if (!canUseDOM()) | ||
export var useEvent = function (eventHandler) { | ||
return function (ref, cb) { | ||
if (cb === void 0) { cb = noop; } | ||
/* eslint-disable-next-line react-hooks/rules-of-hooks */ | ||
React.useEffect(function () { | ||
if (!canUseDOM()) | ||
return noop; | ||
var el = ref.current; | ||
if (el) { | ||
return eventHandler(el, cb); | ||
} | ||
return noop; | ||
var el = ref.current; | ||
if (el) { | ||
return eventHandler(el, cb); | ||
} | ||
return noop; | ||
}, [ref, cb]); | ||
}; }; | ||
}, [ref, cb]); | ||
}; | ||
}; | ||
export var useClickOutside = function (ref, cb) { | ||
@@ -36,0 +38,0 @@ if (cb === void 0) { cb = noop; } |
{ | ||
"name": "@pluralsight/ps-design-system-util", | ||
"version": "9.2.9", | ||
"version": "9.3.0", | ||
"description": "Runtime dependencies for utilitarian tasks. Analogous to a lodash.", | ||
@@ -39,3 +39,3 @@ "license": "Apache-2.0", | ||
}, | ||
"gitHead": "7e77be08ee73856226ec5b8a4681dddddce65394" | ||
"gitHead": "a11fb89004fe37c34a137116ae79b0625956e084" | ||
} |
@@ -7,7 +7,7 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ | ||
*/ | ||
export const callAll = <Params extends any[]>( | ||
...fns: (Callback<Params> | undefined)[] | ||
) => (...args: Params) => { | ||
return fns.forEach(fn => fn && fn(...args)) | ||
} | ||
export const callAll = | ||
<Params extends any[]>(...fns: (Callback<Params> | undefined)[]) => | ||
(...args: Params) => { | ||
return fns.forEach(fn => fn && fn(...args)) | ||
} | ||
@@ -14,0 +14,0 @@ interface Callback<Params extends any[]> { |
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
import { isFunction } from './is-function' | ||
export const combineFns = <Params extends any[]>( | ||
...fns: (Callback<Params> | undefined)[] | ||
) => (...args: Params) => { | ||
return fns.filter(isFunction).forEach(fn => { | ||
if (fn) fn(...args) | ||
}) | ||
} | ||
export const combineFns = | ||
<Params extends any[]>(...fns: (Callback<Params> | undefined)[]) => | ||
(...args: Params) => { | ||
return fns.filter(isFunction).forEach(fn => { | ||
if (fn) fn(...args) | ||
}) | ||
} | ||
@@ -12,0 +12,0 @@ interface Callback<Params extends any[]> { |
@@ -9,2 +9,3 @@ export * from './jest' | ||
export { cloneElementWithRef } from './clone-element-with-ref' | ||
export { dashify } from './dashify' | ||
export { displayNameMatches } from './display-name-matches' | ||
@@ -11,0 +12,0 @@ export { classNames } from './class-names' |
@@ -130,26 +130,28 @@ import React from 'react' | ||
export const handleMenuKeyDownEvents: React.KeyboardEventHandler<HTMLUListElement> = synthetic => { | ||
const evt = synthetic.nativeEvent | ||
export const handleMenuKeyDownEvents: React.KeyboardEventHandler<HTMLUListElement> = | ||
synthetic => { | ||
const evt = synthetic.nativeEvent | ||
evt.key === 'ArrowDown' | ||
? downArrow(evt) | ||
: evt.key === 'ArrowUp' | ||
? upArrow(evt) | ||
: evt.key === 'Home' | ||
? home(evt) | ||
: evt.key === 'End' | ||
? end(evt) | ||
: character(evt) | ||
evt.key === 'ArrowDown' | ||
? downArrow(evt) | ||
: evt.key === 'ArrowUp' | ||
? upArrow(evt) | ||
: evt.key === 'Home' | ||
? home(evt) | ||
: evt.key === 'End' | ||
? end(evt) | ||
: character(evt) | ||
evt.preventDefault() | ||
} | ||
evt.preventDefault() | ||
} | ||
export const handleMenuKeyUpEvents: React.KeyboardEventHandler<HTMLUListElement> = synthetic => { | ||
const evt = synthetic.nativeEvent | ||
export const handleMenuKeyUpEvents: React.KeyboardEventHandler<HTMLUListElement> = | ||
synthetic => { | ||
const evt = synthetic.nativeEvent | ||
evt.key === 'ArrowRight' && rightArrow(evt) | ||
evt.key === 'ArrowLeft' && leftArrow(evt) | ||
evt.key === 'ArrowRight' && rightArrow(evt) | ||
evt.key === 'ArrowLeft' && leftArrow(evt) | ||
evt.preventDefault() | ||
} | ||
evt.preventDefault() | ||
} | ||
@@ -156,0 +158,0 @@ export const useMenuRef = <El extends HTMLElement>(focus = false) => { |
@@ -36,15 +36,15 @@ import React from 'react' | ||
export const useEvent: ( | ||
eventHander: EventHandler | ||
) => EventHandlerHook = eventHandler => (ref, cb = noop) => { | ||
/* eslint-disable-next-line react-hooks/rules-of-hooks */ | ||
React.useEffect(() => { | ||
if (!canUseDOM()) return noop | ||
const el = ref.current | ||
if (el) { | ||
return eventHandler(el, cb) | ||
} | ||
return noop | ||
}, [ref, cb]) | ||
} | ||
export const useEvent: (eventHander: EventHandler) => EventHandlerHook = | ||
eventHandler => | ||
(ref, cb = noop) => { | ||
/* eslint-disable-next-line react-hooks/rules-of-hooks */ | ||
React.useEffect(() => { | ||
if (!canUseDOM()) return noop | ||
const el = ref.current | ||
if (el) { | ||
return eventHandler(el, cb) | ||
} | ||
return noop | ||
}, [ref, cb]) | ||
} | ||
@@ -51,0 +51,0 @@ export const useClickOutside: EventHandlerHook = (ref, cb = noop) => |
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
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
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
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
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
243919
267
3565