sidebar-toggle.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. "use strict";
  6. const { DOM, createClass, PropTypes } = require("devtools/client/shared/vendor/react");
  7. // Shortcuts
  8. const { button } = DOM;
  9. /**
  10. * Sidebar toggle button. This button is used to exapand
  11. * and collapse Sidebar.
  12. */
  13. var SidebarToggle = createClass({
  14. displayName: "SidebarToggle",
  15. propTypes: {
  16. // Set to true if collapsed.
  17. collapsed: PropTypes.bool.isRequired,
  18. // Tooltip text used when the button indicates expanded state.
  19. collapsePaneTitle: PropTypes.string.isRequired,
  20. // Tooltip text used when the button indicates collapsed state.
  21. expandPaneTitle: PropTypes.string.isRequired,
  22. // Click callback
  23. onClick: PropTypes.func.isRequired,
  24. },
  25. getInitialState: function () {
  26. return {
  27. collapsed: this.props.collapsed,
  28. };
  29. },
  30. // Events
  31. onClick: function (event) {
  32. this.props.onClick(event);
  33. },
  34. // Rendering
  35. render: function () {
  36. let title = this.state.collapsed ?
  37. this.props.expandPaneTitle :
  38. this.props.collapsePaneTitle;
  39. let classNames = ["devtools-button", "sidebar-toggle"];
  40. if (this.state.collapsed) {
  41. classNames.push("pane-collapsed");
  42. }
  43. return (
  44. button({
  45. className: classNames.join(" "),
  46. title: title,
  47. onClick: this.onClick
  48. })
  49. );
  50. }
  51. });
  52. module.exports = SidebarToggle;