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

DeviceStatus.tsx 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. import React from 'react';
  2. import { WithTranslation } from 'react-i18next';
  3. import { connect } from 'react-redux';
  4. import { makeStyles } from 'tss-react/mui';
  5. import { IReduxState } from '../../../../app/types';
  6. import { translate } from '../../../../base/i18n/functions';
  7. import { withPixelLineHeight } from '../../../../base/styles/functions.web';
  8. import {
  9. getDeviceStatusText,
  10. getDeviceStatusType
  11. } from '../../../functions';
  12. export interface IProps extends WithTranslation {
  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. const useStyles = makeStyles()(theme => {
  24. return {
  25. deviceStatus: {
  26. display: 'flex',
  27. alignItems: 'center',
  28. justifyContent: 'center',
  29. ...withPixelLineHeight(theme.typography.bodyShortRegular),
  30. color: '#fff',
  31. marginTop: theme.spacing(4),
  32. '& span': {
  33. marginLeft: theme.spacing(3)
  34. },
  35. '&.device-status-error': {
  36. alignItems: 'flex-start',
  37. backgroundColor: theme.palette.warning01,
  38. borderRadius: '6px',
  39. color: theme.palette.uiBackground,
  40. padding: '12px 16px',
  41. textAlign: 'left',
  42. marginTop: theme.spacing(2)
  43. },
  44. '@media (max-width: 720px)': {
  45. marginTop: 0
  46. }
  47. },
  48. indicator: {
  49. width: '16px',
  50. height: '16px',
  51. borderRadius: '100%',
  52. backgroundColor: theme.palette.success01
  53. }
  54. };
  55. });
  56. /**
  57. * Strip showing the current status of the devices.
  58. * User is informed if there are missing or malfunctioning devices.
  59. *
  60. * @returns {ReactElement}
  61. */
  62. function DeviceStatus({ deviceStatusType, deviceStatusText, t }: IProps) {
  63. const { classes, cx } = useStyles();
  64. const hasError = deviceStatusType === 'warning';
  65. const containerClassName = cx(classes.deviceStatus, { 'device-status-error': hasError });
  66. return (
  67. <div
  68. className = { containerClassName }
  69. role = 'alert'
  70. tabIndex = { -1 }>
  71. {!hasError && <div className = { classes.indicator } />}
  72. <span role = 'heading'>
  73. {hasError ? t('prejoin.errorNoPermissions') : t(deviceStatusText ?? '')}
  74. </span>
  75. </div>
  76. );
  77. }
  78. /**
  79. * Maps (parts of) the redux state to the React {@code Component} props.
  80. *
  81. * @param {Object} state - The redux state.
  82. * @returns {{ deviceStatusText: string, deviceStatusText: string }}
  83. */
  84. function mapStateToProps(state: IReduxState) {
  85. return {
  86. deviceStatusText: getDeviceStatusText(state),
  87. deviceStatusType: getDeviceStatusType(state)
  88. };
  89. }
  90. export default translate(connect(mapStateToProps)(DeviceStatus));