Sidebar.jsx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import { withTranslation } from 'react-i18next';
  4. import AddIcon from '@atlaskit/icon/glyph/add';
  5. import BacklogIcon from '@atlaskit/icon/glyph/backlog';
  6. import BoardIcon from '@atlaskit/icon/glyph/board';
  7. import GraphLineIcon from '@atlaskit/icon/glyph/graph-line';
  8. import ShortcutIcon from '@atlaskit/icon/glyph/shortcut';
  9. import SearchIcon from '@atlaskit/icon/glyph/search';
  10. import { JiraIcon, JiraWordmark } from '@atlaskit/logo';
  11. import {
  12. GlobalNav,
  13. GroupHeading,
  14. HeaderSection,
  15. Item,
  16. LayoutManager,
  17. MenuSection,
  18. NavigationProvider,
  19. Separator,
  20. Wordmark,
  21. } from '@atlaskit/navigation-next';
  22. import Drawer from '@atlaskit/drawer';
  23. import { createSubscribedElement } from './UnstatedUtils';
  24. import AppContainer from '../services/AppContainer';
  25. class GlobalNavigation extends React.Component {
  26. state = {
  27. isDrawerOpen: false,
  28. };
  29. openDrawer = () => this.setState({ isDrawerOpen: true });
  30. closeDrawer = () => this.setState({ isDrawerOpen: false });
  31. render() {
  32. const { isDrawerOpen } = this.state;
  33. return (
  34. <div>
  35. <GlobalNav
  36. primaryItems={[
  37. {
  38. id: 'jira',
  39. icon: () => <JiraIcon size="medium" label="Jira" />,
  40. label: 'Jira',
  41. },
  42. {
  43. id: 'search',
  44. icon: SearchIcon,
  45. label: 'Search',
  46. onClick: this.openDrawer,
  47. },
  48. { id: 'create', icon: AddIcon, label: 'Add' },
  49. ]}
  50. secondaryItems={[]}
  51. />
  52. <Drawer onClose={this.closeDrawer} isOpen={isDrawerOpen} width="wide">
  53. <code>Drawer contents</code>
  54. </Drawer>
  55. </div>
  56. );
  57. }
  58. }
  59. class Sidebar extends React.Component {
  60. constructor(props) {
  61. super(props);
  62. this.state = {
  63. isDrawerOpen: false,
  64. };
  65. this.renderContainerNavigation = this.renderContainerNavigation.bind(this);
  66. }
  67. renderContainerNavigation() {
  68. return (
  69. <div data-webdriver-test-key="container-navigation">
  70. <HeaderSection>
  71. { () => (
  72. <Wordmark wordmark={JiraWordmark} />
  73. ) }
  74. </HeaderSection>
  75. <MenuSection>
  76. {({ className }) => (
  77. <div className={className}>
  78. <Item
  79. before={BacklogIcon}
  80. text="Backlog"
  81. isSelected
  82. />
  83. <Item
  84. before={BoardIcon}
  85. text="Active sprints"
  86. />
  87. <Item
  88. before={GraphLineIcon}
  89. text="Reports"
  90. />
  91. <Separator />
  92. <GroupHeading>Shortcuts</GroupHeading>
  93. <Item before={ShortcutIcon} text="Project space" />
  94. <Item before={ShortcutIcon} text="Project repo" />
  95. </div>
  96. )}
  97. </MenuSection>
  98. </div>
  99. );
  100. }
  101. render() {
  102. return (
  103. <NavigationProvider>
  104. <LayoutManager
  105. globalNavigation={GlobalNavigation}
  106. productNavigation={() => null}
  107. containerNavigation={this.renderContainerNavigation}
  108. >
  109. </LayoutManager>
  110. </NavigationProvider>
  111. );
  112. }
  113. }
  114. /**
  115. * Wrapper component for using unstated
  116. */
  117. const SidebarWrapper = (props) => {
  118. return createSubscribedElement(Sidebar, props, [AppContainer]);
  119. };
  120. Sidebar.propTypes = {
  121. };
  122. export default withTranslation()(SidebarWrapper);