Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

DeviceStatus.js 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. // @flow
  2. import { makeStyles } from '@material-ui/styles';
  3. import clsx from 'clsx';
  4. import React from 'react';
  5. import { translate } from '../../../base/i18n';
  6. import { Icon, IconCheckSolid, IconExclamationTriangle } from '../../../base/icons';
  7. import { connect } from '../../../base/redux';
  8. import {
  9. getDeviceStatusType,
  10. getDeviceStatusText
  11. } from '../../functions';
  12. export type Props = {
  13. /**
  14. * The text to be displayed in relation to the status of the audio/video devices.
  15. */
  16. deviceStatusText: string,
  17. /**
  18. * The type of status for current devices, controlling the background color of the text.
  19. * Can be `ok` or `warning`.
  20. */
  21. deviceStatusType: string,
  22. /**
  23. * Used for translation.
  24. */
  25. t: Function
  26. };
  27. const useStyles = makeStyles(theme => {
  28. return {
  29. deviceStatus: {
  30. alignItems: 'center',
  31. color: '#fff',
  32. display: 'flex',
  33. fontSize: '14px',
  34. lineHeight: '20px',
  35. padding: '6px',
  36. textAlign: 'center',
  37. '& span': {
  38. marginLeft: theme.spacing(3)
  39. },
  40. '&.device-status-error': {
  41. alignItems: 'flex-start',
  42. backgroundColor: theme.palette.warning01,
  43. borderRadius: '6px',
  44. color: theme.palette.uiBackground,
  45. padding: '12px 16px',
  46. textAlign: 'left'
  47. },
  48. '& .device-icon': {
  49. backgroundPosition: 'center',
  50. backgroundRepeat: 'no-repeat',
  51. display: 'inline-block',
  52. height: '16px',
  53. width: '16px'
  54. },
  55. '& .device-icon--ok svg path': {
  56. fill: '#189B55'
  57. }
  58. }
  59. };
  60. });
  61. const iconMap = {
  62. warning: {
  63. src: IconExclamationTriangle,
  64. className: 'device-icon--warning'
  65. },
  66. ok: {
  67. src: IconCheckSolid,
  68. className: 'device-icon--ok'
  69. }
  70. };
  71. /**
  72. * Strip showing the current status of the devices.
  73. * User is informed if there are missing or malfunctioning devices.
  74. *
  75. * @returns {ReactElement}
  76. */
  77. function DeviceStatus({ deviceStatusType, deviceStatusText, t }: Props) {
  78. const classes = useStyles();
  79. const { src, className } = iconMap[deviceStatusType];
  80. const hasError = deviceStatusType === 'warning';
  81. const containerClassName = clsx(classes.deviceStatus, { 'device-status-error': hasError });
  82. return (
  83. <div
  84. className = { containerClassName }
  85. role = 'alert'
  86. tabIndex = { -1 }>
  87. <Icon
  88. className = { `device-icon ${className}` }
  89. size = { 16 }
  90. src = { src } />
  91. <span role = 'heading'>
  92. {hasError ? t('prejoin.errorNoPermissions') : t(deviceStatusText)}
  93. </span>
  94. </div>
  95. );
  96. }
  97. /**
  98. * Maps (parts of) the redux state to the React {@code Component} props.
  99. *
  100. * @param {Object} state - The redux state.
  101. * @returns {{ deviceStatusText: string, deviceStatusText: string }}
  102. */
  103. function mapStateToProps(state) {
  104. return {
  105. deviceStatusText: getDeviceStatusText(state),
  106. deviceStatusType: getDeviceStatusType(state)
  107. };
  108. }
  109. export default translate(connect(mapStateToProps)(DeviceStatus));