tabs.tsx 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import styled from '@emotion/styled';
  2. import ListLink from 'sentry/components/links/listLink';
  3. import ScrollableTabs from 'sentry/components/replays/scrollableTabs';
  4. import {t} from 'sentry/locale';
  5. import {space} from 'sentry/styles/space';
  6. import {useLocation} from 'sentry/utils/useLocation';
  7. import useUrlParams from 'sentry/utils/useUrlParams';
  8. type Props = {
  9. className?: string;
  10. underlined?: boolean;
  11. };
  12. const TABS = {
  13. details: t('Details'),
  14. request: t('Request'),
  15. response: t('Response'),
  16. };
  17. export type TabKey = keyof typeof TABS;
  18. function NetworkDetailsTabs({className, underlined = true}: Props) {
  19. const {pathname, query} = useLocation();
  20. const {getParamValue, setParamValue} = useUrlParams('n_detail_tab', 'details');
  21. const activeTab = getParamValue();
  22. return (
  23. <ScrollableTabs className={className} underlined={underlined}>
  24. {Object.entries(TABS).map(([tab, label]) => (
  25. <ListLink
  26. key={tab}
  27. isActive={() => tab === activeTab}
  28. to={{
  29. pathname,
  30. query: {...query, t_main: tab},
  31. }}
  32. onClick={e => {
  33. e.preventDefault();
  34. setParamValue(tab);
  35. }}
  36. >
  37. {label}
  38. </ListLink>
  39. ))}
  40. </ScrollableTabs>
  41. );
  42. }
  43. const StyledNetworkDetailsTabs = styled(NetworkDetailsTabs)`
  44. /*
  45. Use padding instead of margin so all the <li> will cover the <SplitDivider>
  46. without taking 100% width.
  47. */
  48. & > li {
  49. margin-right: 0;
  50. padding-right: ${space(3)};
  51. background: ${p => p.theme.surface400};
  52. z-index: ${p => p.theme.zIndex.initial};
  53. }
  54. & > li:first-child {
  55. padding-left: ${space(2)};
  56. }
  57. & > li:last-child {
  58. padding-right: ${space(1)};
  59. }
  60. & > li > a {
  61. padding-top: ${space(1)};
  62. padding-bottom: ${space(0.5)};
  63. height: 100%;
  64. border-bottom: ${space(0.5)} solid transparent;
  65. }
  66. `;
  67. export default StyledNetworkDetailsTabs;