UNPKG

@actinc/dls

Version:

Design Language System (DLS) for ACT & Encoura front-end projects.

49 lines 1.57 kB
/** * Copyright (c) ACT, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ import { useEffect, useState } from 'react'; import { useIdleTimer } from 'react-idle-timer'; export var IdleTimer = function (_a) { var children = _a.children, onAction = _a.onAction, onActive = _a.onActive, onIdle = _a.onIdle, stopOnIdle = _a.stopOnIdle, timeoutMs = _a.timeoutMs; var _b = useState(timeoutMs), remainingTimeMs = _b[0], setRemainingTimeMs = _b[1]; var _c = useIdleTimer({ debounce: 250, onAction: function (event) { if (onAction) { onAction(event); } }, onActive: function (event) { if (onActive) { onActive(event); } }, onIdle: function () { if (onIdle) { onIdle({}); } }, stopOnIdle: stopOnIdle, timeout: timeoutMs, }), getRemainingTime = _c.getRemainingTime, reset = _c.reset; var refresh = function () { setRemainingTimeMs(getRemainingTime()); }; useEffect(function () { var interval = setInterval(function () { refresh(); }, 1000); return function () { clearInterval(interval); }; }, []); if (children) { return children({ remainingTimeMs: remainingTimeMs, reset: reset }); } return null; }; export default IdleTimer; //# sourceMappingURL=index.js.map