import {
cloneElement,
ComponentProps,
Fragment,
ReactElement,
ReactNode,
useRef,
useState,
} from 'react';
import Badge, { TypeOptions } from '../Badge';
import Box from '../Box';
import Dropdown from '../Dropdown';
import Flex from '../Flex';
import Heading from '../Heading';
import IconButton from '../IconButton';
import Link from '../Link';
import Mask from '../Mask';
import { ActionType } from '../PageHeader';
import Text from '../Text';
export function PageHeaderTitle({
marginTop,
title,
}: {
marginTop: number | null | undefined;
title: string;
}) {
return (
{title}
{title}
);
}
export function PageHeaderThumbnail({ thumbnail }: { thumbnail: ReactNode }) {
return (
{thumbnail}
);
}
export function PageHeaderBadge({
badgeText,
badgeTooltip,
type = 'info',
}: {
badgeText: string;
badgeTooltip?: ComponentProps['tooltip'];
type?: TypeOptions;
}) {
return badgeTooltip ? (
) : (
);
}
export function PageHeaderHelperIconButton({
accessibilityLabel,
accessibilityControls,
accessibilityExpanded,
onClick,
}: {
accessibilityLabel: string;
accessibilityControls: string;
accessibilityExpanded: boolean;
onClick: (arg1: {
event: React.MouseEvent | React.KeyboardEvent;
}) => void;
}) {
return (
);
}
export function PageHeaderSubtext({
subtext,
helperLink,
}: {
subtext: string;
helperLink?: {
text: string;
accessibilityLabel: string;
href: string;
onClick?: (arg1: {
event: React.MouseEvent | React.KeyboardEvent;
dangerouslyDisableOnNavigation: () => void;
}) => void;
};
}) {
return (
{subtext}
{helperLink ? (
{' '}
{helperLink.text}
) : null}
);
}
export function PageHeaderActionBlock({
primaryAction,
secondaryAction,
dropdownAccessibilityLabel = '',
}: {
primaryAction?: {
component: ActionType;
dropdownItems: ReadonlyArray;
};
secondaryAction?: {
component: ActionType;
dropdownItems: ReadonlyArray;
};
dropdownAccessibilityLabel?: string;
}) {
const [open, setOpen] = useState(false);
const anchorRef = useRef(null);
const consolidatedDropdownItems = [
...(primaryAction?.dropdownItems ?? []),
...(secondaryAction?.dropdownItems ?? []),
];
return (
{/* 48px height needed to maintain proper sizing when action is a Link */}
{secondaryAction ? (
{secondaryAction.component}
) : null}
{primaryAction ? (
{primaryAction.component}
) : null}
' is not assignable to type 'LegacyRef | undefined'.
ref={anchorRef}
accessibilityControls="pageheader-dropdown"
accessibilityExpanded={open}
accessibilityHaspopup
accessibilityLabel={dropdownAccessibilityLabel}
icon="ellipsis"
iconColor="darkGray"
onClick={() => setOpen((prevVal) => !prevVal)}
selected={open}
size="lg"
/>
{open && (
)}
);
}
export function PageHeaderItemsBlock({ items }: { items: ReadonlyArray }) {
return (
{items.slice(0, 2).map((item, i) => (
// eslint-disable-next-line react/no-array-index-key
{item}
))}
);
}