package.src.components.AboutModal.AboutModal.tsx Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of react-core Show documentation
Show all versions of react-core Show documentation
This library provides a set of common React components for use with the PatternFly reference implementation.
The newest version!
import * as React from 'react';
import { css } from '@patternfly/react-styles';
import backgroundImage from '@patternfly/react-tokens/dist/esm/c_about_modal_box_BackgroundImage';
import { AboutModalBoxContent } from './AboutModalBoxContent';
import { AboutModalBoxHeader } from './AboutModalBoxHeader';
import { AboutModalBoxBrand } from './AboutModalBoxBrand';
import { AboutModalBoxCloseButton } from './AboutModalBoxCloseButton';
import { AboutModalBox } from './AboutModalBox';
import { Modal, ModalVariant } from '../Modal';
import { GenerateId } from '../../helpers/GenerateId/GenerateId';
export interface AboutModalProps extends React.HTMLProps {
/** Content rendered inside the about modal */
children: React.ReactNode;
/** Additional classes added to the about modal */
className?: string;
/** Flag to show the about modal */
isOpen?: boolean;
/** A callback for when the close button is clicked */
onClose?: (event: React.MouseEvent | MouseEvent | KeyboardEvent) => void;
/** Product name */
productName?: string;
/** Trademark information */
trademark?: string;
/** The URL of the image for the brand */
brandImageSrc: string;
/** The alternate text of the brand image */
brandImageAlt: string;
/** The URL or file path of the image for the background */
backgroundImageSrc?: string;
/** Prevents the about modal from rendering content inside a container; allows for more flexible layouts */
hasNoContentContainer?: boolean;
/** The parent container to append the modal to. Defaults to document.body */
appendTo?: HTMLElement | (() => HTMLElement);
/** Aria label for the about modal. This should be used when no productName prop is provided */
'aria-label'?: string;
/** Set aria label to the close button */
closeButtonAriaLabel?: string;
/** Flag to disable focus trap */
disableFocusTrap?: boolean;
}
export const AboutModal: React.FunctionComponent = ({
children,
className,
isOpen = false,
onClose = (_e): any => undefined,
productName,
trademark,
backgroundImageSrc,
brandImageSrc,
brandImageAlt,
hasNoContentContainer = false,
appendTo,
closeButtonAriaLabel,
'aria-label': ariaLabel,
disableFocusTrap,
...props
}: AboutModalProps) => {
if (brandImageSrc && !brandImageAlt) {
// eslint-disable-next-line no-console
console.error(
'AboutModal:',
'brandImageAlt is required when a brandImageSrc is specified, and should not be an empty string.'
);
}
if (!productName && !ariaLabel) {
// eslint-disable-next-line no-console
console.error('AboutModal:', 'Either productName or ariaLabel is required for component to be accessible');
}
if (!isOpen) {
return null;
}
return (
{(ariaLabelledBy) => (
{productName && }
{children}
)}
);
};
AboutModal.displayName = 'AboutModal';