import { css, cx } from '@emotion/css';
import * as React from 'react';
import { NavModelItem, GrafanaTheme2 } from '@grafana/data';
import { Tab, TabsBar, Icon, useStyles2, toIconName } from '@grafana/ui';
import { PageInfoItem } from '../../../core/components/Page/types';
import { PageInfo } from '../../../core/components/PageInfo/PageInfo';
import { ProBadge } from '../../../core/components/Upgrade/ProBadge';
import { PanelHeaderMenuItem } from './PanelHeaderMenuItem';
export interface Props {
navItem: NavModelItem;
renderTitle?: (title: string) => React.ReactNode;
actions?: React.ReactNode;
info?: PageInfoItem[];
subTitle?: React.ReactNode;
}
const SelectNav = ({ children, customCss }: { children: NavModelItem[]; customCss: string }) => {
if (!children || children.length === 0) {
return null;
}
const defaultSelectedItem = children.find((navItem) => {
return navItem.active === true;
});
return (
{children.map((navItem: NavModelItem) => {
if (navItem.hideFromTabs) {
// TODO: Rename hideFromTabs => hideFromNav
return null;
}
return (
);
})}
);
};
const Navigation = ({ children }: { children: NavModelItem[] }) => {
if (!children || children.length === 0) {
return null;
}
return (
);
};
export const PageHeader = ({ navItem: model, renderTitle, actions, info, subTitle }: Props) => {
const styles = useStyles2(getStyles);
if (!model) {
return null;
}
const renderHeader = (main: NavModelItem) => {
const marginTop = main.icon === 'grafana' ? 12 : 14;
const icon = main.icon && toIconName(main.icon);
const sub = subTitle ?? main.subTitle;
return (
{icon && }
{main.img &&
}
{renderTitle ? renderTitle(main.text) : renderHeaderTitle(main.text, main.highlightText)}
{info &&
}
{sub &&
{sub}
}
{actions &&
{actions}
}
);
};
return (
{renderHeader(model)}
{model.children && model.children.length > 0 && {model.children}}
);
};
function renderHeaderTitle(title: string, highlightText: NavModelItem['highlightText']) {
if (!title) {
return null;
}
return (
{title}
{highlightText && (
)}
);
}
const getStyles = (theme: GrafanaTheme2) => ({
actions: css({
display: 'flex',
flexDirection: 'row',
gap: theme.spacing(1),
}),
headerText: css({
display: 'flex',
flexDirection: 'column',
gap: theme.spacing(1),
}),
headerCanvas: css`
background: ${theme.colors.background.canvas};
`,
});