DashNavButton.tsx 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // Libraries
  2. import { css } from '@emotion/css';
  3. import React, { FunctionComponent, MouseEvent } from 'react';
  4. // Components
  5. import { GrafanaTheme } from '@grafana/data';
  6. import { IconName, IconType, IconSize, IconButton, useTheme, stylesFactory } from '@grafana/ui';
  7. interface Props {
  8. icon?: IconName;
  9. tooltip: string;
  10. onClick?: (event: MouseEvent<HTMLButtonElement>) => void;
  11. href?: string;
  12. children?: React.ReactNode;
  13. iconType?: IconType;
  14. iconSize?: IconSize;
  15. }
  16. export const DashNavButton: FunctionComponent<Props> = ({ icon, iconType, iconSize, tooltip, onClick, children }) => {
  17. const theme = useTheme();
  18. const styles = getStyles(theme);
  19. return (
  20. <div className={styles.noBorderContainer}>
  21. {icon && (
  22. <IconButton
  23. name={icon}
  24. size={iconSize}
  25. iconType={iconType}
  26. tooltip={tooltip}
  27. tooltipPlacement="bottom"
  28. onClick={onClick}
  29. />
  30. )}
  31. {children}
  32. </div>
  33. );
  34. };
  35. const getStyles = stylesFactory((theme: GrafanaTheme) => ({
  36. noBorderContainer: css`
  37. padding: 0 ${theme.spacing.xs};
  38. display: flex;
  39. `,
  40. }));