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.9KB

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