@clayui/shared
Advanced tools
Comparing version 3.87.0 to 3.88.0
@@ -21,3 +21,3 @@ /** | ||
export { useId } from './useId'; | ||
export { useInteractionFocus } from './useInteractionFocus'; | ||
export { useInteractionFocus, useFocusVisible } from './useInteractionFocus'; | ||
export { useInternalState } from './useInternalState'; | ||
@@ -24,0 +24,0 @@ export { useMousePosition } from './useMousePosition'; |
@@ -139,2 +139,8 @@ "use strict"; | ||
}); | ||
Object.defineProperty(exports, "useFocusVisible", { | ||
enumerable: true, | ||
get: function get() { | ||
return _useInteractionFocus.useFocusVisible; | ||
} | ||
}); | ||
Object.defineProperty(exports, "useHover", { | ||
@@ -141,0 +147,0 @@ enumerable: true, |
@@ -20,2 +20,3 @@ /** | ||
}; | ||
export declare function useFocusVisible(): boolean; | ||
export {}; |
@@ -6,2 +6,3 @@ "use strict"; | ||
}); | ||
exports.useFocusVisible = useFocusVisible; | ||
exports.useInteractionFocus = useInteractionFocus; | ||
@@ -13,6 +14,16 @@ | ||
/** | ||
* SPDX-FileCopyrightText: © 2019 Liferay, Inc. <https://liferay.com> | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
*/ | ||
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } | ||
function _nonIterableRest() { 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 _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } | ||
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } | ||
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; } | ||
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } | ||
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } | ||
var currentInteraction = null; | ||
@@ -22,2 +33,3 @@ var hasSetupGlobalListeners = false; | ||
var hasBlurredWindowRecently = false; | ||
var handlers = new Set(); | ||
@@ -44,2 +56,18 @@ function isValidKey(event) { | ||
} | ||
function callHandlers(interaction) { | ||
var _iterator = _createForOfIteratorHelper(handlers), | ||
_step; | ||
try { | ||
for (_iterator.s(); !(_step = _iterator.n()).done;) { | ||
var handler = _step.value; | ||
handler(interaction); | ||
} | ||
} catch (err) { | ||
_iterator.e(err); | ||
} finally { | ||
_iterator.f(); | ||
} | ||
} | ||
/** | ||
@@ -66,2 +94,3 @@ * Detects what type of interaction the user is doing with the page, using the | ||
currentInteraction = 'keyboard'; | ||
callHandlers(currentInteraction); | ||
} | ||
@@ -74,2 +103,3 @@ }; | ||
currentInteraction = 'virtual'; | ||
callHandlers(currentInteraction); | ||
} | ||
@@ -85,2 +115,3 @@ }; | ||
currentInteraction = 'virtual'; | ||
callHandlers(currentInteraction); | ||
} | ||
@@ -102,2 +133,3 @@ | ||
hasEventBeforeFocus = true; | ||
callHandlers(currentInteraction); | ||
} | ||
@@ -147,2 +179,23 @@ }; | ||
}; | ||
} | ||
function useFocusVisible() { | ||
useInteractionFocus(); | ||
var _useState = (0, _react.useState)(isFocusVisible()), | ||
_useState2 = _slicedToArray(_useState, 2), | ||
interaction = _useState2[0], | ||
setInteraction = _useState2[1]; | ||
(0, _react.useEffect)(function () { | ||
var handler = function handler(interaction) { | ||
setInteraction(interaction !== 'pointer'); | ||
}; | ||
handlers.add(handler); | ||
return function () { | ||
handlers.delete(handler); | ||
}; | ||
}, []); | ||
return interaction; | ||
} |
{ | ||
"name": "@clayui/shared", | ||
"version": "3.87.0", | ||
"version": "3.88.0", | ||
"description": "ClayShared component", | ||
@@ -30,3 +30,3 @@ "license": "BSD-3-Clause", | ||
"@clayui/button": "^3.83.0", | ||
"@clayui/link": "^3.85.0", | ||
"@clayui/link": "^3.88.0", | ||
"@clayui/provider": "^3.77.0", | ||
@@ -46,3 +46,3 @@ "aria-hidden": "^1.2.2", | ||
], | ||
"gitHead": "f071126e11f2c0ddeab525b5c14eb83f984f6f37" | ||
"gitHead": "cf84d2b2f04d7576be26ce3917e40ec9da52bef8" | ||
} |
@@ -6,3 +6,3 @@ /** | ||
import {useEffect} from 'react'; | ||
import {useEffect, useState} from 'react'; | ||
@@ -18,2 +18,6 @@ import {isMac} from './platform'; | ||
type Handler = (interaction: Interaction) => void; | ||
const handlers = new Set<Handler>(); | ||
function isValidKey(event: KeyboardEvent) { | ||
@@ -47,2 +51,8 @@ // Control and Shift keys trigger when navigating back to the tab with keyboard. | ||
function callHandlers(interaction: Interaction) { | ||
for (const handler of handlers) { | ||
handler(interaction); | ||
} | ||
} | ||
/** | ||
@@ -67,2 +77,3 @@ * Detects what type of interaction the user is doing with the page, using the | ||
currentInteraction = 'keyboard'; | ||
callHandlers(currentInteraction); | ||
} | ||
@@ -75,2 +86,3 @@ }; | ||
currentInteraction = 'virtual'; | ||
callHandlers(currentInteraction); | ||
} | ||
@@ -86,2 +98,3 @@ }; | ||
currentInteraction = 'virtual'; | ||
callHandlers(currentInteraction); | ||
} | ||
@@ -103,2 +116,3 @@ | ||
hasEventBeforeFocus = true; | ||
callHandlers(currentInteraction); | ||
} | ||
@@ -150,1 +164,21 @@ }; | ||
} | ||
export function useFocusVisible() { | ||
useInteractionFocus(); | ||
const [interaction, setInteraction] = useState(isFocusVisible()); | ||
useEffect(() => { | ||
const handler = (interaction: Interaction) => { | ||
setInteraction(interaction !== 'pointer'); | ||
}; | ||
handlers.add(handler); | ||
return () => { | ||
handlers.delete(handler); | ||
}; | ||
}, []); | ||
return interaction; | ||
} |
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
172242
4829
Updated@clayui/link@^3.88.0