mirror of
https://github.com/grafana/grafana.git
synced 2025-09-20 12:33:26 +08:00

* Add and configure eslint-plugin-import * Fix the lint:ts npm command * Autofix + prettier all the files * Manually fix remaining files * Move jquery code in jest-setup to external file to safely reorder imports * Resolve issue caused by circular dependencies within Prometheus * Update .betterer.results * Fix missing // @ts-ignore * ignore iconBundle.ts * Fix missing // @ts-ignore
58 lines
1.2 KiB
TypeScript
58 lines
1.2 KiB
TypeScript
import React, { FC } from 'react';
|
|
|
|
import { IconName, Tooltip, LinkButton, Button } from '@grafana/ui';
|
|
import { PopoverContent, TooltipPlacement } from '@grafana/ui/src/components/Tooltip';
|
|
|
|
interface Props {
|
|
tooltip: PopoverContent;
|
|
icon: IconName;
|
|
className?: string;
|
|
tooltipPlacement?: TooltipPlacement;
|
|
to?: string;
|
|
target?: string;
|
|
onClick?: () => void;
|
|
'data-testid'?: string;
|
|
}
|
|
|
|
export const ActionIcon: FC<Props> = ({
|
|
tooltip,
|
|
icon,
|
|
to,
|
|
target,
|
|
onClick,
|
|
className,
|
|
tooltipPlacement = 'top',
|
|
...rest
|
|
}) => {
|
|
const ariaLabel = typeof tooltip === 'string' ? tooltip : undefined;
|
|
|
|
return (
|
|
<Tooltip content={tooltip} placement={tooltipPlacement}>
|
|
{to ? (
|
|
<LinkButton
|
|
variant="secondary"
|
|
fill="text"
|
|
icon={icon}
|
|
href={to}
|
|
size="sm"
|
|
target={target}
|
|
{...rest}
|
|
aria-label={ariaLabel}
|
|
/>
|
|
) : (
|
|
<Button
|
|
className={className}
|
|
variant="secondary"
|
|
fill="text"
|
|
size="sm"
|
|
icon={icon}
|
|
type="button"
|
|
onClick={onClick}
|
|
{...rest}
|
|
aria-label={ariaLabel}
|
|
/>
|
|
)}
|
|
</Tooltip>
|
|
);
|
|
};
|