Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

VideoMenuButton.js 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. * @augments {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 synthetic event.
  53. * @returns {void}
  54. */
  55. _onKeyPress(e) {
  56. if (this.props.onClick && (e.key === ' ' || e.key === 'Enter')) {
  57. e.preventDefault();
  58. this.props.onClick();
  59. }
  60. }
  61. /**
  62. * Implements React's {@link Component#render()}.
  63. *
  64. * @inheritdoc
  65. * @returns {ReactElement}
  66. */
  67. render() {
  68. const {
  69. buttonText,
  70. displayClass,
  71. icon,
  72. id,
  73. onClick
  74. } = this.props;
  75. const linkClassName = `popupmenu__link ${displayClass || ''}`;
  76. return (
  77. <li className = 'popupmenu__item'>
  78. <a
  79. aria-label = { buttonText ? buttonText : 'some thing' }
  80. className = { linkClassName }
  81. id = { id }
  82. onClick = { onClick }
  83. onKeyPress = { this._onKeyPress }
  84. role = 'button'
  85. tabIndex = { 0 }>
  86. <span className = 'popupmenu__icon'>
  87. { icon && <Icon src = { icon } /> }
  88. </span>
  89. <span className = 'popupmenu__text'>
  90. { buttonText }
  91. </span>
  92. </a>
  93. </li>
  94. );
  95. }
  96. }