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.

PrimaryToolbar.web.js 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /* @flow */
  2. import PropTypes from 'prop-types';
  3. import React, { Component } from 'react';
  4. import { connect } from 'react-redux';
  5. import { getToolbarClassNames } from '../functions';
  6. import Toolbar from './Toolbar';
  7. declare var interfaceConfig: Object;
  8. /**
  9. * Implementation of PrimaryToolbar React Component.
  10. *
  11. * @class PrimaryToolbar
  12. * @extends Component
  13. */
  14. class PrimaryToolbar extends Component<*, *> {
  15. static propTypes = {
  16. /**
  17. * Contains toolbar buttons for primary toolbar.
  18. */
  19. _primaryToolbarButtons: PropTypes.instanceOf(Map),
  20. /**
  21. * Shows whether toolbox is visible.
  22. */
  23. _visible: PropTypes.bool
  24. };
  25. state: Object;
  26. /**
  27. * Renders primary toolbar component.
  28. *
  29. * @returns {ReactElement}
  30. */
  31. render(): React$Element<*> | null {
  32. const { _primaryToolbarButtons } = this.props;
  33. // The number of buttons to show in the toolbar isn't fixed, it depends
  34. // on the availability of features and configuration parameters. So
  35. // there may be nothing to render.
  36. if (_primaryToolbarButtons.size === 0) {
  37. return null;
  38. }
  39. const { primaryToolbarClassName } = getToolbarClassNames(this.props);
  40. const tooltipPosition
  41. = interfaceConfig.filmStripOnly ? 'left' : 'bottom';
  42. return (
  43. <Toolbar
  44. className = { primaryToolbarClassName }
  45. toolbarButtons = { _primaryToolbarButtons }
  46. tooltipPosition = { tooltipPosition } />
  47. );
  48. }
  49. }
  50. /**
  51. * Maps part of Redux store to React component props.
  52. *
  53. * @param {Object} state - Snapshot of Redux store.
  54. * @returns {{
  55. * _primaryToolbarButtons: Map,
  56. * _visible: boolean
  57. * }}
  58. * @private
  59. */
  60. function _mapStateToProps(state: Object): Object {
  61. const {
  62. primaryToolbarButtons,
  63. visible
  64. } = state['features/toolbox'];
  65. return {
  66. /**
  67. * Default toolbar buttons for primary toolbar.
  68. *
  69. * @private
  70. * @type {Map}
  71. */
  72. _primaryToolbarButtons: primaryToolbarButtons,
  73. /**
  74. * Shows whether toolbox is visible.
  75. *
  76. * @private
  77. * @type {boolean}
  78. */
  79. _visible: visible
  80. };
  81. }
  82. export default connect(_mapStateToProps)(PrimaryToolbar);