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.

VideoMenuButton.js 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /* @flow */
  2. import React, { Component } from 'react';
  3. import { Icon } from '../../../base/icons';
  4. /**
  5. * The type of the React {@code Component} props of
  6. * {@link VideoMenuButton}.
  7. */
  8. type Props = {
  9. /**
  10. * Text to display within the component that describes the onClick action.
  11. */
  12. buttonText: string,
  13. /**
  14. * Additional CSS classes to add to the component.
  15. */
  16. displayClass?: string,
  17. /**
  18. * The icon that will display within the component.
  19. */
  20. icon?: Object,
  21. /**
  22. * The id attribute to be added to the component's DOM for retrieval when
  23. * querying the DOM. Not used directly by the component.
  24. */
  25. id: string,
  26. /**
  27. * Callback to invoke when the component is clicked.
  28. */
  29. onClick: Function,
  30. };
  31. /**
  32. * React {@code Component} for displaying an action in {@code VideoMenuButton}.
  33. *
  34. * @extends {Component}
  35. */
  36. export default class VideoMenuButton extends Component<Props> {
  37. /**
  38. * Initializes a new {@code RemoteVideoMenuButton} instance.
  39. *
  40. * @param {*} props - The read-only properties with which the new instance
  41. * is to be initialized.
  42. */
  43. constructor(props: Props) {
  44. super(props);
  45. // Bind event handler so it is only bound once for every instance.
  46. this._onKeyPress = this._onKeyPress.bind(this);
  47. }
  48. _onKeyPress: (Object) => void;
  49. /**
  50. * KeyPress handler for accessibility.
  51. *
  52. * @param {Object} e - The key event to handle.
  53. *
  54. * @returns {void}
  55. */
  56. _onKeyPress(e) {
  57. if (this.props.onClick && (e.key === ' ' || e.key === 'Enter')) {
  58. e.preventDefault();
  59. this.props.onClick();
  60. }
  61. }
  62. /**
  63. * Implements React's {@link Component#render()}.
  64. *
  65. * @inheritdoc
  66. * @returns {ReactElement}
  67. */
  68. render() {
  69. const {
  70. buttonText,
  71. displayClass,
  72. icon,
  73. id,
  74. onClick
  75. } = this.props;
  76. const linkClassName = `popupmenu__link ${displayClass || ''}`;
  77. return (
  78. <li className = 'popupmenu__item'>
  79. <a
  80. aria-label = { buttonText ? buttonText : 'some thing' }
  81. className = { linkClassName }
  82. id = { id }
  83. onClick = { onClick }
  84. onKeyPress = { this._onKeyPress }
  85. role = 'button'
  86. tabIndex = { 0 }>
  87. <span className = 'popupmenu__icon'>
  88. { icon && <Icon src = { icon } /> }
  89. </span>
  90. <span className = 'popupmenu__text'>
  91. { buttonText }
  92. </span>
  93. </a>
  94. </li>
  95. );
  96. }
  97. }