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.

WorkspaceHeader.tsx 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2022 SonarSource SA
  4. * mailto:info AT sonarsource DOT com
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 3 of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. import * as React from 'react';
  21. import { DraggableCore, DraggableData } from 'react-draggable';
  22. import { ButtonIcon } from '../../components/controls/buttons';
  23. import ClearIcon from '../../components/icons/ClearIcon';
  24. import CollapseIcon from '../../components/icons/CollapseIcon';
  25. import ExpandIcon from '../../components/icons/ExpandIcon';
  26. import { IconProps } from '../../components/icons/Icon';
  27. import MinimizeIcon from '../../components/icons/MinimizeIcon';
  28. import { translate } from '../../helpers/l10n';
  29. export interface Props {
  30. children: React.ReactNode;
  31. maximized?: boolean;
  32. onClose: () => void;
  33. onCollapse: () => void;
  34. onMaximize: () => void;
  35. onMinimize: () => void;
  36. onResize: (deltaY: number) => void;
  37. }
  38. export default class WorkspaceHeader extends React.PureComponent<Props> {
  39. handleDrag = (_event: MouseEvent, data: DraggableData) => {
  40. this.props.onResize(data.deltaY);
  41. };
  42. render() {
  43. return (
  44. <header className="workspace-viewer-header">
  45. <h6 className="workspace-viewer-name">{this.props.children}</h6>
  46. <DraggableCore offsetParent={document.body} onDrag={this.handleDrag}>
  47. <div className="workspace-viewer-resize js-resize" />
  48. </DraggableCore>
  49. <div className="workspace-viewer-actions">
  50. <WorkspaceHeaderButton
  51. icon={MinimizeIcon}
  52. onClick={this.props.onCollapse}
  53. tooltip="workspace.minimize"
  54. />
  55. {this.props.maximized ? (
  56. <WorkspaceHeaderButton
  57. icon={CollapseIcon}
  58. onClick={this.props.onMinimize}
  59. tooltip="workspace.normal_size"
  60. />
  61. ) : (
  62. <WorkspaceHeaderButton
  63. icon={ExpandIcon}
  64. onClick={this.props.onMaximize}
  65. tooltip="workspace.full_window"
  66. />
  67. )}
  68. <WorkspaceHeaderButton
  69. icon={ClearIcon}
  70. onClick={this.props.onClose}
  71. tooltip="workspace.close"
  72. />
  73. </div>
  74. </header>
  75. );
  76. }
  77. }
  78. interface WorkspaceHeaderButtonProps {
  79. icon: React.SFC<IconProps>;
  80. onClick: () => void;
  81. tooltip: string;
  82. }
  83. function WorkspaceHeaderButton({ icon: Icon, onClick, tooltip }: WorkspaceHeaderButtonProps) {
  84. return (
  85. <ButtonIcon
  86. className="workspace-header-icon"
  87. color="#fff"
  88. onClick={onClick}
  89. tooltip={translate(tooltip)}>
  90. <Icon fill={undefined} />
  91. </ButtonIcon>
  92. );
  93. }