Sidebar.jsx 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import { withTranslation } from 'react-i18next';
  4. import {
  5. withNavigationUIController,
  6. LayoutManager,
  7. NavigationProvider,
  8. ThemeProvider, modeGenerator,
  9. } from '@atlaskit/navigation-next';
  10. import Drawer from '@atlaskit/drawer';
  11. import { createSubscribedElement } from './UnstatedUtils';
  12. import AppContainer from '../services/AppContainer';
  13. import GrowiLogo from './GrowiLogo';
  14. import SidebarNav from './Sidebar/SidebarNav';
  15. import History from './Sidebar/History';
  16. import CustomSidebar from './Sidebar/CustomSidebar';
  17. class Sidebar extends React.Component {
  18. static propTypes = {
  19. navigationUIController: PropTypes.any.isRequired,
  20. };
  21. state = {
  22. currentContentsId: 'custom',
  23. isDrawerOpen: false,
  24. };
  25. openDrawer = () => this.setState({ isDrawerOpen: true });
  26. closeDrawer = () => this.setState({ isDrawerOpen: false });
  27. itemSelectedHandler = (contentsId) => {
  28. const { navigationUIController } = this.props;
  29. const { currentContentsId } = this.state;
  30. // already selected
  31. if (currentContentsId === contentsId) {
  32. navigationUIController.toggleCollapse();
  33. }
  34. // switch and expand
  35. else {
  36. this.setState({ currentContentsId: contentsId });
  37. navigationUIController.expand();
  38. }
  39. // if (contentsId === 'drawer') {
  40. // this.openDrawer();
  41. // }
  42. }
  43. renderGlobalNavigation = () => (
  44. <>
  45. <div className="grw-logo">
  46. <a href="/"><GrowiLogo /></a>
  47. </div>
  48. <SidebarNav currentContentsId={this.state.currentContentsId} onItemSelected={this.itemSelectedHandler} />
  49. <Drawer onClose={this.closeDrawer} isOpen={this.state.isDrawerOpen} width="wide">
  50. <code>Drawer contents</code>
  51. </Drawer>
  52. </>
  53. );
  54. renderSidebarContents = () => {
  55. let contents = <CustomSidebar></CustomSidebar>;
  56. switch (this.state.currentContentsId) {
  57. case 'history':
  58. contents = <History></History>;
  59. break;
  60. }
  61. return contents;
  62. }
  63. render() {
  64. return (
  65. <ThemeProvider
  66. theme={theme => ({
  67. ...theme,
  68. context: 'product',
  69. mode: modeGenerator({
  70. product: { text: '#ffffff', background: '#334455' },
  71. }),
  72. })}
  73. >
  74. <LayoutManager
  75. globalNavigation={this.renderGlobalNavigation}
  76. productNavigation={() => null}
  77. containerNavigation={this.renderSidebarContents}
  78. experimental_hideNavVisuallyOnCollapse
  79. experimental_flyoutOnHover
  80. experimental_alternateFlyoutBehaviour
  81. // experimental_fullWidthFlyout
  82. shouldHideGlobalNavShadow
  83. showContextualNavigation
  84. >
  85. </LayoutManager>
  86. </ThemeProvider>
  87. );
  88. }
  89. }
  90. const SidebarWithNavigationUI = withNavigationUIController(Sidebar);
  91. const SidebarWithNavigationUIAndTranslation = withTranslation()(SidebarWithNavigationUI);
  92. /**
  93. * Wrapper component for using unstated
  94. */
  95. const SidebarWrapper = (props) => {
  96. return createSubscribedElement(SidebarWithNavigationUIAndTranslation, props, [AppContainer]);
  97. };
  98. export default () => (
  99. <NavigationProvider><SidebarWrapper /></NavigationProvider>
  100. );