UNPKG

@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

35 lines 1.49 kB
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 import React, { useEffect, useRef, useState } from 'react'; function RuntimeActionWrapper({ mountContent, unmountContent, context }) { const ref = useRef(null); useEffect(() => { const container = ref.current; mountContent(container, context); return () => { unmountContent(container); }; // eslint-disable-next-line react-hooks/exhaustive-deps }, []); return React.createElement("div", { ref: ref }); } function convertRuntimeAction(action, context) { if (!action) { return null; } return (React.createElement(RuntimeActionWrapper, { key: action.id + '-' + context.type, context: context, mountContent: action.mountContent, unmountContent: action.unmountContent })); } export function createUseDiscoveredAction(onActionRegistered) { return function useDiscoveredAction(type) { const [discoveredActions, setDiscoveredActions] = useState([]); const headerRef = useRef(null); const contentRef = useRef(null); useEffect(() => { return onActionRegistered(actions => { setDiscoveredActions(actions.map(action => convertRuntimeAction(action, { type, headerRef, contentRef }))); }); }, [type]); return { discoveredActions, headerRef, contentRef }; }; } //# sourceMappingURL=use-discovered-action.js.map