Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

ContextMenuItem.js 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. // @flow
  2. import { makeStyles } from '@material-ui/styles';
  3. import clsx from 'clsx';
  4. import React from 'react';
  5. import { useSelector } from 'react-redux';
  6. import { showOverflowDrawer } from '../../../toolbox/functions.web';
  7. import { Icon } from '../../icons';
  8. export type Props = {
  9. /**
  10. * Label used for accessibility.
  11. */
  12. accessibilityLabel: string,
  13. /**
  14. * CSS class name used for custom styles.
  15. */
  16. className?: string,
  17. /**
  18. * Custom icon. If used, the icon prop is ignored.
  19. * Used to allow custom children instead of just the default icons.
  20. */
  21. customIcon?: React$Node,
  22. /**
  23. * Whether or not the action is disabled.
  24. */
  25. disabled?: boolean,
  26. /**
  27. * Id of the action container.
  28. */
  29. id?: string,
  30. /**
  31. * Default icon for action.
  32. */
  33. icon?: Function,
  34. /**
  35. * Click handler.
  36. */
  37. onClick?: Function,
  38. /**
  39. * Action text.
  40. */
  41. text: string,
  42. /**
  43. * Class name for the text.
  44. */
  45. textClassName?: string
  46. }
  47. const useStyles = makeStyles(theme => {
  48. return {
  49. contextMenuItem: {
  50. alignItems: 'center',
  51. cursor: 'pointer',
  52. display: 'flex',
  53. minHeight: '40px',
  54. padding: '10px 16px',
  55. boxSizing: 'border-box',
  56. '& > *:not(:last-child)': {
  57. marginRight: `${theme.spacing(3)}px`
  58. },
  59. '&:hover': {
  60. backgroundColor: theme.palette.ui04
  61. }
  62. },
  63. contextMenuItemDisabled: {
  64. pointerEvents: 'none'
  65. },
  66. contextMenuItemDrawer: {
  67. padding: '12px 16px'
  68. },
  69. contextMenuItemIcon: {
  70. '& svg': {
  71. fill: theme.palette.icon01
  72. }
  73. }
  74. };
  75. });
  76. const ContextMenuItem = ({
  77. accessibilityLabel,
  78. className,
  79. customIcon,
  80. disabled,
  81. id,
  82. icon,
  83. onClick,
  84. text,
  85. textClassName }: Props) => {
  86. const styles = useStyles();
  87. const _overflowDrawer = useSelector(showOverflowDrawer);
  88. return (
  89. <div
  90. aria-label = { accessibilityLabel }
  91. className = { clsx(styles.contextMenuItem,
  92. _overflowDrawer && styles.contextMenuItemDrawer,
  93. disabled && styles.contextMenuItemDisabled,
  94. className
  95. ) }
  96. id = { id }
  97. key = { text }
  98. onClick = { onClick }>
  99. {customIcon ? customIcon
  100. : icon && <Icon
  101. className = { styles.contextMenuItemIcon }
  102. size = { 20 }
  103. src = { icon } />}
  104. <span className = { textClassName ?? '' }>{text}</span>
  105. </div>
  106. );
  107. };
  108. export default ContextMenuItem;