ActionIcon.tsx 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import React, { FC } from 'react';
  2. import { IconName, Tooltip, LinkButton, Button } from '@grafana/ui';
  3. import { PopoverContent, TooltipPlacement } from '@grafana/ui/src/components/Tooltip';
  4. interface Props {
  5. tooltip: PopoverContent;
  6. icon: IconName;
  7. className?: string;
  8. tooltipPlacement?: TooltipPlacement;
  9. to?: string;
  10. target?: string;
  11. onClick?: () => void;
  12. 'data-testid'?: string;
  13. }
  14. export const ActionIcon: FC<Props> = ({
  15. tooltip,
  16. icon,
  17. to,
  18. target,
  19. onClick,
  20. className,
  21. tooltipPlacement = 'top',
  22. ...rest
  23. }) => {
  24. const ariaLabel = typeof tooltip === 'string' ? tooltip : undefined;
  25. return (
  26. <Tooltip content={tooltip} placement={tooltipPlacement}>
  27. {to ? (
  28. <LinkButton
  29. variant="secondary"
  30. fill="text"
  31. icon={icon}
  32. href={to}
  33. size="sm"
  34. target={target}
  35. {...rest}
  36. aria-label={ariaLabel}
  37. />
  38. ) : (
  39. <Button
  40. className={className}
  41. variant="secondary"
  42. fill="text"
  43. size="sm"
  44. icon={icon}
  45. type="button"
  46. onClick={onClick}
  47. {...rest}
  48. aria-label={ariaLabel}
  49. />
  50. )}
  51. </Tooltip>
  52. );
  53. };