SidebarNav.jsx 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import { withTranslation } from 'react-i18next';
  4. import {
  5. GlobalNav,
  6. } from '@atlaskit/navigation-next';
  7. import { createSubscribedElement } from '../UnstatedUtils';
  8. import AppContainer from '../../services/AppContainer';
  9. class SidebarNav extends React.Component {
  10. static propTypes = {
  11. currentContentsId: PropTypes.string,
  12. onItemSelected: PropTypes.func,
  13. };
  14. state = {
  15. };
  16. itemSelectedHandler = (contentsId) => {
  17. const { onItemSelected } = this.props;
  18. if (onItemSelected != null) {
  19. onItemSelected(contentsId);
  20. }
  21. }
  22. generateSidebarItemObj(id, label, icon) {
  23. return {
  24. id,
  25. icon,
  26. label,
  27. isSelected: this.props.currentContentsId === id,
  28. onClick: () => this.itemSelectedHandler(id),
  29. };
  30. }
  31. generateIconFactory(classNames) {
  32. return () => <i className={classNames}></i>;
  33. }
  34. render() {
  35. return (
  36. <GlobalNav
  37. primaryItems={[
  38. this.generateSidebarItemObj('custom', 'Custom Sidebar', this.generateIconFactory('fa fa-2x fa-code')),
  39. this.generateSidebarItemObj('history', 'History', this.generateIconFactory('icon-clock fa-2x')),
  40. ]}
  41. secondaryItems={[]}
  42. />
  43. );
  44. }
  45. }
  46. /**
  47. * Wrapper component for using unstated
  48. */
  49. const SidebarNavWrapper = (props) => {
  50. return createSubscribedElement(SidebarNav, props, [AppContainer]);
  51. };
  52. export default withTranslation()(SidebarNavWrapper);