UNPKG

@workday/canvas-kit-react

Version:

The parent module that contains all Workday Canvas Kit React components

32 lines (31 loc) 1.36 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.usePopupPopper = void 0; const common_1 = require("@workday/canvas-kit-react/common"); const usePopupModel_1 = require("./usePopupModel"); const react_1 = __importDefault(require("react")); /** * Adds the necessary props to a {@link Popper} component. Used by the * {@link PopupPopper Popup.Popper} subcomponent. */ exports.usePopupPopper = (0, common_1.createElemPropsHook)(usePopupModel_1.usePopupModel)(({ state, events }, ref) => { const elementRef = (0, common_1.useForkRef)(ref, state.stackRef); // Create a mutable ref of the placement to keep a stable `onPlacementChange` reference. const placementRef = react_1.default.useRef(state.placement); placementRef.current = state.placement; const onPlacementChange = react_1.default.useCallback((placement) => { if (placement !== placementRef.current) { // only update if the placement has changed events.updatePlacement({ placement }); } }, [events]); return { open: state.visibility !== 'hidden', anchorElement: state.targetRef, ref: elementRef, onPlacementChange, }; });