IconButton.tsx 819 B

12345678910111213141516171819202122232425262728293031323334
  1. import { cx, css } from '@emotion/css';
  2. import React, { ComponentProps, ButtonHTMLAttributes } from 'react';
  3. import { Icon } from '@grafana/ui';
  4. const SROnly = css`
  5. clip: rect(0 0 0 0);
  6. clip-path: inset(50%);
  7. height: 1px;
  8. overflow: hidden;
  9. position: absolute;
  10. white-space: nowrap;
  11. width: 1px;
  12. `;
  13. interface Props {
  14. iconName: ComponentProps<typeof Icon>['name'];
  15. onClick: () => void;
  16. className?: string;
  17. label: string;
  18. }
  19. export const IconButton = ({
  20. iconName,
  21. onClick,
  22. className,
  23. label,
  24. ...buttonProps
  25. }: Props & ButtonHTMLAttributes<HTMLButtonElement>) => (
  26. <button className={cx('gf-form-label gf-form-label--btn query-part', className)} onClick={onClick} {...buttonProps}>
  27. <span className={SROnly}>{label}</span>
  28. <Icon name={iconName} aria-hidden="true" />
  29. </button>
  30. );