rsuite
Version:
A suite of react components
69 lines (68 loc) • 1.91 kB
JavaScript
'use client';
;
exports.__esModule = true;
exports.default = void 0;
var _react = require("react");
var _hooks = require("../../hooks");
var _symbols = require("../../symbols");
/**
* A hook of the exposed method of Picker
*/
function usePickerRef(ref) {
const trigger = (0, _react.useRef)(null);
const root = (0, _react.useRef)(null);
const target = (0, _react.useRef)(null);
const overlay = (0, _react.useRef)(null);
const list = (0, _react.useRef)(null);
const searchInput = (0, _react.useRef)(null);
const treeView = (0, _react.useRef)(null);
const handleOpen = (0, _hooks.useEventCallback)(() => {
trigger?.current?.open();
});
const handleClose = (0, _hooks.useEventCallback)(() => {
trigger?.current?.close();
});
const handleUpdatePosition = (0, _hooks.useEventCallback)(() => {
trigger?.current?.updatePosition();
});
(0, _react.useImperativeHandle)(ref, () => {
return {
get root() {
return (root?.current || trigger?.current?.root) ?? null;
},
get overlay() {
if (!overlay?.current) {
throw new Error('The overlay is not found. Please confirm whether the picker is open.');
}
return overlay?.current ?? null;
},
get target() {
return target?.current ?? null;
},
get list() {
if (!list?.current) {
throw new Error(`
The list is not found.
1.Please set virtualized for the component.
2.Please confirm whether the picker is open.
`);
}
return list?.current;
},
type: _symbols.RSUITE_PICKER_TYPE,
updatePosition: handleUpdatePosition,
open: handleOpen,
close: handleClose
};
});
return {
trigger,
root,
overlay,
target,
list,
searchInput,
treeView
};
}
var _default = exports.default = usePickerRef;