@carbon/ibm-products
Version:
Carbon for IBM Products
130 lines (128 loc) • 5.3 kB
JavaScript
/**
* Copyright IBM Corp. 2020, 2026
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/
import { __toESM } from "../../_virtual/_rolldown/runtime.js";
import { require_classnames } from "../../node_modules/classnames/index.js";
import { pkg } from "../../settings.js";
import { useFocus } from "../../global/js/hooks/useFocus.js";
import { getDevtoolsProps } from "../../global/js/utils/devtools.js";
import { usePortalTarget } from "../../global/js/hooks/usePortalTarget.js";
import uuidv4 from "../../global/js/utils/uuidv4.js";
import React, { useEffect, useRef } from "react";
import PropTypes from "prop-types";
import { ComposedModal, ModalBody, ModalFooter, ModalHeader, unstable_FeatureFlags } from "@carbon/react";
//#region src/components/AboutModal/AboutModal.tsx
/**
* Copyright IBM Corp. 2020, 2021
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/
var import_classnames = /* @__PURE__ */ __toESM(require_classnames());
const blockClass = `${pkg.prefix}--about-modal`;
const componentName = "AboutModal";
/**
* The `AboutModal` component provides a way to communicate product information
* to users. It is triggered by a user’s action, appears on top of the main
* page content, and is persistent until dismissed. The purpose of this modal
* should be immediately apparent to the user, with a clear and obvious path
* to completion.
*/
const AboutModal = React.forwardRef(({ additionalInfo, className, closeIconDescription, copyrightText, content, links, logo, modalAriaLabel, onClose, open, portalTarget: portalTargetIn, title, version, ...rest }, ref) => {
const bodyRef = useRef(null);
const localRef = useRef(void 0);
const modalRef = ref || localRef;
const contentRef = useRef(null);
const contentId = uuidv4();
const renderPortalUse = usePortalTarget(portalTargetIn);
const { claimFocus } = useFocus(modalRef);
useEffect(() => {
bodyRef.current = contentRef.current?.parentElement;
}, [bodyRef]);
useEffect(() => {
if (open) claimFocus();
}, [modalRef, open]);
return renderPortalUse(/* @__PURE__ */ React.createElement(unstable_FeatureFlags, { enableExperimentalFocusWrapWithoutSentinels: true }, /* @__PURE__ */ React.createElement(ComposedModal, {
...rest,
className: (0, import_classnames.default)(blockClass, className),
"aria-label": modalAriaLabel,
ref: modalRef,
onClose,
open,
...getDevtoolsProps(componentName)
}, /* @__PURE__ */ React.createElement("div", { className: `${blockClass}__logo` }, logo), /* @__PURE__ */ React.createElement(ModalHeader, {
className: `${blockClass}__header`,
closeModal: onClose,
iconDescription: closeIconDescription,
label: title,
labelClassName: `${blockClass}__title`
}), /* @__PURE__ */ React.createElement(ModalBody, { className: `${blockClass}__body` }, /* @__PURE__ */ React.createElement("div", {
className: `${blockClass}__body-content`,
ref: contentRef,
id: contentId
}, /* @__PURE__ */ React.createElement("div", { className: `${blockClass}__version` }, version), links && links.length > 0 && /* @__PURE__ */ React.createElement("div", { className: `${blockClass}__links-container` }, links.map((link, i) => /* @__PURE__ */ React.createElement(React.Fragment, { key: i }, link))), content && /* @__PURE__ */ React.createElement("p", { className: `${blockClass}__content` }, content), copyrightText && /* @__PURE__ */ React.createElement("p", { className: `${blockClass}__copyright-text` }, copyrightText))), additionalInfo && /* @__PURE__ */ React.createElement(ModalFooter, { className: `${blockClass}__footer` }, additionalInfo))));
});
AboutModal.displayName = componentName;
AboutModal.propTypes = {
/**
* Provide additional detail for the modal footer, such as logos of
* technologies used in the product, legally required for some products
*/
additionalInfo: PropTypes.node,
/**
* Specify an optional className to be applied to the modal root node
*/
className: PropTypes.string,
/**
* Provide an accessible name for the close icon
*/
closeIconDescription: PropTypes.string.isRequired,
/**
* Provide any relevant product disclaimers or legal information
*/
content: PropTypes.node,
/**
* Specify the first year of product release to the current year
*/
copyrightText: PropTypes.string.isRequired,
/**
* Provide an array of Carbon `Link`s for additional detail about the
* product
*/
links: PropTypes.arrayOf(PropTypes.element),
/**
* Provide a visual representation of the product
*/
logo: PropTypes.node.isRequired,
/**
* Specify an aria-label for the modal
*/
modalAriaLabel: PropTypes.string,
/**
* Specify an optional handler for closing modal. Returning `false`
* prevents the modal from closing
*/
onClose: PropTypes.func,
/**
* Specify whether the modal is currently open
*/
open: PropTypes.bool,
/**
* Provide the DOM node where the modal should be rendered.
* Defaults to `document.body`
*/
portalTarget: PropTypes.node,
/**
* Provide the product name for the modal header
*/
title: PropTypes.node.isRequired,
/**
* Provide the product’s version number
*/
version: PropTypes.string.isRequired
};
//#endregion
export { AboutModal };