UNPKG

@wordpress/components

Version:
81 lines (66 loc) 2.37 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.Provider = exports.default = void 0; var _element = require("@wordpress/element"); var _compose = require("@wordpress/compose"); var _deprecated = _interopRequireDefault(require("@wordpress/deprecated")); /** * WordPress dependencies */ /** * Returns true if the given object is component-like. An object is component- * like if it is an instance of wp.element.Component, or is a function. * * @param {*} object Object to test. * * @return {boolean} Whether object is component-like. */ function isComponentLike(object) { return object instanceof _element.Component || typeof object === 'function'; } /** * Higher Order Component used to be used to wrap disposable elements like * sidebars, modals, dropdowns. When mounting the wrapped component, we track a * reference to the current active element so we know where to restore focus * when the component is unmounted. * * @param {(WPComponent|Object)} options The component to be enhanced with * focus return behavior, or an object * describing the component and the * focus return characteristics. * * @return {Function} Higher Order Component with the focus restauration behaviour. */ var _default = (0, _compose.createHigherOrderComponent)(options => { const HoC = ({ onFocusReturn } = {}) => WrappedComponent => { const WithFocusReturn = props => { const ref = (0, _compose.useFocusReturn)(onFocusReturn); return (0, _element.createElement)("div", { ref: ref }, (0, _element.createElement)(WrappedComponent, props)); }; return WithFocusReturn; }; if (isComponentLike(options)) { const WrappedComponent = options; return HoC()(WrappedComponent); } return HoC(options); }, 'withFocusReturn'); exports.default = _default; const Provider = ({ children }) => { (0, _deprecated.default)('wp.components.FocusReturnProvider component', { since: '5.7', hint: 'This provider is not used anymore. You can just remove it from your codebase' }); return children; }; exports.Provider = Provider; //# sourceMappingURL=index.js.map