@awsui/components-react
Version:
On July 19th, 2022, we launched [Cloudscape Design System](https://cloudscape.design). Cloudscape is an evolution of AWS-UI. It consists of user interface guidelines, front-end components, design resources, and development tools for building intuitive, en
29 lines • 1.92 kB
JavaScript
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import { useEffect, useState } from 'react';
import { findUpUntil } from '@awsui/component-toolkit/dom';
import { awsuiPluginsInternal } from '../../internal/plugins/api';
export const useRuntimeDrawerContext = ({ rootRef }) => {
const [drawerContext, setDrawerContext] = useState(null);
useEffect(() => {
var _a, _b;
// Determine if the hook is inside a runtime drawer.
// There’s no other reliable way to check this, since runtime drawers are separate applications rendered into specific DOM nodes.
if (!(rootRef === null || rootRef === void 0 ? void 0 : rootRef.current)) {
return;
}
const runtimeDrawerWrapper = findUpUntil(rootRef === null || rootRef === void 0 ? void 0 : rootRef.current, node => { var _a; return !!((_a = node === null || node === void 0 ? void 0 : node.dataset) === null || _a === void 0 ? void 0 : _a.awsuiRuntimeDrawerRootId); });
const drawerId = (_a = runtimeDrawerWrapper === null || runtimeDrawerWrapper === void 0 ? void 0 : runtimeDrawerWrapper.dataset) === null || _a === void 0 ? void 0 : _a.awsuiRuntimeDrawerRootId;
if (!drawerId) {
return;
}
const drawers = awsuiPluginsInternal.appLayout.getDrawersState();
setDrawerContext((_b = drawers === null || drawers === void 0 ? void 0 : drawers.find(drawer => drawer.id === drawerId)) !== null && _b !== void 0 ? _b : null);
return awsuiPluginsInternal.appLayout.onDrawersUpdated(drawers => {
var _a;
setDrawerContext((_a = drawers === null || drawers === void 0 ? void 0 : drawers.find(drawer => drawer.id === drawerId)) !== null && _a !== void 0 ? _a : null);
});
}, [rootRef]);
return drawerContext;
};
//# sourceMappingURL=use-runtime-drawer-context.js.map