@wordpress/components
Version:
UI components for WordPress.
72 lines (70 loc) • 2.42 kB
JavaScript
;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = exports.Provider = void 0;
var _element = require("@wordpress/element");
var _compose = require("@wordpress/compose");
var _deprecated = _interopRequireDefault(require("@wordpress/deprecated"));
var _jsxRuntime = require("react/jsx-runtime");
/**
* 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 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 options The component to be enhanced with
* focus return behavior, or an object
* describing the component and the
* focus return characteristics.
*
* @return Higher Order Component with the focus restoration behaviour.
*/
var _default = exports.default = (0, _compose.createHigherOrderComponent)(
// @ts-expect-error TODO: Reconcile with intended `createHigherOrderComponent` types
options => {
const HoC = ({
onFocusReturn
} = {}) => WrappedComponent => {
const WithFocusReturn = props => {
const ref = (0, _compose.useFocusReturn)(onFocusReturn);
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
ref: ref,
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(WrappedComponent, {
...props
})
});
};
return WithFocusReturn;
};
if (isComponentLike(options)) {
const WrappedComponent = options;
return HoC()(WrappedComponent);
}
return HoC(options);
}, 'withFocusReturn');
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