toggleSidebar.tsx 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import styled from '@emotion/styled';
  2. import {Button} from 'sentry/components/button';
  3. import {IconChevron} from 'sentry/icons/iconChevron';
  4. import {t} from 'sentry/locale';
  5. import {space} from 'sentry/styles/space';
  6. import {useIssueDetails} from 'sentry/views/issueDetails/streamline/context';
  7. export function ToggleSidebar({size = 'lg'}: {size?: 'lg' | 'sm'}) {
  8. const {isSidebarOpen, dispatch} = useIssueDetails();
  9. const direction = isSidebarOpen ? 'right' : 'left';
  10. return (
  11. <ToggleContainer
  12. sidebarOpen={isSidebarOpen ?? true}
  13. style={{paddingTop: size === 'lg' ? '4px' : '0px'}}
  14. >
  15. <ToggleButton
  16. onClick={() => dispatch({type: 'UPDATE_SIDEBAR_STATE', isOpen: !isSidebarOpen})}
  17. aria-label={isSidebarOpen ? t('Close sidebar') : t('Open sidebar')}
  18. style={{height: size === 'lg' ? '30px' : '26px'}}
  19. analyticsEventKey="issue_details.sidebar_toggle"
  20. analyticsEventName="Issue Details: Sidebar Toggle"
  21. analyticsParams={{
  22. sidebar_open: !isSidebarOpen,
  23. }}
  24. >
  25. <LeftChevron direction={direction} />
  26. <RightChevron direction={direction} />
  27. </ToggleButton>
  28. </ToggleContainer>
  29. );
  30. }
  31. const ToggleContainer = styled('div')<{sidebarOpen: boolean}>`
  32. width: ${p => (p.sidebarOpen ? '30px' : '50px')};
  33. position: relative;
  34. @media (max-width: ${p => p.theme.breakpoints.large}) {
  35. display: none;
  36. }
  37. `;
  38. // The extra 1px on width is to display above the sidebar border
  39. const ToggleButton = styled(Button)`
  40. border-radius: ${p => p.theme.borderRadiusLeft};
  41. border-right-color: ${p => p.theme.background} !important;
  42. box-shadow: none;
  43. position: absolute;
  44. padding: 0;
  45. left: ${space(0.5)};
  46. width: calc(100% - ${space(0.5)} + 1px);
  47. outline: 0;
  48. min-height: unset;
  49. `;
  50. const LeftChevron = styled(IconChevron)`
  51. position: absolute;
  52. color: ${p => p.theme.subText};
  53. height: 10px;
  54. width: 10px;
  55. left: ${space(0.75)};
  56. `;
  57. const RightChevron = styled(LeftChevron)`
  58. left: ${space(1.5)};
  59. `;