chevronDividedList.tsx 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import {ReactElement} from 'react';
  2. import styled from '@emotion/styled';
  3. import {IconChevron} from 'sentry/icons';
  4. import space from 'sentry/styles/space';
  5. type Props = {
  6. items: ReactElement[];
  7. };
  8. function ChevronDividedList({items}: Props) {
  9. return (
  10. <List cols={items.length}>
  11. {items.flatMap((item, i) => {
  12. const li = <Item key={`${i}-item`}>{item}</Item>;
  13. return i === 0
  14. ? li
  15. : [
  16. <Item key={`${i}-chev`}>
  17. <Chevron>
  18. <IconChevron color="gray300" size="xs" direction="right" />
  19. </Chevron>
  20. </Item>,
  21. li,
  22. ];
  23. })}
  24. </List>
  25. );
  26. }
  27. const List = styled('ul')<{cols: number}>`
  28. padding: 0;
  29. margin: 0;
  30. list-style: none;
  31. display: grid;
  32. gap: ${space(1)};
  33. grid-template-columns: ${p =>
  34. `minmax(auto, max-content) repeat(${
  35. (p.cols - 2) * 2 + 1
  36. }, max-content) minmax(auto, max-content)`};
  37. flex-wrap: nowrap;
  38. align-items: center;
  39. overflow: hidden;
  40. `;
  41. const Item = styled('li')`
  42. display: flex;
  43. flex-direction: column;
  44. overflow: hidden;
  45. `;
  46. const Chevron = styled('span')`
  47. color: ${p => p.theme.gray300};
  48. font-size: ${p => p.theme.fontSizeSmall};
  49. line-height: 1;
  50. `;
  51. export default ChevronDividedList;