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

ContactListItem.web.js 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /* global APP */
  2. import React, { Component } from 'react';
  3. import UIEvents from '../../../../service/UI/UIEvents';
  4. import { Avatar } from '../../base/participants';
  5. /**
  6. * Implements a React {@code Component} for showing a participant's avatar and
  7. * name and emits an event when it has been clicked.
  8. *
  9. * @extends Component
  10. */
  11. class ContactListItem extends Component {
  12. /**
  13. * Default values for {@code ContactListItem} component's properties.
  14. *
  15. * @static
  16. */
  17. static propTypes = {
  18. /**
  19. * The link to the participant's avatar image.
  20. */
  21. avatarURI: React.PropTypes.string,
  22. /**
  23. * An id attribute to set on the root of {@code ContactListItem}. Used
  24. * by the torture tests.
  25. */
  26. id: React.PropTypes.string,
  27. /**
  28. * The participant's display name.
  29. */
  30. name: React.PropTypes.string
  31. };
  32. /**
  33. * Initializes new {@code ContactListItem} instance.
  34. *
  35. * @param {Object} props - The read-only properties with which the new
  36. * instance is to be initialized.
  37. */
  38. constructor(props) {
  39. super(props);
  40. // Bind event handler so it is only bound once for every instance.
  41. this._onClick = this._onClick.bind(this);
  42. }
  43. /**
  44. * Implements React's {@link Component#render()}.
  45. *
  46. * @inheritdoc
  47. * @returns {ReactElement}
  48. */
  49. render() {
  50. return (
  51. <li
  52. className = 'clickable contact-list-item'
  53. id = { this.props.id }
  54. onClick = { this._onClick }>
  55. { this.props.avatarURI ? this._renderAvatar() : null }
  56. <p className = 'contact-list-item-name'>
  57. { this.props.name }
  58. </p>
  59. </li>
  60. );
  61. }
  62. /**
  63. * Emits an event notifying the contact list item for the passed in
  64. * participant ID has been clicked.
  65. *
  66. * @private
  67. * @returns {void}
  68. */
  69. _onClick() {
  70. // FIXME move this call to a pinning action, which is what's happening
  71. // on the listener end, when the listener is properly hooked into redux.
  72. APP.UI.emitEvent(UIEvents.CONTACT_CLICKED, this.props.id);
  73. }
  74. /**
  75. * Renders the React Element for displaying the participant's avatar image.
  76. *
  77. * @private
  78. * @returns {ReactElement}
  79. */
  80. _renderAvatar() {
  81. return (
  82. <Avatar
  83. className = 'icon-avatar avatar'
  84. uri = { this.props.avatarURI } />
  85. );
  86. }
  87. }
  88. export default ContactListItem;