grafana/public/app/features/dashboard/dashgrid/PanelLinks.tsx
Polina Boneva d48a8fd227
PanelChrome: Styling issues (#62466)
* all panel icons are 16x16 in size; allow ToolbarButton to have its icon size set from outside;

* use TitleItem for streaming too, so that the style of focus-visible is the same

* allow menu icon to be visible when panel is focused

* remove some styling of title icons in panel header

* panel alert notices are too big

* PanelHeaderNotice: Fix styling issue with background and hover when
feature toggle is not enable

---------

Co-authored-by: Alexandra Vargas <alexa1866@gmail.com>
2023-01-31 11:39:15 +02:00

56 lines
1.5 KiB
TypeScript

import { css } from '@emotion/css';
import React from 'react';
import { DataLink, GrafanaTheme2, LinkModel } from '@grafana/data';
import { Dropdown, Icon, Menu, ToolbarButton, useStyles2, PanelChrome } from '@grafana/ui';
interface Props {
panelLinks: DataLink[];
onShowPanelLinks: () => LinkModel[];
}
export function PanelLinks({ panelLinks, onShowPanelLinks }: Props) {
const styles = useStyles2(getStyles);
const getLinksContent = (): JSX.Element => {
const interpolatedLinks = onShowPanelLinks();
return (
<Menu>
{interpolatedLinks?.map((link, idx) => {
return <Menu.Item key={idx} label={link.title} url={link.href} target={link.target} />;
})}
</Menu>
);
};
if (panelLinks.length === 1) {
const linkModel = onShowPanelLinks()[0];
return (
<PanelChrome.TitleItem
href={linkModel.href}
onClick={linkModel.onClick}
target={linkModel.target}
title={linkModel.title}
>
<Icon name="external-link-alt" size="md" />
</PanelChrome.TitleItem>
);
} else {
return (
<Dropdown overlay={getLinksContent}>
<ToolbarButton icon="external-link-alt" iconSize="md" aria-label="panel links" className={styles.menuTrigger} />
</Dropdown>
);
}
}
const getStyles = (theme: GrafanaTheme2) => {
return {
menuTrigger: css({
border: 'none',
borderRadius: `${theme.shape.borderRadius()}`,
cursor: 'context-menu',
}),
};
};