您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

NumbersList.web.js 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. import PropTypes from 'prop-types';
  2. import React, { Component } from 'react';
  3. import { translate } from '../../../base/i18n';
  4. /**
  5. * Displays a table with phone numbers to dial in to a conference.
  6. *
  7. * @extends Component
  8. */
  9. class NumbersList extends Component {
  10. /**
  11. * {@code NumbersList} component's property types.
  12. *
  13. * @static
  14. */
  15. static propTypes = {
  16. /**
  17. * The phone numbers to display. Can be an array of numbers
  18. * or an object with countries as keys and an array of numbers
  19. * as values.
  20. */
  21. numbers: PropTypes.oneOfType([
  22. PropTypes.array,
  23. PropTypes.object
  24. ]),
  25. /**
  26. * Invoked to obtain translated strings.
  27. */
  28. t: PropTypes.func
  29. };
  30. /**
  31. * Implements React's {@link Component#render()}.
  32. *
  33. * @inheritdoc
  34. * @returns {ReactElement}
  35. */
  36. render() {
  37. const { numbers, t } = this.props;
  38. const showWithoutCountries = Array.isArray(numbers);
  39. return (
  40. <table className = 'dial-in-numbers-list'>
  41. <thead>
  42. <tr>
  43. { showWithoutCountries
  44. ? null
  45. : <th>{ t('info.country') }</th> }
  46. <th>{ t('info.numbers') }</th>
  47. </tr>
  48. </thead>
  49. <tbody>
  50. { showWithoutCountries
  51. ? numbers.map(this._renderNumberRow)
  52. : this._renderWithCountries() }
  53. </tbody>
  54. </table>);
  55. }
  56. /**
  57. * Renders rows of countries and associated phone numbers.
  58. *
  59. * @private
  60. * @returns {ReactElement[]}
  61. */
  62. _renderWithCountries() {
  63. const rows = [];
  64. for (const [ country, numbers ] of Object.entries(this.props.numbers)) {
  65. const formattedNumbers = numbers.map(this._renderNumberDiv);
  66. rows.push(
  67. <tr key = { country }>
  68. <td>{ country }</td>
  69. <td className = 'dial-in-numbers'>{ formattedNumbers }</td>
  70. </tr>
  71. );
  72. }
  73. return rows;
  74. }
  75. /**
  76. * Renders a table row for a phone number.
  77. *
  78. * @param {string} number - The phone number to display.
  79. * @private
  80. * @returns {ReactElement[]}
  81. */
  82. _renderNumberRow(number) {
  83. return (
  84. <tr key = { number }>
  85. <td className = 'dial-in-number'>
  86. { number }
  87. </td>
  88. </tr>
  89. );
  90. }
  91. /**
  92. * Renders a div container for a phone number.
  93. *
  94. * @param {string} number - The phone number to display.
  95. * @private
  96. * @returns {ReactElement[]}
  97. */
  98. _renderNumberDiv(number) {
  99. return (
  100. <div
  101. className = 'dial-in-number'
  102. key = { number }>
  103. { number }
  104. </div>
  105. );
  106. }
  107. }
  108. export default translate(NumbersList);