UNPKG

@gechiui/components

Version:
70 lines (63 loc) 2.22 kB
import { createElement } from "@gechiui/element"; /** * GeChiUI dependencies */ import { Component } from '@gechiui/element'; import { createHigherOrderComponent, useFocusReturn } from '@gechiui/compose'; import deprecated from '@gechiui/deprecated'; /** * Returns true if the given object is component-like. An object is component- * like if it is an instance of gc.element.Component, or is a function. * * @param {*} object Object to test. * * @return {boolean} Whether object is component-like. */ function isComponentLike(object) { return object instanceof 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 {(GCComponent|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. */ export default createHigherOrderComponent(options => { const HoC = function () { let { onFocusReturn } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; return WrappedComponent => { const WithFocusReturn = props => { const ref = useFocusReturn(onFocusReturn); return createElement("div", { ref: ref }, createElement(WrappedComponent, props)); }; return WithFocusReturn; }; }; if (isComponentLike(options)) { const WrappedComponent = options; return HoC()(WrappedComponent); } return HoC(options); }, 'withFocusReturn'); export const Provider = _ref => { let { children } = _ref; deprecated('gc.components.FocusReturnProvider component', { since: '5.7', hint: 'This provider is not used anymore. You can just remove it from your codebase' }); return children; }; //# sourceMappingURL=index.js.map