You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ClickableIcon.tsx 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import React from 'react';
  2. import { makeStyles } from 'tss-react/mui';
  3. import { isMobileBrowser } from '../../../environment/utils';
  4. import Icon from '../../../icons/components/Icon';
  5. interface IProps {
  6. accessibilityLabel: string;
  7. className?: string;
  8. icon: Function;
  9. id?: string;
  10. onClick: () => void;
  11. }
  12. const useStyles = makeStyles()(theme => {
  13. return {
  14. button: {
  15. padding: '2px',
  16. backgroundColor: theme.palette.action03,
  17. border: 0,
  18. outline: 0,
  19. borderRadius: `${theme.shape.borderRadius}px`,
  20. '&:hover': {
  21. backgroundColor: theme.palette.ui02
  22. },
  23. '&.focus-visible': {
  24. outline: 0,
  25. boxShadow: `0px 0px 0px 2px ${theme.palette.focus01}`
  26. },
  27. '&:active': {
  28. backgroundColor: theme.palette.ui03
  29. },
  30. '&.is-mobile': {
  31. padding: '10px'
  32. }
  33. }
  34. };
  35. });
  36. const ClickableIcon = ({ accessibilityLabel, className, icon, id, onClick }: IProps) => {
  37. const { classes: styles, cx } = useStyles();
  38. const isMobile = isMobileBrowser();
  39. return (
  40. <button
  41. aria-label = { accessibilityLabel }
  42. className = { cx(styles.button, isMobile && 'is-mobile', className) }
  43. id = { id }
  44. onClick = { onClick }>
  45. <Icon
  46. size = { 24 }
  47. src = { icon } />
  48. </button>
  49. );
  50. };
  51. export default ClickableIcon;