@julo-ui/sliders
Version:
A React Slider component that implements input[type='range']
59 lines (57 loc) • 2.11 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/slider/usecase/use-handle-focus-thumb.ts
var use_handle_focus_thumb_exports = {};
__export(use_handle_focus_thumb_exports, {
default: () => use_handle_focus_thumb_default
});
module.exports = __toCommonJS(use_handle_focus_thumb_exports);
var import_react = require("react");
var import_function_utils = require("@julo-ui/function-utils");
function useHandleFocusThumb(options) {
const {
focusThumbOnChange,
thumbRef,
eventSource,
onChangeEnd = import_function_utils._noop,
value
} = options;
const timeoutId = (0, import_react.useRef)();
const onFocusThumb = (0, import_react.useCallback)(() => {
if (!focusThumbOnChange)
return;
timeoutId.current = setTimeout(() => {
var _a;
return (_a = thumbRef.current) == null ? void 0 : _a.focus();
});
}, [focusThumbOnChange, thumbRef]);
(0, import_react.useEffect)(() => {
onFocusThumb();
if (eventSource === "keyboard") {
onChangeEnd(value);
}
}, [eventSource, onChangeEnd, onFocusThumb, value]);
(0, import_react.useEffect)(() => {
return () => clearTimeout(timeoutId.current);
}, []);
return { onFocusThumb };
}
var use_handle_focus_thumb_default = useHandleFocusThumb;
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {});