2023-03-14 07:38:21 -07:00
|
|
|
import React from 'react';
|
2022-04-22 14:33:13 +01:00
|
|
|
|
2022-02-11 10:12:26 +01:00
|
|
|
import { IconName, Tooltip, LinkButton, Button } from '@grafana/ui';
|
2022-02-08 22:58:20 +01:00
|
|
|
import { PopoverContent, TooltipPlacement } from '@grafana/ui/src/components/Tooltip';
|
2021-04-07 08:42:43 +03:00
|
|
|
|
|
|
|
|
interface Props {
|
|
|
|
|
tooltip: PopoverContent;
|
|
|
|
|
icon: IconName;
|
2021-05-06 12:32:45 +03:00
|
|
|
className?: string;
|
2021-04-07 08:42:43 +03:00
|
|
|
tooltipPlacement?: TooltipPlacement;
|
2021-05-06 12:32:45 +03:00
|
|
|
to?: string;
|
2021-04-07 08:42:43 +03:00
|
|
|
target?: string;
|
2022-02-11 10:12:26 +01:00
|
|
|
onClick?: () => void;
|
2021-05-06 12:32:45 +03:00
|
|
|
'data-testid'?: string;
|
2021-04-07 08:42:43 +03:00
|
|
|
}
|
|
|
|
|
|
2023-03-14 07:38:21 -07:00
|
|
|
export const ActionIcon = ({
|
2021-05-06 12:32:45 +03:00
|
|
|
tooltip,
|
|
|
|
|
icon,
|
|
|
|
|
to,
|
|
|
|
|
target,
|
|
|
|
|
onClick,
|
|
|
|
|
className,
|
|
|
|
|
tooltipPlacement = 'top',
|
|
|
|
|
...rest
|
2023-03-14 07:38:21 -07:00
|
|
|
}: Props) => {
|
2021-12-21 16:06:23 +01:00
|
|
|
const ariaLabel = typeof tooltip === 'string' ? tooltip : undefined;
|
2021-04-07 08:42:43 +03:00
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Tooltip content={tooltip} placement={tooltipPlacement}>
|
2022-01-10 13:11:43 +01:00
|
|
|
{to ? (
|
2022-02-11 10:12:26 +01:00
|
|
|
<LinkButton
|
|
|
|
|
variant="secondary"
|
|
|
|
|
fill="text"
|
|
|
|
|
icon={icon}
|
|
|
|
|
href={to}
|
|
|
|
|
size="sm"
|
|
|
|
|
target={target}
|
|
|
|
|
{...rest}
|
|
|
|
|
aria-label={ariaLabel}
|
|
|
|
|
/>
|
2022-01-10 13:11:43 +01:00
|
|
|
) : (
|
2022-02-11 10:12:26 +01:00
|
|
|
<Button
|
|
|
|
|
className={className}
|
|
|
|
|
variant="secondary"
|
|
|
|
|
fill="text"
|
|
|
|
|
size="sm"
|
|
|
|
|
icon={icon}
|
|
|
|
|
type="button"
|
|
|
|
|
onClick={onClick}
|
|
|
|
|
{...rest}
|
|
|
|
|
aria-label={ariaLabel}
|
|
|
|
|
/>
|
2022-01-10 13:11:43 +01:00
|
|
|
)}
|
2021-04-07 08:42:43 +03:00
|
|
|
</Tooltip>
|
|
|
|
|
);
|
|
|
|
|
};
|