tabs.tsx 1.9 KB

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