toggleSidebar.tsx 2.0 KB

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