123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- 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>
- );
- };
|