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.

DeviceHidContainer.web.tsx 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. import React, { useCallback } from 'react';
  2. import { useTranslation } from 'react-i18next';
  3. import { useDispatch, useSelector } from 'react-redux';
  4. import { makeStyles } from 'tss-react/mui';
  5. import Icon from '../../base/icons/components/Icon';
  6. import { IconTrash } from '../../base/icons/svg';
  7. import { withPixelLineHeight } from '../../base/styles/functions.web';
  8. import Button from '../../base/ui/components/web/Button';
  9. import { BUTTON_TYPES } from '../../base/ui/constants.any';
  10. import { closeHidDevice, requestHidDevice } from '../../web-hid/actions';
  11. import { getDeviceInfo, shouldRequestHIDDevice } from '../../web-hid/functions';
  12. const useStyles = makeStyles()(theme => {
  13. return {
  14. callControlContainer: {
  15. display: 'flex',
  16. flexDirection: 'column',
  17. alignItems: 'flex-start'
  18. },
  19. label: {
  20. ...withPixelLineHeight(theme.typography.bodyShortRegular),
  21. color: theme.palette.text01,
  22. marginBottom: theme.spacing(2)
  23. },
  24. deviceRow: {
  25. display: 'flex',
  26. justifyContent: 'space-between'
  27. },
  28. deleteDevice: {
  29. cursor: 'pointer',
  30. textAlign: 'center'
  31. },
  32. headerConnectedDevice: {
  33. fontWeight: 600
  34. },
  35. hidContainer: {
  36. '> span': {
  37. marginLeft: '16px'
  38. }
  39. }
  40. };
  41. });
  42. /**
  43. * Device hid container.
  44. *
  45. * @param {IProps} props - The props of the component.
  46. * @returns {ReactElement}
  47. */
  48. function DeviceHidContainer() {
  49. const { t } = useTranslation();
  50. const deviceInfo = useSelector(getDeviceInfo);
  51. const showRequestDeviceInfo = shouldRequestHIDDevice(deviceInfo);
  52. const { classes } = useStyles();
  53. const dispatch = useDispatch();
  54. const onRequestControl = useCallback(() => {
  55. dispatch(requestHidDevice());
  56. }, [ dispatch ]);
  57. const onDeleteHid = useCallback(() => {
  58. dispatch(closeHidDevice());
  59. }, [ dispatch ]);
  60. return (
  61. <div
  62. className = { classes.callControlContainer }
  63. key = 'callControl'>
  64. <label
  65. className = { classes.label }
  66. htmlFor = 'callControl'>
  67. {t('deviceSelection.hid.callControl')}
  68. </label>
  69. {showRequestDeviceInfo && (
  70. <Button
  71. accessibilityLabel = { t('deviceSelection.hid.pairDevice') }
  72. id = 'request-control-btn'
  73. key = 'request-control-btn'
  74. label = { t('deviceSelection.hid.pairDevice') }
  75. onClick = { onRequestControl }
  76. type = { BUTTON_TYPES.SECONDARY } />
  77. )}
  78. {!showRequestDeviceInfo && (
  79. <div className = { classes.hidContainer }>
  80. <p className = { classes.headerConnectedDevice }>{t('deviceSelection.hid.connectedDevices')}</p>
  81. <div className = { classes.deviceRow }>
  82. <span>{deviceInfo.device?.productName}</span>
  83. <Icon
  84. ariaLabel = { t('deviceSelection.hid.deleteDevice') }
  85. className = { classes.deleteDevice }
  86. onClick = { onDeleteHid }
  87. role = 'button'
  88. src = { IconTrash }
  89. tabIndex = { 0 } />
  90. </div>
  91. </div>
  92. )}
  93. </div>
  94. );
  95. }
  96. export default DeviceHidContainer;