CardButton.tsx 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import { css } from '@emotion/css';
  2. import React, { HTMLAttributes } from 'react';
  3. import { GrafanaTheme2 } from '@grafana/data';
  4. import { Icon, IconName, useStyles2 } from '@grafana/ui';
  5. interface Props extends HTMLAttributes<HTMLButtonElement> {
  6. icon: IconName;
  7. onClick: () => void;
  8. children: React.ReactNode;
  9. }
  10. export const CardButton = React.forwardRef<HTMLButtonElement, Props>(
  11. ({ icon, children, onClick, ...restProps }, ref) => {
  12. const styles = useStyles2(getStyles);
  13. return (
  14. <button {...restProps} className={styles.action} onClick={onClick}>
  15. <Icon name={icon} size="xl" />
  16. {children}
  17. </button>
  18. );
  19. }
  20. );
  21. CardButton.displayName = 'CardButton';
  22. const getStyles = (theme: GrafanaTheme2) => {
  23. return {
  24. action: css`
  25. display: flex;
  26. flex-direction: column;
  27. height: 100%;
  28. justify-self: center;
  29. cursor: pointer;
  30. background: ${theme.colors.background.secondary};
  31. border-radius: ${theme.shape.borderRadius(1)};
  32. color: ${theme.colors.text.primary};
  33. border: unset;
  34. width: 100%;
  35. display: flex;
  36. justify-content: center;
  37. align-items: center;
  38. text-align: center;
  39. &:hover {
  40. background: ${theme.colors.emphasize(theme.colors.background.secondary)};
  41. }
  42. `,
  43. };
  44. };